diff options
author | Tobias Schwarz | 2012-10-22 10:34:01 +0000 |
---|---|---|
committer | Tobias Schwarz | 2012-10-22 10:34:38 +0000 |
commit | 3f6109bedbf34e43ec86e2c6202db8ec7fc697ae (patch) | |
tree | e4b2d694eb894171f46d03db105b6162d09f053a /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence | |
parent | 12af7faaa3b155d79fded5aa33eab7c25f005946 (diff) | |
download | org.eclipse.tcf-3f6109bedbf34e43ec86e2c6202db8ec7fc697ae.tar.gz org.eclipse.tcf-3f6109bedbf34e43ec86e2c6202db8ec7fc697ae.tar.xz org.eclipse.tcf-3f6109bedbf34e43ec86e2c6202db8ec7fc697ae.zip |
[Target Explorer] variable delegates and provider für persistence
delegates
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence')
12 files changed, 477 insertions, 10 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF index a88a8d288..17f2c1ecd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF @@ -9,7 +9,8 @@ Require-Bundle: com.google.gson;bundle-version="2.1.0", org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.core.expressions;bundle-version="3.4.400", org.eclipse.tcf.te.runtime;bundle-version="1.1.0", - org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0" + org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0", + org.eclipse.core.variables;bundle-version="3.2.600" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml index 57db69c0e..ef2d60cee 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml @@ -6,6 +6,7 @@ <extension-point id="delegates" name="%ExtensionPoint.delegates.name" schema="schema/delegates.exsd"/> <extension-point id="bindings" name="%ExtensionPoint.bindings.name" schema="schema/bindings.exsd"/> <extension-point id="variableDelegates" name="%ExtensionPoint.variableDelegates.name" schema="schema/variableDelegates.exsd"/> + <extension-point id="variableProviders" name="%ExtensionPoint.variableProviders.name" schema="schema/variableProviders.exsd"/> <!-- Service contributions --> <extension point="org.eclipse.tcf.te.runtime.services.services"> @@ -58,4 +59,12 @@ </binding> </extension> +<!-- Variable Provider Contribution --> + <extension point="org.eclipse.tcf.te.runtime.persistence.variableProviders"> + <provider + id="org.eclipse.tcf.te.runtime.persistence.variableProvider" + class="org.eclipse.tcf.te.runtime.persistence.internal.VariableProvider"> + </provider> + </extension> + </plugin> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableDelegates.exsd b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableDelegates.exsd index 5cac61732..e3cbe6a84 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableDelegates.exsd +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableDelegates.exsd @@ -54,8 +54,6 @@ </documentation> </annotation> <complexType> - <sequence> - </sequence> <attribute name="id" type="string" use="required"> <annotation> <documentation> @@ -101,7 +99,7 @@ </appinfo> <documentation> <pre> - <extension point="org.eclipse.tcf.te.runtime.persistence.variableDelegatess"> + <extension point="org.eclipse.tcf.te.runtime.persistence.variableDelegates"> <delegate id="org.eclipse.tcf.te.runtime.persistence.delegate.VariableDelegate" class="org.eclipse.tcf.te.runtime.persistence.internal.VariableDelegate" diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableProviders.exsd b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableProviders.exsd new file mode 100644 index 000000000..ec35625a0 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/variableProviders.exsd @@ -0,0 +1,118 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.tcf.te.runtime.persistence" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.tcf.te.runtime.persistence" id="variableProviders" name="Variable Providers Extension Point"/> + </appinfo> + <documentation> + This extension point is used to declare the variable provider + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence> + <element ref="provider" minOccurs="1" maxOccurs="unbounded"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="provider"> + <annotation> + <documentation> + Declares a variable provider. + </documentation> + </annotation> + <complexType> + <attribute name="id" type="string" use="required"> + <annotation> + <documentation> + The unique id of the variable provider contribution. + </documentation> + </annotation> + </attribute> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + The variable provider implementation. + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + Target Explorer 1.0.0 + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + <pre> + <extension point="org.eclipse.tcf.te.runtime.persistence.variableProviders"> + <provider + id="org.eclipse.tcf.te.runtime.persistence.delegate.VariableProvider" + class="org.eclipse.tcf.te.runtime.persistence.internal.VariableProvider"/> + </extension> +</pre> + </documentation> + </annotation> + + + + <annotation> + <appinfo> + <meta.section type="copyright"/> + </appinfo> + <documentation> + 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. + </documentation> + </annotation> + +</schema> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java new file mode 100644 index 000000000..09da17128 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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 org.eclipse.core.runtime.Path; +import org.eclipse.tcf.te.runtime.utils.Host; + +/** + * AbstractPathVariableDelegate + */ +public abstract class AbstractPathVariableDelegate extends AbstractVariableDelegate { + + /** + * Return true, if the key represents a path value. + * @param key The key to check. + * @return <code>true</code> if the key represents a path value. + */ + protected abstract boolean isPathKey(String key); + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.AbstractVariableDelegate#useVariable(java.lang.String, java.lang.Object, java.lang.String, java.lang.String) + */ + @Override + protected Object useVariable(String key, Object value, String variableName, String variableValue) { + if (isPathKey(key) && value instanceof String) { + String valuePath = new Path(Host.isWindowsHost() ? ((String)value).toLowerCase() : (String)value).toString(); + String variablePath = new Path(Host.isWindowsHost() ? variableValue.toLowerCase() : (String)variableValue).toString(); + return super.useVariable(key, valuePath, variableName, variablePath); + } + + return super.useVariable(key, value, variableName, variableValue); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java new file mode 100644 index 000000000..b709d41d8 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * 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.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider; + +/** + * AbstractVariableDelegate + */ +public abstract class AbstractVariableDelegate implements IVariableDelegate { + + /** + * Get the list of keys this delegate is handling. + * @return The list of handled keys. + */ + protected abstract String[] getKeysToHandle(); + + /** + * Try to use a variable inside the given value. + * @param key The key of the value. + * @param value The value to inspect. + * @param variableName The variable name to use. + * @param variableValue The variable value. + * @return The new value if the variable was used, <code>null</code> otherwise. + */ + protected Object useVariable(String key, Object value, String variableName, String variableValue) { + if (value instanceof String && ((String)value).contains(variableValue)) { + return ((String)value).replaceAll(variableValue, "<"+variableName+">"); //$NON-NLS-1$ //$NON-NLS-2$ + } + return null; + } + + /** + * Try to restore a variable inside the given value. + * @param key The key of the value. + * @param value The value to inspect. + * @param variableName The variable name to restore. + * @param variableValue The variable value. + * @return The new value if the variable was used, <code>null</code> otherwise. + */ + protected Object restoreValue(String key, Object value, String variableName, String variableValue) { + if (value instanceof String && ((String)value).contains("<"+variableName+">")) { //$NON-NLS-1$ //$NON-NLS-2$ + return ((String)value).replaceAll("<"+variableName+">", variableValue); //$NON-NLS-1$ //$NON-NLS-2$ + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate#getVariables(java.util.Map) + */ + @Override + public Map<String,String> getVariables(Map<String, Object> map) { + Map<String,String> usedVariables = new HashMap<String, String>(); + + for (String key : getKeysToHandle()) { + if (map.get(key) != null) { + for (Entry<String,String> variable : getVariablesMap(null).entrySet()) { + Object newValue = useVariable(key, map.get(key), variable.getKey(), variable.getValue()); + if (newValue != null) { + map.put(key, newValue); + usedVariables.put(variable.getKey(), variable.getValue()); + } + } + } + } + + return usedVariables; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate#putVariables(java.util.Map, java.util.Map) + */ + @Override + public Map<String,Object> putVariables(Map<String,Object> map, Map<String,String> defaultVariables) { + for (String key : getKeysToHandle()) { + if (map.get(key) != null) { + for (Entry<String,String> variable : getVariablesMap(defaultVariables).entrySet()) { + Object newValue = restoreValue(key, map.get(key), variable.getKey(), variable.getValue()); + if (newValue != null) { + map.put(key, newValue); + } + } + } + } + + return map; + } + + /** + * Calculate and return the map of variables to use. + * If a map of default variables is given, all variables will be added to the result + * map if the name does not exist in the list of provided {@link IVariableProvider} variables. + * @param defaultVariables Default variables or <code>null</code>. + * @return Map of variables to use. + */ + protected Map<String,String> getVariablesMap(Map<String,String> defaultVariables) { + Map<String,String> variables = new HashMap<String, String>(); + for (IVariableProvider provider : PersistenceManager.getInstance().getVariableProviders()) { + variables.putAll(provider.getVariables()); + } + + if (defaultVariables != null) { + for (Entry<String,String> defaultVariable : defaultVariables.entrySet()) { + if (!variables.containsKey(defaultVariable.getKey())) { + variables.put(defaultVariable.getKey(), defaultVariable.getValue()); + } + } + } + + return variables; + } + +} 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 71b4e4409..06c37d5b0 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 @@ -134,12 +134,12 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I Map<String,Object> data = toMap(context); if (data != null) { - Map<String,String> variables = new HashMap<String, String>(); + Map<String,String> variables = null; IVariableDelegate[] delegates = PersistenceManager.getInstance().getVariableDelegates(this); for (IVariableDelegate delegate : delegates) { - delegate.getVariables(data, variables); + variables = delegate.getVariables(data); } - if (!variables.isEmpty()) { + if (variables != null && !variables.isEmpty()) { data.put(VARIABLES, variables); } } @@ -196,7 +196,7 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I Map<String,String> variables = (Map<String,String>)data.remove(VARIABLES); IVariableDelegate[] delegates = PersistenceManager.getInstance().getVariableDelegates(this); for (IVariableDelegate delegate : delegates) { - delegate.putVariables(data, variables); + data = delegate.putVariables(data, variables); } } 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 795c9b564..b89b29d3f 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 @@ -22,9 +22,11 @@ import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy; import org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleActivator; import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider; import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBinding; import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBindingExtensionPointManager; import org.eclipse.tcf.te.runtime.persistence.internal.VariableDelegateExtensionPointManager; +import org.eclipse.tcf.te.runtime.persistence.internal.VariableProviderExtensionPointManager; /** * Persistence delegate manager implementation. @@ -155,4 +157,13 @@ public class PersistenceManager extends AbstractExtensionPointManager<IPersisten public IVariableDelegate[] getVariableDelegates(IPersistenceDelegate persistenceDelegate) { return VariableDelegateExtensionPointManager.getInstance().getDelegates(persistenceDelegate); } + + /** + * Returns all variable providers. + * + * @return The list of variable providers or an empty array. + */ + public IVariableProvider[] getVariableProviders() { + return VariableProviderExtensionPointManager.getInstance().getProviders(); + } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java index 5a95009c9..7817f54be 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java @@ -17,7 +17,18 @@ import java.util.Map; */ public interface IVariableDelegate { - public void getVariables(Map<String,Object> map, Map<String,String> variables); + /** + * Extract variables from map and use them inside map values. + * @param map The map to inspect. + * @return The used variables. + */ + public Map<String,String> getVariables(Map<String, Object> map); - public void putVariables(Map<String,Object> map, Map<String,String> variables); + /** + * Replace all variables inside map values by current variable value or given default. + * @param map The map with variables to inspect. + * @param defaultVariables The default variables. + * @return The map without variables. + */ + public Map<String,Object> putVariables(Map<String,Object> map, Map<String,String> defaultVariables); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java new file mode 100644 index 000000000..a13ca029b --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.interfaces; + +import java.util.Map; + +/** + * IVariableProvider + */ +public interface IVariableProvider { + + /** + * Get the list of provided variables. + * @return The provided variables. + */ + public Map<String,String> getVariables(); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java new file mode 100644 index 000000000..bbf3b0861 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java @@ -0,0 +1,48 @@ +/** + * VariableProvider.java + * Created on 22.10.2012 + * + * Copyright (c) 2012 Wind River Systems, Inc. + * + * The right to copy, distribute, modify, or otherwise make use + * of this software may be licensed only pursuant to the terms + * of an applicable Wind River license agreement. + */ +package org.eclipse.tcf.te.runtime.persistence.internal; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.Path; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider; + +/** + * + */ +public class VariableProvider implements IVariableProvider { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider#getVariables() + */ + @Override + public Map<String, String> getVariables() { + Map<String,String> variables = new HashMap<String, String>(); + + try { + IDynamicVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable("workspace_loc"); //$NON-NLS-1$ + if (variable != null) { + String value = variable.getValue(null); + if (value != null) { + variables.put("WORKSPACE_LOC", new Path(value).toString()); //$NON-NLS-1$ + } + } + } + catch (Exception e) { + } + + return variables; + } + +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java new file mode 100644 index 000000000..452b3193d --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.internal; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager; +import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider; + + +/** + * VariableProviderExtensionPointManager + */ +public class VariableProviderExtensionPointManager extends AbstractExtensionPointManager<IVariableProvider> { + + /* + * Thread save singleton instance creation. + */ + private static class LazyInstance { + public static VariableProviderExtensionPointManager instance = new VariableProviderExtensionPointManager(); + } + + /** + * Constructor. + */ + VariableProviderExtensionPointManager() { + super(); + } + + /** + * Returns the singleton instance of the extension point manager. + */ + public static VariableProviderExtensionPointManager 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.variableProviders"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName() + */ + @Override + protected String getConfigurationElementName() { + return "provider"; //$NON-NLS-1$ + } + + /** + * Returns all variable providers. + * + * @return The list of variable providers or an empty array. + */ + public IVariableProvider[] getProviders() { + List<IVariableProvider> contributions = new ArrayList<IVariableProvider>(); + Collection<ExecutableExtensionProxy<IVariableProvider>> delegates = getExtensions().values(); + for (ExecutableExtensionProxy<IVariableProvider> delegate : delegates) { + IVariableProvider instance = delegate.getInstance(); + if (instance != null && !contributions.contains(instance)) { + contributions.add(instance); + } + } + return contributions.toArray(new IVariableProvider[contributions.size()]); + } +} |