Home | History | Annotate | Download | only in packet
      1 /**
      2  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      3  * you may not use this file except in compliance with the License.
      4  * You may obtain a copy of the License at
      5  *
      6  *     http://www.apache.org/licenses/LICENSE-2.0
      7  *
      8  * Unless required by applicable law or agreed to in writing, software
      9  * distributed under the License is distributed on an "AS IS" BASIS,
     10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11  * See the License for the specific language governing permissions and
     12  * limitations under the License.
     13  */
     14 package org.jivesoftware.smackx.bytestreams.ibb.packet;
     15 
     16 import org.jivesoftware.smack.packet.IQ;
     17 
     18 /**
     19  * Represents a chunk of data sent over an In-Band Bytestream encapsulated in an
     20  * IQ stanza.
     21  *
     22  * @author Henning Staib
     23  */
     24 public class Data extends IQ {
     25 
     26     /* the data packet extension */
     27     private final DataPacketExtension dataPacketExtension;
     28 
     29     /**
     30      * Constructor.
     31      *
     32      * @param data data packet extension containing the encoded data
     33      */
     34     public Data(DataPacketExtension data) {
     35         if (data == null) {
     36             throw new IllegalArgumentException("Data must not be null");
     37         }
     38         this.dataPacketExtension = data;
     39 
     40         /*
     41          * also set as packet extension so that data packet extension can be
     42          * retrieved from IQ stanza and message stanza in the same way
     43          */
     44         addExtension(data);
     45         setType(IQ.Type.SET);
     46     }
     47 
     48     /**
     49      * Returns the data packet extension.
     50      * <p>
     51      * Convenience method for <code>packet.getExtension("data",
     52      * "http://jabber.org/protocol/ibb")</code>.
     53      *
     54      * @return the data packet extension
     55      */
     56     public DataPacketExtension getDataPacketExtension() {
     57         return this.dataPacketExtension;
     58     }
     59 
     60     public String getChildElementXML() {
     61         return this.dataPacketExtension.toXML();
     62     }
     63 
     64 }
     65