Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-05-14 01:54:55 -0400
committerslewis2008-05-14 01:54:55 -0400
commitf561ff685d9173e6adabc8298bbacc1404f1f53d (patch)
tree0db726115951ff105ff5773ece786274d6562325 /framework/bundles/org.eclipse.ecf.identity/src
parentca28e56059e28b378ca912510b7ab9b85da370f8 (diff)
downloadorg.eclipse.ecf-f561ff685d9173e6adabc8298bbacc1404f1f53d.tar.gz
org.eclipse.ecf-f561ff685d9173e6adabc8298bbacc1404f1f53d.tar.xz
org.eclipse.ecf-f561ff685d9173e6adabc8298bbacc1404f1f53d.zip
Fix for 231969
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.identity/src')
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java39
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java26
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/StringID.java27
3 files changed, 80 insertions, 12 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java
index 4a7349d0d..3e725d943 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java
@@ -11,6 +11,7 @@ package org.eclipse.ecf.core.identity;
import java.security.SecureRandom;
import org.eclipse.ecf.core.util.Base64;
import org.eclipse.ecf.internal.core.identity.Messages;
+import org.eclipse.osgi.util.NLS;
/**
* Globally unique ID implementation class. Uses
@@ -28,15 +29,37 @@ public class GUID extends StringID {
super(GUID.class.getName(), Messages.GUID_GUID_Namespace_Description_Default);
}
+ private String getInitFromExternalForm(Object[] args) {
+ if (args == null || args.length < 1 || args[0] == null)
+ return null;
+ if (args[0] instanceof String) {
+ String arg = (String) args[0];
+ if (arg.startsWith(getScheme() + Namespace.SCHEME_SEPARATOR)) {
+ int index = arg.indexOf(Namespace.SCHEME_SEPARATOR);
+ if (index >= arg.length())
+ return null;
+ return arg.substring(index + 1);
+ }
+ }
+ return null;
+ }
+
public ID createInstance(Object[] args) throws IDCreateException {
- if (args == null || args.length <= 0)
- return new GUID(this);
- else if (args.length == 1 && args[0] instanceof Integer)
- return new GUID(this, ((Integer) args[0]).intValue());
- else if (args.length == 1 && args[0] instanceof String)
- return new GUID(this, ((String) args[0]));
- else
- return new GUID(this);
+ try {
+ String init = getInitFromExternalForm(args);
+ if (init != null)
+ return new GUID(this, init);
+ if (args == null || args.length <= 0)
+ return new GUID(this);
+ else if (args.length == 1 && args[0] instanceof Integer)
+ return new GUID(this, ((Integer) args[0]).intValue());
+ else if (args.length == 1 && args[0] instanceof String)
+ return new GUID(this, ((String) args[0]));
+ else
+ return new GUID(this);
+ } catch (Exception e) {
+ throw new IDCreateException(NLS.bind("{0} createInstance()", getName()), e); //$NON-NLS-1$
+ }
}
public String getScheme() {
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java
index 48942c18f..d091008dc 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java
@@ -8,6 +8,8 @@
******************************************************************************/
package org.eclipse.ecf.core.identity;
+import org.eclipse.osgi.util.NLS;
+
/**
* A unique ID class based upon Long/long
*
@@ -24,13 +26,35 @@ public class LongID extends BaseID {
super(LongID.class.getName(), "LongID Namespace"); //$NON-NLS-1$
}
+ private String getInitFromExternalForm(Object[] args) {
+ if (args == null || args.length < 1 || args[0] == null)
+ return null;
+ if (args[0] instanceof String) {
+ String arg = (String) args[0];
+ if (arg.startsWith(getScheme() + Namespace.SCHEME_SEPARATOR)) {
+ int index = arg.indexOf(Namespace.SCHEME_SEPARATOR);
+ if (index >= arg.length())
+ return null;
+ return arg.substring(index + 1);
+ }
+ }
+ return null;
+ }
+
/**
* @param args must not be <code>null></code>
* @return ID created. Will not be <code>null</code>.
* @throws IDCreateException never thrown
*/
public ID createInstance(Object[] args) throws IDCreateException {
- return new LongID(this, (Long) args[0]);
+ try {
+ String init = getInitFromExternalForm(args);
+ if (init != null)
+ return new LongID(this, Long.decode(init));
+ return new LongID(this, (Long) args[0]);
+ } catch (Exception e) {
+ throw new IDCreateException(NLS.bind("{0} createInstance()", getName()), e); //$NON-NLS-1$
+ }
}
public String getScheme() {
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/StringID.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/StringID.java
index 2b2e2df0b..9e4a3b457 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/StringID.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/StringID.java
@@ -8,6 +8,8 @@
******************************************************************************/
package org.eclipse.ecf.core.identity;
+import org.eclipse.osgi.util.NLS;
+
/**
* A string-based identity
*
@@ -26,11 +28,30 @@ public class StringID extends BaseID {
super(StringID.class.getName(), "StringID Namespace"); //$NON-NLS-1$
}
+ private String getInitFromExternalForm(Object[] args) {
+ if (args == null || args.length < 1 || args[0] == null)
+ return null;
+ if (args[0] instanceof String) {
+ String arg = (String) args[0];
+ if (arg.startsWith(getScheme() + Namespace.SCHEME_SEPARATOR)) {
+ int index = arg.indexOf(Namespace.SCHEME_SEPARATOR);
+ if (index >= arg.length())
+ return null;
+ return arg.substring(index + 1);
+ }
+ }
+ return null;
+ }
+
public ID createInstance(Object[] parameters) throws IDCreateException {
- if (parameters == null || parameters.length == 0) {
- throw new IDCreateException("StringID name cannot be null"); //$NON-NLS-1$
+ try {
+ String init = getInitFromExternalForm(parameters);
+ if (init != null)
+ return new StringID(this, init);
+ return new StringID(this, (String) parameters[0]);
+ } catch (Exception e) {
+ throw new IDCreateException(NLS.bind("{0} createInstance()", StringIDNamespace.this.getName()), e); //$NON-NLS-1$
}
- return new StringID(this, (String) parameters[0]);
}
public String getScheme() {

Back to the top