JingleContentTransport.java

  1. /**
  2.  *
  3.  * Copyright 2017-2021 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.jingle.element;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import org.jivesoftware.smack.packet.XmlElement;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.util.XmlStringBuilder;

  23. /**
  24.  * A jingle transport extension.
  25.  *
  26.  */
  27. public abstract class JingleContentTransport implements XmlElement {

  28.     public static final String ELEMENT = "transport";

  29.     protected final List<JingleContentTransportCandidate> candidates;
  30.     protected final JingleContentTransportInfo info;

  31.     protected JingleContentTransport(List<JingleContentTransportCandidate> candidates) {
  32.         this(candidates, null);
  33.     }

  34.     protected JingleContentTransport(List<JingleContentTransportCandidate> candidates, JingleContentTransportInfo info) {
  35.         if (candidates != null) {
  36.             this.candidates = Collections.unmodifiableList(candidates);
  37.         }
  38.         else {
  39.             this.candidates = Collections.emptyList();
  40.         }

  41.         this.info = info;
  42.     }

  43.     public List<JingleContentTransportCandidate> getCandidates() {
  44.         return candidates;
  45.     }

  46.     public JingleContentTransportInfo getInfo() {
  47.         return info;
  48.     }

  49.     @Override
  50.     public String getElementName() {
  51.         return ELEMENT;
  52.     }

  53.     protected void addExtraAttributes(XmlStringBuilder xml) {

  54.     }

  55.     @Override
  56.     public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
  57.         XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
  58.         addExtraAttributes(xml);

  59.         if (candidates.isEmpty() && info == null) {
  60.             xml.closeEmptyElement();

  61.         } else {

  62.             xml.rightAngleBracket();
  63.             xml.append(candidates);
  64.             xml.optElement(info);
  65.             xml.closeElement(this);
  66.         }

  67.         return xml;
  68.     }
  69. }