You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/03/27 16:06:09 UTC
svn commit: r522919 - in
/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas:
./ controller/ controller/actions/ model/ view/views/ view/wizards/
Author: pamarcelot
Date: Tue Mar 27 07:06:08 2007
New Revision: 522919
URL: http://svn.apache.org/viewvc?view=rev&rev=522919
Log:
Fixed DIRSTUDIO-39 (Allow the user to switch between 'Standard schemas files' and 'Use specific schemas files' without having to relaunch the application.)
Modified:
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/SchemasViewController.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/OpenLocalFileAction.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/SchemaPool.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemaElementsViewContentProvider.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemasViewContentProvider.java
directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/wizards/CreateANewSchemaWizard.java
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java Tue Mar 27 07:06:08 2007
@@ -25,6 +25,8 @@
import org.apache.directory.ldapstudio.schemas.view.views.SchemaCodeScanner;
import org.apache.directory.ldapstudio.schemas.view.views.SchemaTextAttributeProvider;
import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -35,16 +37,21 @@
public class Activator extends AbstractUIPlugin
{
- // The plug-in ID
+ /** The plug-in ID */
public static final String PLUGIN_ID = "org.apache.directory.ldapstudio.schemas"; //$NON-NLS-1$
- // The shared instance
+ /** The shared instance */
private static Activator plugin;
+ /** the Schema Code Scanner */
private static ITokenScanner schemaCodeScanner;
+ /** The Schema Text Attribute Provider */
private static SchemaTextAttributeProvider schemaTextAttributeProvider;
+ /** The Schema Pool */
+ private SchemaPool schemaPool;
+
/**
* The constructor
@@ -62,6 +69,13 @@
public void start( BundleContext context ) throws Exception
{
super.start( context );
+
+ // Loading the Schema Pool
+ schemaPool = SchemaPool.getInstance();
+
+ // Initialiazing the Preferences Listener
+ initPreferencesListener();
+
}
@@ -72,7 +86,7 @@
public void stop( BundleContext context ) throws Exception
{
// Saving workspace configuration
- SchemaPool.getInstance().savePool();
+ schemaPool.saveUserSchemasPaths();
plugin = null;
super.stop( context );
@@ -121,5 +135,24 @@
}
return schemaTextAttributeProvider;
+ }
+
+
+ /**
+ * Initializes the listener on the preferences store.
+ */
+ private void initPreferencesListener()
+ {
+ Activator.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener()
+ {
+ public void propertyChange( PropertyChangeEvent event )
+ {
+ if ( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE == event.getProperty() )
+ {
+ // Reloading the SchemaPool
+ schemaPool.reload();
+ }
+ }
+ } );
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/SchemasViewController.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/SchemasViewController.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/SchemasViewController.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/SchemasViewController.java Tue Mar 27 07:06:08 2007
@@ -354,7 +354,7 @@
{
try
{
- pool.addAlreadyExistingSchema( file, SchemaType.userSchema );
+ pool.addSchema( Schema.localPathToURL( file ) );
}
catch ( SchemaCreationException e )
{
@@ -400,8 +400,7 @@
}
else if ( objectSelection instanceof ObjectClassWrapper )
{
- input = new ObjectClassEditorInput( ( ( ObjectClassWrapper ) objectSelection )
- .getMyObjectClass() );
+ input = new ObjectClassEditorInput( ( ( ObjectClassWrapper ) objectSelection ).getMyObjectClass() );
editorId = ObjectClassEditor.ID;
}
else if ( ( objectSelection instanceof IntermediateNode )
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/OpenLocalFileAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/OpenLocalFileAction.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/OpenLocalFileAction.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/OpenLocalFileAction.java Tue Mar 27 07:06:08 2007
@@ -24,8 +24,8 @@
import org.apache.directory.ldapstudio.schemas.Activator;
import org.apache.directory.ldapstudio.schemas.Messages;
import org.apache.directory.ldapstudio.schemas.PluginConstants;
+import org.apache.directory.ldapstudio.schemas.model.Schema;
import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
-import org.apache.directory.ldapstudio.schemas.model.Schema.SchemaType;
import org.apache.log4j.Logger;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
@@ -74,7 +74,7 @@
SchemaPool pool = SchemaPool.getInstance();
try
{
- pool.addAlreadyExistingSchema( selected, SchemaType.userSchema );
+ pool.addSchema( Schema.localPathToURL( selected ) );
}
catch ( Exception e )
{
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java Tue Mar 27 07:06:08 2007
@@ -41,7 +41,7 @@
*/
public enum Reason
{
- SchemaAdded, SchemaRemoved, multipleSchemaRemoved, multipleSchemaAdded, SchemaSaved, OCAdded, OCRemoved, ATAdded, ATRemoved, OCModified, ATModified, poolCleared
+ SchemaAdded, SchemaRemoved, SchemaSaved, OCAdded, OCModified, OCRemoved, ATAdded, ATModified, ATRemoved, PoolReloaded
}
/** The reason */
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/SchemaPool.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/SchemaPool.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/SchemaPool.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/SchemaPool.java Tue Mar 27 07:06:08 2007
@@ -35,6 +35,8 @@
import org.apache.directory.ldapstudio.schemas.Activator;
import org.apache.directory.ldapstudio.schemas.PluginConstants;
+import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent.Reason;
+import org.apache.directory.ldapstudio.schemas.model.Schema.SchemaType;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -44,80 +46,117 @@
/**
+ * This class represents the Schema Pool.
+ *
* A pool of schema is a common repository for all the currently loaded
- * schemas in LDAP Studio.
- * -> You can add or remove schema from the pool.
- * -> You can obtain a complete list of all the objectClasses and attribute
- * Type currently loaded (even if they are squattered in various schema files).
- * -> the pool of schema can be seen as ONE big schema containing all the
- * definitions of the currently loaded schemas.
- *
- * NOW USING A SINGLETON DESIGN PATTERN
- * -> use the getPool() static method to get the schema pool
- *
+ * schemas in LDAP Studio Schemas Editor Plugin.
*/
public class SchemaPool implements SchemaListener
{
+ /** The logger */
private static Logger logger = Logger.getLogger( SchemaPool.class );
- private static SchemaPool instance_;
- private static Object syncObject_ = new Object();
+ /** The SchemaPool instance */
+ private static SchemaPool schemaPool;
- private List<Schema> schemaList;
+ /** The Listeners List */
private List<PoolListener> listeners;
- private List<AttributeType> attributeTypes = new ArrayList<AttributeType>();
- private List<ObjectClass> objectClasses = new ArrayList<ObjectClass>();
+ /** The Schema List */
+ private List<Schema> schemaList;
+
+ /** The Attribute Type List */
+ private List<AttributeType> attributeTypes;
+
+ /** The Object Class List */
+ private List<ObjectClass> objectClasses;
+
+ /** The Attribute Type Map*/
+ private Map<String, AttributeType> attributeTypesMap;
- private Map<String, AttributeType> attributeTypesMap = new HashMap<String, AttributeType>();
- private Map<String, ObjectClass> objectClassesMap = new HashMap<String, ObjectClass>();
+ /** The Object Class Map*/
+ private Map<String, ObjectClass> objectClassesMap;
+ /** The Schemas Tag */
private static final String SCHEMAS_TAG = "Schemas";
+
+ /** The Schema Tag */
private static final String SCHEMA_TAG = "Schema";
+
+ /** the Path Tag */
private static final String PATH_TAG = "path";
/**
- * Write the pool configuration to the LDAPStudio preferences backing store.
- * It consists of all the non-core schemas that have been added by the user.
+ * Creates a new instance of SchemaPool.
*/
- public void savePool()
+ private SchemaPool()
{
- //we only store the references to schemas that have ALREADY
- //been saved. -> url != null
- XMLMemento memento = XMLMemento.createWriteRoot( SCHEMAS_TAG );
+ listeners = new ArrayList<PoolListener>();
+ schemaList = new ArrayList<Schema>();
+ attributeTypes = new ArrayList<AttributeType>();
+ objectClasses = new ArrayList<ObjectClass>();
+ attributeTypesMap = new HashMap<String, AttributeType>();
+ objectClassesMap = new HashMap<String, ObjectClass>();
+ }
- for ( Schema schema : schemaList )
+
+ /**
+ * Returns the unique initialized pool.
+ *
+ * @return
+ * the pool
+ */
+ public static SchemaPool getInstance()
+ {
+ if ( schemaPool == null )
{
- if ( ( schema.type == Schema.SchemaType.userSchema ) && ( schema.getURL() != null ) )
+ schemaPool = new SchemaPool();
+ synchronized ( schemaPool )
{
- IMemento child = memento.createChild( SCHEMA_TAG );
- child.putString( PATH_TAG, schema.getURL().getPath() );
+ schemaPool.loadSchemas();
}
}
- try
+ return schemaPool;
+ }
+
+
+ /**
+ * Loads the Schemas (Core and User Schemas)
+ */
+ private void loadSchemas()
+ {
+ schemaPool.loadCoreSchemas();
+ schemaPool.loadUserSchemas();
+ }
+
+
+ /**
+ * Loads the Core Schemas Files.
+ */
+ private void loadCoreSchemas()
+ {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ boolean useSpecificCore = store.getBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE );
+ if ( useSpecificCore )
{
- FileWriter writer = new FileWriter( getSchemaPoolFile() );
- memento.save( writer );
- writer.close();
+ schemaPool.loadCoreSchemasFromSpecifiedLocation();
}
- catch ( IOException e )
+ else
{
- logger.debug( "Error when saving opened schemas.", e ); //$NON-NLS-1$
+ schemaPool.loadCoreSchemasFromBundle();
}
}
/**
- * Read the pool configuration from the LDAPStudio preferences backing store.
- * It consists of all the non-core schemas that have been added by the user.
+ * Loads the User Schemas Files.
*/
- public void loadPool()
+ public void loadUserSchemas()
{
try
{
-
FileReader reader = new FileReader( getSchemaPoolFile() );
XMLMemento memento = XMLMemento.createReadRoot( reader );
IMemento[] children = memento.getChildren( SCHEMA_TAG );
@@ -125,8 +164,8 @@
{
try
{
- addAlreadyExistingSchema( Schema.localPathToURL( child.getString( PATH_TAG ) ), //$NON-NLS-1$
- Schema.SchemaType.userSchema );
+ addSchema( Schema.localPathToURL( child.getString( PATH_TAG ) ), //$NON-NLS-1$
+ Schema.SchemaType.userSchema, false );
}
catch ( SchemaCreationException e )
{
@@ -146,7 +185,39 @@
}
- private static void initializeWithBundled( SchemaPool pool )
+ /**
+ * Saves the User Schemas Paths to a XML File.
+ */
+ public void saveUserSchemasPaths()
+ {
+ XMLMemento memento = XMLMemento.createWriteRoot( SCHEMAS_TAG );
+
+ for ( Schema schema : schemaList )
+ {
+ if ( ( schema.type == Schema.SchemaType.userSchema ) && ( schema.getURL() != null ) )
+ {
+ IMemento child = memento.createChild( SCHEMA_TAG );
+ child.putString( PATH_TAG, schema.getURL().getPath() );
+ }
+ }
+
+ try
+ {
+ FileWriter writer = new FileWriter( getSchemaPoolFile() );
+ memento.save( writer );
+ writer.close();
+ }
+ catch ( IOException e )
+ {
+ logger.debug( "Error when saving opened schemas.", e ); //$NON-NLS-1$
+ }
+ }
+
+
+ /**
+ * Loads the Core Schemas From the plugin's Bundle.
+ */
+ private void loadCoreSchemasFromBundle()
{
URL urlcore = Platform.getBundle( Activator.PLUGIN_ID ).getResource( "ressources/schemas/core.schema" ); //$NON-NLS-1$
URL urljava = Platform.getBundle( Activator.PLUGIN_ID ).getResource( "ressources/schemas/java.schema" ); //$NON-NLS-1$
@@ -158,28 +229,22 @@
URL urlinetorgperson = Platform.getBundle( Activator.PLUGIN_ID ).getResource(
"ressources/schemas/inetorgperson.schema" ); //$NON-NLS-1$
- try
- {
- pool.addAlreadyExistingSchema( urlcore, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urljava, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urlnis, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urlsystem, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urlautofs, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urlcorba, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urlcosine, Schema.SchemaType.coreSchema );
- pool.addAlreadyExistingSchema( urlinetorgperson, Schema.SchemaType.coreSchema );
- }
- catch ( SchemaCreationException e )
- {
- logger
- .debug( "error when inializing the schema pool with bundled schemas. One of the core schemas is not accessible:" + e ); //$NON-NLS-1$
- }
+ schemaPool.addSchema( urlcore, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urljava, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urlnis, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urlsystem, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urlautofs, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urlcorba, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urlcosine, SchemaType.coreSchema, false );
+ schemaPool.addSchema( urlinetorgperson, SchemaType.coreSchema, false );
}
- private static void initializeWithSpecified( SchemaPool pool )
+ /**
+ * Loads the Core Schemas Files from the Location specified in the preferences.
+ */
+ private void loadCoreSchemasFromSpecifiedLocation()
{
-
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
String specificPath = store.getString( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE_DIRECTORY );
@@ -199,19 +264,13 @@
URL fileURL = curFile.toURL();
if ( Schema.URLtoFileName( fileURL ) != null )
{
- pool.addAlreadyExistingSchema( fileURL, Schema.SchemaType.coreSchema );
+ schemaPool.addSchema( fileURL, Schema.SchemaType.coreSchema, false );
}
}
catch ( MalformedURLException e )
{
logger.debug( "error whith the content of the specified core schema directory" ); //$NON-NLS-1$
}
- catch ( SchemaCreationException e )
- {
- logger
- .debug( "error when inializing the schema pool with specified schemas. One of the core schemas is not accessible:" //$NON-NLS-1$
- + e );
- }
}
}
}
@@ -219,105 +278,111 @@
/**
- * Returns the unique initialized pool with all the core schemas pre-loaded
- * @return the pool
+ * Returns all the schemas contained in the pool.
+ *
+ * @return
+ * the schemas stored in a Schema array
*/
- public static SchemaPool getInstance()
+ public Schema[] getSchemas()
{
- //thread-safe version but not as good as with the static bloc method. Here it would have
- //made a too big static block.
- if ( instance_ == null )
- {
- synchronized ( syncObject_ )
- {
- if ( instance_ == null )
- {
- //1) create the pool instance
- SchemaPool pool = new SchemaPool();
+ return schemaList.toArray( new Schema[0] );
+ }
- //2) initialize the pool
- IPreferenceStore store = Activator.getDefault().getPreferenceStore();
- boolean initialize_with_specified = store
- .getBoolean( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE );
- if ( initialize_with_specified )
- {
- //2a) with user-specified core schemas
- initializeWithSpecified( pool );
- }
- else
- {
- //2b) or with bundled core schemas
- initializeWithBundled( pool );
- }
- //3) the unique instance is this initialized pool
- instance_ = pool;
+ /**
+ * Returns the List of Object Classes.
+ *
+ * @return
+ * the List of Object Classes
+ */
+ public List<ObjectClass> getObjectClasses()
+ {
+ return objectClasses;
+ }
- //4) load the pool with all the schemas that the user did select the last time
- //LDAPStudio was launched
- instance_.loadPool();
- }
- }
- }
- //1) or 5) returns the unique pool instance
- return instance_;
+ /**
+ * Return the List of Attribute Types.
+ *
+ * @return
+ * the List of Attribute Types
+ */
+ public List<AttributeType> getAttributeTypes()
+ {
+ return attributeTypes;
}
/**
- * Default constructor, no pre-loaded schemas. Despite the fact that we are using a
- * singleton design pattern, it's a public constructor. It allows you to create
- * temporary unitialized pools (for testing purposes for example).
+ * Returns the Object Classes as a Map.
+ *
+ * @return
+ * the Object Classes as a Map
*/
- public SchemaPool()
+ public Map<String, ObjectClass> getObjectClassesAsMap()
{
- schemaList = new ArrayList<Schema>();
- listeners = new ArrayList<PoolListener>();
+ return objectClassesMap;
}
/**
- * @return the number of schemas in the pool
+ * Gets the Attribute Types as a Map.
+ *
+ * @return
+ * the Attribute Types as a Map
*/
- public int count()
+ public Map<String, AttributeType> getAttributeTypesAsMap()
{
- return schemaList.size();
+ return attributeTypesMap;
}
/**
- * Returns all the schemas contained in the pool
- * @return the schemas stored in a Schema array
+ * Get the Schema Elements as a Map
+ *
+ * @return
+ * the Schema Elements as a Map
*/
- public Schema[] getSchemas()
+ public Map<String, SchemaElement> getSchemaElements()
{
- return schemaList.toArray( new Schema[0] );
+ Map<String, SchemaElement> elementsTable = new HashMap<String, SchemaElement>();
+
+ elementsTable.putAll( attributeTypesMap );
+ elementsTable.putAll( objectClassesMap );
+
+ return elementsTable;
}
/**
- * Returns the schema specified by the following name.
- * @param name the name of the schema to find
+ * Returns the schema specified by the given name.
+ *
+ * @param name
+ * the name of the schema to find
* @return
+ * the schema specified by the given name.
*/
public Schema getSchema( String name )
{
for ( Schema schema : schemaList )
{
if ( schema.getName().equals( name ) )
+ {
return schema;
+ }
}
+
return null;
}
/**
- * Tests if a schema OF THE FOLLOWING NAME is inside the pool, it does NOT test
- * against the schema instances.
- * @param name the name of the schema
- * @return true if inside
- * @see containsSchema(Schema schema) if you want to test instances
+ * Tests if a schema with the given name is inside the pool.
+ *
+ * @param name
+ * the name of the schema
+ * @return
+ * true if inside
*/
public boolean containsSchema( String name )
{
@@ -326,9 +391,12 @@
/**
- * Tests if the following schema is inside the pool
- * @param schema the name of the schema to test
- * @return true if inside, false if not
+ * Tests if the given schema is inside the pool.
+ *
+ * @param schema
+ * the name of the schema to test
+ * @return
+ * true if inside, false if not
*/
public boolean containsSchema( Schema schema )
{
@@ -337,9 +405,12 @@
/**
- * Tests if the following objectClass is inside the pool
- * @param name the name of the object class to test
- * @return true if inside, false if not
+ * Tests if an objectClass with the given name is inside the pool.
+ *
+ * @param name
+ * the name of the object class to test
+ * @return
+ * true if inside, false if not
*/
public boolean containsObjectClass( String name )
{
@@ -348,9 +419,12 @@
/**
- * Tests if the following attribute type is inside the pool
- * @param name the name of the attribute type to test
- * @return true if inside, false if not
+ * Tests if an attribute type with the given name is inside the pool.
+ *
+ * @param name
+ * the name of the attribute type to test
+ * @return
+ * true if inside, false if not
*/
public boolean containsAttributeType( String name )
{
@@ -359,9 +433,12 @@
/**
- * Tests if the following element is inside the pool
- * @param name the name of the eleme,t to test
- * @return true if inside, false if not
+ * Tests if an element with the given name is inside the pool.
+ *
+ * @param name
+ * the name of the eleme,t to test
+ * @return
+ * true if inside, false if not
*/
public boolean containsSchemaElement( String name )
{
@@ -370,10 +447,12 @@
/**
- * Tests if an objectClass of the following name(s) exists inside the pool
- * -> test each alias of the following objectClass against the content of the pool
- * @param objectClass the objectClass to test
- * @return if inside the pool, false if not
+ * Tests if the given object class is inside the pool.
+ *
+ * @param objectClass
+ * the objectClass to test
+ * @return
+ * if inside the pool, false if not
*/
public boolean containsObjectClass( ObjectClass objectClass )
{
@@ -382,10 +461,12 @@
/**
- * Tests if an attributeType of the following name(s) exists inside the pool
- * -> test each alias of the following attributeType against the content of the pool
- * @param attributeType the attributeType to test
- * @return if inside the pool, false if not
+ * Tests if the given attributeType is inside the pool.
+ *
+ * @param attributeType
+ * the attributeType to test
+ * @return
+ * if inside the pool, false if not
*/
public boolean containsAttributeType( AttributeType attributeType )
{
@@ -394,9 +475,12 @@
/**
- * Tests if the given element exists in the pool
- * @param schemaElement the Schema Element to test
- * @return if inside the pool, false if not
+ * Tests if the given element exists in the pool.
+ *
+ * @param schemaElement
+ * the Schema Element to test
+ * @return
+ * if inside the pool, false if not
*/
public boolean containsSchemaElement( SchemaElement schemaElement )
{
@@ -405,9 +489,12 @@
/**
- * Returns a specific object class
- * @param name the name of the object class to return
- * @return null if the name is not mapped
+ * Returns the object class corresponding to the given name.
+ *
+ * @param name
+ * the name of the object class to return
+ * @return
+ * null if the name is not mapped
*/
public ObjectClass getObjectClass( String name )
{
@@ -417,9 +504,12 @@
/**
- * Returns a specific attribute type
- * @param name the name of the attriute type to return
- * @return null if the name is not mapped
+ * Returns the attribute type corresponding to the given name.
+ *
+ * @param name
+ * the name of the attriute type to return
+ * @return
+ * null if the name is not mapped
*/
public AttributeType getAttributeType( String name )
{
@@ -428,88 +518,15 @@
/**
- * Returns the Object Classes as a Map.
- *
- * @return
- * the Object Classes as a Map
- */
- public Map<String, ObjectClass> getObjectClassesAsMap()
- {
- return objectClassesMap;
- }
-
-
- /**
- * Gets the Attribute Types as a Map.
+ * Adds a schema to the pool.
*
- * @return
- * the Attribute Types as a Map
- */
- public Map<String, AttributeType> getAttributeTypesAsMap()
- {
- return attributeTypesMap;
- }
-
-
- /**
- * Get the Schema Elements as a Map
+ * @param s
+ * the schema to add
*
- * @return
- * the Schema Elements as a Map
+ * @param notifyListeners
+ * a boolean to indicate if the listeners need to be notified
*/
- public Map<String, SchemaElement> getSchemaElements()
- {
- Map<String, SchemaElement> elementsTable = new HashMap<String, SchemaElement>();
-
- elementsTable.putAll( attributeTypesMap );
- elementsTable.putAll( objectClassesMap );
-
- return elementsTable;
- }
-
-
- /**
- * Accessor to all the objectClasses defined by the schemas stored in the pool
- * @return as an array
- */
- public List<ObjectClass> getObjectClasses()
- {
- return objectClasses;
- }
-
-
- /**
- * Accessor to all the attributeType defined by the schemas stored in the pool
- * @return as an array
- */
- public List<AttributeType> getAttributeTypes()
- {
- return attributeTypes;
- }
-
-
- /**
- * Adds a bunch of already initialized schemas into the pool
- * @param schemaArray the schema array
- */
- public void addSchemas( Schema[] schemaArray )
- {
- for ( Schema schema : schemaArray )
- {
- addSchema( schema );
- }
-
- //notify of the changement
- //notifyChanged(LDAPModelEvent.Reason.multipleSchemaAdded,null);
- }
-
-
- /**
- * Adds an already initialized schema into the pool
- * @param s the schema to be added
- * @return true if the schema has been added
- */
- public boolean addSchema( Schema s )
+ private void addSchema( Schema s, boolean notifyListeners )
{
if ( s != null )
{
@@ -530,49 +547,36 @@
addObjectClass( oc );
}
- notifyChanged( LDAPModelEvent.Reason.SchemaAdded, s );
- return true;
+ if ( notifyListeners )
+ {
+ notifyChanged( LDAPModelEvent.Reason.SchemaAdded, s );
+ }
}
}
- return false;
}
/**
- * Adds a new schema into the pool (not loaded from file)
- * @param name the name of the new schema
- * @param type the schema type
- * @return the schema that has been added to the pool, null if not added or already in the pool
+ * Adds a new schema to the Schema Pool.
+ *
+ * @param name
+ * the name of the new schema
*/
- public Schema addSchema( String name, Schema.SchemaType type )
+ public void addNewSchema( String name )
{
- Schema temp = new Schema( type, name );
-
- if ( addSchema( temp ) )
- return temp;
-
- return null;
+ addSchema( new Schema( SchemaType.userSchema, name ), true );
}
/**
- * Adds an already existing schema into the pool (load the schema from a file)
- * @param path the path to the .schema file
- * @param type the schema type
- * @return the schema that has been added to the pool, null if not added or already in the pool
- * @throws SchemaCreationException if no schema was found at the specified
- * path or if any error occurs during its initialization.
+ * Adds a schema to the Schema Pool.
+ *
+ * @param url
+ * the url of the schema
*/
- public Schema addAlreadyExistingSchema( String path, Schema.SchemaType type ) throws SchemaCreationException
+ public void addSchema( URL url )
{
- try
- {
- return addAlreadyExistingSchema( new URL( "file", "localhost", -1, path ), type ); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch ( MalformedURLException e )
- {
- throw new SchemaCreationException( "error opening " + path, e ); //$NON-NLS-1$
- }
+ addSchema( url, SchemaType.userSchema, true );
}
@@ -584,43 +588,51 @@
* @throws SchemaCreationException if no schema was found at the specified
* URL or if any error occurs during its initialization.
*/
- public Schema addAlreadyExistingSchema( URL url, Schema.SchemaType type ) throws SchemaCreationException
+ /**
+ * Adds a schema to the Schema Pool.
+ *
+ * @param url
+ * the url of the schema
+ * @param type
+ * the type of the schema
+ * @param notifyListeners
+ * true if the listeners should be notified
+ */
+ private void addSchema( URL url, SchemaType type, boolean notifyListeners )
{
- Schema temp;
- temp = new Schema( url, type );
-
- if ( addSchema( temp ) )
- return temp;
-
- return null;
+ try
+ {
+ addSchema( new Schema( url, type ), notifyListeners );
+ }
+ catch ( SchemaCreationException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
/**
- * Removes a bunch of schemas from the pool
- * @param schemaArray the schemas to remove
+ * Removes a schema from the pool.
+ *
+ * @param s
+ * the schema to be removed
*/
- public void removeSchemas( Schema[] schemaArray )
+ public void removeSchema( Schema s )
{
- if ( ( schemaArray != null ) && ( schemaArray.length > 0 ) )
- {
- for ( Schema schema : schemaArray )
- {
- removeSchema( schema );
- schema.removeListener( this );
- }
-
- //notify of the changement
- notifyChanged( LDAPModelEvent.Reason.multipleSchemaRemoved, null );
- }
+ removeSchema( s, true );
}
/**
- * Removes a schema from the pool
- * @param s the schema to be removed
+ * Removes a schema from the pool.
+ *
+ * @param s
+ * the schema to be removed
+ * @param notifyListeners
+ * a boolean to indicate if the listeners need to be notified
*/
- public void removeSchema( Schema s )
+ private void removeSchema( Schema s, boolean notifyListeners )
{
if ( s != null )
{
@@ -640,23 +652,9 @@
removeObjectClass( oc );
}
- notifyChanged( LDAPModelEvent.Reason.SchemaRemoved, s );
- }
- }
-
-
- /**
- * Removes a schema from the pool
- * @param name the name of the schema to be removed
- */
- public void removeSchema( String name )
- {
- for ( Schema schema : schemaList )
- {
- if ( schema.getName().equals( name ) )
+ if ( notifyListeners )
{
- removeSchema( schema );
- return;
+ notifyChanged( LDAPModelEvent.Reason.SchemaRemoved, s );
}
}
}
@@ -687,43 +685,37 @@
/**
- * Clears the pool from all the stored schemas
- * @param saveBefore if true, all the schemas are saved before the pool
- * is cleared
+ * Reloads the Schema Pool.
*/
- public void clearPool( boolean saveBefore )
+ public void reload()
{
- //save the pool
- if ( saveBefore )
+ // Removing Core Schemas
+ Schema[] schemas = schemaList.toArray( new Schema[0] );
+ for ( int i = 0; i < schemas.length; i++ )
{
- try
+ if ( schemas[i].type == SchemaType.coreSchema )
{
- saveAll();
- }
- catch ( Exception e )
- {
- logger.debug( "error when clearing the pool" ); //$NON-NLS-1$
+ removeSchema( schemas[i], false );
}
}
- //remove all the associations (listeners,...)
- for ( Schema schema : schemaList )
+ // Loading Schemas
+ schemaPool.loadCoreSchemas();
+
+ // Notifying Listeners
+ for ( PoolListener listener : listeners )
{
- removeSchema( schema );
+ listener.poolChanged( this, new LDAPModelEvent( Reason.PoolReloaded ) );
}
-
- //make sure we have an empty list
- schemaList = new ArrayList<Schema>();
-
- //notify of the changement
- notifyChanged( LDAPModelEvent.Reason.poolCleared, null );
}
- /******************************************
- * Events emmiting *
- ******************************************/
-
+ /**
+ * Adds a listener to the Schema Pool.
+ *
+ * @param listener
+ * the listener to add
+ */
public void addListener( PoolListener listener )
{
if ( !listeners.contains( listener ) )
@@ -731,12 +723,26 @@
}
+ /**
+ * Removed a Lister from the Schema Pool.
+ *
+ * @param listener
+ * the listener to remove
+ */
public void removeListener( PoolListener listener )
{
listeners.remove( listener );
}
+ /**
+ * Notifies listeners of Schema Pool notification
+ *
+ * @param reason
+ * the reson
+ * @param sc
+ * the schema
+ */
private void notifyChanged( LDAPModelEvent.Reason reason, Schema sc )
{
for ( PoolListener listener : listeners )
@@ -791,7 +797,6 @@
catch ( Exception e1 )
{
logger.debug( "error when notifying " + listener + " of pool modification" ); //$NON-NLS-1$ //$NON-NLS-2$
- e1.printStackTrace(); // TODO remove this
}
}
}
@@ -965,6 +970,12 @@
}
+ /**
+ * Gets the Schema Pool File (where is store information about the loaded User Schemas).
+ *
+ * @return
+ * the Schema Pool File
+ */
private File getSchemaPoolFile()
{
return Activator.getDefault().getStateLocation().append( "schemaPool.xml" ).toFile();
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemaElementsViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemaElementsViewContentProvider.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemaElementsViewContentProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemaElementsViewContentProvider.java Tue Mar 27 07:06:08 2007
@@ -287,6 +287,10 @@
aTOrOCRemoved( p, e );
break;
+ case PoolReloaded:
+ viewer.setInput( new SchemaElementsViewRoot() );
+ break;
+
default:
break;
}
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemasViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemasViewContentProvider.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemasViewContentProvider.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/views/SchemasViewContentProvider.java Tue Mar 27 07:06:08 2007
@@ -309,6 +309,10 @@
aTOrOCRemoved( p, e );
break;
+ case PoolReloaded:
+ viewer.setInput( new SchemasViewRoot() );
+ break;
+
default:
break;
}
Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/wizards/CreateANewSchemaWizard.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/wizards/CreateANewSchemaWizard.java?view=diff&rev=522919&r1=522918&r2=522919
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/wizards/CreateANewSchemaWizard.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/wizards/CreateANewSchemaWizard.java Tue Mar 27 07:06:08 2007
@@ -21,7 +21,6 @@
package org.apache.directory.ldapstudio.schemas.view.wizards;
-import org.apache.directory.ldapstudio.schemas.model.Schema;
import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
@@ -47,7 +46,7 @@
public boolean performFinish()
{
SchemaPool pool = SchemaPool.getInstance();
- pool.addSchema( this.page.getNameField(), Schema.SchemaType.userSchema );
+ pool.addNewSchema( this.page.getNameField() );
return true;
}