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()));
}
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);
}
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;
}
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()]);
}
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);
}
}
Aggregations