Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF2
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java1
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/URIID.java49
-rw-r--r--tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java137
4 files changed, 187 insertions, 2 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF
index 331f2bb12..66ee45953 100644
--- a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf.identity;singleton:=true
-Bundle-Version: 3.1.100.qualifier
+Bundle-Version: 3.1.200.qualifier
Bundle-Activator: org.eclipse.ecf.internal.core.identity.Activator
Bundle-Localization: plugin
Bundle-Vendor: %plugin.provider
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java
index c040aed6e..7bbadf36a 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java
@@ -36,6 +36,7 @@ public class IDFactory implements IIDFactory {
addNamespace0(new StringID.StringIDNamespace());
addNamespace0(new GUID.GUIDNamespace());
addNamespace0(new LongID.LongNamespace());
+ addNamespace0(new URIID.URIIDNamespace());
}
private synchronized static void initialize() {
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/URIID.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/URIID.java
index 5c76c2ed0..661fbc7d0 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/URIID.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/URIID.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+ * Copyright (c) 2011 Composent and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -19,6 +19,49 @@ import org.eclipse.core.runtime.Assert;
*/
public class URIID extends BaseID implements IResourceID {
+ static class URIIDNamespace extends Namespace {
+
+ private static final long serialVersionUID = 115165512542491014L;
+
+ public URIIDNamespace(String name, String desc) {
+ super(name, desc);
+ }
+
+ public URIIDNamespace() {
+ super(URIID.class.getName(), "URIID Namespace"); //$NON-NLS-1$
+ }
+
+ public ID createInstance(Object[] parameters) throws IDCreateException {
+ try {
+ String init = getInitStringFromExternalForm(parameters);
+ if (init != null)
+ return new URIID(this, new URI(init));
+ if (parameters[0] instanceof URI)
+ return new URIID(this, (URI) parameters[0]);
+ if (parameters[0] instanceof String)
+ return new URIID(this, new URI((String) parameters[0]));
+ throw new IDCreateException("Cannot create URIID");
+ } catch (Exception e) {
+ throw new IDCreateException(URIIDNamespace.this.getName()
+ + " createInstance()", e); //$NON-NLS-1$
+ }
+ }
+
+ public String getScheme() {
+ return "uri";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ecf.core.identity.Namespace#
+ * getSupportedParameterTypesForCreateInstance()
+ */
+ public Class[][] getSupportedParameterTypes() {
+ return new Class[][] { { String.class }, { URI.class } };
+ }
+ }
+
private static final long serialVersionUID = 7328962407044918278L;
private final URI uri;
@@ -56,4 +99,8 @@ public class URIID extends BaseID implements IResourceID {
return uri;
}
+ public String toString() {
+ return "URIID [uri=" + uri + "]";
+ }
+
}
diff --git a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java
new file mode 100644
index 000000000..c962348b8
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/core/identity/URIIDTest.java
@@ -0,0 +1,137 @@
+/****************************************************************************
+* Copyright (c) 2011 Composent, Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* Composent, Inc. - initial API and implementation
+*****************************************************************************/
+package org.eclipse.ecf.tests.core.identity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.NotSerializableException;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.identity.URIID;
+
+public class URIIDTest extends IDAbstractTestCase {
+
+ public static final String URIIDNAMESPACE = URIID.class.getName();
+ public static final String URI1 = "http://lala/lala/lala";
+ public static final String URI2 = "zooo:barbarbarbarbarbarbarbar";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.IDTestCase#createID()
+ */
+ protected ID createID() throws IDCreateException {
+ return createID(URI1);
+ }
+
+ protected ID createID(String val) throws IDCreateException {
+ return IDFactory.getDefault().createID(URIIDNAMESPACE,val);
+ }
+
+ public void testCreate() throws Exception {
+ final ID newID = createID();
+ assertNotNull(newID);
+ }
+
+ public void testNullCreate() throws Exception {
+ try {
+ createID(null);
+ fail();
+ } catch (final IDCreateException e) {
+ // success
+ }
+ }
+
+ public void testGetName() throws Exception {
+ final ID id = createID(URI1);
+ assertTrue(id.getName().equals(URI1));
+ }
+
+ public void testToExternalForm() throws Exception {
+ final ID id = createID(URI1);
+ assertNotNull(id.toExternalForm());
+ }
+
+ public void testToString() throws Exception {
+ final ID id = createID(URI1);
+ assertNotNull(id.toString());
+ }
+
+ public void testIsEqual() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ assertTrue(id1.equals(id2));
+ }
+
+ public void testHashCode() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ assertTrue(id1.hashCode() == id2.hashCode());
+ }
+
+ public void testCompareToEqual() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ assertTrue(id1.compareTo(id2) == 0);
+ assertTrue(id2.compareTo(id1) == 0);
+ }
+
+ public void testCompareToNotEqual() throws Exception {
+ final ID id1 = createID(URI1);
+ final ID id2 = createID(URI2);
+ assertTrue(id1.compareTo(id2) < 0);
+ assertTrue(id2.compareTo(id1) > 0);
+ }
+
+ public void testGetNamespace() throws Exception {
+ final ID id = createID();
+ final Namespace ns = id.getNamespace();
+ assertNotNull(ns);
+ }
+
+ public void testEqualNamespaces() throws Exception {
+ final ID id1 = createID();
+ final ID id2 = createID();
+ final Namespace ns1 = id1.getNamespace();
+ final Namespace ns2 = id2.getNamespace();
+ assertTrue(ns1.equals(ns2));
+ assertTrue(ns2.equals(ns2));
+ }
+
+ public void testSerializable() throws Exception {
+ final ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ final ObjectOutputStream out = new ObjectOutputStream(buf);
+ try {
+ out.writeObject(createID());
+ } catch (final NotSerializableException ex) {
+ fail(ex.getLocalizedMessage());
+ } finally {
+ out.close();
+ }
+ }
+
+ public void testCreateFromExternalForm() throws Exception {
+ final ID id1 = createID();
+ final String externalForm = id1.toExternalForm();
+ final ID id2 = IDFactory.getDefault().createID(id1.getNamespace(), externalForm);
+ assertTrue(id1.equals(id2));
+ }
+
+ public void testCreateFromURIForm() throws Exception {
+ final ID id1 = IDFactory.getDefault().createID(URIIDNAMESPACE,new Object[] { new URI(URI1) });
+ final String externalForm = id1.toExternalForm();
+ final ID id2 = IDFactory.getDefault().createID(id1.getNamespace(), externalForm);
+ assertTrue(id1.equals(id2));
+ }
+
+}

Back to the top