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 2006/11/16 17:05:29 UTC
svn commit: r475786 [7/13] - in
/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin: ./
META-INF/ icons/ ressources/ ressources/help/ ressources/help/html/
ressources/help/html/concepts/ ressources/help/html/concepts/images/
ressources/h...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAction.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAction.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.controller.ICommandIds;
+import org.apache.directory.ldapstudio.schemas.model.Schema;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.directory.ldapstudio.schemas.view.viewers.PoolManager;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.AttributeTypeWrapper;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.IntermediateNode;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ObjectClassWrapper;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.SchemaWrapper;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Action for saving a schema
+ */
+public class SaveAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate
+{
+ private static Logger logger = Logger.getLogger( SaveAction.class );
+
+
+ /**
+ * Default constructor
+ * @param window
+ * @param label
+ */
+ public SaveAction()
+ {
+ setText( Messages.getString( "SaveAction.Save_schema" ) ); //$NON-NLS-1$
+ // The id is used to refer to the action in a menu or toolbar
+ setId( ICommandIds.CMD_SAVE );
+ // Associate the action with a pre-defined command, to allow key bindings.
+ setActionDefinitionId( ICommandIds.CMD_SAVE );
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, IImageKeys.SAVE ) );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ PoolManager view = ( PoolManager ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .findView( Application.PLUGIN_ID + ".view.PoolManager" ); //$NON-NLS-1$
+ Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement();
+
+ // We have to check on which node we are to get the schema name
+ if ( selection != null )
+ {
+
+ Schema schema = null;
+
+ if ( selection instanceof SchemaWrapper )
+ {
+ schema = ( ( SchemaWrapper ) selection ).getMySchema();
+ }
+ else if ( selection instanceof AttributeTypeWrapper )
+ {
+ // We have to get the parent of the parent ( AttributeTypeWrapper => IntermediateNode => SchemaWrapper )
+ schema = ( ( SchemaWrapper ) ( ( AttributeTypeWrapper ) selection ).getParent().getParent() )
+ .getMySchema();
+ }
+ else if ( selection instanceof ObjectClassWrapper )
+ {
+ // We have to get the parent of the parent ( ObjectClassWrapper => IntermediateNode => SchemaWrapper )
+ schema = ( ( SchemaWrapper ) ( ( ObjectClassWrapper ) selection ).getParent().getParent() )
+ .getMySchema();
+ }
+ else if ( selection instanceof IntermediateNode )
+ {
+ schema = ( ( SchemaWrapper ) ( ( IntermediateNode ) selection ).getParent() ).getMySchema();
+ }
+
+ if ( schema != null )
+ {
+ try
+ {
+ schema.save();
+ }
+ catch ( Exception e )
+ {
+ ErrorDialog
+ .openError(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.getString( "SaveAction.Error" ), Messages.getString( "SaveAction.An_error_occurred_when_saving_schema" ) + schema.getName(), new Status( IStatus.ERROR, Application.PLUGIN_ID, 0, "Status Error Message", null ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ logger.debug( "An error occured when saving schema " + schema.getName() ); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public void init( IWorkbenchWindow window )
+ {
+ }
+
+
+ public void run( IAction action )
+ {
+ this.run();
+ }
+
+
+ public void selectionChanged( IAction action, ISelection selection )
+ {
+ }
+
+
+ public void init( IViewPart view )
+ {
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAllAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAllAction.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAllAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAllAction.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.controller.ICommandIds;
+import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Action for saving all schemas
+ */
+public class SaveAllAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate
+{
+ private static Logger logger = Logger.getLogger( SaveAllAction.class );
+
+
+ /**
+ * Default constructor
+ * @param window
+ * @param label
+ */
+ public SaveAllAction()
+ {
+ setText( Messages.getString( "SaveAllAction.Save_all_schemas" ) ); //$NON-NLS-1$
+
+ // The id is used to refer to the action in a menu or toolbar
+ setId( ICommandIds.CMD_SAVE_ALL );
+ // Associate the action with a pre-defined command, to allow key bindings.
+ setActionDefinitionId( ICommandIds.CMD_SAVE_ALL );
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, IImageKeys.SAVE_ALL ) );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ SchemaPool schemaPool = SchemaPool.getInstance();
+ try
+ {
+ schemaPool.saveAll();
+ }
+ catch ( Exception e )
+ {
+ ErrorDialog
+ .openError(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.getString( "SaveAllAction.Error" ), Messages.getString( "SaveAllAction.An_error_occured_when_saving_schemas" ), new Status( IStatus.ERROR, Application.PLUGIN_ID, 0, //$NON-NLS-1$ //$NON-NLS-2$
+ "Status Error Message", null ) ); //$NON-NLS-1$
+ logger.debug( "An error occured when saving schemas" ); //$NON-NLS-1$
+ }
+ }
+
+
+ public void run( IAction action )
+ {
+ this.run();
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public void init( IWorkbenchWindow window )
+ {
+ }
+
+
+ public void selectionChanged( IAction action, ISelection selection )
+ {
+ }
+
+
+ public void init( IViewPart view )
+ {
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAsAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAsAction.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAsAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SaveAsAction.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.controller.ICommandIds;
+import org.apache.directory.ldapstudio.schemas.model.Schema;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.directory.ldapstudio.schemas.view.viewers.PoolManager;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.SchemaWrapper;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Action for "saving as..." a schema
+ */
+public class SaveAsAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate
+{
+ private static Logger logger = Logger.getLogger( SaveAsAction.class );
+
+
+ /**
+ * Default constructor
+ * @param window
+ * @param label
+ */
+ public SaveAsAction()
+ {
+ setText( Messages.getString( "SaveAsAction.Save_schema_as" ) ); //$NON-NLS-1$
+
+ // The id is used to refer to the action in a menu or toolbar
+ setId( ICommandIds.CMD_SAVE_AS );
+ // Associate the action with a pre-defined command, to allow key bindings.
+ setActionDefinitionId( ICommandIds.CMD_SAVE_AS );
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, IImageKeys.SAVE_AS ) );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ PoolManager view = ( PoolManager ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .findView( Application.PLUGIN_ID + ".view.PoolManager" ); //$NON-NLS-1$
+ Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement();
+
+ // We have to check on which node we are to get the schema name
+ if ( selection != null )
+ {
+ if ( selection instanceof SchemaWrapper )
+ {
+ Schema schema = ( ( SchemaWrapper ) selection ).getMySchema();
+
+ try
+ {
+ schema.saveas();
+ }
+ catch ( Exception e )
+ {
+ ErrorDialog
+ .openError(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.getString( "SaveAsAction.Error" ), Messages.getString( "SaveAsAction.An_error_occurred_when_saving_schemas" ) + schema.getName(), new Status( IStatus.ERROR, Application.PLUGIN_ID, 0, //$NON-NLS-1$ //$NON-NLS-2$
+ "Status Error Message", null ) ); //$NON-NLS-1$
+ logger.debug( "An error occured when saving schema " + schema.getName() ); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public void init( IWorkbenchWindow window )
+ {
+ }
+
+
+ public void run( IAction action )
+ {
+ this.run();
+ }
+
+
+ public void selectionChanged( IAction action, ISelection selection )
+ {
+ }
+
+
+ public void init( IViewPart view )
+ {
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortHierarchicalViewAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortHierarchicalViewAction.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortHierarchicalViewAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortHierarchicalViewAction.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.controller.ICommandIds;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.directory.ldapstudio.schemas.view.viewers.HierarchicalViewer;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.AlphabeticalOrderComparator;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.UnAlphabeticalOrderComparator;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Action for sorting the Hierarchy View
+ */
+@SuppressWarnings("unused")//$NON-NLS-1$
+public class SortHierarchicalViewAction extends Action
+{
+ private final IWorkbenchWindow window;
+
+ public enum SortType
+ {
+ alphabetical, unalphabetical
+ };
+
+ private SortType type;
+
+
+ /**
+ * Default constructor
+ * @param window the attached window
+ * @param type the type of sorting
+ * @param label the label to be displayed
+ */
+ public SortHierarchicalViewAction( IWorkbenchWindow window, SortType type, String label )
+ {
+ this.window = window;
+ setText( label );
+ this.type = type;
+
+ // The id is used to refer to the action in a menu or toolbar
+ setId( ICommandIds.CMD_SORT_HIERACHICAL_VIEWER );
+ // Associate the action with a pre-defined command, to allow key bindings.
+ setActionDefinitionId( ICommandIds.CMD_SORT_HIERACHICAL_VIEWER );
+
+ if ( type.equals( SortType.alphabetical ) )
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID,
+ IImageKeys.SORT_ALPHABETICAL ) );
+ else if ( type.equals( SortType.unalphabetical ) )
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID,
+ IImageKeys.SORT_UNALPHABETICAL ) );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ HierarchicalViewer viewer = ( HierarchicalViewer ) window.getActivePage().findView(
+ Application.PLUGIN_ID + ".view.HierarchicalViewer" ); //$NON-NLS-1$
+
+ if ( type.equals( SortType.alphabetical ) )
+ {
+ viewer.setOrder( new AlphabeticalOrderComparator() );
+ }
+ else if ( type.equals( SortType.unalphabetical ) )
+ {
+ viewer.setOrder( new UnAlphabeticalOrderComparator() );
+ }
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortPoolManagerAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortPoolManagerAction.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortPoolManagerAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/controller/actions/SortPoolManagerAction.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.controller.actions;
+
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.controller.ICommandIds;
+import org.apache.directory.ldapstudio.schemas.view.IImageKeys;
+import org.apache.directory.ldapstudio.schemas.view.viewers.PoolManager;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.AlphabeticalOrderComparator;
+import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.UnAlphabeticalOrderComparator;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Action for sorting the Schemas View
+ */
+public class SortPoolManagerAction extends Action
+{
+ private final IWorkbenchWindow window;
+
+ public enum SortType
+ {
+ alphabetical, unalphabetical
+ };
+
+ private SortType type;
+
+
+ /**
+ * Default constructor
+ * @param window the attached window
+ * @param type the type of sorting
+ * @param label the label to be displayed
+ */
+ public SortPoolManagerAction( IWorkbenchWindow window, SortType type, String label )
+ {
+ this.window = window;
+ setText( label );
+ this.type = type;
+
+ // The id is used to refer to the action in a menu or toolbar
+ setId( ICommandIds.CMD_SORT_POOL_MANAGER );
+ // Associate the action with a pre-defined command, to allow key
+ // bindings.
+ setActionDefinitionId( ICommandIds.CMD_SORT_POOL_MANAGER );
+
+ if ( type.equals( SortType.alphabetical ) )
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID,
+ IImageKeys.SORT_ALPHABETICAL ) );
+ else if ( type.equals( SortType.unalphabetical ) )
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID,
+ IImageKeys.SORT_UNALPHABETICAL ) );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ PoolManager viewer = ( PoolManager ) window.getActivePage().findView(
+ Application.PLUGIN_ID + ".view.PoolManager" ); //$NON-NLS-1$
+
+ if ( type.equals( SortType.alphabetical ) )
+ {
+ viewer.setOrder( new AlphabeticalOrderComparator() );
+ }
+ else if ( type.equals( SortType.unalphabetical ) )
+ {
+ viewer.setOrder( new UnAlphabeticalOrderComparator() );
+ }
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/Messages.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/Messages.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/Messages.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/Messages.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.io;
+
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+
+public class Messages
+{
+ private static final String BUNDLE_NAME = "org.apache.directory.ldapstudio.schemas.io.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
+
+
+ private Messages()
+ {
+ }
+
+
+ public static String getString( String key )
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString( key );
+ }
+ catch ( MissingResourceException e )
+ {
+ return '!' + key + '!';
+ }
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaParser.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaParser.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaParser.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaParser.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.io;
+
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.text.ParseException;
+
+import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
+import org.apache.directory.server.core.tools.schema.ObjectClassLiteral;
+import org.apache.directory.server.core.tools.schema.OpenLdapSchemaParser;
+import org.apache.log4j.Logger;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class is a schema-parser factory.
+ * You should use one of the static generation methods to get a parser.
+ *
+ */
+public class SchemaParser
+{
+
+ private static Logger logger = Logger.getLogger( SchemaParser.class );
+ /******************************************
+ * Fields *
+ ******************************************/
+
+ private URL fileURL = null;
+ private AttributeTypeLiteral[] attributeTypes = null;
+ private ObjectClassLiteral[] objectClasses = null;
+
+
+ /******************************************
+ * Accessors *
+ ******************************************/
+
+ /**
+ * Use this method to access generated attribute types
+ * @return the attribute types stored in an array
+ */
+ public AttributeTypeLiteral[] getAttributeTypes()
+ {
+ return attributeTypes;
+ }
+
+
+ /**
+ * Use this method to access generated object classes
+ * @return the object classes stored in an array
+ */
+ public ObjectClassLiteral[] getObjectClasses()
+ {
+ return objectClasses;
+ }
+
+
+ private void setAttributeTypes( AttributeTypeLiteral[] attributeTypes )
+ {
+ this.attributeTypes = attributeTypes;
+ }
+
+
+ private void setObjectClasses( ObjectClassLiteral[] objectClasses )
+ {
+ this.objectClasses = objectClasses;
+ }
+
+
+ /******************************************
+ * Initialization *
+ ******************************************/
+
+ private SchemaParser( URL url )
+ {
+ this.fileURL = url;
+ }
+
+
+ /**
+ * Use this method to obtain a schema parser from an URL.
+ * @param url the location of the schema that will be parsed.
+ * @return the schema parser
+ */
+ public static SchemaParser parserFromURL( URL url )
+ {
+ return new SchemaParser( url );
+
+ }
+
+
+ /******************************************
+ * Logic *
+ ******************************************/
+
+ /**
+ * Launch schema parsing
+ * @throws IOException if error opening the .schema file
+ * @throws ParseException if error during parsing of the .schema file
+ */
+ public void parse() throws IOException, ParseException
+ {
+ InputStream in = null;
+ in = fileURL.openStream();
+
+ if ( in == null )
+ throw new FileNotFoundException( Messages.getString( "SchemaParser.0" ) ); //$NON-NLS-1$
+
+ OpenLdapSchemaParser parser = new OpenLdapSchemaParser();
+ try
+ {
+ parser.parse( in );
+ }
+ catch ( ParseException e )
+ {
+ logger.error( "An error occured when parsing the file - " + e.getMessage() ); //$NON-NLS-1$
+ MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ SWT.OK | SWT.ICON_ERROR );
+ messageBox
+ .setMessage( Messages.getString( "SchemaParser.An_error_has_occurred_when_parsing_the_file" ) + fileURL.toString() + Messages.getString( "SchemaParser.The_schema_cannot_be_opened" ) + " " + "See log file for debug information about the schema." ); //$NON-NLS-1$ //$NON-NLS-2$
+ messageBox.open();
+ throw e;
+ }
+
+ generateAttributeTypes( parser );
+ generateObjectClasses( parser );
+ }
+
+
+ /**
+ * Generate all attributeTypes from schema
+ * @param parser the schema parser
+ */
+ @SuppressWarnings("unchecked")//$NON-NLS-1$
+ private void generateAttributeTypes( OpenLdapSchemaParser parser )
+ {
+ int size = parser.getAttributeTypes().size();
+ setAttributeTypes( new AttributeTypeLiteral[size] );
+ setAttributeTypes( ( AttributeTypeLiteral[] ) parser.getAttributeTypes().values().toArray( getAttributeTypes() ) );
+ }
+
+
+ /**
+ * Generate all objectClasses from schema
+ * @param parser the schema parser
+ */
+ @SuppressWarnings("unchecked")//$NON-NLS-1$
+ private void generateObjectClasses( OpenLdapSchemaParser parser )
+ {
+ int size = parser.getObjectClassTypes().size();
+ setObjectClasses( new ObjectClassLiteral[size] );
+ setObjectClasses( ( ObjectClassLiteral[] ) parser.getObjectClassTypes().values().toArray( getObjectClasses() ) );
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaWriter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaWriter.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaWriter.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/io/SchemaWriter.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.io;
+
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Date;
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.model.Schema;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.eclipse.core.runtime.Platform;
+
+
+/**
+ * This class is a LDAP schema generator
+ *
+ */
+public class SchemaWriter
+{
+ private VelocityEngine ve;
+
+
+ public SchemaWriter()
+ {
+ ve = new VelocityEngine();
+ }
+
+
+ /**
+ * Launch schema generation
+ * @param schema the schema
+ * @param src the file-path where it will be generated
+ * @throws Exception if an exception during the generation of the schema
+ */
+ @SuppressWarnings("deprecation")//$NON-NLS-1$
+ public void write( Schema schema, String src ) throws Exception
+ {
+ // VelocityEngine initialization
+ ve.init( new java.util.Properties() );
+
+ // VelocityContext initialization and variables setup
+ VelocityContext context = new VelocityContext();
+ context.put( "schemaName", schema.getName() ); //$NON-NLS-1$
+ Date date = new Date();
+ context.put( "date", date.toLocaleString() ); //$NON-NLS-1$
+ context.put( "attributeTypes", schema.getAttributeTypesAsArray() ); //$NON-NLS-1$
+ context.put( "objectClasses", schema.getObjectClassesAsArray() ); //$NON-NLS-1$
+
+ // Schema generation
+ URL template = Platform.getBundle( Application.PLUGIN_ID ).getResource( "ressources/templates/Schema.template" ); //$NON-NLS-1$
+ Reader fileIn = new BufferedReader( new InputStreamReader( template.openStream() ) );
+ Writer writer = new FileWriter( new File( src ) );
+ ve.evaluate( context, writer, "LOG", fileIn ); //$NON-NLS-1$
+
+ writer.flush();
+ writer.close();
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/AttributeType.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/AttributeType.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/AttributeType.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/AttributeType.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,514 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+import java.util.ArrayList;
+
+import org.apache.directory.ldapstudio.schemas.controller.PoolManagerController;
+import org.apache.directory.ldapstudio.schemas.view.editors.AttributeTypeFormEditor;
+import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+
+/**
+ * This class is the model for 'attribute type' LDAP schema
+ * elements. It is modeled after the RFC 2252 recommandation but
+ * not all of the properties are implemented in the ApacheDS
+ * Directory Server.
+ *
+ */
+@SuppressWarnings("unused")//$NON-NLS-1$
+public class AttributeType implements SchemaElement
+{
+ private static Logger logger = Logger.getLogger( AttributeType.class );
+ private AttributeTypeLiteral literal;
+ private Schema originatingSchema;
+ private ArrayList<SchemaElementListener> listeners;
+ private AttributeTypeFormEditor editor;
+
+
+ /******************************************
+ * Constructors *
+ ******************************************/
+
+ /**
+ * Default constructor
+ * @param literal the literal given by the schema parser that represents this element
+ * @param originatingSchema the schema file that defines this element
+ */
+ public AttributeType( AttributeTypeLiteral literal, Schema originatingSchema )
+ {
+ this.literal = literal;
+ this.originatingSchema = originatingSchema;
+ listeners = new ArrayList<SchemaElementListener>();
+ }
+
+
+ /******************************************
+ * Accessors *
+ ******************************************/
+
+ /**
+ * @return the openldap parser literal associated with this attributeType
+ */
+ public AttributeTypeLiteral getLiteral()
+ {
+ return literal;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.ldapstudio.schemas.model.SchemaElement#getOriginatingSchema()
+ */
+ public Schema getOriginatingSchema()
+ {
+ return originatingSchema;
+ }
+
+
+ /**
+ * Returns the editor associated to this attributeType
+ * @return the editor
+ */
+ public AttributeTypeFormEditor getEditor()
+ {
+ return editor;
+ }
+
+
+ /**
+ * Sets the editor associated to this attributeType
+ * @param editor the associated editor
+ */
+ public void setEditor( AttributeTypeFormEditor editor )
+ {
+ this.editor = editor;
+ }
+
+
+ /******************************************
+ * Logic *
+ ******************************************/
+
+ /**
+ * Call this method to remove the attributeType<->Editor association
+ * @param editor the associated editor
+ */
+ public void removeEditor( AttributeTypeFormEditor editor )
+ {
+ if ( this.editor == editor )
+ this.editor = null;
+ }
+
+
+ /**
+ * Close the editor associated to this attributeType WITHOUT applying the
+ * modifications
+ */
+ public void closeAssociatedEditor()
+ {
+ if ( editor != null )
+ {
+ // This is a trick, so you don't get asked a second time to close and save or not the editor that has already been closed.
+ editor.setDirty( false );
+
+ editor.close( false );
+ removeEditor( editor );
+ }
+ }
+
+
+ /**
+ * Checks if the attributeType has pending modifications in its editor
+ * @return
+ */
+ public boolean hasPendingModifications()
+ {
+ if ( this.editor != null )
+ {
+ return editor.isDirty();
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Apply the pending modifications to the model (this instance)
+ */
+ public void applyPendingModifications()
+ {
+ if ( hasPendingModifications() )
+ {
+ editor.doSave( new NullProgressMonitor() );
+ }
+ }
+
+
+ /******************************************
+ * Wrapper Methods *
+ ******************************************/
+
+ //get
+ public String getDescription()
+ {
+ return literal.getDescription();
+ }
+
+
+ public String getEquality()
+ {
+ return literal.getEquality();
+ }
+
+
+ public int getLength()
+ {
+ return literal.getLength();
+ }
+
+
+ public String[] getNames()
+ {
+ return literal.getNames();
+ }
+
+
+ public String getOid()
+ {
+ return literal.getOid();
+ }
+
+
+ public String getOrdering()
+ {
+ return literal.getOrdering();
+ }
+
+
+ public String getSubstr()
+ {
+ return literal.getSubstr();
+ }
+
+
+ public String getSuperior()
+ {
+ return literal.getSuperior();
+ }
+
+
+ public String getSyntax()
+ {
+ return literal.getSyntax();
+ }
+
+
+ public UsageEnum getUsage()
+ {
+ return literal.getUsage();
+ }
+
+
+ //set
+ public void setDescription( String description )
+ {
+ literal.setDescription( description );
+ notifyChanged();
+ }
+
+
+ public void setEquality( String equality )
+ {
+ literal.setEquality( equality );
+ notifyChanged();
+ }
+
+
+ public void setLength( int length )
+ {
+ literal.setLength( length );
+ notifyChanged();
+ }
+
+
+ public void setNames( String[] names )
+ {
+ literal.setNames( names );
+ notifyChanged();
+ }
+
+
+ public void setOrdering( String ordering )
+ {
+ literal.setOrdering( ordering );
+ notifyChanged();
+ }
+
+
+ public void setSubstr( String substr )
+ {
+ literal.setSubstr( substr );
+ notifyChanged();
+ }
+
+
+ public void setSuperior( String superior )
+ {
+ literal.setSuperior( superior );
+ notifyChanged();
+ }
+
+
+ public void setSyntax( String syntax )
+ {
+ literal.setSyntax( syntax );
+ notifyChanged();
+ }
+
+
+ public void setUsage( UsageEnum usage )
+ {
+ literal.setUsage( usage );
+ notifyChanged();
+ }
+
+
+ public void setObsolete( boolean bool )
+ {
+ literal.setObsolete( bool );
+ notifyChanged();
+ }
+
+
+ public void setSingleValue( boolean bool )
+ {
+ literal.setSingleValue( bool );
+ notifyChanged();
+ }
+
+
+ public void setCollective( boolean bool )
+ {
+ literal.setCollective( bool );
+ notifyChanged();
+ }
+
+
+ public void setNoUserModification( boolean bool )
+ {
+ literal.setNoUserModification( bool );
+ notifyChanged();
+ }
+
+
+ //test
+ public boolean isObsolete()
+ {
+ return literal.isObsolete();
+ }
+
+
+ public boolean isCollective()
+ {
+ return literal.isCollective();
+ }
+
+
+ public boolean isNoUserModification()
+ {
+ return literal.isNoUserModification();
+ }
+
+
+ public boolean isSingleValue()
+ {
+ return literal.isSingleValue();
+ }
+
+
+ /******************************************
+ * I/O *
+ ******************************************/
+
+ public String write()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ // Open the definition and OID
+ sb.append( "attributetype ( " + literal.getOid() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // NAME(S)
+ String[] names = literal.getNames();
+ sb.append( "\tNAME " ); //$NON-NLS-1$
+ if ( names.length > 1 )
+ {
+ sb.append( "( " ); //$NON-NLS-1$
+ for ( int i = 0; i < names.length; i++ )
+ {
+ sb.append( "'" + names[i] + "' " ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ sb.append( ") \n" ); //$NON-NLS-1$
+ }
+ else
+ {
+ sb.append( "'" + names[0] + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // DESC
+ if ( ( literal.getDescription() != null ) && ( literal.getDescription().length() != 0 ) )
+ {
+ sb.append( "\tDESC '" + literal.getDescription() + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // OBSOLETE
+ if ( literal.isObsolete() )
+ {
+ sb.append( "\tOBSOLETE \n" ); //$NON-NLS-1$
+ }
+
+ // SUP
+ if ( ( literal.getSuperior() != null ) && ( literal.getSuperior().length() != 0 ) )
+ {
+ sb.append( "\tSUP " + literal.getSuperior() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // EQUALITY
+ if ( ( literal.getEquality() != null ) && ( literal.getEquality().length() != 0 ) )
+ {
+ sb.append( "\tEQUALITY " + literal.getEquality() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // ORDERING
+ if ( ( literal.getOrdering() != null ) && ( literal.getOrdering().length() != 0 ) )
+ {
+ sb.append( "\tORDERING " + literal.getOrdering() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // SUBSTR
+ if ( ( literal.getSubstr() != null ) && ( literal.getSubstr().length() != 0 ) )
+ {
+ sb.append( "\tSUBSTR " + literal.getSubstr() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // SYNTAX
+ if ( ( literal.getSyntax() != null ) && ( literal.getSyntax().length() != 0 ) )
+ {
+ sb.append( "\tSYNTAX " + literal.getSyntax() ); //$NON-NLS-1$
+ if ( literal.getLength() > 0 )
+ {
+ sb.append( "{" + literal.getLength() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ sb.append( " \n" ); //$NON-NLS-1$
+ }
+
+ // SINGLE-VALUE
+ if ( literal.isSingleValue() )
+ {
+ sb.append( "\tSINGLE-VALUE \n" ); //$NON-NLS-1$
+ }
+
+ // COLLECTIVE
+ if ( literal.isCollective() )
+ {
+ sb.append( "\tCOLLECTIVE \n" ); //$NON-NLS-1$
+ }
+
+ // NO-USER-MODIFICATION
+ if ( literal.isNoUserModification() )
+ {
+ sb.append( "\tNO-USER-MODIFICATION \n" ); //$NON-NLS-1$
+ }
+
+ // USAGE
+ UsageEnum usage = literal.getUsage();
+ if ( usage != null )
+ {
+ if ( usage == UsageEnum.DIRECTORYOPERATION )
+ {
+ sb.append( "\tUSAGE directoryOperation \n" ); //$NON-NLS-1$
+ }
+ else if ( usage == UsageEnum.DISTRIBUTEDOPERATION )
+ {
+ sb.append( "\tUSAGE distributedOperation \n" ); //$NON-NLS-1$
+ }
+ else if ( usage == UsageEnum.DSAOPERATION )
+ {
+ sb.append( "\tUSAGE dSAOperation \n" ); //$NON-NLS-1$
+ }
+ else if ( usage == UsageEnum.USERAPPLICATIONS )
+ {
+ // There's nothing to write, this is the default option
+ }
+ }
+
+ // Close the definition
+ sb.append( " )\n" ); //$NON-NLS-1$
+
+ return sb.toString();
+ }
+
+
+ /******************************************
+ * Object Redefinition *
+ ******************************************/
+
+ public String toString()
+ {
+ return getNames()[0];
+ }
+
+
+ /******************************************
+ * Events emmiting *
+ ******************************************/
+
+ public void addListener( SchemaElementListener listener )
+ {
+ if ( !listeners.contains( listener ) )
+ listeners.add( listener );
+ }
+
+
+ public void removeListener( SchemaElementListener listener )
+ {
+ listeners.remove( listener );
+ }
+
+
+ private void notifyChanged()
+ {
+ for ( SchemaElementListener listener : listeners )
+ {
+ try
+ {
+ listener.schemaElementChanged( this, new LDAPModelEvent( LDAPModelEvent.Reason.ATModified, this ) );
+ }
+ catch ( Exception e )
+ {
+ logger.debug( "error when notifying listener: " + listener ); //$NON-NLS-1$
+ }
+ }
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+/**
+ * This class is a model for creation of events related to modifications of the model elements
+ * manipulated by this application. Like when a schema is added to the pool, or when the properties
+ * of an attributeType are modified.
+ * When creating an event, the reason is mandatory, but not the originating element.
+ *
+ * @see the Reason enumeration for the complete list of supported events
+ *
+ */
+public class LDAPModelEvent
+{
+
+ public enum Reason
+ {
+ SchemaAdded, SchemaRemoved, multipleSchemaRemoved, multipleSchemaAdded, SchemaSaved, OCAdded, OCRemoved, ATAdded, ATRemoved, OCModified, ATModified, poolCleared
+ };
+
+ private Reason reason = null;
+ private Object element = null;
+
+
+ /******************************************
+ * Constructors *
+ ******************************************/
+
+ /**
+ * Default constructor, takes only a reason as argument
+ */
+ public LDAPModelEvent( Reason reason )
+ {
+ this.reason = reason;
+ }
+
+
+ /**
+ * Constructor for objectClass motivated events
+ * @param reason takes only OCAdded, OCRemoved or OCModified reasons
+ * @param objectClass the incriminated objectClass
+ * @throws Exception if bad reason
+ */
+ public LDAPModelEvent( Reason reason, ObjectClass objectClass ) throws Exception
+ {
+ this( reason );
+ if ( ( reason == Reason.OCAdded ) || ( reason == Reason.OCModified ) || ( reason == Reason.OCRemoved ) )
+ {
+ this.element = objectClass;
+ }
+ else
+ throw new Exception( "Event creation exception " + reason + " " + objectClass ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ /**
+ * Constructor for attributeType motivated events
+ * @param reason takes only ATAdded, ATRemoved or ATModified reasons
+ * @param attributeType the incriminated attributeType
+ * @throws Exception if bad reason
+ */
+ public LDAPModelEvent( Reason reason, AttributeType attributeType ) throws Exception
+ {
+ this( reason );
+ if ( ( reason == Reason.ATAdded ) || ( reason == Reason.ATModified ) || ( reason == Reason.ATRemoved ) )
+ {
+ this.element = attributeType;
+ }
+ else
+ throw new Exception( "Event creation exception " + reason + " " + attributeType ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ /**
+ * Constructor for schema motivated events
+ * @param reason takes only SchemaAdded or SchemaRemoved reasons
+ * @param schema the incriminated schema
+ * @throws Exception if bad reason
+ */
+ public LDAPModelEvent( Reason reason, Schema schema ) throws Exception
+ {
+ this( reason );
+
+ if ( ( reason == Reason.SchemaAdded ) || ( reason == Reason.SchemaRemoved ) )
+ {
+ this.element = schema;
+ }
+ else
+ throw new Exception( "Event creation exception " + reason + " " + schema ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ /******************************************
+ * Accessors *
+ ******************************************/
+
+ /**
+ * If specified, returns the element that was the cause of the Event
+ * @return an ObjectClass, an AttributeType, a Schema or null if not specified
+ */
+ public Object getElement()
+ {
+ return element;
+ }
+
+
+ /**
+ * @return Returns the reason of the event
+ */
+ public Reason getReason()
+ {
+ return reason;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRule.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRule.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRule.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+/**
+ * This class is the model for 'Matching Rule' LDAP schema
+ * elements. It is modeled after the RFC 2252 recommandation.
+ *
+ */
+public class MatchingRule
+{
+ private String name;
+ private String oid;
+ private String syntax;
+
+
+ /**
+ * Default constructor
+ * @param name the name of the matching rule
+ * @param oid the oid of the matching rule
+ * @param syntax the syntax of the matching rule
+ */
+ public MatchingRule( String name, String oid, String syntax )
+ {
+ this.name = name;
+ this.oid = oid;
+ this.syntax = syntax;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+
+ public String getOid()
+ {
+ return oid;
+ }
+
+
+ public void setOid( String oid )
+ {
+ this.oid = oid;
+ }
+
+
+ public String getSyntax()
+ {
+ return syntax;
+ }
+
+
+ public void setSyntax( String syntax )
+ {
+ this.syntax = syntax;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRules.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRules.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRules.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/MatchingRules.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.eclipse.core.runtime.Platform;
+
+
+/**
+ * This class allows to get the list of all matching rules
+ * (which is initialized once parsing a XML file)
+ *
+ */
+public class MatchingRules
+{
+ private static final ArrayList<MatchingRule> equalityMatchingRules;
+ private static final ArrayList<MatchingRule> orderingMatchingRules;
+ private static final ArrayList<MatchingRule> substringMatchingRules;
+
+ static
+ {
+ try
+ {
+ equalityMatchingRules = new ArrayList<MatchingRule>();
+ URL url = Platform.getBundle( Application.PLUGIN_ID ).getResource( "ressources/utils/matching_rules.xml" ); //$NON-NLS-1$
+ XMLConfiguration config = new XMLConfiguration( url );
+
+ // We get the number of matching rules to parse for EQUALITY
+ Object matchingRules = config.getProperty( "equality.matchingRule.name" ); //$NON-NLS-1$
+ if ( matchingRules instanceof Collection )
+ {
+ for ( int i = 0; i < ( ( Collection ) matchingRules ).size(); i++ )
+ {
+ // We parse each syntax and get its properties
+ String name = config.getString( "equality.matchingRule(" + i + ").name" ); //$NON-NLS-1$ //$NON-NLS-2$
+ String oid = config.getString( "equality.matchingRule(" + i + ").oid" ); //$NON-NLS-1$ //$NON-NLS-2$
+ String syntax = config.getString( "equality.matchingRule(" + i + ").syntax" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // We create the corresponding syntax object and add it to the ArrayList
+ MatchingRule matchingRule = new MatchingRule( name, oid, syntax );
+ equalityMatchingRules.add( matchingRule );
+ }
+ }
+ }
+ catch ( Throwable e )
+ {
+ throw new RuntimeException( e.getMessage() );
+ }
+ }
+
+ static
+ {
+ try
+ {
+ orderingMatchingRules = new ArrayList<MatchingRule>();
+
+ URL url = Platform.getBundle( Application.PLUGIN_ID ).getResource( "ressources/utils/matching_rules.xml" ); //$NON-NLS-1$
+ XMLConfiguration config = new XMLConfiguration( url );
+
+ // We get the number of matching rules to parse for ORDERING
+ Object matchingRules = config.getProperty( "ordering.matchingRule.name" ); //$NON-NLS-1$
+ if ( matchingRules instanceof Collection )
+ {
+ for ( int i = 0; i < ( ( Collection ) matchingRules ).size(); i++ )
+ {
+ // We parse each syntax and get its properties
+ String name = config.getString( "ordering.matchingRule(" + i + ").name" ); //$NON-NLS-1$ //$NON-NLS-2$
+ String oid = config.getString( "ordering.matchingRule(" + i + ").oid" ); //$NON-NLS-1$ //$NON-NLS-2$
+ String syntax = config.getString( "ordering.matchingRule(" + i + ").syntax" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // We create the corresponding syntax object and add it to the ArrayList
+ MatchingRule matchingRule = new MatchingRule( name, oid, syntax );
+ orderingMatchingRules.add( matchingRule );
+ }
+ }
+ }
+ catch ( Throwable e )
+ {
+ throw new RuntimeException( e.getMessage() );
+ }
+ }
+
+ static
+ {
+ try
+ {
+ substringMatchingRules = new ArrayList<MatchingRule>();
+ URL url = Platform.getBundle( Application.PLUGIN_ID ).getResource( "ressources/utils/matching_rules.xml" ); //$NON-NLS-1$
+ XMLConfiguration config = new XMLConfiguration( url );
+
+ // We get the number of matching rules to parse for SUBSTRING
+ Object matchingRules = config.getProperty( "substring.matchingRule.name" ); //$NON-NLS-1$
+ if ( matchingRules instanceof Collection )
+ {
+ for ( int i = 0; i < ( ( Collection ) matchingRules ).size(); i++ )
+ {
+ // We parse each syntax and get its properties
+ String name = config.getString( "substring.matchingRule(" + i + ").name" ); //$NON-NLS-1$ //$NON-NLS-2$
+ String oid = config.getString( "substring.matchingRule(" + i + ").oid" ); //$NON-NLS-1$ //$NON-NLS-2$
+ String syntax = config.getString( "substring.matchingRule(" + i + ").syntax" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // We create the corresponding syntax object and add it to the ArrayList
+ MatchingRule matchingRule = new MatchingRule( name, oid, syntax );
+ substringMatchingRules.add( matchingRule );
+ }
+ }
+ }
+ catch ( Throwable e )
+ {
+ throw new RuntimeException( e.getMessage() );
+ }
+ }
+
+
+ /**
+ * Return the unique initialized ArrayList containing all Equality Matching Rules
+ * @return the Equality Matching Rules ArrayList
+ */
+ public static ArrayList<MatchingRule> getEqualityMatchingRules()
+ {
+ return equalityMatchingRules;
+ }
+
+
+ /**
+ * Return the unique initialized ArrayList containing all Ordering Matching Rules
+ * @return the Ordering Matching Rules ArrayList
+ */
+ public static ArrayList<MatchingRule> getOrderingMatchingRules()
+ {
+ return orderingMatchingRules;
+ }
+
+
+ /**
+ * Return the unique initialized ArrayList containing all Substring Matching Rules
+ * @return the Substring Matching Rules ArrayList
+ */
+ public static ArrayList<MatchingRule> getSubstringMatchingRules()
+ {
+ return substringMatchingRules;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Messages.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Messages.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Messages.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/Messages.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+
+public class Messages
+{
+ private static final String BUNDLE_NAME = "org.apache.directory.ldapstudio.schemas.model.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
+
+
+ private Messages()
+ {
+ }
+
+
+ public static String getString( String key )
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString( key );
+ }
+ catch ( MissingResourceException e )
+ {
+ return '!' + key + '!';
+ }
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/OID.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/OID.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/OID.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/OID.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+/**
+ * This class is the placeholder fot the model for OID strings.
+ *
+ * Currently we only use string validation, but the ultimate goal would be to fully
+ * represent OIDs as model object in LDAP Studio.
+ *
+ * An oid is a string of numbers separated by dots, like 1.2.3.4.567
+ *
+ */
+public class OID
+{
+
+ /**
+ * Validate an OID string
+ * @param str the OID
+ * @return true if it's a correcly formed OID
+ */
+ public static boolean validate( String str )
+ {
+ return java.util.regex.Pattern.matches( "^\\d+(\\.\\d+)*", str ); //$NON-NLS-1$
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/ObjectClass.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/ObjectClass.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/ObjectClass.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,427 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+import java.util.ArrayList;
+
+import org.apache.directory.ldapstudio.schemas.controller.Application;
+import org.apache.directory.ldapstudio.schemas.view.editors.AttributeTypeFormEditor;
+import org.apache.directory.ldapstudio.schemas.view.editors.ObjectClassFormEditor;
+import org.apache.directory.server.core.tools.schema.ObjectClassLiteral;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+
+/**
+ * This class is the model for 'object type' LDAP schema
+ * elements it's based on the ASN.1 description.
+ *
+ */
+@SuppressWarnings("unused")//$NON-NLS-1$
+public class ObjectClass implements SchemaElement
+{
+ private static Logger logger = Logger.getLogger( ObjectClass.class );
+ private ObjectClassLiteral literal;
+ private Schema originatingSchema;
+ private ArrayList<SchemaElementListener> listeners;
+ private ObjectClassFormEditor editor;
+
+
+ /******************************************
+ * Constructors *
+ ******************************************/
+
+ /**
+ * Default constructor
+ * @param literal the literal given by the schema parser that represents this element
+ * @param originatingSchema the schema file that defines this element
+ */
+ public ObjectClass( ObjectClassLiteral literal, Schema originatingSchema )
+ {
+ this.literal = literal;
+ this.originatingSchema = originatingSchema;
+ listeners = new ArrayList<SchemaElementListener>();
+ }
+
+
+ /******************************************
+ * Accessors *
+ ******************************************/
+
+ /**
+ * @return the openldap parser literal associated with this objectClass
+ */
+ public ObjectClassLiteral getLiteral()
+ {
+ return literal;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.ldapstudio.schemas.model.SchemaElement#getOriginatingSchema()
+ */
+ public Schema getOriginatingSchema()
+ {
+ return originatingSchema;
+ }
+
+
+ /**
+ * Returns the editor associated to this objectClass
+ * @return the editor
+ */
+ public ObjectClassFormEditor getEditor()
+ {
+ return editor;
+ }
+
+
+ /**
+ * Sets the editor associated to this objectClass
+ * @param editor the associated editor
+ */
+ public void setEditor( ObjectClassFormEditor editor )
+ {
+ this.editor = editor;
+ }
+
+
+ /******************************************
+ * Logic *
+ ******************************************/
+
+ /**
+ * Call this method to remove the objectClass<->Editor association
+ * @param editor the associated editor
+ */
+ public void removeEditor( ObjectClassFormEditor editor )
+ {
+ if ( this.editor == editor )
+ this.editor = null;
+ }
+
+
+ /**
+ * Close the editor associated to this objectClass WITHOUT applying the
+ * modifications
+ */
+ public void closeAssociatedEditor()
+ {
+ if ( editor != null )
+ {
+ // This is a trick, so you don't get asked a second time to close and save or not the editor that has already been closed.
+ editor.setDirty( false );
+
+ editor.close( false );
+ removeEditor( editor );
+ }
+ }
+
+
+ /**
+ * Checks if the objectClass has pending modifications in its editor
+ * @return
+ */
+ public boolean hasPendingModifications()
+ {
+ if ( this.editor != null )
+ {
+ return editor.isDirty();
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Apply the pending modifications to the model (this instance)
+ */
+ public void applyPendingModifications()
+ {
+ if ( hasPendingModifications() )
+ {
+ editor.doSave( new NullProgressMonitor() );
+ }
+ }
+
+
+ /******************************************
+ * Wrapper Methods *
+ ******************************************/
+ //get
+ public String[] getNames()
+ {
+ return literal.getNames();
+ }
+
+
+ public String getOid()
+ {
+ return literal.getOid();
+ }
+
+
+ public String getDescription()
+ {
+ return literal.getDescription();
+ }
+
+
+ public String[] getSuperiors()
+ {
+ return literal.getSuperiors();
+ }
+
+
+ public ObjectClassTypeEnum getClassType()
+ {
+ return literal.getClassType();
+ }
+
+
+ public boolean isObsolete()
+ {
+ return literal.isObsolete();
+ }
+
+
+ public String[] getMay()
+ {
+ return literal.getMay();
+ }
+
+
+ public String[] getMust()
+ {
+ return literal.getMust();
+ }
+
+
+ //set
+
+ public void setNames( String[] names )
+ {
+ literal.setNames( names );
+ notifyChanged();
+ }
+
+
+ public void setOid( String oid )
+ {
+ literal.setOid( oid );
+ notifyChanged();
+ }
+
+
+ public void setDescription( String description )
+ {
+ literal.setDescription( description );
+ notifyChanged();
+ }
+
+
+ public void setClassType( ObjectClassTypeEnum type )
+ {
+ literal.setClassType( type );
+ notifyChanged();
+ }
+
+
+ public void setObsolete( boolean bool )
+ {
+ literal.setObsolete( bool );
+ notifyChanged();
+ }
+
+
+ public void setSuperiors( String[] superiors )
+ {
+ literal.setSuperiors( superiors );
+ notifyChanged();
+ }
+
+
+ public void setMay( String[] may )
+ {
+ literal.setMay( may );
+ notifyChanged();
+ }
+
+
+ public void setMust( String[] must )
+ {
+ literal.setMust( must );
+ notifyChanged();
+ }
+
+
+ /******************************************
+ * I/O *
+ ******************************************/
+ public String write()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ // Open the definition and OID
+ sb.append( "objectclass ( " + literal.getOid() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // NAME(S)
+ String[] names = literal.getNames();
+ sb.append( "\tNAME " ); //$NON-NLS-1$
+ if ( names.length > 1 )
+ {
+ sb.append( "( " ); //$NON-NLS-1$
+ for ( int i = 0; i < names.length; i++ )
+ {
+ sb.append( "'" + names[i] + "' " ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ sb.append( ") \n" ); //$NON-NLS-1$
+ }
+ else
+ {
+ sb.append( "'" + names[0] + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // DESC
+ if ( ( literal.getDescription() != null ) && ( literal.getDescription().length() != 0 ) )
+ {
+ sb.append( "\tDESC '" + literal.getDescription() + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // OBSOLETE
+ if ( literal.isObsolete() )
+ {
+ sb.append( "\tOBSOLETE \n" ); //$NON-NLS-1$
+ }
+
+ // SUP
+ String[] superiors = literal.getSuperiors();
+ if ( superiors.length != 0 )
+ {
+ sb.append( "\tSUP " + superiors[0] + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // CLASSTYPE
+ ObjectClassTypeEnum classtype = literal.getClassType();
+ if ( classtype == ObjectClassTypeEnum.ABSTRACT )
+ {
+ sb.append( "\tABSTRACT \n" ); //$NON-NLS-1$
+ }
+ else if ( classtype == ObjectClassTypeEnum.AUXILIARY )
+ {
+ sb.append( "\tAUXILIARY \n" ); //$NON-NLS-1$
+ }
+ else if ( classtype == ObjectClassTypeEnum.STRUCTURAL )
+ {
+ sb.append( "\tSTRUCTURAL \n" ); //$NON-NLS-1$
+ }
+
+ // MUST
+ String[] must = literal.getMust();
+ if ( must.length != 0 )
+ {
+ sb.append( "\tMUST " ); //$NON-NLS-1$
+ if ( must.length > 1 )
+ {
+ sb.append( "( " + must[0] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+ for ( int i = 1; i < must.length; i++ )
+ {
+ sb.append( "$ " + must[i] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ sb.append( ") \n" ); //$NON-NLS-1$
+ }
+ else if ( must.length == 1 )
+ {
+ sb.append( must[0] + " \n" ); //$NON-NLS-1$
+ }
+ }
+
+ // MAY
+ String[] may = literal.getMay();
+ if ( may.length != 0 )
+ {
+ sb.append( "\tMAY " ); //$NON-NLS-1$
+ if ( may.length > 1 )
+ {
+ sb.append( "( " + may[0] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+ for ( int i = 1; i < may.length; i++ )
+ {
+ sb.append( "$ " + may[i] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ sb.append( ") \n" ); //$NON-NLS-1$
+ }
+ else if ( may.length == 1 )
+ {
+ sb.append( may[0] + " \n" ); //$NON-NLS-1$
+ }
+ }
+ // Close the definition
+ sb.append( " )\n" ); //$NON-NLS-1$
+
+ return sb.toString();
+ }
+
+
+ /******************************************
+ * Object Redefinition *
+ ******************************************/
+
+ public String toString()
+ {
+ return getNames()[0];
+ }
+
+
+ /******************************************
+ * Events emmiting *
+ ******************************************/
+
+ public void addListener( SchemaElementListener listener )
+ {
+ if ( !listeners.contains( listener ) )
+ listeners.add( listener );
+ }
+
+
+ public void removeListener( SchemaElementListener listener )
+ {
+ listeners.remove( listener );
+ }
+
+
+ private void notifyChanged()
+ {
+ for ( SchemaElementListener listener : listeners )
+ {
+ try
+ {
+ listener.schemaElementChanged( this, new LDAPModelEvent( LDAPModelEvent.Reason.OCModified, this ) );
+ }
+ catch ( Exception e )
+ {
+ logger.debug( "error when notifying " + listener + " of " + this.getNames()[0] + " modification" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/PoolListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/PoolListener.java?view=auto&rev=475786
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/PoolListener.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/PoolListener.java Thu Nov 16 08:05:20 2006
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.schemas.model;
+
+
+/**
+ * Listener to pool instances must implement this interface
+ */
+public interface PoolListener
+{
+
+ /**
+ * Called if the pool has changed (if a schema has been modified, added or removed)
+ *
+ */
+ public void poolChanged( SchemaPool p, LDAPModelEvent e );
+}