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/04/18 12:30:26 UTC
svn commit: r529955 - in
/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model:
ServerConfigurationParser.java ServerConfigurationParserException.java
Author: pamarcelot
Date: Wed Apr 18 03:30:25 2007
New Revision: 529955
URL: http://svn.apache.org/viewvc?view=rev&rev=529955
Log:
Replace the ServerConfigurationParser that was using Spring by a new one using DOM4J. The old one was causing errors when loading configuration with different Extended Operations than the standard ones.
Modified:
directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParser.java
directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParserException.java
Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParser.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParser.java?view=diff&rev=529955&r1=529954&r2=529955
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParser.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParser.java Wed Apr 18 03:30:25 2007
@@ -20,17 +20,25 @@
package org.apache.directory.ldapstudio.apacheds.configuration.model;
-import java.util.Collection;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import org.apache.directory.server.configuration.MutableServerStartupConfiguration;
-import org.apache.directory.server.core.configuration.MutableInterceptorConfiguration;
-import org.apache.directory.server.core.configuration.PartitionConfiguration;
-import org.apache.directory.server.core.partition.impl.btree.MutableIndexConfiguration;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
/**
@@ -57,100 +65,766 @@
{
try
{
- ApplicationContext ac = new FileSystemXmlApplicationContext( "file:" + path );
- MutableServerStartupConfiguration config = ( MutableServerStartupConfiguration ) ac
- .getBean( "configuration" );
- Properties environment = ( Properties ) ac.getBean( "environment" );
-
+ Document document = parseAndGetDocument( path );
ServerConfiguration serverConfiguration = new ServerConfiguration();
serverConfiguration.setPath( path );
- serverConfiguration.setAllowAnonymousAccess( config.isAllowAnonymousAccess() );
- serverConfiguration.setEnableAccessControl( config.isAccessControlEnabled() );
- serverConfiguration.setEnableChangePassword( config.isEnableChangePassword() );
- serverConfiguration.setEnableKerberos( config.isEnableKerberos() );
- serverConfiguration.setEnableNTP( config.isEnableNtp() );
- serverConfiguration.setMaxSizeLimit( config.getMaxSizeLimit() );
- serverConfiguration.setMaxThreads( config.getMaxThreads() );
- serverConfiguration.setMaxTimeLimit( config.getMaxTimeLimit() );
- serverConfiguration.setPassword( environment.getProperty( "java.naming.security.credentials", "" ) );
- serverConfiguration.setPort( config.getLdapPort() );
- serverConfiguration.setPrincipal( environment.getProperty( "java.naming.security.principal", "" ) );
- serverConfiguration.setSynchronizationPeriod( config.getSynchPeriodMillis() );
-
- // System Partition
- Partition systemPartition = createPartition( config.getSystemPartitionConfiguration(), true );
- serverConfiguration.addPartition( systemPartition );
-
- // Other Partitions
- Set<PartitionConfiguration> partitionConfigurations = config.getPartitionConfigurations();
- for ( PartitionConfiguration partitionConfiguration : partitionConfigurations )
- {
- Partition partition = createPartition( partitionConfiguration, false );
- serverConfiguration.addPartition( partition );
- }
-
- // Interceptors
- List interceptorConfigurations = config.getInterceptorConfigurations();
- for ( Object interceptorConfiguration : interceptorConfigurations )
- {
- MutableInterceptorConfiguration interceptor = ( MutableInterceptorConfiguration ) interceptorConfiguration;
- Interceptor newInterceptor = new Interceptor( interceptor.getName() );
- newInterceptor.setClassType( interceptor.getInterceptor().getClass().getName() );
- serverConfiguration.addInterceptor( newInterceptor );
- }
-
- // Extended Operations
- Collection extendedOperationHandlers = config.getExtendedOperationHandlers();
- for ( Object extendedOperationHandler : extendedOperationHandlers )
- {
- ExtendedOperation extendedOperation = new ExtendedOperation( extendedOperationHandler.getClass()
- .getName() );
- serverConfiguration.addExtendedOperation( extendedOperation );
- }
- return serverConfiguration;
+ // Reading the 'Environment' Bean
+ readEnvironmentBean( document, serverConfiguration );
+ // Reading the 'Configuration' Bean
+ readConfigurationBean( document, serverConfiguration );
+
+ return serverConfiguration;
}
catch ( Exception e )
{
- ServerConfigurationParserException exception = new ServerConfigurationParserException( e.getMessage(), e
- .getCause() );
- exception.setStackTrace( e.getStackTrace() );
- throw exception;
+ if ( e instanceof ServerConfigurationParserException )
+ {
+ throw ( ServerConfigurationParserException ) e;
+ }
+ else
+ {
+ ServerConfigurationParserException exception = new ServerConfigurationParserException( e.getMessage(),
+ e.getCause() );
+ exception.setStackTrace( e.getStackTrace() );
+ throw exception;
+ }
+ }
+ }
+
+
+ /**
+ * Parses the ServerConfiguration File and get the associated DOM4J Document.
+ *
+ * @param path
+ * the path of the file to parse
+ * @return
+ * the associated Document
+ * @throws DocumentException
+ * if an error occurrs during parsing
+ */
+ private Document parseAndGetDocument( String path ) throws DocumentException
+ {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read( path );
+ return document;
+ }
+
+
+ /**
+ * Reads the "Environment" Bean and store its values in the given ServerConfiguration.
+ *
+ * @param document
+ * the document to use
+ * @param serverConfiguration
+ * the Server Configuration
+ */
+ private void readEnvironmentBean( Document document, ServerConfiguration serverConfiguration )
+ {
+ Element environmentBean = getBeanElementById( document, "environment" );
+
+ // Principal
+ String principal = readEnvironmentBeanProperty( "java.naming.security.principal", environmentBean );
+ if ( principal != null )
+ {
+ serverConfiguration.setPrincipal( principal );
+ }
+
+ // Password
+ String password = readEnvironmentBeanProperty( "java.naming.security.credentials", environmentBean );
+ if ( password != null )
+ {
+ serverConfiguration.setPassword( password );
+ }
+
+ // TODO Add Other Values...
+ }
+
+
+ /**
+ * Reads the given property in the 'Environment' Bean and returns it.
+ *
+ * @param property
+ * the property
+ * @param element
+ * the Environment Bean Element
+ * @return
+ * the value of the property, or null if the property has not been found
+ */
+ private String readEnvironmentBeanProperty( String property, Element element )
+ {
+ Element propertyElement = element.element( "property" );
+ if ( propertyElement != null )
+ {
+ Element propsElement = propertyElement.element( "props" );
+ if ( propsElement != null )
+ {
+ for ( Iterator i = propsElement.elementIterator( "prop" ); i.hasNext(); )
+ {
+ Element propElement = ( Element ) i.next();
+ Attribute keyAttribute = propElement.attribute( "key" );
+ if ( keyAttribute != null && ( keyAttribute.getValue().equals( property ) ) )
+ {
+ return propElement.getText();
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Reads the "Configuration" Bean and store its values in the given ServerConfiguration.
+ *
+ * @param document
+ * the document to use
+ * @param serverConfiguration
+ * the Server Configuration
+ * @throws NumberFormatException
+ * @throws BooleanFormatException
+ * @throws ServerConfigurationParserException
+ */
+ private void readConfigurationBean( Document document, ServerConfiguration serverConfiguration )
+ throws NumberFormatException, BooleanFormatException, ServerConfigurationParserException
+ {
+ Element configurationBean = getBeanElementById( document, "configuration" );
+
+ // LdapPort
+ String ldapPort = readBeanProperty( "ldapPort", configurationBean );
+ if ( ldapPort != null )
+ {
+ serverConfiguration.setPort( Integer.parseInt( ldapPort ) );
+ }
+
+ // SynchPeriodMillis
+ String synchPeriodMillis = readBeanProperty( "synchPeriodMillis", configurationBean );
+ if ( synchPeriodMillis != null )
+ {
+ serverConfiguration.setSynchronizationPeriod( Long.parseLong( synchPeriodMillis ) );
+ }
+
+ // MaxTimeLimit
+ String maxTimeLimit = readBeanProperty( "maxTimeLimit", configurationBean );
+ if ( maxTimeLimit != null )
+ {
+ serverConfiguration.setMaxTimeLimit( Integer.parseInt( maxTimeLimit ) );
+ }
+
+ // MaxSizeLimit
+ String maxSizeLimit = readBeanProperty( "maxSizeLimit", configurationBean );
+ if ( maxSizeLimit != null )
+ {
+ serverConfiguration.setMaxSizeLimit( Integer.parseInt( maxSizeLimit ) );
+ }
+
+ // MaxThreads
+ String maxThreads = readBeanProperty( "maxThreads", configurationBean );
+ if ( maxThreads != null )
+ {
+ serverConfiguration.setMaxThreads( Integer.parseInt( maxThreads ) );
+ }
+
+ // AllowAnonymousAccess
+ String allowAnonymousAccess = readBeanProperty( "allowAnonymousAccess", configurationBean );
+ if ( allowAnonymousAccess != null )
+ {
+ serverConfiguration.setAllowAnonymousAccess( parseBoolean( allowAnonymousAccess ) );
+ }
+
+ // AccessControlEnabled
+ String accessControlEnabled = readBeanProperty( "accessControlEnabled", configurationBean );
+ if ( accessControlEnabled != null )
+ {
+ serverConfiguration.setEnableAccessControl( parseBoolean( accessControlEnabled ) );
}
+
+ // EnableNtp
+ String enableNtp = readBeanProperty( "enableNtp", configurationBean );
+ if ( enableNtp != null )
+ {
+ serverConfiguration.setEnableNTP( parseBoolean( enableNtp ) );
+ }
+
+ // EnableKerberos
+ String enableKerberos = readBeanProperty( "enableKerberos", configurationBean );
+ if ( enableKerberos != null )
+ {
+ serverConfiguration.setEnableKerberos( parseBoolean( enableKerberos ) );
+ }
+
+ // EnableChangePassword
+ String enableChangePassword = readBeanProperty( "enableChangePassword", configurationBean );
+ if ( enableChangePassword != null )
+ {
+ serverConfiguration.setEnableChangePassword( parseBoolean( enableChangePassword ) );
+ }
+
+ // SystemPartition
+ String systemPartitionConfiguration = readBeanProperty( "systemPartitionConfiguration", configurationBean );
+ if ( systemPartitionConfiguration != null )
+ {
+ Partition systemPartition = readPartition( document, systemPartitionConfiguration, true );
+ if ( systemPartition != null )
+ {
+ serverConfiguration.addPartition( systemPartition );
+ }
+ }
+ else
+ {
+ throw new ServerConfigurationParserException(
+ "The Server Configuration does not contain a 'systemPartitionConfiguration' property." );
+ }
+
+ // Other Partitions
+ readOtherPartitions( configurationBean, serverConfiguration );
+
+ // Interceptors
+ readInterceptors( configurationBean, serverConfiguration );
+
+ // ExtendedOperations
+ readExtendedOperations( configurationBean, serverConfiguration );
}
/**
- * Creates a Partition from the given Partition Configuration.
+ * Reads and adds Partitions (other than the SystemPartition) to the Server Configuration.
*
- * @param partitionConfiguration
- * the Partition Configuration
+ * @param configurationBean
+ * the Configuration Bean Element
+ * @param serverConfiguration
+ * the Server Configuration
+ * @throws BooleanFormatException
+ * @throws NumberFormatException
+ */
+ private void readOtherPartitions( Element configurationBean, ServerConfiguration serverConfiguration )
+ throws NumberFormatException, BooleanFormatException
+ {
+ Element propertyElement = null;
+ for ( Iterator i = configurationBean.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute nameAttribute = element.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( "partitionConfigurations" ) ) )
+ {
+ propertyElement = element;
+ break;
+ }
+ }
+ if ( propertyElement != null )
+ {
+ Element setElement = propertyElement.element( "set" );
+ if ( setElement != null )
+ {
+ for ( Iterator i = setElement.elementIterator( "ref" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute beanAttribute = element.attribute( "bean" );
+ if ( beanAttribute != null )
+ {
+ Partition partition = readPartition( configurationBean.getDocument(), beanAttribute.getValue(),
+ false );
+ if ( partition != null )
+ {
+ serverConfiguration.addPartition( partition );
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Reads the partition associated with the given Bean ID and return it.
+ *
+ * @param document
+ * the document
+ * @param id
+ * the Bean ID of the partition
* @param isSystemPartition
- * a flag to indicate if the created partition must be the system partition
+ * true if this partition is the System Partition
+ * @return
+ * the partition associated with the given Bean ID
+ * @throws BooleanFormatException
+ */
+ private Partition readPartition( Document document, String id, boolean isSystemPartition )
+ throws BooleanFormatException, NumberFormatException
+ {
+ Element partitionBean = getBeanElementById( document, id );
+ if ( partitionBean != null )
+ {
+ Partition partition = new Partition();
+ partition.setSystemPartition( isSystemPartition );
+
+ // Name
+ String name = readBeanProperty( "name", partitionBean );
+ if ( name != null )
+ {
+ partition.setName( name );
+ }
+
+ // CacheSize
+ String cacheSize = readBeanProperty( "cacheSize", partitionBean );
+ if ( cacheSize != null )
+ {
+ partition.setCacheSize( Integer.parseInt( cacheSize ) );
+ }
+
+ // Suffix
+ String suffix = readBeanProperty( "suffix", partitionBean );
+ if ( suffix != null )
+ {
+ partition.setSuffix( suffix );
+ }
+
+ // OptimizerEnabled
+ String optimizerEnabled = readBeanProperty( "optimizerEnabled", partitionBean );
+ if ( optimizerEnabled != null )
+ {
+ partition.setEnableOptimizer( parseBoolean( optimizerEnabled ) );
+ }
+
+ // SynchOnWrite
+ String synchOnWrite = readBeanProperty( "synchOnWrite", partitionBean );
+ if ( synchOnWrite != null )
+ {
+ partition.setSynchronizationOnWrite( parseBoolean( synchOnWrite ) );
+ }
+
+ // IndexedAttributes
+ partition.setIndexedAttributes( readPartitionIndexedAttributes( partitionBean ) );
+
+ // ContextEntry
+ partition.setContextEntry( readPartitionContextEntry( partitionBean ) );
+
+ return partition;
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Reads the Indexed Attributes of the given Partition Bean Element
+ *
+ * @param partitionBean
+ * the Partition Bean Element
* @return
- * the corresponding Partition
- * @throws Exception
- * if an error occurrs
+ * the Indexed Attributes
*/
- private Partition createPartition( PartitionConfiguration partitionConfiguration, boolean isSystemPartition )
- throws Exception
+ private List<IndexedAttribute> readPartitionIndexedAttributes( Element partitionBean ) throws NumberFormatException
{
- Partition partition = new Partition();
- partition.setSystemPartition( isSystemPartition );
- partition.setName( partitionConfiguration.getName() );
- partition.setCacheSize( partitionConfiguration.getCacheSize() );
- partition.setContextEntry( partitionConfiguration.getContextEntry() );
- partition.setSuffix( partitionConfiguration.getSuffix() );
+ List<IndexedAttribute> indexedAttributes = new ArrayList<IndexedAttribute>();
- for ( Object indexedAt : partitionConfiguration.getIndexedAttributes() )
+ Element propertyElement = null;
+ for ( Iterator i = partitionBean.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute nameAttribute = element.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( "indexedAttributes" ) ) )
+ {
+ propertyElement = element;
+ break;
+ }
+ }
+ if ( propertyElement != null )
{
- MutableIndexConfiguration indexConfiguration = ( MutableIndexConfiguration ) indexedAt;
- IndexedAttribute indexedAttribute = new IndexedAttribute( indexConfiguration.getAttributeId(),
- indexConfiguration.getCacheSize() );
- partition.addIndexedAttribute( indexedAttribute );
+ Element setElement = propertyElement.element( "set" );
+ if ( setElement != null )
+ {
+ for ( Iterator i = setElement.elementIterator( "bean" ); i.hasNext(); )
+ {
+ Element beanElement = ( Element ) i.next();
+ IndexedAttribute ia = readIndexedAttribute( beanElement );
+ if ( ia != null )
+ {
+ indexedAttributes.add( ia );
+ }
+ }
+ }
}
- return partition;
+ return indexedAttributes;
+ }
+
+
+ /**
+ * Reads an Indexed Attribute.
+ *
+ * @param beanElement
+ * the Bean Element of the Indexed Attribute
+ * @return
+ * the corresponding Indexed Attribute or null if it could not be parsed
+ * @throws NumberFormatException
+ */
+ private IndexedAttribute readIndexedAttribute( Element beanElement ) throws NumberFormatException
+ {
+ Attribute classAttribute = beanElement.attribute( "class" );
+ if ( classAttribute != null
+ && classAttribute.getValue().equals(
+ "org.apache.directory.server.core.partition.impl.btree.MutableIndexConfiguration" ) )
+ {
+ String attributeId = readBeanProperty( "attributeId", beanElement );
+ String cacheSize = readBeanProperty( "cacheSize", beanElement );
+ if ( ( attributeId != null ) && ( cacheSize != null ) )
+ {
+ return new IndexedAttribute( attributeId, Integer.parseInt( cacheSize ) );
+ }
+
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Reads the Context Entry of the given Partition Bean Element
+ *
+ * @param partitionBean
+ * the Partition Bean Element
+ * @return
+ * the Context Entry
+ */
+ private Attributes readPartitionContextEntry( Element partitionBean )
+ {
+ Element propertyElement = null;
+ for ( Iterator i = partitionBean.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute nameAttribute = element.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( "contextEntry" ) ) )
+ {
+ propertyElement = element;
+ break;
+ }
+ }
+ if ( propertyElement != null )
+ {
+ Element valueElement = propertyElement.element( "value" );
+ if ( valueElement != null )
+ {
+ return readContextEntry( valueElement.getText() );
+ }
+ }
+
+ return new BasicAttributes( true );
+ }
+
+
+ /**
+ * Read an entry (without DN)
+ *
+ * @param text
+ * The ldif format text
+ * @return An Attributes.
+ */
+ private Attributes readContextEntry( String text )
+ {
+ StringReader strIn = new StringReader( text );
+ BufferedReader in = new BufferedReader( strIn );
+
+ String line = null;
+ Attributes attributes = new AttributesImpl( true );
+
+ try
+ {
+ while ( ( line = ( ( BufferedReader ) in ).readLine() ) != null )
+ {
+ if ( line.length() == 0 )
+ {
+ continue;
+ }
+
+ String addedLine = line.trim();
+
+ if ( StringTools.isEmpty( addedLine ) )
+ {
+ continue;
+ }
+
+ javax.naming.directory.Attribute attribute = LdifReader.parseAttributeValue( addedLine );
+ javax.naming.directory.Attribute oldAttribute = attributes.get( attribute.getID() );
+
+ if ( oldAttribute != null )
+ {
+ try
+ {
+ oldAttribute.add( attribute.get() );
+ attributes.put( oldAttribute );
+ }
+ catch ( NamingException ne )
+ {
+ // Do nothing
+ }
+ }
+ else
+ {
+ attributes.put( attribute );
+ }
+ }
+ }
+ catch ( IOException ioe )
+ {
+ // Do nothing : we can't reach this point !
+ }
+
+ return attributes;
+ }
+
+
+ /**
+ * Reads and adds the Interceptors to the Server Configuration.
+ *
+ * @param configurationBean
+ * the Configuration Bean Element
+ * @param serverConfiguration
+ * the Server Configuration
+ */
+ private void readInterceptors( Element configurationBean, ServerConfiguration serverConfiguration )
+ {
+ Element propertyElement = null;
+ for ( Iterator i = configurationBean.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute nameAttribute = element.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( "interceptorConfigurations" ) ) )
+ {
+ propertyElement = element;
+ break;
+ }
+ }
+ if ( propertyElement != null )
+ {
+ Element listElement = propertyElement.element( "list" );
+ if ( listElement != null )
+ {
+ for ( Iterator i = listElement.elementIterator( "bean" ); i.hasNext(); )
+ {
+ Interceptor interceptor = readInterceptor( ( Element ) i.next() );
+ if ( interceptor != null )
+ {
+ serverConfiguration.addInterceptor( interceptor );
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Reads an Interceptor.
+ *
+ * @param element
+ * the Interceptor Element
+ * @return
+ * the Interceptor or null if it could not be parsed
+ */
+ private Interceptor readInterceptor( Element element )
+ {
+ Attribute classAttribute = element.attribute( "class" );
+ if ( classAttribute != null
+ && classAttribute.getValue().equals(
+ "org.apache.directory.server.core.configuration.MutableInterceptorConfiguration" ) )
+ {
+ String name = readBeanProperty( "name", element );
+
+ for ( Iterator i = element.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element propertyElement = ( Element ) i.next();
+ Attribute nameAttribute = propertyElement.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( "interceptor" ) ) )
+ {
+ Element beanElement = propertyElement.element( "bean" );
+ if ( beanElement != null )
+ {
+ Attribute beanClassAttribute = beanElement.attribute( "class" );
+ if ( beanClassAttribute != null )
+ {
+ Interceptor interceptor = new Interceptor( name );
+ interceptor.setClassType( beanClassAttribute.getValue() );
+ return interceptor;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Reads and adds the ExtendedOperations to the Server Configuration.
+ *
+ * @param configurationBean
+ * the Configuration Bean Element
+ * @param serverConfiguration
+ * the Server Configuration
+ */
+ private void readExtendedOperations( Element configurationBean, ServerConfiguration serverConfiguration )
+ {
+ Element propertyElement = null;
+ for ( Iterator i = configurationBean.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute nameAttribute = element.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( "extendedOperationHandlers" ) ) )
+ {
+ propertyElement = element;
+ break;
+ }
+ }
+ if ( propertyElement != null )
+ {
+ Element listElement = propertyElement.element( "list" );
+ if ( listElement != null )
+ {
+ for ( Iterator i = listElement.elementIterator( "bean" ); i.hasNext(); )
+ {
+ ExtendedOperation extendedOperation = readExtendedOperation( ( Element ) i.next() );
+ if ( extendedOperation != null )
+ {
+ serverConfiguration.addExtendedOperation( extendedOperation );
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Reads an Extended Operation.
+ *
+ * @param element
+ * the Extended Operation Element
+ * @return
+ * the Extended Operation or null if it could not be parsed
+ */
+ private ExtendedOperation readExtendedOperation( Element element )
+ {
+ Attribute classAttribute = element.attribute( "class" );
+ if ( classAttribute != null )
+ {
+ return new ExtendedOperation( classAttribute.getValue() );
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Gets the Bean element corresponding to the given ID.
+ *
+ * @param document
+ * the document to use
+ * @param id
+ * the id
+ * @return
+ * the Bean element corresponding to the given ID or null if the bean was not found
+ */
+ private Element getBeanElementById( Document document, String id )
+ {
+ for ( Iterator i = document.getRootElement().elementIterator( "bean" ); i.hasNext(); )
+ {
+ Element element = ( Element ) i.next();
+ Attribute idAttribute = element.attribute( "id" );
+ if ( idAttribute != null && ( idAttribute.getValue().equals( id ) ) )
+ {
+ return element;
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Reads the given property in the Bean and returns it.
+ *
+ * @param property
+ * the property
+ * @param element
+ * the Configuration Bean Element
+ * @return
+ * the value of the property, or null if the property has not been found
+ */
+ private String readBeanProperty( String property, Element element )
+ {
+ for ( Iterator i = element.elementIterator( "property" ); i.hasNext(); )
+ {
+ Element propertyElement = ( Element ) i.next();
+ Attribute nameAttribute = propertyElement.attribute( "name" );
+ if ( nameAttribute != null && ( nameAttribute.getValue().equals( property ) ) )
+ {
+ Attribute valueAttribute = propertyElement.attribute( "value" );
+ if ( valueAttribute != null )
+ {
+ return valueAttribute.getValue();
+ }
+
+ Attribute refAttribute = propertyElement.attribute( "ref" );
+ if ( refAttribute != null )
+ {
+ return refAttribute.getValue();
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Parses the string argument as a boolean.
+ *
+ * @param s
+ * a String containing the boolean representation to be parsed
+ * @return
+ * the boolean value represented by the argument.
+ * @throws BooleanFormatException
+ * if the string does not contain a parsable boolean.
+ */
+ private boolean parseBoolean( String s ) throws BooleanFormatException
+ {
+ if ( "true".equals( s ) )
+ {
+ return true;
+ }
+ else if ( "false".equals( s ) )
+ {
+ return false;
+ }
+ else
+ {
+ throw new BooleanFormatException( "The String '" + s + "' could not be parsed as a boolean." );
+ }
+ }
+
+ /**
+ * Thrown to indicate that the application has attempted to convert a string to a boolean,
+ * but that the string does not have the appropriate format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ private class BooleanFormatException extends Exception
+ {
+ /** The Serial Version UID */
+ private static final long serialVersionUID = -6426955193802317452L;
+
+
+ /**
+ * Creates a new instance of BooleanFormatException.
+ *
+ * @param message
+ * @param cause
+ */
+ public BooleanFormatException( String message )
+ {
+ super( message );
+ }
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParserException.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParserException.java?view=diff&rev=529955&r1=529954&r2=529955
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParserException.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationParserException.java Wed Apr 18 03:30:25 2007
@@ -39,6 +39,19 @@
* @param message
* the detail message (which is saved for later retrieval by the
* getMessage() method).
+ */
+ public ServerConfigurationParserException( String message )
+ {
+ super( message );
+ }
+
+
+ /**
+ * Creates a new instance of ServerConfigurationParserException.
+ *
+ * @param message
+ * the detail message (which is saved for later retrieval by the
+ * getMessage() method).
* @param cause
* the cause (which is saved for later retrieval by the getCause()
* method). (A null value is permitted, and indicates that the cause