Search in sources :

Example 21 with IServiceTypeID

use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.

the class JSLPServiceIDTest method testCreateServiceTypeIDWithProviderSpecificString.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testCreateServiceTypeIDFromInternalString()
	 */
public void testCreateServiceTypeIDWithProviderSpecificString() {
    final String internalRep = "service:foo.eclipse:bar";
    IServiceTypeID stid = (IServiceTypeID) new JSLPNamespace().createInstance(new Object[] { internalRep });
    assertEquals(internalRep, stid.getInternal());
    assertTrue(stid.getName().startsWith("_foo._bar"));
    assertTrue(stid.getName().endsWith("._eclipse"));
    assertEquals("eclipse", stid.getNamingAuthority());
    assertTrue(Arrays.equals(new String[] { "foo", "bar" }, stid.getServices()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_PROTO, stid.getProtocols()));
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) JSLPNamespace(org.eclipse.ecf.provider.jslp.identity.JSLPNamespace)

Example 22 with IServiceTypeID

use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.

the class DnsSdTestHelper method createServiceInfo.

public static IServiceInfo createServiceInfo(Namespace namespace) {
    final Properties props = new Properties();
    final URI uri = URI.create(SCHEME + "://" + DOMAIN_A_RECORD + ":" + PORT + PATH);
    IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(namespace, new String[] { SCHEME }, new String[] { DOMAIN }, new String[] { PROTO }, NAMING_AUTH);
    final ServiceProperties serviceProperties = new ServiceProperties(props);
    serviceProperties.setPropertyString("path", PATH);
    serviceProperties.setPropertyString("dns-sd.ptcl", SCHEME);
    return new ServiceInfo(uri, DOMAIN_A_RECORD, serviceTypeID, 10, 0, serviceProperties);
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) Properties(java.util.Properties) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) URI(java.net.URI)

Example 23 with IServiceTypeID

use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.

the class DnsSdDiscoveryLocator method getServiceInfos.

private List getServiceInfos(Collection srvQueryResult) {
    List infos = new ArrayList();
    for (Iterator iterator = srvQueryResult.iterator(); iterator.hasNext(); ) {
        SRVRecord srvRecord = (SRVRecord) iterator.next();
        long ttl = srvRecord.getTTL();
        int priority = srvRecord.getPriority();
        int weight = srvRecord.getWeight();
        int port = srvRecord.getPort();
        Name target = srvRecord.getTarget();
        String host = target.toString();
        host = host.substring(0, host.length() - 1);
        IServiceTypeID aServiceTypeID = new DnsSdServiceTypeID(getConnectNamespace(), srvRecord.getName());
        // query for txt records (attributes)
        Properties props = new Properties();
        Lookup txtQuery = new Lookup(srvRecord.getName(), Type.TXT);
        txtQuery.setResolver(resolver);
        Record[] txtQueryResults = txtQuery.run();
        int length = txtQueryResults == null ? 0 : txtQueryResults.length;
        for (int l = 0; l < length; l++) {
            TXTRecord txtResult = (TXTRecord) txtQueryResults[l];
            List strings = txtResult.getStrings();
            for (Iterator itr = strings.iterator(); itr.hasNext(); ) {
                String str = (String) itr.next();
                // $NON-NLS-1$
                String[] split = str.split("=");
                props.put(split[0], split[1]);
            }
        }
        String path = props.getProperty(DNS_SD_PATH);
        String proto = props.getProperty(DNS_SD_PTCL) == null ? aServiceTypeID.getProtocols()[0] : props.getProperty(DNS_SD_PTCL);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        URI uri = URI.create(proto + "://" + host + ":" + port + (path == null ? "" : path));
        IServiceInfo info = new ServiceInfo(uri, host, aServiceTypeID, priority, weight, new ServiceProperties(props), ttl);
        infos.add(info);
    }
    return infos;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) URI(java.net.URI) Name(org.xbill.DNS.Name) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) TXTRecord(org.xbill.DNS.TXTRecord) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Lookup(org.xbill.DNS.Lookup) PTRRecord(org.xbill.DNS.PTRRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) TXTRecord(org.xbill.DNS.TXTRecord) SRVRecord(org.xbill.DNS.SRVRecord)

Example 24 with IServiceTypeID

use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.

the class DnsSdDiscoveryLocator method getServiceTypes.

private IServiceTypeID[] getServiceTypes(final DnsSdServiceTypeID serviceTypeId) {
    List result = new ArrayList();
    Record[] queryResult = getRecords(serviceTypeId);
    for (int j = 0; j < queryResult.length; j++) {
        Record record = queryResult[j];
        if (record instanceof PTRRecord) {
            PTRRecord ptrRecord = (PTRRecord) record;
            result.add(new DnsSdServiceTypeID(getServicesNamespace(), ptrRecord.getTarget()));
        } else if (record instanceof SRVRecord) {
            SRVRecord srvRecord = (SRVRecord) record;
            result.add(new DnsSdServiceTypeID(getServicesNamespace(), srvRecord.getName()));
        }
    }
    return (IServiceTypeID[]) result.toArray(new IServiceTypeID[result.size()]);
}
Also used : PTRRecord(org.xbill.DNS.PTRRecord) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PTRRecord(org.xbill.DNS.PTRRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) TXTRecord(org.xbill.DNS.TXTRecord) SRVRecord(org.xbill.DNS.SRVRecord)

Example 25 with IServiceTypeID

use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.

the class DnsSdNamespace method createInstance.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[])
	 */
public ID createInstance(Object[] parameters) throws IDCreateException {
    if (parameters != null && parameters.length == 1 && parameters[0] instanceof String) {
        String str = (String) parameters[0];
        return new DnsSdServiceTypeID(this, str);
    } else if (parameters != null && parameters.length == 1 && parameters[0] instanceof IServiceTypeID) {
        IServiceTypeID serviceTypeID = (IServiceTypeID) parameters[0];
        return new DnsSdServiceTypeID(this, serviceTypeID);
    } else if (parameters != null && parameters.length == 1 && parameters[0] instanceof IServiceID) {
        IServiceID serviceID = (IServiceID) parameters[0];
        return new DnsSdServiceTypeID(this, serviceID.getServiceTypeID());
    } else if (parameters != null && parameters.length == 1 && parameters[0] instanceof StringID) {
        StringID stringID = (StringID) parameters[0];
        return new DnsSdServiceTypeID(this, stringID.getName());
    } else if (parameters != null && parameters.length == 2 && parameters[0] instanceof IServiceTypeID && parameters[1] instanceof URI) {
        IServiceTypeID serviceTypeID = (IServiceTypeID) parameters[0];
        URI uri = (URI) parameters[1];
        return new DnsSdServiceID(this, new DnsSdServiceTypeID(this, serviceTypeID), uri);
    } else if (parameters != null && parameters.length == 2 && parameters[0] instanceof String && parameters[1] instanceof URI) {
        String serviceType = (String) parameters[0];
        URI uri = (URI) parameters[1];
        return new DnsSdServiceID(this, new DnsSdServiceTypeID(this, serviceType), uri);
    } else {
        throw new IDCreateException(Messages.DnsSdNamespace_Wrong_Parameters);
    }
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) StringID(org.eclipse.ecf.core.identity.StringID) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) URI(java.net.URI)

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