1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-06-19 18:14:52 +02:00
Smack/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContent.java
Florian Schmaus 3d4e7938a7 Make ExtensionElement marker interface wrt. QNAME field
ExtensionElement is now a marker interface that requires all
implementation non-abstract classes to carry a static final QNAME
field (of type QName). This is verified by a new unit test.

Also FullyQualifiedElement is renamed to simply XmlElement. XmlElement
is used over ExtensionElement when implementing classes do not
statically know the qualified name of the XML elements they
represent. In general, XmlElement should be used sparingly, and every
XML element should be modeled by its own Java class (implementing
ExtensionElement).
2021-04-18 21:07:19 +02:00

215 lines
5.9 KiB
Java

/**
*
* Copyright 2017-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.element;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Jingle content element.
*/
public final class JingleContent implements XmlElement {
public static final String ELEMENT = "content";
public static final String NAMESPACE = Jingle.NAMESPACE;
public static final String CREATOR_ATTRIBUTE_NAME = "creator";
public enum Creator {
initiator,
responder,
}
/**
* Which party originally generated the content type. Defined values are 'initiator' and 'responder'. Default is
* 'initiator'.
*/
private final Creator creator;
public static final String DISPOSITION_ATTRIBUTE_NAME = "disposition";
private final String disposition;
public static final String NAME_ATTRIBUTE_NAME = "name";
private final String name;
public static final String SENDERS_ATTRIBUTE_NAME = "senders";
public enum Senders {
both,
initiator,
none,
responder,
}
/**
* Which parties in the session will be generation the content. Defined values are 'both', 'initiator', 'none' and
* 'responder. Default is 'both'.
*/
private final Senders senders;
private final JingleContentDescription description;
private final JingleContentTransport transport;
/**
* Creates a content description..
*/
private JingleContent(Creator creator, String disposition, String name, Senders senders,
JingleContentDescription description, JingleContentTransport transport) {
this.creator = Objects.requireNonNull(creator, "Jingle content creator must not be null");
this.disposition = disposition;
this.name = StringUtils.requireNotNullNorEmpty(name, "Jingle content name must not be null nor empty");
this.senders = senders;
this.description = description;
this.transport = transport;
}
public Creator getCreator() {
return creator;
}
public String getDisposition() {
return disposition;
}
public String getName() {
return name;
}
public Senders getSenders() {
return senders;
}
/**
* Gets the description for this Jingle content.
*
* @return The description.
*/
public JingleContentDescription getDescription() {
return description;
}
/**
* Returns an Iterator for the JingleTransports in the packet.
*
* @return an Iterator for the JingleTransports in the packet.
* @deprecated use {@link #getTransport()} instead.
*/
@Deprecated
public JingleContentTransport getJingleTransport() {
return getTransport();
}
/**
* Returns an Iterator for the JingleTransports in the packet.
*
* @return an Iterator for the JingleTransports in the packet.
*/
public JingleContentTransport getTransport() {
return transport;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment) {
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingXmlEnvironment);
xml.attribute(CREATOR_ATTRIBUTE_NAME, creator);
xml.optAttribute(DISPOSITION_ATTRIBUTE_NAME, disposition);
xml.attribute(NAME_ATTRIBUTE_NAME, name);
xml.optAttribute(SENDERS_ATTRIBUTE_NAME, senders);
xml.rightAngleBracket();
xml.optAppend(description);
xml.optElement(transport);
xml.closeElement(this);
return xml;
}
public static Builder getBuilder() {
return new Builder();
}
public static final class Builder {
private Creator creator;
private String disposition;
private String name;
private Senders senders;
private JingleContentDescription description;
private JingleContentTransport transport;
private Builder() {
}
public Builder setCreator(Creator creator) {
this.creator = creator;
return this;
}
public Builder setDisposition(String disposition) {
this.disposition = disposition;
return this;
}
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder setSenders(Senders senders) {
this.senders = senders;
return this;
}
public Builder setDescription(JingleContentDescription description) {
if (this.description != null) {
throw new IllegalStateException("Jingle content description already set");
}
this.description = description;
return this;
}
public Builder setTransport(JingleContentTransport transport) {
this.transport = transport;
return this;
}
public JingleContent build() {
return new JingleContent(creator, disposition, name, senders, description, transport);
}
}
}