diff options
author | slewis | 2008-05-20 06:48:46 +0000 |
---|---|---|
committer | slewis | 2008-05-20 06:48:46 +0000 |
commit | cb79acd7f4f366bcb6868c8efb37b4424db28e1f (patch) | |
tree | e73fb17b9c713d31bb738d7a90375c62b8d7c2c5 | |
parent | 2c2c4441949cc6d454dfcd0183f830bb51b69eab (diff) | |
download | org.eclipse.ecf-cb79acd7f4f366bcb6868c8efb37b4424db28e1f.tar.gz org.eclipse.ecf-cb79acd7f4f366bcb6868c8efb37b4424db28e1f.tar.xz org.eclipse.ecf-cb79acd7f4f366bcb6868c8efb37b4424db28e1f.zip |
Added IContainerStore and IContainerEntry to API and implementation.
10 files changed, 310 insertions, 5 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 f1f0769a1..09bdb32b9 100644 --- a/framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.storage/META-INF/MANIFEST.MF @@ -14,6 +14,6 @@ Import-Package: org.eclipse.equinox.security.storage;version="1.0.0", org.osgi.util.tracker;version="1.3.3" Bundle-ActivationPolicy: lazy Require-Bundle: org.eclipse.equinox.common, - org.eclipse.ecf.identity;bundle-version="2.0.0" + org.eclipse.ecf;bundle-version="2.0.0" Bundle-Localization: plugin Export-Package: org.eclipse.ecf.storage diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/Activator.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/Activator.java index 7dffb62c3..ca4b591c6 100644 --- a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/Activator.java +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/Activator.java @@ -2,6 +2,7 @@ package org.eclipse.ecf.internal.storage; import org.eclipse.core.runtime.*; import org.eclipse.ecf.core.util.*; +import org.eclipse.ecf.storage.IContainerStore; import org.eclipse.ecf.storage.IIDStore; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -40,7 +41,10 @@ public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { plugin = this; this.context = context; - context.registerService(IIDStore.class.getName(), new IDStore(), null); + IDStore idStore = new IDStore(); + ContainerStore containerStore = new ContainerStore(idStore); + context.registerService(IIDStore.class.getName(), idStore, null); + context.registerService(IContainerStore.class.getName(), containerStore, null); } /* diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/ContainerEntry.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/ContainerEntry.java new file mode 100644 index 000000000..bdc04f266 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/ContainerEntry.java @@ -0,0 +1,87 @@ +/**************************************************************************** + * Copyright (c) 2008 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.internal.storage; + +import org.eclipse.ecf.core.*; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.identity.IDCreateException; +import org.eclipse.ecf.storage.IContainerEntry; +import org.eclipse.ecf.storage.IIDEntry; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.StorageException; + +/** + * + */ +public class ContainerEntry implements IContainerEntry { + + private static final String FACTORY_NAME_KEY = "factoryName"; //$NON-NLS-1$ + + ISecurePreferences prefs; + IIDEntry idEntry; + + ID containerID; + + /** + * @param node + * @param idEntry + */ + public ContainerEntry(ISecurePreferences node, IIDEntry idEntry) { + this.prefs = node; + this.idEntry = idEntry; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerEntry#createContainer() + */ + public IContainer createContainer() throws ContainerCreateException { + try { + return ContainerFactory.getDefault().createContainer(getFactoryName(), getContainerID()); + } catch (IDCreateException e) { + throw new ContainerCreateException("Could not create ID for container", e); //$NON-NLS-1$ + } catch (StorageException e) { + throw new ContainerCreateException("Could not get factory name", e); //$NON-NLS-1$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerEntry#delete() + */ + public void delete() { + prefs.removeNode(); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerEntry#getContainerID() + */ + public ID getContainerID() throws IDCreateException { + if (containerID == null) { + containerID = idEntry.createID(); + } + return containerID; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerEntry#getFactoryName() + */ + public String getFactoryName() throws StorageException { + return prefs.get(FACTORY_NAME_KEY, ""); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerEntry#getPreferences() + */ + public ISecurePreferences getPreferences() { + return prefs; + } + +} diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/ContainerStore.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/ContainerStore.java new file mode 100644 index 000000000..6edd41158 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/internal/storage/ContainerStore.java @@ -0,0 +1,82 @@ +/**************************************************************************** + * Copyright (c) 2008 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.internal.storage; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.storage.*; +import org.eclipse.equinox.security.storage.ISecurePreferences; + +/** + * + */ +public class ContainerStore implements IContainerStore { + + private static final String CONTAINER_NODE_NAME = "container"; //$NON-NLS-1$ + + final IDStore idStore; + + public ContainerStore(IDStore idStore) { + this.idStore = idStore; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerStore#getContainerEntries() + */ + public IContainerEntry[] getContainerEntries() { + INamespaceEntry[] namespaceEntries = idStore.getNamespaceEntries(); + List results = new ArrayList(); + for (int i = 0; i < namespaceEntries.length; i++) { + IIDEntry[] idEntries = namespaceEntries[i].getIDEntries(); + for (int j = 0; j < idEntries.length; j++) { + ISecurePreferences pref = idEntries[j].getPreferences(); + String[] names = pref.childrenNames(); + for (int k = 0; k < names.length; k++) { + if (names[k].equals(CONTAINER_NODE_NAME)) + results.add(new ContainerEntry(pref.node(CONTAINER_NODE_NAME), idEntries[j])); + } + } + } + return (IContainerEntry[]) results.toArray(new IContainerEntry[] {}); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.storage.IContainerStore#store(org.eclipse.ecf.storage.IStorableContainerAdapter) + */ + public IContainerEntry store(IStorableContainerAdapter containerAdapter) { + String factoryName = containerAdapter.getFactoryName(); + Assert.isNotNull(factoryName); + ID containerID = containerAdapter.getID(); + Assert.isNotNull(containerID); + IIDEntry idEntry = idStore.store(containerID); + ISecurePreferences prefs = idEntry.getPreferences(); + ISecurePreferences containerPrefs = prefs.node(CONTAINER_NODE_NAME); + return new ContainerEntry(containerPrefs, idEntry); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter == null) + return null; + if (adapter.isInstance(this)) { + return this; + } + IAdapterManager adapterManager = Activator.getDefault().getAdapterManager(); + return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName()); + } + +} 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 a2ee95019..dca66d918 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 @@ -49,7 +49,7 @@ public class IDStore implements IIDStore { /* (non-Javadoc) * @see org.eclipse.ecf.storage.IIDStore#getEntry(org.eclipse.ecf.core.identity.ID) */ - public IIDEntry getEntry(ID id) { + public IIDEntry store(ID id) { ISecurePreferences namespaceRoot = getNamespaceRoot(); if (namespaceRoot == null) return null; diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IContainerEntry.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IContainerEntry.java new file mode 100644 index 000000000..f7b603e9c --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IContainerEntry.java @@ -0,0 +1,66 @@ +/**************************************************************************** + * Copyright (c) 2008 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.storage; + +import org.eclipse.ecf.core.ContainerCreateException; +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.identity.IDCreateException; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.StorageException; + +/** + * Storage entry for IContainer instances. + */ +public interface IContainerEntry { + + /** + * Get the underlying {@link ISecurePreferences} node that represents this IContainerEntry + * in the storage. + * + * @return {@link ISecurePreferences} that represents this IContainerEntry in the underlying storage. Will + * not return <code>null</code>. + */ + public ISecurePreferences getPreferences(); + + /** + * Get the container's ID for the stored {@link IContainer}. The returned ID will be equivalent to + * the ID returned by the original container's {@link IContainer#getID()}. + * + * @return ID for the container. Will not be <code>null</code>. + * @throws IDCreateException if ID cannot be created. + */ + public ID getContainerID() throws IDCreateException; + + /** + * Get the container factory name for the stored {@link IContainer}. + * @return String the container factory name. Will not be <code>null</code>. + * @throws StorageException if some exception reading from {@link ISecurePreferences}. + */ + public String getFactoryName() throws StorageException; + + /** + * Create an IContainer from this IContainerEntry. This method may be used to create new IContainer instance from this + * {@link IContainerEntry}. The created IContainer will be equivalent (via ID.equals(other)) to the ID previously + * stored via {@link IContainerStore#store(IStorableContainerAdapter)}. + * + * @return {@link IContainer} that corresponds to this previously stored {@link IContainerEntry}. + * @throws ContainerCreateException if the IContainer cannot be created in this environment. + */ + public IContainer createContainer() throws ContainerCreateException; + + /** + * Delete this IContainerEntry from the {@link IContainerStore}. + */ + public void delete(); + +} diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IContainerStore.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IContainerStore.java new file mode 100644 index 000000000..c514339cc --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IContainerStore.java @@ -0,0 +1,38 @@ +/**************************************************************************** + * Copyright (c) 2008 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.storage; + +import org.eclipse.core.runtime.IAdaptable; + +/** + * Storage interface for IContainer instances. + */ +public interface IContainerStore extends IAdaptable { + + /** + * Get all {@link IContainerEntry}s. Will return from secure storage all container entries previously added + * via {@link #store(IStorableContainerAdapter)}. + * + * @return IContainerEntry[] of all container entries. Will not return <code>null</code>. If no containers previously + * stored, will return empty array. + */ + public IContainerEntry[] getContainerEntries(); + + /** + * Store a {@link IStorableContainerAdapter} in this container store. + * + * @param containerAdapter the {@link IStorableContainerAdapter} to store. Must not be <code>null</code>. + * @return {@link IContainerEntry} result of storage. Will not return <code>null</code>. + */ + public IContainerEntry store(IStorableContainerAdapter containerAdapter); + +} diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDEntry.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDEntry.java index 283eac812..6725ed9f4 100644 --- a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDEntry.java +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IIDEntry.java @@ -31,7 +31,7 @@ public interface IIDEntry { /** * Create an ID from this IDEntry. This method may be used to create new ID instance from this * {@link IIDEntry}. The created ID will be equivalent (via ID.equals(other)) to the ID previously - * stored via {@link IIDStore#getEntry(ID)}. + * stored via {@link IIDStore#store(ID)}. * * @return {@link ID} that corresponds to this previously stored {@link IIDEntry}. * @throws IDCreateException if the ID cannot be created in this environment...e.g. due to missing 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 5b53bde46..942e14522 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 @@ -52,6 +52,6 @@ public interface IIDStore extends IAdaptable { * Will return an existing {@link IIDEntry} if ID is already present, and a new {@link IIDEntry} if not previously * stored. */ - public IIDEntry getEntry(ID id); + public IIDEntry store(ID id); } diff --git a/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IStorableContainerAdapter.java b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IStorableContainerAdapter.java new file mode 100644 index 000000000..66efbe3f3 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.storage/src/org/eclipse/ecf/storage/IStorableContainerAdapter.java @@ -0,0 +1,28 @@ +/**************************************************************************** + * Copyright (c) 2008 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.storage; + +import org.eclipse.ecf.core.identity.IIdentifiable; +import org.eclipse.equinox.security.storage.ISecurePreferences; + +/** + * + */ +public interface IStorableContainerAdapter extends IIdentifiable { + + public String getFactoryName(); + + public void handleStore(ISecurePreferences prefs); + + public void handleRestore(ISecurePreferences prefs); + +} |