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 stanza extension containing the encoded data
036     */
037    @SuppressWarnings("this-escape")
038    public Data(DataPacketExtension data) {
039        super(DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE);
040        if (data == null) {
041            throw new IllegalArgumentException("Data must not be null");
042        }
043        this.dataPacketExtension = data;
044
045        setType(IQ.Type.set);
046    }
047
048    /**
049     * Returns the data stanza extension.
050     *
051     * @return the data stanza extension
052     */
053    public DataPacketExtension getDataPacketExtension() {
054        return this.dataPacketExtension;
055    }
056
057    @Override
058    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
059        return dataPacketExtension.getIQChildElementBuilder(xml);
060    }
061
062}