Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java125
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java238
4 files changed, 191 insertions, 195 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
index b89b29d3f..8dd39d08b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
@@ -96,16 +96,15 @@ public class PersistenceManager extends AbstractExtensionPointManager<IPersisten
* delegate with the specified id is registered, <code>null</code> is returned.
*
* @param id The unique id of the persistence delegate or <code>null</code>
- * @param unique If <code>true</code>, the method returns new instances of the persistence delegate contribution.
*
* @return The persistence delegate instance or <code>null</code>.
*/
- protected IPersistenceDelegate getDelegate(String id, boolean unique) {
+ protected IPersistenceDelegate getDelegate(String id) {
IPersistenceDelegate contribution = null;
if (getExtensions().containsKey(id)) {
ExecutableExtensionProxy<IPersistenceDelegate> proxy = getExtensions().get(id);
// Get the extension instance
- contribution = unique ? proxy.newInstance() : proxy.getInstance();
+ contribution = proxy.getInstance();
}
return contribution;
@@ -119,7 +118,7 @@ public class PersistenceManager extends AbstractExtensionPointManager<IPersisten
* @param container The persistence container or <code>null</code>.
* @return The persistence delegate which is enabled or <code>null</code>.
*/
- public IPersistenceDelegate getDelegate(Object context, Object container, boolean unique) {
+ public IPersistenceDelegate getDelegate(Object context, Object container) {
Assert.isNotNull(context);
List<IPersistenceDelegate> delegates = new ArrayList<IPersistenceDelegate>();
@@ -127,7 +126,7 @@ public class PersistenceManager extends AbstractExtensionPointManager<IPersisten
// Get the list of applicable bindings
PersistenceDelegateBinding[] bindings = PersistenceDelegateBindingExtensionPointManager.getInstance().getApplicableBindings(context, container);
for (PersistenceDelegateBinding binding : bindings) {
- IPersistenceDelegate delegate = getDelegate(binding.getDelegateId(), unique);
+ IPersistenceDelegate delegate = getDelegate(binding.getDelegateId());
if (delegate != null && !delegates.contains(delegate)) {
delegates.add(delegate);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java
index 8427fcdee..737183b5b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java
@@ -77,10 +77,10 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
}
/* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.lang.Object, java.lang.Object, java.lang.String)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.lang.Object, java.lang.Object)
*/
@Override
- public final Object write(Object context, Object container, String key) throws IOException {
+ public final Object write(Object context, Object container) throws IOException {
Assert.isNotNull(context);
Assert.isNotNull(container);
@@ -118,7 +118,7 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
}
}
}
- else if (container instanceof String || String.class.equals(container)) {
+ else if (String.class.equals(container)) {
Gson gson = new GsonBuilder().create();
container = gson.toJson(internalToMap(context));
@@ -154,10 +154,10 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
}
/* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.lang.Object, java.lang.Object, java.lang.String)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.lang.Object, java.lang.Object)
*/
@Override
- public final Object read(Object context, Object container, String key) throws IOException {
+ public final Object read(Object context, Object container) throws IOException {
Assert.isNotNull(container);
Gson gson = new GsonBuilder().create();
@@ -208,10 +208,10 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
}
/* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.lang.Object, java.lang.Object, java.lang.String)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.lang.Object, java.lang.Object)
*/
@Override
- public boolean delete(Object context, Object container, String key) throws IOException {
+ public boolean delete(Object context, Object container) throws IOException {
Assert.isNotNull(container);
if (container instanceof URI) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java
index f0392a452..bf8a72c70 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java
@@ -1,64 +1,61 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Wind River Systems, 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.runtime.persistence.interfaces;
-
-import java.io.IOException;
-
-import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
-
-/**
- * Interface to be implemented by persistence delegates.
- */
-public interface IPersistenceDelegate extends IExecutableExtension {
-
- /**
- * Writes the given context to the given persistence container using the key.
- * If the container does not exist yet, the class needs to be given.
- *
- * @param context The context to persist. Must not be <code>null</code>.
- * @param container The persistence container or class for a new one. Must not be <code>null</code>.
- * @param key The key for the context inside the container or <code>null</code>.
- *
- * @return The new or updated container instance.
- */
- public Object write(Object context, Object container, String key) throws IOException;
-
- /**
- * Get the class or interface for the context.
- *
- * @param context The context to persist. Must not be <code>null</code>.
- * @return The class or interface for the given context.
- */
- public Class<?> getPersistedClass(Object context);
-
- /**
- * Reads the context from the given persistence container.
- * If the context does not exist yet, the class needs to be given.
- *
- * @param context The context to update or class for a new context. Must not be <code>null</code>.
- * @param container The persistence container. Must not be <code>null</code>.
- * @param key The key for the context inside the container or <code>null</code>.
- *
- * @return The new or updated context instance.
- */
- public Object read(Object context, Object container, String key) throws IOException;
-
- /**
- * Deletes the given context inside the container or the whole container.
- *
- * @param context The context to delete inside the storage or <code>null</code>.
- * @param container The persistence container. Must not be <code>null</code>.
- * @param key The key for the context inside the container or <code>null</code>.
- *
- * @return <code>True</code> if the persistence context or the whole storage was successfully deleted;
- * <code>false</code> otherwise.
- */
- public boolean delete(Object context, Object container, String key) throws IOException;
-}
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Wind River Systems, 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.runtime.persistence.interfaces;
+
+import java.io.IOException;
+
+import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
+
+/**
+ * Interface to be implemented by persistence delegates.
+ */
+public interface IPersistenceDelegate extends IExecutableExtension {
+
+ /**
+ * Writes the given context to the given persistence container using the key.
+ * If the container does not exist yet, the class needs to be given.
+ *
+ * @param context The context to persist. Must not be <code>null</code>.
+ * @param container The persistence container or class for a new one. Must not be <code>null</code>.
+ *
+ * @return The new or updated container instance.
+ */
+ public Object write(Object context, Object container) throws IOException;
+
+ /**
+ * Get the class or interface for the context.
+ *
+ * @param context The context to persist. Must not be <code>null</code>.
+ * @return The class or interface for the given context.
+ */
+ public Class<?> getPersistedClass(Object context);
+
+ /**
+ * Reads the context from the given persistence container.
+ * If the context does not exist yet, the class needs to be given.
+ *
+ * @param context The context to update or class for a new context. Must not be <code>null</code>.
+ * @param container The persistence container. Must not be <code>null</code>.
+ *
+ * @return The new or updated context instance.
+ */
+ public Object read(Object context, Object container) throws IOException;
+
+ /**
+ * Deletes the given context inside the container or the whole container.
+ *
+ * @param context The context to delete inside the storage or <code>null</code>.
+ * @param container The persistence container. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the persistence context or the whole storage was successfully deleted;
+ * <code>false</code> otherwise.
+ */
+ public boolean delete(Object context, Object container) throws IOException;
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java
index 5308aab3c..91cb851bd 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java
@@ -1,119 +1,119 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Wind River Systems, 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.runtime.persistence.services;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.tcf.te.runtime.persistence.PersistenceManager;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
-import org.eclipse.tcf.te.runtime.services.AbstractService;
-
-/**
- * Persistence service implementation.
- */
-public class URIPersistenceService extends AbstractService implements IURIPersistenceService {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#write(java.lang.Object, java.net.URI)
- */
- @Override
- public void write(Object context, URI uri) throws IOException {
- Assert.isNotNull(context);
-
- uri = uri != null ? uri : getURI(context);
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false);
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) {
- throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Pass on to the delegate for writing
- delegate.write(context, uri, null);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#read(java.lang.Object, java.net.URI)
- */
- @Override
- public Object read(Object context, URI uri) throws IOException {
- Assert.isNotNull(context);
-
- uri = uri != null ? uri : getURI(context);
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false);
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) {
- throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Pass on to the delegate for reading
- return delegate.read(context, uri, null);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#delete(java.lang.Object, java.net.URI)
- */
- @Override
- public boolean delete(Object context, URI uri) throws IOException {
- Assert.isNotNull(context);
-
- uri = uri != null ? uri : getURI(context);
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false);
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) {
- throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- return delegate.delete(context, uri, null);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#getURI(java.lang.Object)
- */
- @Override
- public URI getURI(Object context) throws IOException {
- Assert.isNotNull(context);
-
- // Determine the persistable element for the given data object
- IPersistableURIProvider persistableURIProvider = context instanceof IPersistableURIProvider ? (IPersistableURIProvider)context : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistableURIProvider == null) {
- persistableURIProvider = context instanceof IAdaptable ? (IPersistableURIProvider) ((IAdaptable)context).getAdapter(IPersistableURIProvider.class) : null;
- }
- if (persistableURIProvider == null) {
- persistableURIProvider = (IPersistableURIProvider) Platform.getAdapterManager().getAdapter(context, IPersistableURIProvider.class);
- }
-
- // If the persistable could be still not determined, throw an IOException
- if (persistableURIProvider == null) {
- throw new IOException("'context' must be adaptable to IPersistableURIProvider."); //$NON-NLS-1$
- }
-
- URI uri = persistableURIProvider.getURI(context);
-
- if (uri == null) {
- throw new IOException("The URI cannot be determined for context '" + context.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Determine the URI
- return uri;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Wind River Systems, 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.runtime.persistence.services;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.tcf.te.runtime.persistence.PersistenceManager;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
+import org.eclipse.tcf.te.runtime.services.AbstractService;
+
+/**
+ * Persistence service implementation.
+ */
+public class URIPersistenceService extends AbstractService implements IURIPersistenceService {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#write(java.lang.Object, java.net.URI)
+ */
+ @Override
+ public void write(Object context, URI uri) throws IOException {
+ Assert.isNotNull(context);
+
+ uri = uri != null ? uri : getURI(context);
+
+ // Determine the persistence delegate
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri);
+ // If the persistence delegate could not be determined, throw an IOException
+ if (delegate == null) {
+ throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Pass on to the delegate for writing
+ delegate.write(context, uri);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#read(java.lang.Object, java.net.URI)
+ */
+ @Override
+ public Object read(Object context, URI uri) throws IOException {
+ Assert.isNotNull(context);
+
+ uri = uri != null ? uri : getURI(context);
+
+ // Determine the persistence delegate
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri);
+ // If the persistence delegate could not be determined, throw an IOException
+ if (delegate == null) {
+ throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Pass on to the delegate for reading
+ return delegate.read(context, uri);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#delete(java.lang.Object, java.net.URI)
+ */
+ @Override
+ public boolean delete(Object context, URI uri) throws IOException {
+ Assert.isNotNull(context);
+
+ uri = uri != null ? uri : getURI(context);
+
+ // Determine the persistence delegate
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri);
+ // If the persistence delegate could not be determined, throw an IOException
+ if (delegate == null) {
+ throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return delegate.delete(context, uri);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#getURI(java.lang.Object)
+ */
+ @Override
+ public URI getURI(Object context) throws IOException {
+ Assert.isNotNull(context);
+
+ // Determine the persistable element for the given data object
+ IPersistableURIProvider persistableURIProvider = context instanceof IPersistableURIProvider ? (IPersistableURIProvider)context : null;
+ // If the element isn't a persistable by itself, try to adapt the element
+ if (persistableURIProvider == null) {
+ persistableURIProvider = context instanceof IAdaptable ? (IPersistableURIProvider) ((IAdaptable)context).getAdapter(IPersistableURIProvider.class) : null;
+ }
+ if (persistableURIProvider == null) {
+ persistableURIProvider = (IPersistableURIProvider) Platform.getAdapterManager().getAdapter(context, IPersistableURIProvider.class);
+ }
+
+ // If the persistable could be still not determined, throw an IOException
+ if (persistableURIProvider == null) {
+ throw new IOException("'context' must be adaptable to IPersistableURIProvider."); //$NON-NLS-1$
+ }
+
+ URI uri = persistableURIProvider.getURI(context);
+
+ if (uri == null) {
+ throw new IOException("The URI cannot be determined for context '" + context.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Determine the URI
+ return uri;
+ }
+}

Back to the top