Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2011-11-28 16:35:31 +0000
committerEugene Tarassov2011-11-28 16:35:31 +0000
commita4909f42c8ce248e4d5bd9a0dab72c075ae8a6e9 (patch)
treea438d80de6c8df3f71975366671754e24ad1937c /target_explorer/plugins/org.eclipse.tcf.te.core
parentbec08e6e0af73f33c0fc57ac7b441a39e1c20672 (diff)
parent58e864152fa713a0bcea66ae79fee5dd582a64e2 (diff)
downloadorg.eclipse.tcf-a4909f42c8ce248e4d5bd9a0dab72c075ae8a6e9.tar.gz
org.eclipse.tcf-a4909f42c8ce248e4d5bd9a0dab72c075ae8a6e9.tar.xz
org.eclipse.tcf-a4909f42c8ce248e4d5bd9a0dab72c075ae8a6e9.zip
Merge branch 'juno-refactoring' of ssh://git.eclipse.org/gitroot/tcf/org.eclipse.tcf into juno-refactoring
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.core')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java142
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.properties3
3 files changed, 134 insertions, 14 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
index decfde327..e1c6f6b64 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/adapters/ModelNodePersistableAdapter.java
@@ -26,10 +26,14 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.te.core.activator.CoreBundleActivator;
import org.eclipse.tcf.te.core.nls.Messages;
+import org.eclipse.tcf.te.runtime.model.factory.Factory;
+import org.eclipse.tcf.te.runtime.model.interfaces.IContainerModelNode;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
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.IPersistableNodeProperties;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.osgi.framework.Bundle;
/**
* Model node persistable adapter implementation.
@@ -56,15 +60,33 @@ public class ModelNodePersistableAdapter implements IPersistable {
// Only model nodes are supported
if (data instanceof IModelNode) {
IModelNode node = (IModelNode) data;
- if (node.getName() != null && !"".equals(node.getName().trim())) { //$NON-NLS-1$
- // Get the node name and make it a valid file system name (no spaces etc).
- IPath path = getRoot().append(makeValidFileSystemName(((IModelNode) data).getName().trim()));
- if (!"ini".equals(path.getFileExtension())) path = path.addFileExtension("ini"); //$NON-NLS-1$ //$NON-NLS-2$
- uri = path.toFile().toURI();
+
+ IPath path = null;
+
+ // If the persistence node name is set, use it and ignore all other possibilities
+ String persistenceNodeName = node.getStringProperty(IPersistableNodeProperties.PROPERTY_NODE_NAME);
+ if (persistenceNodeName != null && !"".equals(node.getName().trim())) { //$NON-NLS-1$
+ path = getRoot().append(makeValidFileSystemName(persistenceNodeName.trim()));
+ }
+ // If the persistence name not set, check for the node name
+ else if (node.getName() != null && !"".equals(node.getName().trim())) { //$NON-NLS-1$
+ path = getRoot().append(makeValidFileSystemName(node.getName().trim()));
+ }
+ // If the name is not set, check for an URI
+ else if (node.getProperty(IPersistableNodeProperties.PROPERTY_URI) != null) {
+ Object candidate = node.getProperty(IPersistableNodeProperties.PROPERTY_URI);
+ if (candidate instanceof URI) uri = (URI)candidate;
+ else if (candidate instanceof String && !"".equals(((String)candidate).trim())) { //$NON-NLS-1$
+ uri = URI.create(((String)candidate).trim());
+ }
+ }
+ // No name and no explicit path is set -> use the UUID
+ else if (node.getUUID() != null) {
+ path = getRoot().append(makeValidFileSystemName(node.getUUID().toString().trim()));
}
- // If the name is not set, check for "Path"
- else if (node.getStringProperty("Path") != null && !"".equals(node.getStringProperty("Path").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- IPath path = new Path(node.getStringProperty("Path")); //$NON-NLS-1$
+
+ if (path != null) {
+ if (!"ini".equals(path.getFileExtension())) path = path.addFileExtension("ini"); //$NON-NLS-1$ //$NON-NLS-2$
uri = path.toFile().toURI();
}
}
@@ -112,6 +134,20 @@ public class ModelNodePersistableAdapter implements IPersistable {
}
/* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getInterfaceType(java.lang.Object)
+ */
+ @SuppressWarnings("restriction")
+ @Override
+ public String getInterfaceTypeName(Object data) {
+ if (data instanceof IContainerModelNode) {
+ return org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator.getUniqueIdentifier() + ":" + IContainerModelNode.class.getName(); //$NON-NLS-1$
+ } else if (data instanceof IModelNode) {
+ return org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator.getUniqueIdentifier() + ":" + IModelNode.class.getName(); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#exportFrom(java.lang.Object)
*/
@Override
@@ -193,15 +229,31 @@ public class ModelNodePersistableAdapter implements IPersistable {
IPersistable persistable = value instanceof IAdaptable ? (IPersistable)((IAdaptable)value).getAdapter(IPersistable.class) : null;
if (persistable == null) persistable = (IPersistable)Platform.getAdapterManager().getAdapter(value, IPersistable.class);
if (persistable != null) {
+ String storageID = persistable.getStorageID();
+ URI uri = persistable.getURI(value);
+ String interfaceTypeName = persistable.getInterfaceTypeName(value);
+
+ // Check if the persistable returns complete information to create the reference
+ if (storageID == null) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "storageID")); //$NON-NLS-1$
+ }
+ if (uri == null) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "uri")); //$NON-NLS-1$
+ }
+ if (interfaceTypeName == null) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_export_invalidPersistable, value.getClass().getCanonicalName(), "interfaceTypeName")); //$NON-NLS-1$
+ }
+
// Create a reference object
Map<String, String> reference = new HashMap<String, String>();
- reference.put("storageID", persistable.getStorageID()); //$NON-NLS-1$
- reference.put("uri", persistable.getURI(value).toString()); //$NON-NLS-1$
+ reference.put("storageID", storageID); //$NON-NLS-1$
+ reference.put("uri", uri.toString()); //$NON-NLS-1$
+ reference.put("interfaceType", interfaceTypeName); //$NON-NLS-1$
- IPersistenceDelegate delegate = PersistenceDelegateManager.getInstance().getDelegate(persistable.getStorageID(), false);
+ IPersistenceDelegate delegate = PersistenceDelegateManager.getInstance().getDelegate(storageID, false);
if (delegate != null) {
- delegate.write(persistable.getURI(value), persistable.exportFrom(value));
- dst.put(key, reference);
+ delegate.write(uri, persistable.exportFrom(value));
+ dst.put("reference:" + key, reference); //$NON-NLS-1$
continue;
}
}
@@ -224,7 +276,69 @@ public class ModelNodePersistableAdapter implements IPersistable {
if (data instanceof IModelNode) {
IModelNode node = (IModelNode) data;
for (String key : external.keySet()) {
- node.setProperty(key, external.get(key));
+ // Get the property value
+ Object value = external.get(key);
+
+ // Check for reference objects
+ if (key.startsWith("reference:") && value instanceof Map<?,?>) { //$NON-NLS-1$
+ // Cut the "reference:" from the key
+ String newKey = key.substring(10);
+
+ @SuppressWarnings("unchecked")
+ Map<String, String> reference = (Map<String, String>)value;
+
+ // Get the storage id and the URI from the reference
+ String storageID = reference.get("storageID"); //$NON-NLS-1$
+ String uriString = reference.get("uri"); //$NON-NLS-1$
+ String interfaceTypeName = reference.get("interfaceType"); //$NON-NLS-1$
+
+ // Check if the reference returns complete information to read the referenced storage
+ if (storageID == null) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "storageID")); //$NON-NLS-1$
+ }
+ if (uriString == null) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "uri")); //$NON-NLS-1$
+ }
+ if (interfaceTypeName == null) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_invalidReference, "interfaceType")); //$NON-NLS-1$
+ }
+
+ // Get the persistence delegate
+ IPersistenceDelegate delegate = PersistenceDelegateManager.getInstance().getDelegate(storageID, false);
+ if (delegate != null) {
+ URI uri = URI.create(uriString);
+ Map<String, Object> referenceData = delegate.read(uri);
+ if (referenceData != null && !referenceData.isEmpty()) {
+ try {
+ // Now, we have to recreate the object
+
+ // Separate the bundleId from the interface name
+ String[] pieces = interfaceTypeName.split(":", 2); //$NON-NLS-1$
+ String bundleId = pieces.length > 1 ? pieces[0] : null;
+ if (pieces.length > 1) interfaceTypeName = pieces[1];
+
+ // Determine the bundle to use for loading the class
+ Bundle bundle = bundleId != null && !"".equals(bundleId.trim()) ? Platform.getBundle(bundleId.trim()) : CoreBundleActivator.getContext().getBundle(); //$NON-NLS-1$
+
+ Class<? extends IModelNode> interfaceType = (Class<? extends IModelNode>)bundle.loadClass(interfaceTypeName);
+ IModelNode referenceNode = Factory.getInstance().newInstance(interfaceType);
+
+ IPersistable persistable = (IPersistable)referenceNode.getAdapter(IPersistable.class);
+ if (persistable == null) persistable = (IPersistable)Platform.getAdapterManager().getAdapter(referenceNode, IPersistable.class);
+ if (persistable != null) {
+ persistable.importTo(referenceNode, referenceData);
+ node.setProperty(newKey, referenceNode);
+ }
+ } catch (ClassNotFoundException e) {
+ throw new IOException(NLS.bind(Messages.ModelNodePersistableAdapter_import_cannotLoadClass, interfaceTypeName), e);
+ }
+ }
+ }
+ }
+ // Not a reference object -> store the object as is to the node
+ else {
+ node.setProperty(key, value);
+ }
}
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.java
index ab4825298..ae2936030 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.java
@@ -35,5 +35,8 @@ public class Messages extends NLS {
public static String ConnectStrategyStepExecutor_error_stepFailed;
public static String ConnectStrategyStepExecutor_stepFailed_debugInfo;
+ public static String ModelNodePersistableAdapter_export_invalidPersistable;
public static String ModelNodePersistableAdapter_export_unknownType;
+ public static String ModelNodePersistableAdapter_import_invalidReference;
+ public static String ModelNodePersistableAdapter_import_cannotLoadClass;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.properties
index 292522277..f80734b73 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/nls/Messages.properties
@@ -18,4 +18,7 @@ Connect Strategy: {2}\n\
Connect Step: {3}
ConnectStrategyStepExecutor_stepFailed_debugInfo=Debug info:\n{0}
+ModelNodePersistableAdapter_export_invalidPersistable=Persistable for object type ''{0}'' provides incomplete information for property ''{1}''.
ModelNodePersistableAdapter_export_unknownType=No strategy to persist an object of type ''{0}'', key = ''{1}''.
+ModelNodePersistableAdapter_import_invalidReference=Reference provides incomplete information for property ''{0}'' to restore the object.
+ModelNodePersistableAdapter_import_cannotLoadClass=Cannot load class for name ''{0}''

Back to the top