1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

[187647][api][breaking] add properties capabilities to persistence providers so that they can be told where to store their data.

This commit is contained in:
David Dykstal 2007-05-17 18:50:15 +00:00
parent 4920333314
commit a148f884d7
6 changed files with 128 additions and 12 deletions

View file

@ -22,7 +22,24 @@
autostart="true"
class="org.eclipse.rse.internal.persistence.PropertyFileProvider"
id="org.eclipse.rse.persistence.PropertyFileProvider"
name="Property File Persistence Provider"/>
name="Property File Persistence Provider (workspace)">
<property
name="location"
value="workspace">
</property>
</persistenceProvider>
<!--
<persistenceProvider
autostart="true"
class="org.eclipse.rse.internal.persistence.PropertyFileProvider"
id="org.eclipse.rse.persistence.MetadataPropertyFileProvider"
name="Property File Persistence Provider (metadata)">
<property
name="location"
value="metadata">
</property>
</persistenceProvider>
-->
</extension>
<!-- ================================================================= -->

View file

@ -40,7 +40,15 @@
</element>
<element name="persistenceProvider">
<annotation>
<documentation>
The persistenceProvider element defines a class that implements the IRSEPersistenceProvider interface. It is used to persist the RSE object model to a form of external storage.
</documentation>
</annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="property"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
@ -75,6 +83,30 @@
</complexType>
</element>
<element name="property">
<annotation>
<documentation>
The property element is contained within the persistenceProvider element. Use these to provide properties that can tailor the behavior of a persistence provider. Each provider must document the properties that it expects.
</documentation>
</annotation>
<complexType>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
The name attribute provides the name for this property.
</documentation>
</annotation>
</attribute>
<attribute name="value" type="string" use="required">
<annotation>
<documentation>
The value attribute provides the string value for this property.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="examples"/>

View file

@ -98,6 +98,14 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
private static final String VALID = "abcdefghijklmnopqrstuvwxyz0123456789-._"; //$NON-NLS-1$
private static final String UPPER = "ABCDEFGHIJKLMNOPQRTSUVWXYZ"; //$NON-NLS-1$
/* properties */
private static final String P_LOCATION = "location"; //$NON-NLS-1$
/* property values */
private static final String PV_LOCATION_WORKSPACE = "workspace"; //$NON-NLS-1$
private static final String PV_LOCATION_METADATA = "metadata"; //$NON-NLS-1$
interface PersistenceAnchor {
String[] getProfileLocationNames();
IStatus deleteProfileLocation(String profileName, IProgressMonitor monitor);
@ -337,6 +345,7 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
private Map typeQualifiers = getTypeQualifiers();
private Map saveJobs = new HashMap();
private PersistenceAnchor anchor = new WorkspaceAnchor();
private Properties properties = null;
/* (non-Javadoc)
* @see org.eclipse.rse.persistence.IRSEPersistenceProvider#getSavedProfileNames()
@ -414,6 +423,23 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
return saveJob;
}
/* (non-Javadoc)
* @see org.eclipse.rse.persistence.IRSEPersistenceProvider#setProperties(java.util.Properties)
*/
public void setProperties(Properties properties) {
Properties defaults = new Properties();
defaults.setProperty(P_LOCATION, PV_LOCATION_WORKSPACE);
this.properties = new Properties(defaults);
Set keys = properties.keySet();
for (Iterator z = keys.iterator(); z.hasNext();) {
String key = (String) z.next();
String value = properties.getProperty(key);
if (value != null) {
this.properties.put(key, value);
}
}
}
/**
* Saves a node from the DOM to the file system.
* @param node The node to save.

View file

@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
@ -113,15 +114,7 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
*/
public IRSEPersistenceProvider getPersistenceProvider(String id) {
ProviderRecord pr = getProviderRecord(id);
if (pr.provider == null && pr.configurationElement != null) {
try {
pr.provider = (IRSEPersistenceProvider) pr.configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
loadedProviders.put(pr.provider, pr.providerId);
} catch (CoreException e) {
Logger logger = RSECorePlugin.getDefault().getLogger();
logger.logError("Exception loading persistence provider", e); //$NON-NLS-1$
}
}
loadProvider(pr);
return pr.provider;
}
@ -307,6 +300,35 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
}
}
/**
* Loads a provider given a provider record. If the provider has already been loaded
* it will not load it again. After loading, the provider will be initialized with any
* properties found in the extension.
* @param pr the provider record containing the configuration element describing the provider
* @return the provider
*/
private IRSEPersistenceProvider loadProvider(ProviderRecord pr) {
if (pr.provider == null) {
try {
pr.provider = (IRSEPersistenceProvider) pr.configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
loadedProviders.put(pr.provider, pr.providerId);
Properties properties = new Properties();
IConfigurationElement[] children = pr.configurationElement.getChildren("property"); //$NON-NLS-1$
for (int i = 0; i < children.length; i++) {
IConfigurationElement child = children[i];
String name = child.getAttribute("name"); //$NON-NLS-1$
String value = child.getAttribute("value"); //$NON-NLS-1$
properties.put(name, value);
}
pr.provider.setProperties(properties);
} catch (CoreException e) {
Logger logger = RSECorePlugin.getDefault().getLogger();
logger.logError("Exception loading persistence provider", e); //$NON-NLS-1$
}
}
return pr.provider;
}
/**
* Retrieves the default persistence provider for this workbench configuration.
* Several persistence providers may be registered, but the default one is used for all

View file

@ -23,6 +23,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
@ -173,4 +174,11 @@ public class SerializingProvider implements IRSEPersistenceProvider {
}
return result;
}
/* (non-Javadoc)
* @see org.eclipse.rse.persistence.IRSEPersistenceProvider#setProperties(java.util.Properties)
*/
public void setProperties(Properties properties) {
// Do nothing. The serializing provider does not make use of properties
}
}

View file

@ -17,6 +17,8 @@
package org.eclipse.rse.persistence;
import java.util.Properties;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
@ -34,6 +36,15 @@ import org.eclipse.rse.persistence.dom.RSEDOM;
*/
public interface IRSEPersistenceProvider {
/**
* Sets the properties for this provider. This must be done immediately
* after the provider is instantiated. The persistence manager will
* provide these properties for providers defined as extensions.
* @param properties the properties object containing the properties
* supplied in the extension.
*/
public void setProperties(Properties properties);
/**
* Restores an RSE DOM given a profileName.
*