mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 16:22:06 +01:00
Merge pull request #145 from vanitasvitae/singleJingleTransport
Switch to single transport instead of list
This commit is contained in:
commit
1d53889874
5 changed files with 18 additions and 47 deletions
|
@ -16,10 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle.element;
|
package org.jivesoftware.smackx.jingle.element;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.NamedElement;
|
import org.jivesoftware.smack.packet.NamedElement;
|
||||||
import org.jivesoftware.smack.util.Objects;
|
import org.jivesoftware.smack.util.Objects;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
@ -70,24 +66,19 @@ public final class JingleContent implements NamedElement {
|
||||||
|
|
||||||
private final JingleContentDescription description;
|
private final JingleContentDescription description;
|
||||||
|
|
||||||
private final List<JingleContentTransport> transports;
|
private final JingleContentTransport transport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a content description..
|
* Creates a content description..
|
||||||
*/
|
*/
|
||||||
private JingleContent(Creator creator, String disposition, String name, Senders senders,
|
private JingleContent(Creator creator, String disposition, String name, Senders senders,
|
||||||
JingleContentDescription description, List<JingleContentTransport> transports) {
|
JingleContentDescription description, JingleContentTransport transport) {
|
||||||
this.creator = Objects.requireNonNull(creator, "Jingle content creator must not be null");
|
this.creator = Objects.requireNonNull(creator, "Jingle content creator must not be null");
|
||||||
this.disposition = disposition;
|
this.disposition = disposition;
|
||||||
this.name = StringUtils.requireNotNullOrEmpty(name, "Jingle content name must not be null or empty");
|
this.name = StringUtils.requireNotNullOrEmpty(name, "Jingle content name must not be null or empty");
|
||||||
this.senders = senders;
|
this.senders = senders;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
if (transports != null) {
|
this.transport = transport;
|
||||||
this.transports = Collections.unmodifiableList(transports);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.transports = Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Creator getCreator() {
|
public Creator getCreator() {
|
||||||
|
@ -120,17 +111,8 @@ public final class JingleContent implements NamedElement {
|
||||||
*
|
*
|
||||||
* @return an Iterator for the JingleTransports in the packet.
|
* @return an Iterator for the JingleTransports in the packet.
|
||||||
*/
|
*/
|
||||||
public List<JingleContentTransport> getJingleTransports() {
|
public JingleContentTransport getJingleTransport() {
|
||||||
return transports;
|
return transport;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a count of the JingleTransports in the Jingle packet.
|
|
||||||
*
|
|
||||||
* @return the number of the JingleTransports in the Jingle packet.
|
|
||||||
*/
|
|
||||||
public int getJingleTransportsCount() {
|
|
||||||
return transports.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,8 +130,7 @@ public final class JingleContent implements NamedElement {
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
|
|
||||||
xml.optAppend(description);
|
xml.optAppend(description);
|
||||||
|
xml.optElement(transport);
|
||||||
xml.append(transports);
|
|
||||||
|
|
||||||
xml.closeElement(this);
|
xml.closeElement(this);
|
||||||
return xml;
|
return xml;
|
||||||
|
@ -170,7 +151,7 @@ public final class JingleContent implements NamedElement {
|
||||||
|
|
||||||
private JingleContentDescription description;
|
private JingleContentDescription description;
|
||||||
|
|
||||||
private List<JingleContentTransport> transports;
|
private JingleContentTransport transport;
|
||||||
|
|
||||||
private Builder() {
|
private Builder() {
|
||||||
}
|
}
|
||||||
|
@ -203,16 +184,13 @@ public final class JingleContent implements NamedElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addTransport(JingleContentTransport transport) {
|
public Builder setTransport(JingleContentTransport transport) {
|
||||||
if (transports == null) {
|
this.transport = transport;
|
||||||
transports = new ArrayList<>(4);
|
|
||||||
}
|
|
||||||
transports.add(transport);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleContent build() {
|
public JingleContent build() {
|
||||||
return new JingleContent(creator, disposition, name, senders, description, transports);
|
return new JingleContent(creator, disposition, name, senders, description, transport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,13 @@ public abstract class JingleContentTransport implements ExtensionElement {
|
||||||
public static final String ELEMENT = "transport";
|
public static final String ELEMENT = "transport";
|
||||||
|
|
||||||
protected final List<JingleContentTransportCandidate> candidates;
|
protected final List<JingleContentTransportCandidate> candidates;
|
||||||
protected final List<JingleContentTransportInfo> infos;
|
protected final JingleContentTransportInfo info;
|
||||||
|
|
||||||
protected JingleContentTransport(List<JingleContentTransportCandidate> candidates) {
|
protected JingleContentTransport(List<JingleContentTransportCandidate> candidates) {
|
||||||
this(candidates, null);
|
this(candidates, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JingleContentTransport(List<JingleContentTransportCandidate> candidates, List<JingleContentTransportInfo> infos) {
|
protected JingleContentTransport(List<JingleContentTransportCandidate> candidates, JingleContentTransportInfo info) {
|
||||||
if (candidates != null) {
|
if (candidates != null) {
|
||||||
this.candidates = Collections.unmodifiableList(candidates);
|
this.candidates = Collections.unmodifiableList(candidates);
|
||||||
}
|
}
|
||||||
|
@ -45,19 +45,15 @@ public abstract class JingleContentTransport implements ExtensionElement {
|
||||||
this.candidates = Collections.emptyList();
|
this.candidates = Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infos != null) {
|
this.info = info;
|
||||||
this.infos = infos;
|
|
||||||
} else {
|
|
||||||
this.infos = Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JingleContentTransportCandidate> getCandidates() {
|
public List<JingleContentTransportCandidate> getCandidates() {
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JingleContentTransportInfo> getInfos() {
|
public JingleContentTransportInfo getInfo() {
|
||||||
return infos;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,7 +77,7 @@ public abstract class JingleContentTransport implements ExtensionElement {
|
||||||
|
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
xml.append(candidates);
|
xml.append(candidates);
|
||||||
xml.append(infos);
|
xml.optElement(info);
|
||||||
xml.closeElement(this);
|
xml.closeElement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class JingleProvider extends IQProvider<Jingle> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
JingleContentTransport transport = provider.parse(parser);
|
JingleContentTransport transport = provider.parse(parser);
|
||||||
builder.addTransport(transport);
|
builder.setTransport(transport);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class JingleActionTest extends SmackTestSuite {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void nonExistendEnumTest() {
|
public void nonExistentEnumTest() {
|
||||||
JingleAction.fromString("inexistent-action");
|
JingleAction.fromString("inexistent-action");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,6 @@ public class JingleContentTest extends SmackTestSuite {
|
||||||
assertNotSame(content.toXML().toString(), content1.toXML().toString());
|
assertNotSame(content.toXML().toString(), content1.toXML().toString());
|
||||||
assertEquals(content1.toXML().toString(), builder.build().toXML().toString());
|
assertEquals(content1.toXML().toString(), builder.build().toXML().toString());
|
||||||
|
|
||||||
assertEquals(0, content.getJingleTransportsCount());
|
|
||||||
assertNotNull(content.getJingleTransports());
|
|
||||||
|
|
||||||
String xml =
|
String xml =
|
||||||
"<content creator='initiator' disposition='session' name='A name' senders='both'>" +
|
"<content creator='initiator' disposition='session' name='A name' senders='both'>" +
|
||||||
"</content>";
|
"</content>";
|
||||||
|
|
Loading…
Reference in a new issue