mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-23 00:03:53 +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:
parent
4920333314
commit
a148f884d7
6 changed files with 128 additions and 12 deletions
|
@ -22,7 +22,24 @@
|
||||||
autostart="true"
|
autostart="true"
|
||||||
class="org.eclipse.rse.internal.persistence.PropertyFileProvider"
|
class="org.eclipse.rse.internal.persistence.PropertyFileProvider"
|
||||||
id="org.eclipse.rse.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>
|
</extension>
|
||||||
|
|
||||||
<!-- ================================================================= -->
|
<!-- ================================================================= -->
|
||||||
|
|
|
@ -40,7 +40,15 @@
|
||||||
</element>
|
</element>
|
||||||
|
|
||||||
<element name="persistenceProvider">
|
<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>
|
<complexType>
|
||||||
|
<sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<element ref="property"/>
|
||||||
|
</sequence>
|
||||||
<attribute name="id" type="string" use="required">
|
<attribute name="id" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
@ -75,6 +83,30 @@
|
||||||
</complexType>
|
</complexType>
|
||||||
</element>
|
</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>
|
<annotation>
|
||||||
<appInfo>
|
<appInfo>
|
||||||
<meta.section type="examples"/>
|
<meta.section type="examples"/>
|
||||||
|
|
|
@ -98,6 +98,14 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
|
||||||
private static final String VALID = "abcdefghijklmnopqrstuvwxyz0123456789-._"; //$NON-NLS-1$
|
private static final String VALID = "abcdefghijklmnopqrstuvwxyz0123456789-._"; //$NON-NLS-1$
|
||||||
private static final String UPPER = "ABCDEFGHIJKLMNOPQRTSUVWXYZ"; //$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 {
|
interface PersistenceAnchor {
|
||||||
String[] getProfileLocationNames();
|
String[] getProfileLocationNames();
|
||||||
IStatus deleteProfileLocation(String profileName, IProgressMonitor monitor);
|
IStatus deleteProfileLocation(String profileName, IProgressMonitor monitor);
|
||||||
|
@ -337,6 +345,7 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
|
||||||
private Map typeQualifiers = getTypeQualifiers();
|
private Map typeQualifiers = getTypeQualifiers();
|
||||||
private Map saveJobs = new HashMap();
|
private Map saveJobs = new HashMap();
|
||||||
private PersistenceAnchor anchor = new WorkspaceAnchor();
|
private PersistenceAnchor anchor = new WorkspaceAnchor();
|
||||||
|
private Properties properties = null;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.persistence.IRSEPersistenceProvider#getSavedProfileNames()
|
* @see org.eclipse.rse.persistence.IRSEPersistenceProvider#getSavedProfileNames()
|
||||||
|
@ -414,6 +423,23 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
|
||||||
return saveJob;
|
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.
|
* Saves a node from the DOM to the file system.
|
||||||
* @param node The node to save.
|
* @param node The node to save.
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -113,15 +114,7 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
||||||
*/
|
*/
|
||||||
public IRSEPersistenceProvider getPersistenceProvider(String id) {
|
public IRSEPersistenceProvider getPersistenceProvider(String id) {
|
||||||
ProviderRecord pr = getProviderRecord(id);
|
ProviderRecord pr = getProviderRecord(id);
|
||||||
if (pr.provider == null && pr.configurationElement != null) {
|
loadProvider(pr);
|
||||||
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$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pr.provider;
|
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.
|
* Retrieves the default persistence provider for this workbench configuration.
|
||||||
* Several persistence providers may be registered, but the default one is used for all
|
* Several persistence providers may be registered, but the default one is used for all
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
@ -173,4 +174,11 @@ public class SerializingProvider implements IRSEPersistenceProvider {
|
||||||
}
|
}
|
||||||
return result;
|
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
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.eclipse.rse.persistence;
|
package org.eclipse.rse.persistence;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
@ -34,6 +36,15 @@ import org.eclipse.rse.persistence.dom.RSEDOM;
|
||||||
*/
|
*/
|
||||||
public interface IRSEPersistenceProvider {
|
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.
|
* Restores an RSE DOM given a profileName.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue