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