Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2012-03-30 10:37:38 +0000
committerUwe Stieber2012-03-30 10:37:38 +0000
commit584d406667038d8c2b9595f291f354b1c4aa4416 (patch)
tree3941823891752d3f0092bae69aa1fff8e170ef44 /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence
parentfa6f33666c29c335cfc6a6f6e957a9727529c46d (diff)
downloadorg.eclipse.tcf-584d406667038d8c2b9595f291f354b1c4aa4416.tar.gz
org.eclipse.tcf-584d406667038d8c2b9595f291f354b1c4aa4416.tar.xz
org.eclipse.tcf-584d406667038d8c2b9595f291f354b1c4aa4416.zip
Target Explorer: REWORK persistence, ADD file transfer and referenced projects to remote app launch
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/META-INF/MANIFEST.MF4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties41
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.xml7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd134
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java20
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java103
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java335
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceDelegateManager.java)57
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java78
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java53
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java32
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceDelegate.java59
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java68
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java71
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java66
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java182
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java275
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java152
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java119
19 files changed, 1148 insertions, 708 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 c5c7ec970..278123ed6 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
@@ -7,12 +7,12 @@ Bundle-Activator: org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleAct
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0"
+ org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0",
+ org.eclipse.core.expressions;bundle-version="3.4.300"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.eclipse.tcf.te.runtime.persistence,
org.eclipse.tcf.te.runtime.persistence.activator;x-internal:=true,
org.eclipse.tcf.te.runtime.persistence.interfaces,
- org.eclipse.tcf.te.runtime.persistence.properties,
org.eclipse.tcf.te.runtime.persistence.services
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties
index 4fb372828..09b469fdb 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/plugin.properties
@@ -1,20 +1,21 @@
-##################################################################################
-# Copyright (c) 2011 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
-##################################################################################
-
-pluginName = Target Explorer, Persistence Runtime plug-in
-providerName = Eclipse.org - TCF
-
-# ***** Extension Points *****
-
-ExtensionPoint.delegates.name=Target Explorer Persistence Delegates
-
-# ***** Persistence Delegates *****
-
-PropertiesFilePersistenceDelegate.label=Properties File Persistence Delegate
+##################################################################################
+# Copyright (c) 2011 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
+##################################################################################
+
+pluginName = Target Explorer, Persistence Runtime plug-in
+providerName = Eclipse.org - TCF
+
+# ***** Extension Points *****
+
+ExtensionPoint.delegates.name=Target Explorer Persistence Delegates
+ExtensionPoint.bindings.name=Target Explorer Persistence Delegate Bindings
+
+# ***** Persistence Delegates *****
+
+PropertiesFilePersistenceDelegate.label=Properties File Persistence Delegate
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 5b298f250..b14210714 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
@@ -4,11 +4,12 @@
<!-- Extension points -->
<extension-point id="delegates" name="%ExtensionPoint.delegates.name" schema="schema/delegates.exsd"/>
+ <extension-point id="bindings" name="%ExtensionPoint.bindings.name" schema="schema/bindings.exsd"/>
<!-- Persistence delegate contributions -->
<extension point="org.eclipse.tcf.te.runtime.persistence.delegates">
<delegate
- class="org.eclipse.tcf.te.runtime.persistence.properties.PropertiesFilePersistenceDelegate"
+ class="org.eclipse.tcf.te.runtime.persistence.AbstractPropertiesPersistenceDelegate"
id="org.eclipse.tcf.te.runtime.persistence.properties"
label="%PropertiesFilePersistenceDelegate.label">
</delegate>
@@ -17,9 +18,9 @@
<!-- Service contributions -->
<extension point="org.eclipse.tcf.te.runtime.services.services">
<service
- class="org.eclipse.tcf.te.runtime.persistence.services.PersistenceService"
+ class="org.eclipse.tcf.te.runtime.persistence.services.URIPersistenceService"
id="org.eclipse.tcf.te.runtime.services.persistence">
- <serviceType class="org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService"/>
+ <serviceType class="org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService"/>
</service>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd
new file mode 100644
index 000000000..d222767f9
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/schema/bindings.exsd
@@ -0,0 +1,134 @@
+<?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="bindings" name="Persistence Delegate Bindings Extension Point"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to declare the persistence delegate bindings.
+&lt;p&gt;
+&lt;b&gt;Note:&lt;/b&gt; For the enablement expression evaluation, the default variable and &lt;b&gt;context&lt;/b&gt; is set to the delegate context,
+the variable &lt;b&gt;contextClass&lt;/b&gt; is set to the name of the class if the context to evaluate is an instance of java.lang.Class.
+&lt;br&gt;
+The variable &lt;b&gt;container&lt;/b&gt; is set with the persistence container object (i.e. ILaunchConfiguration, ...),
+the variable &lt;b&gt;containerClass&lt;/b&gt; is set to the name of the class if the container to evaluate is an instance of java.lang.Class,
+
+ </documentation>
+ </annotation>
+
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="binding" 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="binding">
+ <annotation>
+ <documentation>
+ Declares a persistence delegate binding.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="enablement" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ persistence delegaete binding contribution.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="delegateId" type="string" use="required">
+ <annotation>
+ <documentation>
+ The unique id of the referenced persistence delegate.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.tcf.te.runtime.persistence.delegates/delegate/@id"/>
+ </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>
+ &lt;pre&gt;
+ &lt;extension point=&quot;org.eclipse.tcf.te.runtime.persistence.bindings&quot;&gt;
+ &lt;binding
+ id=&quot;org.eclipse.tcf.te.runtime.persistence.binding.LaunchConfigPersistenceDelegate&quot;
+ handlerId=&quot;org.eclipse.tcf.te.launch.core.persistence.LaunchConfigPersistenceDelegate&quot;&gt;
+ &lt;enablement&gt;
+ ...
+ &lt;/enablement&gt;
+ &lt;/binding&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+ </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/AbstractPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java
deleted file mode 100644
index dd04fb2ca..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPersistenceDelegate.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
-
-/**
- * Abstract persistence delegate implementation.
- */
-public abstract class AbstractPersistenceDelegate extends ExecutableExtension implements IPersistenceDelegate {
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java
new file mode 100644
index 000000000..952b6f532
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesPersistenceDelegate.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+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;
+
+/**
+ * Properties file persistence delegate implementation.
+ * <p>
+ * The persistence delegates reads and writes a simple grouped properties file format.
+ */
+public abstract class AbstractPropertiesPersistenceDelegate extends ExecutableExtension implements IPersistenceDelegate {
+
+ public final static String CORE_SECTION_NAME = "core"; //$NON-NLS-1$
+
+ /**
+ * Constructor.
+ */
+ public AbstractPropertiesPersistenceDelegate() {
+ super();
+ }
+
+ /**
+ * 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 (String key : attrs.keySet()) {
+ if (!key.endsWith(".transient")) { //$NON-NLS-1$
+ result.put(key, attrs.get(key));
+ }
+ }
+ }
+
+ 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;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java
new file mode 100644
index 000000000..b5d7e9b98
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPropertiesToURIPersistenceDelegate.java
@@ -0,0 +1,335 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.BufferedReader;
+import java.io.BufferedWriter;
+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.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Properties file persistence delegate implementation.
+ * <p>
+ * The persistence delegates reads and writes a simple grouped properties file format.
+ */
+public abstract class AbstractPropertiesToURIPersistenceDelegate extends AbstractPropertiesPersistenceDelegate {
+
+ private String defaultFileExtension;
+
+ /**
+ * Constructor.
+ *
+ * @param defaultFileExtension The default file extension.
+ */
+ protected AbstractPropertiesToURIPersistenceDelegate(String defaultFileExtension) {
+ super();
+ Assert.isNotNull(defaultFileExtension);
+ this.defaultFileExtension = defaultFileExtension;
+ }
+
+ /**
+ * Return the default extenion.
+ */
+ 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();
+ }
+
+ // Create the writer object
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); //$NON-NLS-1$
+ try {
+ // Write the first level of attributes
+ writeMap(writer, key, toMap(context));
+ } finally {
+ writer.close();
+ }
+ }
+
+ return container;
+ }
+
+ /**
+ * Write the map data.
+ *
+ * @param writer The writer. Must not be <code>null</code>.
+ * @param section The section name or <code>null</code>.
+ * @param data The data. Must not be <code>null</code>.
+ */
+ private void writeMap(BufferedWriter writer, String section, Map<String, Object> data) throws IOException {
+ Assert.isNotNull(writer);
+ Assert.isNotNull(data);
+
+ // Will contain the list of map keys where the value is a map type itself.
+ List<String> childMapKeys = new ArrayList<String>();
+ // Will contain the list of map keys where the value is not an map type.
+ List<String> childKeys = new ArrayList<String>();
+
+ // Get all the map keys and filter the map type values
+ for (String key : data.keySet()) {
+ if (data.get(key) instanceof Map) {
+ childMapKeys.add(key);
+ }
+ else {
+ childKeys.add(key);
+ }
+ }
+
+ // Sort both lists
+ Collections.sort(childMapKeys);
+ Collections.sort(childKeys);
+
+ // If the child key list is not empty, write the section
+ if (!childKeys.isEmpty()) {
+ // Write a new line except it is the "core" section
+ if (section != null && !CORE_SECTION_NAME.equals(section)) {
+ writer.newLine();
+ }
+
+ // Write the header
+ if (section != null) {
+ writer.write("[" + section.trim() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+ writer.newLine();
+ }
+
+ for (String key : childKeys) {
+ if (section != null) {
+ writer.write('\t');
+ }
+ writer.write(key);
+ writer.write(" = "); //$NON-NLS-1$
+
+ Object value = data.get(key);
+ if (value instanceof List) {
+ writer.write(Arrays.deepToString(((List<?>)value).toArray()));
+ } else {
+ writer.write(value.toString());
+ }
+
+ writer.newLine();
+ }
+ }
+
+ // If there are map type values, write them now
+ if (!childMapKeys.isEmpty()) {
+ for (String key : childMapKeys) {
+ // Calculate the section name
+ String newSection = section == null || CORE_SECTION_NAME.equals(section) ? key.trim() : section + "." + key.trim(); //$NON-NLS-1$
+ // Write it
+ writeMap(writer, newSection, (Map<String, Object>)data.get(key));
+ }
+ }
+ }
+
+ /* (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);
+
+ 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$
+ }
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> data = context instanceof Map ? (Map<String,Object>)context : new HashMap<String, Object>();
+
+ // Create the reader object
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
+ try {
+ readMap(reader, key, data);
+ } finally {
+ reader.close();
+ }
+
+ if (key != null && data.containsKey(key) && data.get(key) instanceof Map) {
+ data = (Map<String,Object>)data.get(key);
+ }
+
+ context = fromMap(data, context);
+ }
+
+ return context;
+ }
+
+ private static Pattern SECTION = Pattern.compile("\\s*\\[([^\\]]+)\\]\\s*"); //$NON-NLS-1$
+ private static Pattern PROPERTY = Pattern.compile("\\s*(.+\\s*=\\s*.+)"); //$NON-NLS-1$
+
+ /**
+ * Read the data.
+ *
+ * @param reader The reader. Must not be <code>null</code>.
+ * @param section The section name or <code>null</code>.
+ * @param data The data. Must not be <code>null</code>.
+ */
+ private void readMap(BufferedReader reader, String section, Map<String, Object> data) throws IOException {
+ Assert.isNotNull(reader);
+ Assert.isNotNull(data);
+
+ // The sections by name for easier access.
+ // The "core" section is the incoming data object
+ Map<String, Map<String, Object>> sections = new HashMap<String, Map<String, Object>>();
+ sections.put(section == null ? CORE_SECTION_NAME : section, data);
+
+ String currentSection = section == null ? CORE_SECTION_NAME : section;
+ String line = reader.readLine();
+ while (line != null) {
+ Matcher matcher = SECTION.matcher(line);
+ if (matcher.matches()) {
+ // Section names are case-sensitive too
+ currentSection = matcher.group(1);
+ if (sections.get(currentSection) == null) {
+ sections.put(currentSection, new HashMap<String, Object>());
+ }
+ } else {
+ matcher = PROPERTY.matcher(line);
+ if (matcher.matches()) {
+ String property = matcher.group(1);
+ String[] pieces = property.split("=", 2); //$NON-NLS-1$
+ Map<String, Object> sectionMap = sections.get(currentSection);
+ sectionMap.put(pieces[0].trim(), pieces[1].trim());
+ }
+ }
+
+ line = reader.readLine();
+ }
+
+ // Recreate the sections hierarchy
+ for (String sectionName : sections.keySet()) {
+ if (CORE_SECTION_NAME.equals(sectionName)) {
+ continue;
+ }
+ Map<String, Object> sectionMap = sections.get(sectionName);
+ if (sectionName.contains(".")) { //$NON-NLS-1$
+ // Split the section name and recreate the missing hierarchy
+ String[] pieces = sectionName.split("\\."); //$NON-NLS-1$
+ Map<String, Object> parentSection = data;
+ for (String subSectionName : pieces) {
+ if (CORE_SECTION_NAME.equals(subSectionName)) {
+ continue;
+ }
+
+ if (sectionName.endsWith(subSectionName)) {
+ parentSection.put(subSectionName, sectionMap);
+ } else {
+ Map<String, Object> subSection = (Map<String, Object>)parentSection.get(subSectionName);
+ if (subSection == null) {
+ subSection = new HashMap<String, Object>();
+ parentSection.put(subSectionName, subSection);
+ }
+ parentSection = subSection;
+ }
+ }
+ } else {
+ // Place it into the root object, but check if it may exist
+ Map<String, Object> oldSection = (Map<String, Object>)data.get(sectionName);
+ if (oldSection != null) {
+ oldSection.putAll(sectionMap);
+ }
+ else {
+ data.put(sectionName, sectionMap);
+ }
+ }
+ }
+ }
+
+ /* (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;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceDelegateManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
index 802f94cb9..f9a8dd163 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceDelegateManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
@@ -13,33 +13,40 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.core.runtime.Assert;
+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;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBinding;
+import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBindingExtensionPointManager;
/**
* Persistence delegate manager implementation.
*/
-public class PersistenceDelegateManager extends AbstractExtensionPointManager<IPersistenceDelegate> {
+public class PersistenceManager extends AbstractExtensionPointManager<IPersistenceDelegate> {
/*
* Thread save singleton instance creation.
*/
private static class LazyInstance {
- public static PersistenceDelegateManager instance = new PersistenceDelegateManager();
+ public static PersistenceManager instance = new PersistenceManager();
}
/**
* Constructor.
*/
- PersistenceDelegateManager() {
+ PersistenceManager() {
super();
}
/**
* Returns the singleton instance of the extension point manager.
*/
- public static PersistenceDelegateManager getInstance() {
+ public static PersistenceManager getInstance() {
return LazyInstance.instance;
}
@@ -67,7 +74,7 @@ public class PersistenceDelegateManager extends AbstractExtensionPointManager<IP
*
* @return The list of contributed persistence delegates, or an empty array.
*/
- public IPersistenceDelegate[] getDelegates(boolean unique) {
+ protected IPersistenceDelegate[] getDelegates(boolean unique) {
List<IPersistenceDelegate> contributions = new ArrayList<IPersistenceDelegate>();
Collection<ExecutableExtensionProxy<IPersistenceDelegate>> delegates = getExtensions().values();
for (ExecutableExtensionProxy<IPersistenceDelegate> delegate : delegates) {
@@ -89,7 +96,7 @@ public class PersistenceDelegateManager extends AbstractExtensionPointManager<IP
*
* @return The persistence delegate instance or <code>null</code>.
*/
- public IPersistenceDelegate getDelegate(String id, boolean unique) {
+ protected IPersistenceDelegate getDelegate(String id, boolean unique) {
IPersistenceDelegate contribution = null;
if (getExtensions().containsKey(id)) {
ExecutableExtensionProxy<IPersistenceDelegate> proxy = getExtensions().get(id);
@@ -99,4 +106,40 @@ public class PersistenceDelegateManager extends AbstractExtensionPointManager<IP
return contribution;
}
+
+ /**
+ * Returns the persistence delegate which is enabled for the given
+ * context and persistence container.
+ *
+ * @param context The persistence delegate context. Must not be <code>null</code>.
+ * @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) {
+ Assert.isNotNull(context);
+
+ List<IPersistenceDelegate> delegates = new ArrayList<IPersistenceDelegate>();
+
+ // Get the list of applicable bindings
+ PersistenceDelegateBinding[] bindings = PersistenceDelegateBindingExtensionPointManager.getInstance().getApplicableBindings(context, container);
+ for (PersistenceDelegateBinding binding : bindings) {
+ IPersistenceDelegate delegate = getDelegate(binding.getDelegateId(), unique);
+ if (delegate != null && !delegates.contains(delegate)) {
+ delegates.add(delegate);
+ }
+ }
+
+ // If no applicable persistence delegate is found, always return null
+ if (delegates.isEmpty() || delegates.isEmpty()) {
+ return null;
+ }
+
+ if (delegates.size() > 1) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Found multiple persistence delgates for " + context + //$NON-NLS-1$
+ (container != null ? " to store in " + container : "")); //$NON-NLS-1$ //$NON-NLS-2$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+
+ return delegates.get(0);
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java
deleted file mode 100644
index 17368c32a..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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 java.net.URI;
-import java.util.Map;
-
-/**
- * Interface to be implemented by persistable elements.
- */
-public interface IPersistable {
-
- /**
- * Returns the id of the persistence storage to use for persisting data objects.
- * <p>
- * The method is expected to return never <code>null</code>.
- *
- * @return The persistence storage id.
- */
- public String getStorageID();
-
- /**
- * Returns the URI reference to pass on to the associated persistence delegate to
- * denote the given data object.
- * <p>
- * The interpretation of the URI reference is up to the persistence delegate, but
- * the method is expected to return never <code>null</code>.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @return The URI.
- */
- public URI getURI(Object data);
-
- /**
- * Returns the interface type name to use for recreating the object from the
- * persisted object representation.
- * <p>
- * <b>Note:</b> The returned string is expected in the format <code>&quot;&lt;bundleId&gt;:&lt;full qualified interface type name&gt;&quot;</code>.
- * If the bundle id is not present, it is very likely that the object recreation will fail with a {@link ClassNotFoundException}.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The interface type or <code>null</code>.
- */
- public String getInterfaceTypeName(Object data);
-
- /**
- * Exports the given data object to an external representation.
- * <p>
- * As a general guide line, it is expected that the external representation contains only base
- * Java objects like maps, lists and Strings. Details about the valid object types can be taken
- * from the referenced persistence delegate.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The external representation of the given data object.
- *
- * @throws IOException - if the operation fails.
- */
- public Map<String, Object> exportFrom(Object data) throws IOException;
-
- /**
- * Imports the given external representation into the given data object.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @param external The external representation. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- public void importTo(Object data, Map<String, Object> external) throws IOException;
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java
deleted file mode 100644
index 5667b1982..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistable2.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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;
-
-/**
- * Interface to be implemented by string persistable elements.
- */
-public interface IPersistable2 extends IPersistable {
-
- /**
- * Returns the class name of the encoded context.
- * <p>
- * The class name is used to load the correct class to decode the persistable representation.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The class name of the encoded context.
- */
- public String getEncodedClassName(Object data);
-
-
- /**
- * Exports the given data object to an external representation.
- * <p>
- * As a general guide line, it is expected that the external representation contains only base
- * Java objects like maps, lists and Strings. Details about the valid object types can be taken
- * from the referenced persistence delegate.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The external representation of the given data object.
- *
- * @throws IOException - if the operation fails.
- */
- public String exportStringFrom(Object data) throws IOException;
-
- /**
- * Imports the given external representation.
- *
- * @param external The external representation. Must not be <code>null</code>.
- * @return The data object or <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- public Object importFrom(String external) throws IOException;
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java
new file mode 100644
index 000000000..d1b492c32
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistableURIProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.net.URI;
+
+/**
+ * Interface to be implemented by persistable elements.
+ */
+public interface IPersistableURIProvider {
+
+ /**
+ * Returns the URI reference to pass on to the associated persistence delegate to
+ * denote the given context object.
+ * <p>
+ * The interpretation of the URI reference is up to the persistence delegate, but
+ * the method is expected to return never <code>null</code>.
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ *
+ * @return The URI.
+ */
+ public URI getURI(Object context);
+
+}
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 915680503..983c58b79 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
@@ -10,8 +10,6 @@
package org.eclipse.tcf.te.runtime.persistence.interfaces;
import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
@@ -21,45 +19,46 @@ import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
public interface IPersistenceDelegate extends IExecutableExtension {
/**
- * Writes the given data to the given persistence storage.
- * <p>
- * The persistence storage location is defined by the specified URI reference. The exact
- * interpretation and semantic of the URI reference is up to the persistence delegate
- * contributor.
+ * 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 uri The persistence storage location URI reference. Must not be <code>null</code>.
- * @param data The data. Must not be <code>null</code>.
+ * @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>.
*
- * @throws IOException - if the operation fails
+ * @return The new or updated container instance.
*/
- public void write(URI uri, Map<String, Object> data) throws IOException;
+ public Object write(Object context, Object container, String key) throws IOException;
/**
- * Reads the data from the given persistence storage.
- * <p>
- * The persistence storage location is defined by the specified URI reference. The exact
- * interpretation and semantic of the URI reference is up to the persistence delegate
- * contributor.
+ * 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 uri The persistence storage location URI reference. Must not be <code>null</code>.
- * @return The data.
+ * @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>.
*
- * @throws IOException - if the operation fails
+ * @return The new or updated context instance.
*/
- public Map<String, Object> read(URI uri) throws IOException;
+ public Object read(Object context, Object container, String key) throws IOException;
/**
- * Deletes the given persistence storage.
- * <p>
- * The persistence storage location is defined by the specified URI reference. The exact
- * interpretation and semantic of the URI reference is up to the persistence delegate
- * contributor.
+ * Deletes the given context inside the container or the whole container.
*
- * @param uri The persistence storage location URI reference. Must not be <code>null</code>.
- * @return <code>True</code> if the persistence storage is successfully deleted;
- * <code>false</code> otherwise.
+ * @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>.
*
- * @throws IOException - if the operation fails
+ * @return <code>True</code> if the persistence context or the whole storage was successfully deleted;
+ * <code>false</code> otherwise.
*/
- public boolean delete(URI uri) throws IOException;
+ public boolean delete(Object context, Object container, String key) throws IOException;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java
deleted file mode 100644
index 67b77254f..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IPersistenceService.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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 java.net.URI;
-
-import org.eclipse.tcf.te.runtime.services.interfaces.IService;
-
-/**
- * A service for persisting elements to a persistence store.
- */
-public interface IPersistenceService extends IService {
-
- /**
- * Writes the given data object via a persistence delegate to a persistence storage. The
- * persistence delegate to use will be determined by adapting the given data object to an
- * {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails.
- */
- public void write(Object data) throws IOException;
-
- /**
- * Fills the given data object with the data read via a persistence delegate from a given
- * persistence storage. The persistence delegate to use will be determined by adapting the given
- * data object to an {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @throws IOException - if the operation fails
- */
- public void read(Object data) throws IOException;
-
- /**
- * Deletes the persistence storage for the given data object via a persistence delegate. The
- * persistence delegate to use will be determined by adapting the given data object to an
- * {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- *
- * @return <code>True</code> if the persistence storage is successfully deleted;
- * <code>false</code> otherwise.
- *
- * @throws IOException - if the operation fails
- */
- public boolean delete(Object data) throws IOException;
-
- /**
- * Returns the persistence storage URI for the given data object. The persistence delegate to
- * use will be determined by adapting the given data object to an {@link IPersistable}.
- *
- * @param data The data object. Must not be <code>null</code>.
- * @return The URI or <code>null</code>.
- *
- * @throws IOException - if the operation fails
- */
- public URI getURI(Object data) throws IOException;
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java
new file mode 100644
index 000000000..fdcb6c77e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IURIPersistenceService.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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 java.net.URI;
+
+import org.eclipse.tcf.te.runtime.services.interfaces.IService;
+
+/**
+ * A service for persisting elements to a URI persistence store.
+ */
+public interface IURIPersistenceService extends IService {
+
+ /**
+ * Writes the given context object via a persistence delegate to a persistence storage.
+ * If the given URI is <code>null</code>, it will be determined by adapting the context
+ * to a {@link IPersistableURIProvider}
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ * @param uri The URI or <code>null</code>.
+ *
+ * @throws IOException - if the operation fails.
+ */
+ public void write(Object context, URI uri) throws IOException;
+
+ /**
+ * Reads a context object via a persistence delegate from a given persistence storage.
+ * If the given URI is <code>null</code>, it will be determined by adapting the context
+ * to a {@link IPersistableURIProvider}. In this case the context must not be <code>null</code>.
+ *
+ * @param uri The URI. Must not be <code>null</code>.
+ * @param context The context object or <code>null</code>.
+ *
+ * @throws IOException - if the operation fails
+ */
+ public Object read(URI uri, Object context) throws IOException;
+
+ /**
+ * Deletes the persistence storage for the given context object via a persistence delegate.
+ * If the given URI is <code>null</code>, it will be determined by adapting the context
+ * to a {@link IPersistableURIProvider}
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ * @param uri The URI or <code>null</code>.
+ *
+ * @return <code>True</code> if the persistence storage is successfully deleted;
+ * <code>false</code> otherwise.
+ *
+ * @throws IOException - if the operation fails
+ */
+ public boolean delete(Object context, URI uri) throws IOException;
+
+ /**
+ * Returns the persistence storage URI for the given context object. The persistence delegate to
+ * use will be determined by adapting the given context object to an {@link IPersistable}.
+ *
+ * @param context The context object. Must not be <code>null</code>.
+ * @return The URI or <code>null</code>.
+ *
+ * @throws IOException - if the operation fails
+ */
+ public URI getURI(Object context) throws IOException;
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java
new file mode 100644
index 000000000..0a63f6327
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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 org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionConverter;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
+
+/**
+ * Persistence delegate binding implementation.
+ */
+public class PersistenceDelegateBinding extends ExecutableExtension {
+ // The mandatory delegate identifier
+ private String delegateId;
+ // The converted expression
+ private Expression expression;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtension#doSetInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void doSetInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ super.doSetInitializationData(config, propertyName, data);
+
+ // Initialize the delegate id field by reading the <delegate> extension attribute.
+ // Throws an exception if the id is empty or null.
+ delegateId = config != null ? config.getAttribute("delegateId") : null; //$NON-NLS-1$
+ if (delegateId == null || (delegateId != null && "".equals(delegateId.trim()))) { //$NON-NLS-1$
+ throw createMissingMandatoryAttributeException("delegateId", config.getContributor().getName()); //$NON-NLS-1$
+ }
+
+ // Read the sub elements of the extension
+ IConfigurationElement[] children = config != null ? config.getChildren() : null;
+ // The "enablement" element is the only expected one
+ if (children != null && children.length > 0) {
+ expression = ExpressionConverter.getDefault().perform(children[0]);
+ }
+ }
+
+ /**
+ * Returns the delegate id which is associated with this binding.
+ *
+ * @return The delegate id.
+ */
+ public String getDelegateId() {
+ return delegateId;
+ }
+
+ /**
+ * Returns the enablement expression which is associated with this binding.
+ *
+ * @return The enablement expression or <code>null</code>.
+ */
+ public Expression getEnablement() {
+ return expression;
+ }
+}
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
new file mode 100644
index 000000000..20768e24b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java
deleted file mode 100644
index 8522891c2..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/properties/PropertiesFilePersistenceDelegate.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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.properties;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-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.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.tcf.te.runtime.persistence.AbstractPersistenceDelegate;
-
-/**
- * Properties file persistence delegate implementation.
- * <p>
- * The persistence delegates reads and writes a simple grouped properties file format.
- */
-public class PropertiesFilePersistenceDelegate extends AbstractPersistenceDelegate {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#write(java.net.URI, java.util.Map)
- */
- @Override
- public void write(URI uri, Map<String, Object> data) throws IOException {
- Assert.isNotNull(uri);
- Assert.isNotNull(data);
-
- // 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 extension is no set, default to "properties"
- IPath path = new Path(file.getCanonicalPath());
- if (path.getFileExtension() == null) {
- file = path.addFileExtension("properties").toFile(); //$NON-NLS-1$
- }
-
- // Create the writer object
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); //$NON-NLS-1$
- try {
- // Write the first level of attributes
- writeMap(writer, "core", data); //$NON-NLS-1$
- } finally {
- writer.close();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#delete(java.net.URI)
- */
- @Override
- public boolean delete(URI uri) throws IOException {
- Assert.isNotNull(uri);
-
- // 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 extension is no set, default to "properties"
- IPath path = new Path(file.getCanonicalPath());
- if (path.getFileExtension() == null) {
- file = path.addFileExtension("properties").toFile(); //$NON-NLS-1$
- }
-
- return file.delete();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate#read(java.net.URI)
- */
- @Override
- public Map<String, Object> read(URI uri) throws IOException {
- Assert.isNotNull(uri);
-
- // 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$
- }
-
- Map<String, Object> data = new HashMap<String, Object>();
-
- // Create the reader object
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); //$NON-NLS-1$
- try {
- read(reader, data);
- } finally {
- reader.close();
- }
-
- return !data.isEmpty() ? data : null;
- }
-
- /**
- * Write the map data.
- *
- * @param writer The writer. Must not be <code>null</code>.
- * @param section The section name. Must not be <code>null</code>.
- * @param data The data. Must not be <code>null</code>.
- */
- protected void writeMap(BufferedWriter writer, String section, Map<String, Object> data) throws IOException {
- Assert.isNotNull(writer);
- Assert.isNotNull(section);
- Assert.isNotNull(data);
-
- // Will contain the list of map keys where the value is a map type itself.
- List<String> childMapKeys = new ArrayList<String>();
- // Will contain the list of map keys where the value is not an map type.
- List<String> childKeys = new ArrayList<String>();
-
- // Get all the map keys and filter the map type values
- for (String key : data.keySet()) {
- if (data.get(key) instanceof Map) childMapKeys.add(key);
- else childKeys.add(key);
- }
-
- // Sort both lists
- Collections.sort(childMapKeys);
- Collections.sort(childKeys);
-
- // If the child key list is not empty, write the section
- if (!childKeys.isEmpty()) {
- // Write a new line except it is the "core" section
- if (!"core".equals(section)) writer.newLine(); //$NON-NLS-1$
-
- // Write the header
- writer.write("[" + section.trim() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.newLine();
-
- for (String key : childKeys) {
- writer.write('\t');
- writer.write(key);
- writer.write(" = "); //$NON-NLS-1$
-
- Object value = data.get(key);
- if (value instanceof List) {
- writer.write(Arrays.deepToString(((List<?>)value).toArray()));
- } else {
- writer.write(value.toString());
- }
-
- writer.newLine();
- }
- }
-
- // If there are map type values, write them now
- if (!childMapKeys.isEmpty()) {
- for (String key : childMapKeys) {
- // Calculate the section name
- String newSection = "core".equals(section) ? key.trim() : section + "." + key.trim(); //$NON-NLS-1$ //$NON-NLS-2$
- // Write it
- writeMap(writer, newSection, (Map<String, Object>)data.get(key));
- }
- }
- }
-
- private static Pattern SECTION = Pattern.compile("\\s*\\[([^\\]]+)\\]\\s*"); //$NON-NLS-1$
- private static Pattern PROPERTY = Pattern.compile("\\s*(.+\\s*=\\s*.+)"); //$NON-NLS-1$
-
- /**
- * Read the data.
- *
- * @param reader The reader. Must not be <code>null</code>.
- * @param data The data. Must not be <code>null</code>.
- */
- protected void read(BufferedReader reader, Map<String, Object> data) throws IOException {
- Assert.isNotNull(reader);
- Assert.isNotNull(data);
-
- // The sections by name for easier access.
- // The "core" section is the incoming data object
- Map<String, Map<String, Object>> sections = new HashMap<String, Map<String, Object>>();
- sections.put("core", data); //$NON-NLS-1$
-
- String currentSection = "core"; //$NON-NLS-1$
- String line = reader.readLine();
- while (line != null) {
- Matcher matcher = SECTION.matcher(line);
- if (matcher.matches()) {
- // Section names are case-sensitive too
- currentSection = matcher.group(1);
- if (sections.get(currentSection) == null) {
- sections.put(currentSection, new HashMap<String, Object>());
- }
- } else {
- matcher = PROPERTY.matcher(line);
- if (matcher.matches()) {
- String property = matcher.group(1);
- String[] pieces = property.split("=", 2); //$NON-NLS-1$
- Map<String, Object> section = sections.get(currentSection);
- section.put(pieces[0].trim(), pieces[1].trim());
- }
- }
-
- line = reader.readLine();
- }
-
- // Recreate the sections hierarchy
- for (String sectionName : sections.keySet()) {
- if ("core".equals(sectionName)) continue; //$NON-NLS-1$
- Map<String, Object> section = sections.get(sectionName);
- if (sectionName.contains(".")) { //$NON-NLS-1$
- // Split the section name and recreate the missing hierarchy
- String[] pieces = sectionName.split("\\."); //$NON-NLS-1$
- Map<String, Object> parentSection = data;
- for (String subSectionName : pieces) {
- if ("core".equals(subSectionName)) continue; //$NON-NLS-1$
-
- if (sectionName.endsWith(subSectionName)) {
- parentSection.put(subSectionName, section);
- } else {
- Map<String, Object> subSection = (Map<String, Object>)parentSection.get(subSectionName);
- if (subSection == null) {
- subSection = new HashMap<String, Object>();
- parentSection.put(subSectionName, subSection);
- }
- parentSection = subSection;
- }
- }
- } else {
- // Place it into the root object, but check if it may exist
- Map<String, Object> oldSection = (Map<String, Object>)data.get(sectionName);
- if (oldSection != null) oldSection.putAll(section);
- else data.put(sectionName, section);
- }
- }
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java
deleted file mode 100644
index cf4d9fe29..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/PersistenceService.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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 java.util.Map;
-
-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.PersistenceDelegateManager;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService;
-import org.eclipse.tcf.te.runtime.services.AbstractService;
-
-/**
- * Persistence service implementation.
- */
-public class PersistenceService extends AbstractService implements IPersistenceService {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#write(java.lang.Object)
- */
- @Override
- public void write(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- URI uri = persistable.getURI(data);
- if (uri == null) throw new IOException("The URI cannot be determined."); //$NON-NLS-1$
-
- // Get the external representation of the data object from the
- // associated persistable.
- Map<String, Object> externalData = persistable.exportFrom(data);
- // If the external representation cannot be retrieved, throw an IOException
- if (externalData == null) throw new IOException("Failed to retrieve external data representation."); //$NON-NLS-1$
-
- // Pass on to the delegate for writing
- delegate.write(uri, externalData);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#read(java.lang.Object)
- */
- @Override
- public void read(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- URI uri = persistable.getURI(data);
- if (uri == null) throw new IOException("The URI cannot be determined."); //$NON-NLS-1$
-
- // Pass on to the delegate for reading
- Map<String, Object> externalData = delegate.read(uri);
- if (externalData == null) throw new IOException("Failed to read external data representation from URI '" + uri.toString() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Import the external representation into the data object via
- // the associated persistable
- persistable.importTo(data, externalData);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#delete(java.lang.Object)
- */
- @Override
- public boolean delete(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- URI uri = persistable.getURI(data);
- if (uri == null) throw new IOException("The URI cannot be determined."); //$NON-NLS-1$
-
- // Pass on to the delegate for deleting
- return delegate.delete(uri);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceService#getURI(java.lang.Object)
- */
- @Override
- public URI getURI(Object data) throws IOException {
- Assert.isNotNull(data);
-
- // Determine the persistable element for the given data object
- IPersistable persistable = data instanceof IPersistable ? (IPersistable)data : null;
- // If the element isn't a persistable by itself, try to adapt the element
- if (persistable == null) persistable = data instanceof IAdaptable ? (IPersistable) ((IAdaptable)data).getAdapter(IPersistable.class) : null;
- if (persistable == null) persistable = (IPersistable) Platform.getAdapterManager().getAdapter(data, IPersistable.class);
-
- // If the persistable could be still not determined, throw an IOException
- if (persistable == null) throw new IOException("'data' must be adaptable to IPersistable."); //$NON-NLS-1$
-
- // Determine the persistence delegate
- IPersistenceDelegate delegate = persistable.getStorageID() != null ? PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false) : null;
- // If the persistence delegate could not be determined, throw an IOException
- if (delegate == null) throw new IOException("The persistence delegate for ID '" + persistable.getStorageID() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Determine the URI
- return persistable.getURI(data);
- }
-}
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
new file mode 100644
index 000000000..41942ce5f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.net.URI, java.lang.Object)
+ */
+ @Override
+ public Object read(URI uri, Object context) 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;
+ }
+}

Back to the top