You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/06/10 10:42:33 UTC

svn commit: r189923 - in /directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration: Configuration.java ConfigurationException.java ContextPartitionConfiguration.java MutableContextPartitionConfiguration.java

Author: trustin
Date: Fri Jun 10 01:42:32 2005
New Revision: 189923

URL: http://svn.apache.org/viewcvs?rev=189923&view=rev
Log:
* Added ConfigurationException and replaced IllegalArgumentExceptions with it.
* Modified ContextPartitionConfiguration more IoC framework friendly
* Added MutableContextPartitionConfiguration

Added:
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationException.java   (with props)
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java   (with props)
Modified:
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java
    directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java

Modified: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java?rev=189923&r1=189922&r2=189923&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java (original)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/Configuration.java Fri Jun 10 01:42:32 2005
@@ -39,15 +39,15 @@
      * Gets {@link Configuration} instance from the specified JNDI environment
      * {@link Hashtable}.
      * 
-     * @throws IllegalArgumentException if the specified environment doesn't
-     *                                  contain the configuration instance.
+     * @throws ConfigurationException if the specified environment doesn't
+     *                                contain the configuration instance.
      */
     public static Configuration toConfiguration( Hashtable jndiEnvironment )
     {
         Object value = jndiEnvironment.get( JNDI_KEY );
         if( value == null || !( value instanceof Configuration ) )
         {
-            throw new IllegalArgumentException( "Not an ApacheDS configuration: " + value );
+            throw new ConfigurationException( "Not an ApacheDS configuration: " + value );
         }
         
         return ( Configuration ) value;

Added: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationException.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationException.java?rev=189923&view=auto
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationException.java (added)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationException.java Fri Jun 10 01:42:32 2005
@@ -0,0 +1,62 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.configuration;
+
+/**
+ * A {@link RuntimeException} that is thrown when configuration is not valid.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConfigurationException extends RuntimeException
+{
+    private static final long serialVersionUID = -1439234202862091912L;
+
+    /**
+     * Creates a new instance.
+     */
+    public ConfigurationException()
+    {
+        super();
+    }
+
+    /**
+     * Creates a new instance.
+     */
+    public ConfigurationException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * Creates a new instance.
+     */
+    public ConfigurationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    /**
+     * Creates a new instance.
+     */
+    public ConfigurationException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Propchange: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ConfigurationException.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java?rev=189923&r1=189922&r2=189923&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java (original)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/ContextPartitionConfiguration.java Fri Jun 10 01:42:32 2005
@@ -19,11 +19,18 @@
 package org.apache.ldap.server.configuration;
 
 
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
 import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+
+import org.apache.ldap.server.ContextPartition;
 
 
 /**
- * A configuration bean for ContextPartitions.
+ * A configuration for {@link ContextPartition}.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Id$
@@ -31,77 +38,72 @@
 public class ContextPartitionConfiguration
 {
     private String suffix;
-    private String id;
-    private String[] indices;
-    private Attributes attributes;
-    private String partitionClass;
-    private String properties;
-
-
-    public String getSuffix()
+    private Set indexedAttributes = new HashSet(); // Set<String>
+    private Attributes rootEntry = new BasicAttributes();
+    private ContextPartition partition;
+    
+    /**
+     * Creates a new instance.
+     */
+    protected ContextPartitionConfiguration()
     {
-        return suffix;
     }
 
-
-    public void setSuffix( String suffix )
-    {
-        this.suffix = suffix;
-    }
-
-
-    public String getId()
-    {
-        return id;
-    }
-
-
-    public void setId( String id )
+    public Set getIndexedAttributes()
     {
-        this.id = id;
+        Set result = new HashSet();
+        result.addAll( indexedAttributes );
+        return result;
     }
-
-
-    public String[] getIndices()
+    
+    protected void setIndexedAttributes( Set indexedAttributes )
     {
-        return indices;
-    }
-
+        Set newIndexedAttributes = new HashSet();
 
-    public void setIndices( String[] indices )
-    {
-        this.indices = indices;
+        Iterator i = indexedAttributes.iterator();
+        while( i.hasNext() )
+        {
+            Object e = i.next();
+            if( !(e instanceof String) )
+            {
+                throw new ConfigurationException( "All elements of indexedAttributes must be strings." );
+            }
+            
+            // TODO Attribute name must be normalized and validated
+            String attr = ( ( String ) e ).trim();
+            newIndexedAttributes.add( attr );
+        }
+        this.indexedAttributes = newIndexedAttributes;
     }
-
-
-    public Attributes getAttributes()
+    
+    public ContextPartition getPartition()
     {
-        return attributes;
+        return partition;
     }
-
-
-    public void setAttributes( Attributes attributes )
+    
+    protected void setPartition( ContextPartition partition )
     {
-        this.attributes = attributes;
+        this.partition = partition;
     }
-
-    public String getPartitionClass()
+    
+    public Attributes getRootEntry()
     {
-        return partitionClass;
+        return ( Attributes ) rootEntry.clone();
     }
-
-    public void setPartitionClass( String partitionClass )
+    
+    protected void setRootEntry( Attributes rootEntry )
     {
-        this.partitionClass = partitionClass;
+        this.rootEntry = ( Attributes ) rootEntry.clone();
     }
-
-    public String getProperties()
+    
+    public String getSuffix()
     {
-        return properties;
+        return suffix;
     }
-
-    public void setProperties( String properties )
+    
+    protected void setSuffix( String suffix )
     {
-        this.properties = properties;
+        // TODO Suffix should be normalized before being set
+        this.suffix = suffix.trim();
     }
 }

Added: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java?rev=189923&view=auto
==============================================================================
--- directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java (added)
+++ directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java Fri Jun 10 01:42:32 2005
@@ -0,0 +1,80 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.configuration;
+
+import java.util.Set;
+
+import javax.naming.directory.Attributes;
+
+import org.apache.ldap.server.ContextPartition;
+
+/**
+ * A mutable version of {@link ContextPartitionConfiguration}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Id$
+ */
+public class MutableContextPartitionConfiguration extends
+        ContextPartitionConfiguration
+{
+    /**
+     * Creates a new instance.
+     */
+    public MutableContextPartitionConfiguration()
+    {
+    }
+
+    public void setIndexedAttributes( Set indexedAttributes )
+    {
+        super.setIndexedAttributes( indexedAttributes );
+    }
+
+    public void setPartition( ContextPartition partition )
+    {
+        super.setPartition( partition );
+    }
+
+    public void setRootEntry( Attributes rootEntry )
+    {
+        super.setRootEntry( rootEntry );
+    }
+
+    public void setSuffix( String suffix )
+    {
+        super.setSuffix( suffix );
+    }
+    
+    /**
+     * Validates this configuration.
+     * 
+     * @throws ConfigurationException if this configuration is not valid
+     */
+    public void validate()
+    {
+        if( getSuffix() == null )
+        {
+            throw new ConfigurationException( "Suffix is not specified." );
+        }
+        
+        if( getPartition() == null )
+        {
+            throw new ConfigurationException( "Partition is not specified." );
+        }
+    }
+}

Propchange: directory/apacheds/branches/direve-158/core/src/main/java/org/apache/ldap/server/configuration/MutableContextPartitionConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision