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;
020import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
021
022/**
023 * Represents a request to close an In-Band Bytestream.
024 * 
025 * @author Henning Staib
026 */
027public class Close extends IQ {
028
029    /* unique session ID identifying this In-Band Bytestream */
030    private final String sessionID;
031
032    /**
033     * Creates a new In-Band Bytestream close request packet.
034     * 
035     * @param sessionID unique session ID identifying this In-Band Bytestream
036     */
037    public Close(String sessionID) {
038        if (sessionID == null || "".equals(sessionID)) {
039            throw new IllegalArgumentException("Session ID must not be null or empty");
040        }
041        this.sessionID = sessionID;
042        setType(Type.SET);
043    }
044
045    /**
046     * Returns the unique session ID identifying this In-Band Bytestream.
047     * 
048     * @return the unique session ID identifying this In-Band Bytestream
049     */
050    public String getSessionID() {
051        return sessionID;
052    }
053
054    @Override
055    public String getChildElementXML() {
056        StringBuilder buf = new StringBuilder();
057        buf.append("<close ");
058        buf.append("xmlns=\"");
059        buf.append(InBandBytestreamManager.NAMESPACE);
060        buf.append("\" ");
061        buf.append("sid=\"");
062        buf.append(sessionID);
063        buf.append("\"");
064        buf.append("/>");
065        return buf.toString();
066    }
067
068}