mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-25 03:57:58 +01:00
Improve JingleS5BTransportInfo by introducing abstract class
Introduce a abstract class for shared functionality. And remove static lazy getters.
This commit is contained in:
parent
b8ee8d808f
commit
ed9eae4793
4 changed files with 62 additions and 100 deletions
|
@ -133,19 +133,19 @@ public class JingleS5BTransport extends JingleContentTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setCandidateUsed(String candidateId) {
|
public Builder setCandidateUsed(String candidateId) {
|
||||||
return setTransportInfo(JingleS5BTransportInfo.CandidateUsed(candidateId));
|
return setTransportInfo(new JingleS5BTransportInfo.CandidateUsed(candidateId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setCandidateActivated(String candidateId) {
|
public Builder setCandidateActivated(String candidateId) {
|
||||||
return setTransportInfo(JingleS5BTransportInfo.CandidateActivated(candidateId));
|
return setTransportInfo(new JingleS5BTransportInfo.CandidateActivated(candidateId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setCandidateError() {
|
public Builder setCandidateError() {
|
||||||
return setTransportInfo(JingleS5BTransportInfo.CandidateError());
|
return setTransportInfo(JingleS5BTransportInfo.CandidateError.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProxyError() {
|
public Builder setProxyError() {
|
||||||
return setTransportInfo(JingleS5BTransportInfo.ProxyError());
|
return setTransportInfo(JingleS5BTransportInfo.ProxyError.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleS5BTransport build() {
|
public JingleS5BTransport build() {
|
||||||
|
|
|
@ -24,116 +24,76 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfo;
|
||||||
*/
|
*/
|
||||||
public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo {
|
public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo {
|
||||||
|
|
||||||
private static CandidateError CEI;
|
public static abstract class JingleS5BCandidateTransportInfo extends JingleS5BTransportInfo {
|
||||||
private static ProxyError PEI;
|
|
||||||
|
|
||||||
public static CandidateUsed CandidateUsed(String candidateId) {
|
|
||||||
return new CandidateUsed(candidateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CandidateActivated CandidateActivated(String candidateId) {
|
|
||||||
return new CandidateActivated(candidateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CandidateError CandidateError() {
|
|
||||||
if (CEI == null) {
|
|
||||||
CEI = new CandidateError();
|
|
||||||
}
|
|
||||||
return CEI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ProxyError ProxyError() {
|
|
||||||
if (PEI == null) {
|
|
||||||
PEI = new ProxyError();
|
|
||||||
}
|
|
||||||
return PEI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class CandidateActivated extends JingleS5BTransportInfo {
|
|
||||||
public static final String ELEMENT = "candidate-activated";
|
|
||||||
public static final String ATTR_CID = "cid";
|
public static final String ATTR_CID = "cid";
|
||||||
|
|
||||||
private final String candidateId;
|
private final String candidateId;
|
||||||
|
|
||||||
|
protected JingleS5BCandidateTransportInfo(String candidateId) {
|
||||||
|
this.candidateId = candidateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getCandidateId() {
|
||||||
|
return candidateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final XmlStringBuilder toXML() {
|
||||||
|
XmlStringBuilder xml = new XmlStringBuilder();
|
||||||
|
xml.halfOpenElement(this);
|
||||||
|
xml.attribute(ATTR_CID, getCandidateId());
|
||||||
|
xml.closeEmptyElement();
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean equals(Object other) {
|
||||||
|
if (!(other instanceof JingleS5BCandidateTransportInfo)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
JingleS5BCandidateTransportInfo otherCandidateTransportInfo = (JingleS5BCandidateTransportInfo) other;
|
||||||
|
return toXML().equals(otherCandidateTransportInfo.toXML());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int hashCode() {
|
||||||
|
return getCandidateId().hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class CandidateActivated extends JingleS5BCandidateTransportInfo {
|
||||||
|
public static final String ELEMENT = "candidate-activated";
|
||||||
|
|
||||||
public CandidateActivated(String candidateId) {
|
public CandidateActivated(String candidateId) {
|
||||||
this.candidateId = candidateId;
|
super(candidateId);
|
||||||
}
|
|
||||||
|
|
||||||
public String getCandidateId() {
|
|
||||||
return candidateId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getElementName() {
|
public String getElementName() {
|
||||||
return ELEMENT;
|
return ELEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence toXML() {
|
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(this);
|
|
||||||
xml.attribute(ATTR_CID, candidateId);
|
|
||||||
xml.closeEmptyElement();
|
|
||||||
return xml;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
return other instanceof CandidateActivated &&
|
|
||||||
((CandidateActivated) other).getCandidateId().equals(candidateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return toXML().toString().hashCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CandidateUsed extends JingleS5BTransportInfo {
|
public static final class CandidateUsed extends JingleS5BCandidateTransportInfo {
|
||||||
public static final String ELEMENT = "candidate-used";
|
public static final String ELEMENT = "candidate-used";
|
||||||
public static final String ATTR_CID = "cid";
|
|
||||||
|
|
||||||
private final String candidateId;
|
|
||||||
|
|
||||||
public CandidateUsed(String candidateId) {
|
public CandidateUsed(String candidateId) {
|
||||||
this.candidateId = candidateId;
|
super(candidateId);
|
||||||
}
|
|
||||||
|
|
||||||
public String getCandidateId() {
|
|
||||||
return candidateId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getElementName() {
|
public String getElementName() {
|
||||||
return ELEMENT;
|
return ELEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence toXML() {
|
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(this);
|
|
||||||
xml.attribute(ATTR_CID, candidateId);
|
|
||||||
xml.closeEmptyElement();
|
|
||||||
return xml;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
return other instanceof CandidateUsed &&
|
|
||||||
((CandidateUsed) other).getCandidateId().equals(candidateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return toXML().toString().hashCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CandidateError extends JingleS5BTransportInfo {
|
public static final class CandidateError extends JingleS5BTransportInfo {
|
||||||
|
public static final CandidateError INSTANCE = new CandidateError();
|
||||||
|
|
||||||
public static final String ELEMENT = "candidate-error";
|
public static final String ELEMENT = "candidate-error";
|
||||||
|
|
||||||
private CandidateError() {
|
private CandidateError() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,7 +102,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
XmlStringBuilder xml = new XmlStringBuilder();
|
||||||
xml.halfOpenElement(this);
|
xml.halfOpenElement(this);
|
||||||
xml.closeEmptyElement();
|
xml.closeEmptyElement();
|
||||||
|
@ -151,7 +111,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return other instanceof CandidateError;
|
return other == INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -161,10 +121,11 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class ProxyError extends JingleS5BTransportInfo {
|
public static final class ProxyError extends JingleS5BTransportInfo {
|
||||||
|
public static final ProxyError INSTANCE = new ProxyError();
|
||||||
|
|
||||||
public static final String ELEMENT = "proxy-error";
|
public static final String ELEMENT = "proxy-error";
|
||||||
|
|
||||||
private ProxyError() {
|
private ProxyError() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -182,7 +143,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return other instanceof ProxyError;
|
return other == INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
|
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
|
||||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate;
|
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportInfo;
|
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||||
|
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportInfo.JingleS5BCandidateTransportInfo;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
|
@ -83,23 +84,23 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
||||||
builder.setTransportInfo(JingleS5BTransportInfo.CandidateActivated(
|
builder.setTransportInfo(new JingleS5BTransportInfo.CandidateActivated(
|
||||||
parser.getAttributeValue(null,
|
parser.getAttributeValue(null,
|
||||||
JingleS5BTransportInfo.CandidateActivated.ATTR_CID)));
|
JingleS5BCandidateTransportInfo.ATTR_CID)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
||||||
builder.setTransportInfo(JingleS5BTransportInfo.CandidateUsed(
|
builder.setTransportInfo(new JingleS5BTransportInfo.CandidateUsed(
|
||||||
parser.getAttributeValue(null,
|
parser.getAttributeValue(null,
|
||||||
JingleS5BTransportInfo.CandidateUsed.ATTR_CID)));
|
JingleS5BCandidateTransportInfo.ATTR_CID)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
||||||
builder.setTransportInfo(JingleS5BTransportInfo.CandidateError());
|
builder.setTransportInfo(JingleS5BTransportInfo.CandidateError.INSTANCE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||||
builder.setTransportInfo(JingleS5BTransportInfo.ProxyError());
|
builder.setTransportInfo(JingleS5BTransportInfo.ProxyError.INSTANCE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
||||||
assertNull(candidateErrorTransport.getDestinationAddress());
|
assertNull(candidateErrorTransport.getDestinationAddress());
|
||||||
assertNotNull(candidateErrorTransport.getInfo());
|
assertNotNull(candidateErrorTransport.getInfo());
|
||||||
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
||||||
assertEquals(JingleS5BTransportInfo.CandidateError(),
|
assertEquals(JingleS5BTransportInfo.CandidateError.INSTANCE,
|
||||||
candidateErrorTransport.getInfo());
|
candidateErrorTransport.getInfo());
|
||||||
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
||||||
assertNotNull(proxyErrorTransport.getInfo());
|
assertNotNull(proxyErrorTransport.getInfo());
|
||||||
assertNotNull(candidateErrorTransport.getInfo());
|
assertNotNull(candidateErrorTransport.getInfo());
|
||||||
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
||||||
assertEquals(JingleS5BTransportInfo.ProxyError(),
|
assertEquals(JingleS5BTransportInfo.ProxyError.INSTANCE,
|
||||||
proxyErrorTransport.getInfo());
|
proxyErrorTransport.getInfo());
|
||||||
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
||||||
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
|
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
|
||||||
.parse(TestUtils.getParser(candidateUsed));
|
.parse(TestUtils.getParser(candidateUsed));
|
||||||
assertNotNull(candidateUsedTransport.getInfo());
|
assertNotNull(candidateUsedTransport.getInfo());
|
||||||
assertEquals(JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
|
assertEquals(new JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
|
||||||
candidateUsedTransport.getInfo());
|
candidateUsedTransport.getInfo());
|
||||||
assertEquals("hr65dqyd",
|
assertEquals("hr65dqyd",
|
||||||
((JingleS5BTransportInfo.CandidateUsed)
|
((JingleS5BTransportInfo.CandidateUsed)
|
||||||
|
@ -168,7 +168,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
||||||
assertNotNull(candidateActivatedTransport.getInfo());
|
assertNotNull(candidateActivatedTransport.getInfo());
|
||||||
assertNotNull(candidateErrorTransport.getInfo());
|
assertNotNull(candidateErrorTransport.getInfo());
|
||||||
|
|
||||||
assertEquals(JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
|
assertEquals(new JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
|
||||||
candidateActivatedTransport.getInfo());
|
candidateActivatedTransport.getInfo());
|
||||||
assertEquals("hr65dqyd",
|
assertEquals("hr65dqyd",
|
||||||
((JingleS5BTransportInfo.CandidateActivated)
|
((JingleS5BTransportInfo.CandidateActivated)
|
||||||
|
|
Loading…
Reference in a new issue