Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-05-12 06:14:28 +0000
committerslewis2008-05-12 06:14:28 +0000
commitee16243c4029d3c782402ef83ca3976f1974761a (patch)
tree3c0357412b3ec8a6301d5cca079d1b847d561296
parent80104aa1f6f0c3bd43ee4d07ee1fee956c649278 (diff)
downloadorg.eclipse.ecf-ee16243c4029d3c782402ef83ca3976f1974761a.tar.gz
org.eclipse.ecf-ee16243c4029d3c782402ef83ca3976f1974761a.tar.xz
org.eclipse.ecf-ee16243c4029d3c782402ef83ca3976f1974761a.zip
Added to API and implementation
-rw-r--r--framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF1
-rw-r--r--framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/IDStore.java94
-rw-r--r--framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDStore.java26
3 files changed, 69 insertions, 52 deletions
diff --git a/framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF
index e06ae8130..e21bc1cc0 100644
--- a/framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Eclipse-LazyStart: true
Import-Package: org.eclipse.equinox.security.storage;version="1.0.0",
+ org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.equinox.common,
diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/IDStore.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/IDStore.java
index b3159bc91..a7402d152 100644
--- a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/IDStore.java
+++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/IDStore.java
@@ -16,63 +16,35 @@ import java.util.List;
import org.eclipse.ecf.core.identity.*;
import org.eclipse.ecf.storage.*;
import org.eclipse.equinox.security.storage.*;
+import org.eclipse.osgi.util.NLS;
/**
*
*/
public class IDStore implements IIDStore {
- private static final String idStoreNameSegment = "/ECF/ID Store/"; //$NON-NLS-1$
- private static final String NSSEPARATOR = ":"; //$NON-NLS-1$
+ private static final String idStoreNameSegment = "/ECF/Namespace"; //$NON-NLS-1$
private static final ISecurePreferences[] EMPTY_SECUREPREFERENCES = {};
/* (non-Javadoc)
* @see org.eclipse.ecf.storage.IIDStore#getNode(org.eclipse.ecf.core.identity.ID)
*/
public ISecurePreferences getNode(ID id) {
- if (id == null)
- return null;
- final ISecurePreferences root = SecurePreferencesFactory.getDefault();
- if (root == null)
+ ISecurePreferences namespaceNode = getNamespaceRoot();
+ if (namespaceNode == null)
return null;
final String idAsString = getIDAsString(id);
if (idAsString == null)
return null;
- final String path = idStoreNameSegment + EncodingUtils.encodeSlashes(idAsString);
- return root.node(path);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.storage.IIDStore#getNodes()
- */
- public ISecurePreferences[] getNodes() {
- final ISecurePreferences root = SecurePreferencesFactory.getDefault();
- if (root == null)
- return null;
- ISecurePreferences parentNode = root.node(idStoreNameSegment);
- if (parentNode == null)
- return EMPTY_SECUREPREFERENCES;
- String[] childNames = parentNode.childrenNames();
- List result = new ArrayList();
- for (int i = 0; i < childNames.length; i++) {
- ISecurePreferences p = parentNode.node(childNames[i]);
- if (p != null)
- result.add(p);
- }
- return (ISecurePreferences[]) result.toArray(new ISecurePreferences[] {});
+ return namespaceNode.node(idAsString);
}
private String getIDAsString(ID id) {
- final Namespace ns = id.getNamespace();
- final INamespaceStoreAdapter nsadapter = (INamespaceStoreAdapter) ns.getAdapter(INamespaceStoreAdapter.class);
- final String nsName = (nsadapter != null) ? nsadapter.getNameForStorage() : ns.getName();
- if (nsName == null)
- return null;
final IIDStoreAdapter idadapter = (IIDStoreAdapter) id.getAdapter(IIDStoreAdapter.class);
final String idName = (idadapter != null) ? idadapter.getNameForStorage() : id.toExternalForm();
if (idName == null || idName.equals("")) //$NON-NLS-1$
return null;
- return nsName + NSSEPARATOR + idName;
+ return EncodingUtils.encodeSlashes(idName);
}
/* (non-Javadoc)
@@ -81,17 +53,51 @@ public class IDStore implements IIDStore {
public ID createID(ISecurePreferences node) throws IDCreateException {
if (node == null)
throw new IDCreateException("Node cannot be null"); //$NON-NLS-1$
- final String nodeName = node.name();
- if (nodeName == null)
- throw new IDCreateException("Node name cannot be null"); //$NON-NLS-1$
- final int index = nodeName.indexOf(NSSEPARATOR);
- if (index == -1)
- throw new IDCreateException("Namespace name not found"); //$NON-NLS-1$
- final String nsName = nodeName.substring(0, index);
+ String nsName = node.parent().name();
final Namespace ns = IDFactory.getDefault().getNamespaceByName(nsName);
if (ns == null)
- throw new IDCreateException("Namespace cannot be found"); //$NON-NLS-1$
- final String idName = nodeName.substring(index + NSSEPARATOR.length());
- return IDFactory.getDefault().createID(ns, idName);
+ throw new IDCreateException(NLS.bind("Namespace {0} cannot be found", nsName)); //$NON-NLS-1$
+ return IDFactory.getDefault().createID(ns, node.name());
+ }
+
+ protected ISecurePreferences getRoot() {
+ return SecurePreferencesFactory.getDefault();
+ }
+
+ protected ISecurePreferences getNamespaceRoot() {
+ ISecurePreferences root = getRoot();
+ if (root == null)
+ return null;
+ return root.node(idStoreNameSegment);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.storage.IIDStore#getNamespaceNode(org.eclipse.ecf.core.identity.Namespace)
+ */
+ public ISecurePreferences getNamespaceNode(Namespace namespace) {
+ if (namespace == null)
+ return null;
+ final INamespaceStoreAdapter nsadapter = (INamespaceStoreAdapter) namespace.getAdapter(INamespaceStoreAdapter.class);
+ final String nsName = (nsadapter != null) ? nsadapter.getNameForStorage() : namespace.getName();
+ if (nsName == null)
+ return null;
+ ISecurePreferences namespaceRoot = getNamespaceRoot();
+ if (namespaceRoot == null)
+ return null;
+ return namespaceRoot.node(nsName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.storage.IIDStore#getNamespaceNodes()
+ */
+ public ISecurePreferences[] getNamespaceNodes() {
+ ISecurePreferences namespaceRoot = getNamespaceRoot();
+ if (namespaceRoot == null)
+ return EMPTY_SECUREPREFERENCES;
+ List results = new ArrayList();
+ String names[] = namespaceRoot.childrenNames();
+ for (int i = 0; i < names.length; i++)
+ results.add(namespaceRoot.node(names[i]));
+ return (ISecurePreferences[]) results.toArray(new ISecurePreferences[] {});
}
}
diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDStore.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDStore.java
index f35cc6268..72791bc57 100644
--- a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDStore.java
+++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDStore.java
@@ -11,8 +11,7 @@
package org.eclipse.ecf.storage;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.*;
import org.eclipse.equinox.security.storage.ISecurePreferences;
/**
@@ -22,19 +21,30 @@ import org.eclipse.equinox.security.storage.ISecurePreferences;
public interface IIDStore {
/**
- * Get {@link ISecurePreferences} for all IDs in ID store.
+ * Get the namespace nodes exposed by this ID store.
*
- * @return array of ISecurePreferences instances. If number of instances current stored is 0, returns
- * empty array. Will not return <code>null</code>.
+ * @return array of namespace nodes for this ID store. Will return <code>null</code> if
+ * secure preferences store not available. Will return empty array if preferences available
+ * but no Namespaces have been added. Each ISecurePreferences node represents a given {@link Namespace}, and
+ * the {@link ISecurePreferences#name()} entry will correspond to the {@link Namespace#getName()}.
*/
- public ISecurePreferences[] getNodes();
+ public ISecurePreferences[] getNamespaceNodes();
+
+ /**
+ * Get the given namespace node for this ID store.
+ *
+ * @param namespace the {@link Namespace} to get the node for. Must not be <code>null</code>.
+ * @return the node for the given {@link Namespace}. Will not return <code>null</code>. If node
+ * previously was not present, it will be created.
+ */
+ public ISecurePreferences getNamespaceNode(Namespace namespace);
/**
* Get {@link ISecurePreferences} node for a given ID. Clients may use this to either create an {@link ISecurePreferences}
* instance for a new {@link ID}, or get an existing one from storage.
* @param id the ID to get the storage node for.
- * @return ISecurePreferences for the given ID. Will return an existing node if ID is already present, and a new
- * node if not.
+ * @return ISecurePreferences for the given ID. Will not return <code>null</code>.
+ * Will return an existing node if ID is already present, and a new node if not.
*/
public ISecurePreferences getNode(ID id);

Back to the top