From 6535aaec17b30ef774bc430900e902a4930eeb1d Mon Sep 17 00:00:00 2001 From: Tobias Schwarz Date: Fri, 9 Nov 2012 12:03:28 +0100 Subject: [Target Explorer] automatically import and export remote debugger launch config when peer is imported/exported --- .../te/runtime/persistence/PersistenceManager.java | 9 +- .../delegates/GsonMapPersistenceDelegate.java | 14 +- .../interfaces/IPersistenceDelegate.java | 125 ++++++----- .../services/URIPersistenceService.java | 238 ++++++++++----------- 4 files changed, 191 insertions(+), 195 deletions(-) (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java index b89b29d3f..8dd39d08b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java @@ -96,16 +96,15 @@ public class PersistenceManager extends AbstractExtensionPointManagernull is returned. * * @param id The unique id of the persistence delegate or null - * @param unique If true, the method returns new instances of the persistence delegate contribution. * * @return The persistence delegate instance or null. */ - protected IPersistenceDelegate getDelegate(String id, boolean unique) { + protected IPersistenceDelegate getDelegate(String id) { IPersistenceDelegate contribution = null; if (getExtensions().containsKey(id)) { ExecutableExtensionProxy proxy = getExtensions().get(id); // Get the extension instance - contribution = unique ? proxy.newInstance() : proxy.getInstance(); + contribution = proxy.getInstance(); } return contribution; @@ -119,7 +118,7 @@ public class PersistenceManager extends AbstractExtensionPointManagernull. * @return The persistence delegate which is enabled or null. */ - public IPersistenceDelegate getDelegate(Object context, Object container, boolean unique) { + public IPersistenceDelegate getDelegate(Object context, Object container) { Assert.isNotNull(context); List delegates = new ArrayList(); @@ -127,7 +126,7 @@ public class PersistenceManager extends AbstractExtensionPointManagernull. - * @param container The persistence container or class for a new one. Must not be null. - * @param key The key for the context inside the container or null. - * - * @return The new or updated container instance. - */ - public Object write(Object context, Object container, String key) throws IOException; - - /** - * Get the class or interface for the context. - * - * @param context The context to persist. Must not be null. - * @return The class or interface for the given context. - */ - public Class getPersistedClass(Object context); - - /** - * Reads the context from the given persistence container. - * If the context does not exist yet, the class needs to be given. - * - * @param context The context to update or class for a new context. Must not be null. - * @param container The persistence container. Must not be null. - * @param key The key for the context inside the container or null. - * - * @return The new or updated context instance. - */ - public Object read(Object context, Object container, String key) throws IOException; - - /** - * Deletes the given context inside the container or the whole container. - * - * @param context The context to delete inside the storage or null. - * @param container The persistence container. Must not be null. - * @param key The key for the context inside the container or null. - * - * @return True if the persistence context or the whole storage was successfully deleted; - * false otherwise. - */ - public boolean delete(Object context, Object container, String key) throws IOException; -} +/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.runtime.persistence.interfaces; + +import java.io.IOException; + +import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension; + +/** + * Interface to be implemented by persistence delegates. + */ +public interface IPersistenceDelegate extends IExecutableExtension { + + /** + * Writes the given context to the given persistence container using the key. + * If the container does not exist yet, the class needs to be given. + * + * @param context The context to persist. Must not be null. + * @param container The persistence container or class for a new one. Must not be null. + * + * @return The new or updated container instance. + */ + public Object write(Object context, Object container) throws IOException; + + /** + * Get the class or interface for the context. + * + * @param context The context to persist. Must not be null. + * @return The class or interface for the given context. + */ + public Class getPersistedClass(Object context); + + /** + * Reads the context from the given persistence container. + * If the context does not exist yet, the class needs to be given. + * + * @param context The context to update or class for a new context. Must not be null. + * @param container The persistence container. Must not be null. + * + * @return The new or updated context instance. + */ + public Object read(Object context, Object container) throws IOException; + + /** + * Deletes the given context inside the container or the whole container. + * + * @param context The context to delete inside the storage or null. + * @param container The persistence container. Must not be null. + * + * @return True if the persistence context or the whole storage was successfully deleted; + * false otherwise. + */ + public boolean delete(Object context, Object container) throws IOException; +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java index 5308aab3c..91cb851bd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/services/URIPersistenceService.java @@ -1,119 +1,119 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.runtime.persistence.services; - -import java.io.IOException; -import java.net.URI; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.Platform; -import org.eclipse.tcf.te.runtime.persistence.PersistenceManager; -import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider; -import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; -import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; -import org.eclipse.tcf.te.runtime.services.AbstractService; - -/** - * Persistence service implementation. - */ -public class URIPersistenceService extends AbstractService implements IURIPersistenceService { - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#write(java.lang.Object, java.net.URI) - */ - @Override - public void write(Object context, URI uri) throws IOException { - Assert.isNotNull(context); - - uri = uri != null ? uri : getURI(context); - - // Determine the persistence delegate - IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false); - // If the persistence delegate could not be determined, throw an IOException - if (delegate == null) { - throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - // Pass on to the delegate for writing - delegate.write(context, uri, null); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#read(java.lang.Object, java.net.URI) - */ - @Override - public Object read(Object context, URI uri) throws IOException { - Assert.isNotNull(context); - - uri = uri != null ? uri : getURI(context); - - // Determine the persistence delegate - IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false); - // If the persistence delegate could not be determined, throw an IOException - if (delegate == null) { - throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - // Pass on to the delegate for reading - return delegate.read(context, uri, null); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#delete(java.lang.Object, java.net.URI) - */ - @Override - public boolean delete(Object context, URI uri) throws IOException { - Assert.isNotNull(context); - - uri = uri != null ? uri : getURI(context); - - // Determine the persistence delegate - IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri, false); - // If the persistence delegate could not be determined, throw an IOException - if (delegate == null) { - throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - return delegate.delete(context, uri, null); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#getURI(java.lang.Object) - */ - @Override - public URI getURI(Object context) throws IOException { - Assert.isNotNull(context); - - // Determine the persistable element for the given data object - IPersistableURIProvider persistableURIProvider = context instanceof IPersistableURIProvider ? (IPersistableURIProvider)context : null; - // If the element isn't a persistable by itself, try to adapt the element - if (persistableURIProvider == null) { - persistableURIProvider = context instanceof IAdaptable ? (IPersistableURIProvider) ((IAdaptable)context).getAdapter(IPersistableURIProvider.class) : null; - } - if (persistableURIProvider == null) { - persistableURIProvider = (IPersistableURIProvider) Platform.getAdapterManager().getAdapter(context, IPersistableURIProvider.class); - } - - // If the persistable could be still not determined, throw an IOException - if (persistableURIProvider == null) { - throw new IOException("'context' must be adaptable to IPersistableURIProvider."); //$NON-NLS-1$ - } - - URI uri = persistableURIProvider.getURI(context); - - if (uri == null) { - throw new IOException("The URI cannot be determined for context '" + context.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ - } - - // Determine the URI - return uri; - } -} +/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.runtime.persistence.services; + +import java.io.IOException; +import java.net.URI; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.tcf.te.runtime.persistence.PersistenceManager; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableURIProvider; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; +import org.eclipse.tcf.te.runtime.services.AbstractService; + +/** + * Persistence service implementation. + */ +public class URIPersistenceService extends AbstractService implements IURIPersistenceService { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#write(java.lang.Object, java.net.URI) + */ + @Override + public void write(Object context, URI uri) throws IOException { + Assert.isNotNull(context); + + uri = uri != null ? uri : getURI(context); + + // Determine the persistence delegate + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri); + // If the persistence delegate could not be determined, throw an IOException + if (delegate == null) { + throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Pass on to the delegate for writing + delegate.write(context, uri); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#read(java.lang.Object, java.net.URI) + */ + @Override + public Object read(Object context, URI uri) throws IOException { + Assert.isNotNull(context); + + uri = uri != null ? uri : getURI(context); + + // Determine the persistence delegate + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri); + // If the persistence delegate could not be determined, throw an IOException + if (delegate == null) { + throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Pass on to the delegate for reading + return delegate.read(context, uri); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#delete(java.lang.Object, java.net.URI) + */ + @Override + public boolean delete(Object context, URI uri) throws IOException { + Assert.isNotNull(context); + + uri = uri != null ? uri : getURI(context); + + // Determine the persistence delegate + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(context, uri); + // If the persistence delegate could not be determined, throw an IOException + if (delegate == null) { + throw new IOException("The persistence delegate for context '" + context.getClass().getName() + "' cannot be determined."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + return delegate.delete(context, uri); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService#getURI(java.lang.Object) + */ + @Override + public URI getURI(Object context) throws IOException { + Assert.isNotNull(context); + + // Determine the persistable element for the given data object + IPersistableURIProvider persistableURIProvider = context instanceof IPersistableURIProvider ? (IPersistableURIProvider)context : null; + // If the element isn't a persistable by itself, try to adapt the element + if (persistableURIProvider == null) { + persistableURIProvider = context instanceof IAdaptable ? (IPersistableURIProvider) ((IAdaptable)context).getAdapter(IPersistableURIProvider.class) : null; + } + if (persistableURIProvider == null) { + persistableURIProvider = (IPersistableURIProvider) Platform.getAdapterManager().getAdapter(context, IPersistableURIProvider.class); + } + + // If the persistable could be still not determined, throw an IOException + if (persistableURIProvider == null) { + throw new IOException("'context' must be adaptable to IPersistableURIProvider."); //$NON-NLS-1$ + } + + URI uri = persistableURIProvider.getURI(context); + + if (uri == null) { + throw new IOException("The URI cannot be determined for context '" + context.getClass().getName() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Determine the URI + return uri; + } +} -- cgit v1.2.3