001/**
002 *
003 * Copyright 2017 Florian Schmaus.
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.jingle.element;
018
019import java.util.Collections;
020import java.util.List;
021
022import org.jivesoftware.smack.packet.ExtensionElement;
023import org.jivesoftware.smack.packet.NamedElement;
024import org.jivesoftware.smack.util.XmlStringBuilder;
025
026/**
027 * Jingle content description.
028 *
029 */
030public abstract class JingleContentDescription implements ExtensionElement {
031
032    public static final String ELEMENT = "description";
033
034    private final List<NamedElement> payloads;
035
036    protected JingleContentDescription(List<? extends NamedElement> payloads) {
037        if (payloads != null) {
038            this.payloads = Collections.unmodifiableList(payloads);
039        }
040        else {
041            this.payloads = Collections.emptyList();
042        }
043    }
044
045    @Override
046    public String getElementName() {
047        return ELEMENT;
048    }
049
050    public List<NamedElement> getJingleContentDescriptionChildren() {
051        return payloads;
052    }
053
054    protected void addExtraAttributes(XmlStringBuilder xml) {
055
056    }
057
058    @Override
059    public XmlStringBuilder toXML(String enclosingNamespace) {
060        XmlStringBuilder xml = new XmlStringBuilder(this);
061        addExtraAttributes(xml);
062        xml.rightAngleBracket();
063
064        xml.append(payloads);
065
066        xml.closeElement(this);
067        return xml;
068    }
069
070}