Search in sources :

Example 1 with IServiceTypeID

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");
    }
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 2 with IServiceTypeID

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;
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID)

Example 3 with IServiceTypeID

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());
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) JSLPNamespace(org.eclipse.ecf.provider.jslp.identity.JSLPNamespace) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 4 with IServiceTypeID

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);
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) JSLPNamespace(org.eclipse.ecf.provider.jslp.identity.JSLPNamespace) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 5 with IServiceTypeID

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()));
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID)

Aggregations

IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)35 Namespace (org.eclipse.ecf.core.identity.Namespace)10 URI (java.net.URI)9 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)9 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)5 JSLPNamespace (org.eclipse.ecf.provider.jslp.identity.JSLPNamespace)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)4 ServiceURL (ch.ethz.iks.slp.ServiceURL)3 ServiceProperties (org.eclipse.ecf.discovery.ServiceProperties)3 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 Map (java.util.Map)2 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)2 ServiceTypeID (org.eclipse.ecf.discovery.identity.ServiceTypeID)2 ServicePropertiesAdapter (org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter)2 ServiceURLAdapter (org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter)2 JSLPServiceInfo (org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo)2 PTRRecord (org.xbill.DNS.PTRRecord)2