001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.bytestreams.ibb.packet;
018
019import org.jivesoftware.smack.packet.IQ;
020
021/**
022 * Represents a chunk of data sent over an In-Band Bytestream encapsulated in an
023 * IQ stanza.
024 * 
025 * @author Henning Staib
026 */
027public class Data extends IQ {
028
029    /* the data packet extension */
030    private final DataPacketExtension dataPacketExtension;
031
032    /**
033     * Constructor.
034     * 
035     * @param data data packet extension containing the encoded data
036     */
037    public Data(DataPacketExtension data) {
038        if (data == null) {
039            throw new IllegalArgumentException("Data must not be null");
040        }
041        this.dataPacketExtension = data;
042
043        /*
044         * also set as packet extension so that data packet extension can be
045         * retrieved from IQ stanza and message stanza in the same way
046         */
047        addExtension(data);
048        setType(IQ.Type.SET);
049    }
050
051    /**
052     * Returns the data packet extension.
053     * <p>
054     * Convenience method for <code>packet.getExtension("data",
055     * "http://jabber.org/protocol/ibb")</code>.
056     * 
057     * @return the data packet extension
058     */
059    public DataPacketExtension getDataPacketExtension() {
060        return this.dataPacketExtension;
061    }
062
063    public String getChildElementXML() {
064        return this.dataPacketExtension.toXML();
065    }
066
067}