diff options
author | mkuppe | 2007-11-30 12:32:23 +0000 |
---|---|---|
committer | mkuppe | 2007-11-30 12:32:23 +0000 |
commit | 2ebbca8f0f43d9574763581605ba1d96bfb1094b (patch) | |
tree | 1711e32f2287b028c10404a9e1d436485eaabec4 /framework/bundles/org.eclipse.ecf.discovery | |
parent | 468482788af817a5c89ad7cd4e5664ff396753a9 (diff) | |
download | org.eclipse.ecf-2ebbca8f0f43d9574763581605ba1d96bfb1094b.tar.gz org.eclipse.ecf-2ebbca8f0f43d9574763581605ba1d96bfb1094b.tar.xz org.eclipse.ecf-2ebbca8f0f43d9574763581605ba1d96bfb1094b.zip |
NEW - bug 211585: [Discovery][JMDNS] parsing problem if service type defines a naming authority
https://bugs.eclipse.org/bugs/show_bug.cgi?id=211585
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.discovery')
-rw-r--r-- | framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/identity/ServiceTypeID.java | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/identity/ServiceTypeID.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/identity/ServiceTypeID.java index c6471f51e..105e94347 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/identity/ServiceTypeID.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/identity/ServiceTypeID.java @@ -57,33 +57,48 @@ public class ServiceTypeID extends BaseID implements IServiceTypeID { this(ns, id.getServices(), id.getScopes(), id.getProtocols(), id.getNamingAuthority()); } - public ServiceTypeID(String aType) throws IDCreateException { - if (aType == null) - throw new IDCreateException(Messages.ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_NULL); - try { - // remove the leading _ - String type = aType.substring(1); - - String[] split = StringUtils.split(type, "_"); //$NON-NLS-1$ - // naming authority - int offset = split.length - 1; - this.namingAuthority = split[offset]; - - // protocol and scope - String string = split[--offset]; - String[] protoAndScope = StringUtils.split(string, ".", string.indexOf(".") - 1); //$NON-NLS-1$ //$NON-NLS-2$ - this.protocols = new String[] {protoAndScope[0]}; - this.scopes = new String[] {protoAndScope[1]}; - - // services are the remaining strings in the array - List subList = Arrays.asList(split).subList(0, offset); - this.services = (String[]) subList.toArray(new String[0]); - - createType(); - } catch (Exception e) { - throw new IDCreateException(Messages.ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_PARSEABLE, e); + public ServiceTypeID(Namespace namespace, String aType) throws IDCreateException { + this(namespace); + if (aType != null) { + try { + // sanitize (remove the leading _, dangling . or white spaces + aType = aType.trim(); + if (aType.endsWith(".")) { //$NON-NLS-1$ + aType = aType.substring(0, aType.length() - 1); + } + + // attach naming authority to simplify parsing if not present + int lastDot = aType.lastIndexOf('.'); + int lastUnderscore = aType.lastIndexOf('_'); + if (lastDot + 1 != lastUnderscore) { + aType = aType + "._" + DEFAULT_NA; //$NON-NLS-1$ + } + + String type = aType.substring(1); + + String[] split = StringUtils.split(type, "._"); //$NON-NLS-1$ + // naming authority + int offset = split.length - 1; + this.namingAuthority = split[offset]; + + // protocol and scope + String string = split[--offset]; + String[] protoAndScope = StringUtils.split(string, ".", string.indexOf(".") - 1); //$NON-NLS-1$ //$NON-NLS-2$ + this.protocols = new String[] {protoAndScope[0]}; + this.scopes = new String[] {protoAndScope[1]}; + + // services are the remaining strings in the array + List subList = Arrays.asList(split).subList(0, offset); + this.services = (String[]) subList.toArray(new String[0]); + + createType(); + Assert.isTrue(aType.equals(typeName)); + } catch (Exception e) { + throw new IDCreateException(Messages.ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_PARSEABLE, e); + } + } else { + throw new IDCreateException(Messages.ServiceTypeID_EXCEPTION_SERVICE_TYPE_ID_NOT_PARSEABLE); } - Assert.isTrue(aType.equals(typeName)); } protected void createType() { |