Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2012-07-18 02:56:05 -0400
committerUwe Stieber2012-07-18 03:08:33 -0400
commitb818bd7fa3801c8d25e7f5447567064b10b6756e (patch)
tree0a01ee1062effe30c5f2912d72f9509cb4e2294f /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org
parentd1d63a37e70906b8047a95b2225a40f27842b581 (diff)
downloadorg.eclipse.tcf-b818bd7fa3801c8d25e7f5447567064b10b6756e.tar.gz
org.eclipse.tcf-b818bd7fa3801c8d25e7f5447567064b10b6756e.tar.xz
org.eclipse.tcf-b818bd7fa3801c8d25e7f5447567064b10b6756e.zip
Target Explorer: ADD launch tab handling in editor
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java536
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java370
2 files changed, 456 insertions, 450 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java
index 09e72bdf1..854c33209 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java
@@ -1,268 +1,268 @@
-/*******************************************************************************
- * Copyright (c) 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;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
-import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-/**
- * GsonMapPersistenceDelegate
- */
-public class GsonMapPersistenceDelegate extends ExecutableExtension implements IPersistenceDelegate {
-
- private final String defaultFileExtension;
-
- /**
- * Constructor.
- */
- public GsonMapPersistenceDelegate() {
- this("json"); //$NON-NLS-1$
- }
-
- /**
- * Constructor.
- */
- public GsonMapPersistenceDelegate(String defaultFileExtension) {
- super();
- Assert.isNotNull(defaultFileExtension);
- this.defaultFileExtension = defaultFileExtension;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#getPersistedClass(java.lang.Object)
- */
- @Override
- public Class<?> getPersistedClass(Object context) {
- return Map.class;
- }
-
- /**
- * Return the default file extension if container is an URI.
- */
- protected String getDefaultFileExtension() {
- return defaultFileExtension;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.lang.Object, java.lang.Object, java.lang.String)
- */
- @Override
- public Object write(Object context, Object container, String key) throws IOException {
- Assert.isNotNull(context);
- Assert.isNotNull(container);
-
- if (container instanceof URI) {
- URI uri = (URI)container;
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- // If the file defaultFileExtension is no set, default to "properties"
- IPath path = new Path(file.getCanonicalPath());
- if (path.getFileExtension() == null) {
- file = path.addFileExtension(getDefaultFileExtension()).toFile();
- }
-
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); //$NON-NLS-1$
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- gson.toJson(toMap(context), Map.class, writer);
- } finally {
- if (writer != null) {
- writer.close();
- }
- }
- }
- else if (container instanceof String || String.class.equals(container)) {
- Gson gson = new GsonBuilder().create();
- container = gson.toJson(toMap(context));
- }
-
- return container;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.lang.Object, java.lang.Object, java.lang.String)
- */
- @Override
- public Object read(Object context, Object container, String key) throws IOException {
- Assert.isNotNull(container);
-
- Gson gson = new GsonBuilder().create();
- Map<String, Object> data = null;
-
- if (container instanceof URI) {
- URI uri = (URI)container;
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- Reader reader = null;
- try {
- reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); //$NON-NLS-1$
- data = gson.fromJson(reader, Map.class);
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
- else if (container instanceof String) {
- data = gson.fromJson((String)container, Map.class);
- }
-
- return data != null ? fromMap(data, context) : context;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.lang.Object, java.lang.Object, java.lang.String)
- */
- @Override
- public boolean delete(Object context, Object container, String key) throws IOException {
- Assert.isNotNull(container);
-
- if (container instanceof URI) {
- URI uri = (URI)container;
-
- // Only "file:" URIs are supported
- if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
- throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // Create the file object from the given URI
- File file = new File(uri.normalize());
-
- // The file must be absolute
- if (!file.isAbsolute()) {
- throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
- }
-
- // If the file defaultFileExtension is no set, default to "properties"
- IPath path = new Path(file.getCanonicalPath());
- if (path.getFileExtension() == null) {
- file = path.addFileExtension(getDefaultFileExtension()).toFile();
- }
-
- return file.delete();
- }
-
- return false;
- }
-
- /**
- * Convert the given context to map.
- *
- * @param context The context. Must not be <code>null</code>.
- * @return Map representing the context.
- *
- * @throws IOException
- */
- @SuppressWarnings("unchecked")
- protected Map<String, Object> toMap(final Object context) throws IOException {
- Map<String, Object> result = new HashMap<String,Object>();
-
- Map<String,Object> attrs = null;
- if (context instanceof Map) {
- attrs = (Map<String, Object>)context;
- }
- else if (context instanceof IPropertiesContainer) {
- IPropertiesContainer container = (IPropertiesContainer)context;
- attrs = new HashMap<String,Object>(container.getProperties());
- }
-
- if (attrs != null) {
- for (Entry<String, Object> entry : attrs.entrySet()) {
- if (!entry.getKey().endsWith(".transient")) { //$NON-NLS-1$
- result.put(entry.getKey(), entry.getValue());
- }
- }
- }
-
- return result;
- }
-
- /**
- * Convert a map into the needed context object.
- *
- * @param map The map representing the context. Must not be <code>null</code>.
- * @param context The context to put the map values in or <code>null</code>.
- * @return The context object.
- *
- * @throws IOException
- */
- protected Object fromMap(Map<String,Object> map, Object context) throws IOException {
- if (context == null || Map.class.equals(context.getClass())) {
- return map;
- }
- else if (context instanceof Map) {
- @SuppressWarnings({ "rawtypes", "unchecked" })
- Map<String,Object> newMap = new HashMap<String, Object>((Map)context);
- newMap.putAll(map);
- return newMap;
- }
- else if (IPropertiesContainer.class.equals(context.getClass())) {
- IPropertiesContainer container = new PropertiesContainer();
- container.setProperties(map);
-
- return container;
- }
- else if (context instanceof IPropertiesContainer) {
- IPropertiesContainer container = (IPropertiesContainer)context;
- container.setProperties(map);
-
- return container;
- }
-
- return null;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * GsonMapPersistenceDelegate
+ */
+public class GsonMapPersistenceDelegate extends ExecutableExtension implements IPersistenceDelegate {
+
+ private final String defaultFileExtension;
+
+ /**
+ * Constructor.
+ */
+ public GsonMapPersistenceDelegate() {
+ this("json"); //$NON-NLS-1$
+ }
+
+ /**
+ * Constructor.
+ */
+ public GsonMapPersistenceDelegate(String defaultFileExtension) {
+ super();
+ Assert.isNotNull(defaultFileExtension);
+ this.defaultFileExtension = defaultFileExtension;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#getPersistedClass(java.lang.Object)
+ */
+ @Override
+ public Class<?> getPersistedClass(Object context) {
+ return Map.class;
+ }
+
+ /**
+ * Return the default file extension if container is an URI.
+ */
+ protected String getDefaultFileExtension() {
+ return defaultFileExtension;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object write(Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(context);
+ Assert.isNotNull(container);
+
+ if (container instanceof URI) {
+ URI uri = (URI)container;
+
+ // Only "file:" URIs are supported
+ if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+ throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Create the file object from the given URI
+ File file = new File(uri.normalize());
+
+ // The file must be absolute
+ if (!file.isAbsolute()) {
+ throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
+ }
+
+ // If the file defaultFileExtension is no set, default to "properties"
+ IPath path = new Path(file.getCanonicalPath());
+ if (path.getFileExtension() == null) {
+ file = path.addFileExtension(getDefaultFileExtension()).toFile();
+ }
+
+ Writer writer = null;
+ try {
+ writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); //$NON-NLS-1$
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ gson.toJson(toMap(context), Map.class, writer);
+ } finally {
+ if (writer != null) {
+ writer.close();
+ }
+ }
+ }
+ else if (container instanceof String || String.class.equals(container)) {
+ Gson gson = new GsonBuilder().create();
+ container = gson.toJson(toMap(context));
+ }
+
+ return container;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object read(Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(container);
+
+ Gson gson = new GsonBuilder().create();
+ Map<String, Object> data = null;
+
+ if (container instanceof URI) {
+ URI uri = (URI)container;
+
+ // Only "file:" URIs are supported
+ if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+ throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Create the file object from the given URI
+ File file = new File(uri.normalize());
+
+ // The file must be absolute
+ if (!file.isAbsolute()) {
+ throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
+ }
+
+ Reader reader = null;
+ try {
+ reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); //$NON-NLS-1$
+ data = gson.fromJson(reader, Map.class);
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+ else if (container instanceof String) {
+ data = gson.fromJson((String)container, Map.class);
+ }
+
+ return data != null ? fromMap(data, context) : context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.lang.Object, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public boolean delete(Object context, Object container, String key) throws IOException {
+ Assert.isNotNull(container);
+
+ if (container instanceof URI) {
+ URI uri = (URI)container;
+
+ // Only "file:" URIs are supported
+ if (!"file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+ throw new IOException("Unsupported URI schema '" + uri.getScheme() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Create the file object from the given URI
+ File file = new File(uri.normalize());
+
+ // The file must be absolute
+ if (!file.isAbsolute()) {
+ throw new IOException("URI must denote an absolute file path."); //$NON-NLS-1$
+ }
+
+ // If the file defaultFileExtension is no set, default to "properties"
+ IPath path = new Path(file.getCanonicalPath());
+ if (path.getFileExtension() == null) {
+ file = path.addFileExtension(getDefaultFileExtension()).toFile();
+ }
+
+ return file.delete();
+ }
+
+ return false;
+ }
+
+ /**
+ * Convert the given context to map.
+ *
+ * @param context The context. Must not be <code>null</code>.
+ * @return Map representing the context.
+ *
+ * @throws IOException
+ */
+ @SuppressWarnings("unchecked")
+ protected Map<String, Object> toMap(final Object context) throws IOException {
+ Map<String, Object> result = new HashMap<String,Object>();
+
+ Map<String,Object> attrs = null;
+ if (context instanceof Map) {
+ attrs = (Map<String, Object>)context;
+ }
+ else if (context instanceof IPropertiesContainer) {
+ IPropertiesContainer container = (IPropertiesContainer)context;
+ attrs = new HashMap<String,Object>(container.getProperties());
+ }
+
+ if (attrs != null) {
+ for (Entry<String, Object> entry : attrs.entrySet()) {
+ if (!entry.getKey().endsWith(".transient")) { //$NON-NLS-1$
+ result.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Convert a map into the needed context object.
+ *
+ * @param map The map representing the context. Must not be <code>null</code>.
+ * @param context The context to put the map values in or <code>null</code>.
+ * @return The context object.
+ *
+ * @throws IOException
+ */
+ protected Object fromMap(Map<String,Object> map, Object context) throws IOException {
+ if (context == null || (context instanceof Class && ((Class<?>)context).isInstance(map))) {
+ return map;
+ }
+ else if (context instanceof Map) {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ Map<String,Object> newMap = new HashMap<String, Object>((Map)context);
+ newMap.putAll(map);
+ return newMap;
+ }
+ else if (IPropertiesContainer.class.equals(context.getClass())) {
+ IPropertiesContainer container = new PropertiesContainer();
+ container.setProperties(map);
+
+ return container;
+ }
+ else if (context instanceof IPropertiesContainer) {
+ IPropertiesContainer container = (IPropertiesContainer)context;
+ container.setProperties(map);
+
+ return container;
+ }
+
+ return null;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java
index 165dbbd8a..2e25b1cc1 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java
@@ -1,182 +1,188 @@
-/*******************************************************************************
- * 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.internal;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.expressions.EvaluationContext;
-import org.eclipse.core.expressions.EvaluationResult;
-import org.eclipse.core.expressions.Expression;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
-import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
-import org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleActivator;
-
-
-/**
- */
-public class PersistenceDelegateBindingExtensionPointManager extends AbstractExtensionPointManager<PersistenceDelegateBinding> {
-
- /*
- * Thread save singleton instance creation.
- */
- private static class LazyInstance {
- public static PersistenceDelegateBindingExtensionPointManager instance = new PersistenceDelegateBindingExtensionPointManager();
- }
-
- /**
- * Constructor.
- */
- PersistenceDelegateBindingExtensionPointManager() {
- super();
- }
-
- /**
- * Returns the singleton instance of the extension point manager.
- */
- public static PersistenceDelegateBindingExtensionPointManager getInstance() {
- return LazyInstance.instance;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
- */
- @Override
- protected String getExtensionPointId() {
- return "org.eclipse.tcf.te.runtime.persistence.bindings"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
- */
- @Override
- protected String getConfigurationElementName() {
- return "binding"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#doCreateExtensionProxy(org.eclipse.core.runtime.IConfigurationElement)
- */
- @Override
- protected ExecutableExtensionProxy<PersistenceDelegateBinding> doCreateExtensionProxy(IConfigurationElement element) throws CoreException {
- return new ExecutableExtensionProxy<PersistenceDelegateBinding>(element) {
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy#newInstance()
- */
- @Override
- public PersistenceDelegateBinding newInstance() {
- PersistenceDelegateBinding instance = new PersistenceDelegateBinding();
- try {
- instance.setInitializationData(getConfigurationElement(), null, null);
- } catch (CoreException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- e.getLocalizedMessage(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- return instance;
- }
- };
- }
-
- /**
- * Returns the applicable persistence delegate bindings for the given delegate context.
- *
- * @param context The delegate context or <code>null</code>.
- * @return The list of applicable editor page bindings or an empty array.
- */
- public PersistenceDelegateBinding[] getApplicableBindings(Object context, Object container) {
- List<PersistenceDelegateBinding> applicable = new ArrayList<PersistenceDelegateBinding>();
-
- for (PersistenceDelegateBinding binding : getBindings()) {
- Expression enablement = binding.getEnablement();
-
- // The binding is applicable by default if no expression is specified.
- boolean isApplicable = enablement == null;
-
- if (enablement != null) {
- if (context != null) {
- // Set the default variable to the delegate context.
- EvaluationContext evalContext = new EvaluationContext(null, context);
- evalContext.addVariable("context", context); //$NON-NLS-1$
- if (context instanceof Class) {
- evalContext.addVariable("contextClass", ((Class<?>)context).getName()); //$NON-NLS-1$
- }
- evalContext.addVariable("container", container); //$NON-NLS-1$
- if (container instanceof Class) {
- evalContext.addVariable("containerClass", ((Class<?>)container).getName()); //$NON-NLS-1$
- }
- // Allow plugin activation
- evalContext.setAllowPluginActivation(true);
- // Evaluate the expression
- try {
- isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE);
- } catch (CoreException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- e.getLocalizedMessage(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- } else {
- // The enablement is false by definition if no delegate context is given.
- isApplicable = false;
- }
- }
-
- // Add the binding if applicable
- if (isApplicable) {
- applicable.add(binding);
- }
- }
-
- return applicable.toArray(new PersistenceDelegateBinding[applicable.size()]);
- }
-
- /**
- * Returns the list of all contributed persistence delegate bindings.
- *
- * @return The list of contributed persistence delegate bindings, or an empty array.
- */
- public PersistenceDelegateBinding[] getBindings() {
- List<PersistenceDelegateBinding> contributions = new ArrayList<PersistenceDelegateBinding>();
- Collection<ExecutableExtensionProxy<PersistenceDelegateBinding>> persistenceDelegateBindings = getExtensions().values();
- for (ExecutableExtensionProxy<PersistenceDelegateBinding> persistenceDelegateBinding : persistenceDelegateBindings) {
- PersistenceDelegateBinding instance = persistenceDelegateBinding.getInstance();
- if (instance != null && !contributions.contains(instance)) {
- contributions.add(instance);
- }
- }
-
- return contributions.toArray(new PersistenceDelegateBinding[contributions.size()]);
- }
-
- /**
- * Returns the persistence delegate binding identified by its unique id. If no persistence
- * delegate binding with the specified id is registered, <code>null</code> is returned.
- *
- * @param id The unique id of the persistence delegate binding or <code>null</code>
- *
- * @return The persistence delegate binding instance or <code>null</code>.
- */
- public PersistenceDelegateBinding getBinding(String id) {
- PersistenceDelegateBinding contribution = null;
- if (getExtensions().containsKey(id)) {
- ExecutableExtensionProxy<PersistenceDelegateBinding> proxy = getExtensions().get(id);
- // Get the extension instance
- contribution = proxy.getInstance();
- }
-
- return contribution;
- }
-}
+/*******************************************************************************
+ * 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.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleActivator;
+
+
+/**
+ */
+public class PersistenceDelegateBindingExtensionPointManager extends AbstractExtensionPointManager<PersistenceDelegateBinding> {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstance {
+ public static PersistenceDelegateBindingExtensionPointManager instance = new PersistenceDelegateBindingExtensionPointManager();
+ }
+
+ /**
+ * Constructor.
+ */
+ PersistenceDelegateBindingExtensionPointManager() {
+ super();
+ }
+
+ /**
+ * Returns the singleton instance of the extension point manager.
+ */
+ public static PersistenceDelegateBindingExtensionPointManager getInstance() {
+ return LazyInstance.instance;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
+ */
+ @Override
+ protected String getExtensionPointId() {
+ return "org.eclipse.tcf.te.runtime.persistence.bindings"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
+ */
+ @Override
+ protected String getConfigurationElementName() {
+ return "binding"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#doCreateExtensionProxy(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ @Override
+ protected ExecutableExtensionProxy<PersistenceDelegateBinding> doCreateExtensionProxy(IConfigurationElement element) throws CoreException {
+ return new ExecutableExtensionProxy<PersistenceDelegateBinding>(element) {
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy#newInstance()
+ */
+ @Override
+ public PersistenceDelegateBinding newInstance() {
+ PersistenceDelegateBinding instance = new PersistenceDelegateBinding();
+ try {
+ instance.setInitializationData(getConfigurationElement(), null, null);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ return instance;
+ }
+ };
+ }
+
+ /**
+ * Returns the applicable persistence delegate bindings for the given delegate context.
+ *
+ * @param context The delegate context or <code>null</code>.
+ * @return The list of applicable editor page bindings or an empty array.
+ */
+ public PersistenceDelegateBinding[] getApplicableBindings(Object context, Object container) {
+ List<PersistenceDelegateBinding> applicable = new ArrayList<PersistenceDelegateBinding>();
+
+ for (PersistenceDelegateBinding binding : getBindings()) {
+ Expression enablement = binding.getEnablement();
+
+ // The binding is applicable by default if no expression is specified.
+ boolean isApplicable = enablement == null;
+
+ if (enablement != null) {
+ if (context != null) {
+ // Set the default variable to the delegate context.
+ EvaluationContext evalContext = new EvaluationContext(null, context);
+ evalContext.addVariable("context", context); //$NON-NLS-1$
+ if (context instanceof Class) {
+ evalContext.addVariable("contextClass", ((Class<?>)context).getName()); //$NON-NLS-1$
+ }
+ else {
+ evalContext.addVariable("contextClass", context.getClass().getName()); //$NON-NLS-1$
+ }
+ evalContext.addVariable("container", container); //$NON-NLS-1$
+ if (container instanceof Class) {
+ evalContext.addVariable("containerClass", ((Class<?>)container).getName()); //$NON-NLS-1$
+ }
+ else {
+ evalContext.addVariable("containerClass", container.getClass().getName()); //$NON-NLS-1$
+ }
+ // Allow plugin activation
+ evalContext.setAllowPluginActivation(true);
+ // Evaluate the expression
+ try {
+ isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ } else {
+ // The enablement is false by definition if no delegate context is given.
+ isApplicable = false;
+ }
+ }
+
+ // Add the binding if applicable
+ if (isApplicable) {
+ applicable.add(binding);
+ }
+ }
+
+ return applicable.toArray(new PersistenceDelegateBinding[applicable.size()]);
+ }
+
+ /**
+ * Returns the list of all contributed persistence delegate bindings.
+ *
+ * @return The list of contributed persistence delegate bindings, or an empty array.
+ */
+ public PersistenceDelegateBinding[] getBindings() {
+ List<PersistenceDelegateBinding> contributions = new ArrayList<PersistenceDelegateBinding>();
+ Collection<ExecutableExtensionProxy<PersistenceDelegateBinding>> persistenceDelegateBindings = getExtensions().values();
+ for (ExecutableExtensionProxy<PersistenceDelegateBinding> persistenceDelegateBinding : persistenceDelegateBindings) {
+ PersistenceDelegateBinding instance = persistenceDelegateBinding.getInstance();
+ if (instance != null && !contributions.contains(instance)) {
+ contributions.add(instance);
+ }
+ }
+
+ return contributions.toArray(new PersistenceDelegateBinding[contributions.size()]);
+ }
+
+ /**
+ * Returns the persistence delegate binding identified by its unique id. If no persistence
+ * delegate binding with the specified id is registered, <code>null</code> is returned.
+ *
+ * @param id The unique id of the persistence delegate binding or <code>null</code>
+ *
+ * @return The persistence delegate binding instance or <code>null</code>.
+ */
+ public PersistenceDelegateBinding getBinding(String id) {
+ PersistenceDelegateBinding contribution = null;
+ if (getExtensions().containsKey(id)) {
+ ExecutableExtensionProxy<PersistenceDelegateBinding> proxy = getExtensions().get(id);
+ // Get the extension instance
+ contribution = proxy.getInstance();
+ }
+
+ return contribution;
+ }
+}

Back to the top