use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class JMDNSNamespace method createInstance.
/* (non-Javadoc)
* @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[])
*/
public ID createInstance(final Object[] parameters) {
String type = null;
try {
final String init = getInitFromExternalForm(parameters);
if (init != null)
type = init;
else {
if (parameters == null || parameters.length < 1 || parameters.length > 2) {
// $NON-NLS-1$
throw new IDCreateException("Parameters cannot be null and must be of length 1 or 2");
}
if (parameters[0] instanceof IServiceTypeID) {
type = ((IServiceTypeID) parameters[0]).getName();
} else if (parameters[0] instanceof String) {
type = (String) parameters[0];
} else
// $NON-NLS-1$
throw new IDCreateException("Service type id parameter has to be of type String or IServiceTypeID");
}
} catch (final Exception e) {
// $NON-NLS-1$
throw new IDCreateException(getName() + " createInstance()", e);
}
final JMDNSServiceTypeID stid = new JMDNSServiceTypeID(this, type);
if (parameters.length == 1) {
return stid;
} else if (parameters[1] instanceof String) {
try {
final URI uri = new URI((String) parameters[1]);
return new JMDNSServiceID(this, stid, uri);
} catch (URISyntaxException e) {
// $NON-NLS-1$
throw new IDCreateException("Second parameter as String must follow URI syntax");
}
} else if (parameters[1] instanceof URI) {
return new JMDNSServiceID(this, stid, (URI) parameters[1]);
} else {
// $NON-NLS-1$
throw new IDCreateException("Second parameter must be of either String or URI type");
}
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServiceTypeComparator method compare.
/*
* (non-Javadoc)
*
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(final Object object1, final Object object2) {
Assert.isNotNull(object1);
Assert.isNotNull(object2);
if (object1 == object2) {
return 0;
}
if (object1.equals(object2)) {
return 0;
}
if (object1 instanceof IServiceTypeID && object2 instanceof IServiceTypeID) {
final IServiceTypeID type1 = (IServiceTypeID) object1;
final IServiceTypeID type2 = (IServiceTypeID) object2;
final String name1 = type1.getNamingAuthority();
final String name2 = type2.getNamingAuthority();
if (// $NON-NLS-1$ //$NON-NLS-2$
!name1.equals("*") && !name2.equals("*") && !name1.equals(name2)) {
return -1;
}
final String[] services1 = type1.getServices();
final String[] services2 = type2.getServices();
if (// $NON-NLS-1$ //$NON-NLS-2$
!services1[0].equals("*") && !services2[0].equals("*") && !Arrays.equals(services1, services2)) {
return -1;
}
final String[] protocols1 = type1.getProtocols();
final String[] protocols2 = type2.getProtocols();
if (// $NON-NLS-1$ //$NON-NLS-2$
!protocols1[0].equals("*") && !protocols2[0].equals("*") && !Arrays.equals(protocols1, protocols2)) {
return -1;
}
final String[] scopes1 = type1.getScopes();
final String[] scopes2 = type2.getScopes();
if (// $NON-NLS-1$ //$NON-NLS-2$
!scopes1[0].equals("*") && !scopes2[0].equals("*") && !Arrays.equals(scopes1, scopes2)) {
return -1;
}
return 0;
}
return -1;
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class JSLPServiceIDTest method testjSLPDefaultsToECF.
public void testjSLPDefaultsToECF() {
Namespace namespaceByName = IDFactory.getDefault().getNamespaceByName(namespace);
IServiceTypeID stid = ServiceIDFactory.getDefault().createServiceTypeID(namespaceByName, DiscoveryTestHelper.SERVICES, new String[] { DiscoveryTestHelper.SCOPE }, DiscoveryTestHelper.PROTOCOLS, DiscoveryTestHelper.NAMINGAUTHORITY);
assertNotNull(stid);
assertEquals(DiscoveryTestHelper.NAMINGAUTHORITY, stid.getNamingAuthority());
assertEquals("_ecf._junit._tests._someProtocol." + DiscoveryTestHelper.SCOPE + "._" + DiscoveryTestHelper.NAMINGAUTHORITY, stid.getName());
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class JSLPServiceIDTest method testECFDefaultsTojSLP.
public void testECFDefaultsTojSLP() {
Namespace namespaceByName = IDFactory.getDefault().getNamespaceByName(namespace);
IServiceTypeID stid = ServiceIDFactory.getDefault().createServiceTypeID(namespaceByName, DiscoveryTestHelper.SERVICES, DiscoveryTestHelper.PROTOCOLS);
assertNotNull(stid);
assertTrue(Arrays.equals(DiscoveryTestHelper.SERVICES, stid.getServices()));
assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
assertTrue(Arrays.equals(DiscoveryTestHelper.PROTOCOLS, stid.getProtocols()));
String internal = stid.getInternal();
assertEquals("service:" + DiscoveryTestHelper.SERVICES[0] + ":" + DiscoveryTestHelper.SERVICES[1] + ":" + DiscoveryTestHelper.SERVICES[2], internal);
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class JSLPServiceIDTest method testRemoveServicePrefixECFtojSLP.
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testCreateServiceTypeIDFromInternalString()
*
* test from ECF discovery -> jSLP
*/
public void testRemoveServicePrefixECFtojSLP() throws ServiceLocationException {
final IServiceTypeID stid = (IServiceTypeID) createIDFromString(DiscoveryTestHelper.SERVICE_TYPE);
assertEquals("service:" + DiscoveryTestHelper.SERVICES[0] + "." + DiscoveryTestHelper.NAMINGAUTHORITY + ":" + DiscoveryTestHelper.SERVICES[1] + ":" + DiscoveryTestHelper.SERVICES[2], stid.getInternal());
assertEquals(DiscoveryTestHelper.SERVICE_TYPE, stid.getName());
assertEquals(DiscoveryTestHelper.NAMINGAUTHORITY, stid.getNamingAuthority());
assertTrue(Arrays.equals(DiscoveryTestHelper.SERVICES, stid.getServices()));
assertTrue(Arrays.equals(new String[] { DiscoveryTestHelper.SCOPE }, stid.getScopes()));
assertTrue(Arrays.equals(new String[] { DiscoveryTestHelper.PROTOCOL }, stid.getProtocols()));
}
Aggregations