You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/10/11 13:14:00 UTC
svn commit: r1021303 - in
/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config:
ConfigPartitionReader.java beans/InterceptorBean.java
Author: elecharny
Date: Mon Oct 11 11:14:00 2010
New Revision: 1021303
URL: http://svn.apache.org/viewvc?rev=1021303&view=rev
Log:
Added the Interceptor Bean and the code to read it from the DIT
Added:
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/InterceptorBean.java
Modified:
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java?rev=1021303&r1=1021302&r2=1021303&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java Mon Oct 11 11:14:00 2010
@@ -59,6 +59,7 @@ import javax.naming.directory.SearchCont
import org.apache.directory.server.changepw.ChangePasswordServer;
import org.apache.directory.server.config.beans.ChangeLogBean;
import org.apache.directory.server.config.beans.DnsServerBean;
+import org.apache.directory.server.config.beans.InterceptorBean;
import org.apache.directory.server.config.beans.JdbmIndexBean;
import org.apache.directory.server.config.beans.JdbmPartitionBean;
import org.apache.directory.server.config.beans.JournalBean;
@@ -1164,10 +1165,10 @@ public class ConfigPartitionReader
* reads the Interceptor configuration and instantiates them in the order specified
*
* @param dirServiceDN the DN under which interceptors are configured
- * @return a list of instantiated Interceptor objects
- * @throws Exception
+ * @return a list of InterceptorBean objects
+ * @throws Exception If the configuraton cannot be read
*/
- private List<Interceptor> createInterceptors( DN dirServiceDN ) throws Exception
+ private Set<InterceptorBean> readInterceptors( DN dirServiceDN ) throws Exception
{
AttributeType adsInterceptorIdAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_INTERCEPTOR_ID );
PresenceNode filter = new PresenceNode( adsInterceptorIdAt );
@@ -1176,7 +1177,7 @@ public class ConfigPartitionReader
IndexCursor<Long, Entry, Long> cursor = se.cursor( dirServiceDN, AliasDerefMode.NEVER_DEREF_ALIASES,
filter, controls );
- Set<InterceptorConfig> set = new TreeSet<InterceptorConfig>();
+ Set<InterceptorBean> interceptorBeans = new TreeSet<InterceptorBean>();
while ( cursor.next() )
{
@@ -1193,20 +1194,40 @@ public class ConfigPartitionReader
String fqcn = getString( ConfigSchemaConstants.ADS_INTERCEPTOR_CLASSNAME, interceptorEntry );
int order = getInt( ConfigSchemaConstants.ADS_INTERCEPTOR_ORDER, interceptorEntry );
- InterceptorConfig intConfig = new InterceptorConfig( id, fqcn, order );
- set.add( intConfig );
+ InterceptorBean interceptorBean = new InterceptorBean();
+
+ interceptorBean.setId( id );
+ interceptorBean.setFqcn( fqcn );
+ interceptorBean.setOrder( order );
+
+ interceptorBeans.add( interceptorBean );
}
cursor.close();
+
+ return interceptorBeans;
+ }
- List<Interceptor> interceptors = new ArrayList<Interceptor>();
- for ( InterceptorConfig iconfig : set )
+ /**
+ * Creates the Interceptor instances from the configuration
+ *
+ * @param dirServiceDN the DN under which interceptors are configured
+ * @return a list of instantiated Interceptor objects
+ * @throws Exception If the instanciation failed
+ */
+ private List<Interceptor> createInterceptors( DN dirServiceDN ) throws Exception
+ {
+ Set<InterceptorBean> interceptorBeans = readInterceptors( dirServiceDN );
+
+ List<Interceptor> interceptors = new ArrayList<Interceptor>( interceptorBeans.size() );
+
+ for ( InterceptorBean interceptorBean : interceptorBeans )
{
try
{
- LOG.debug( "loading the interceptor class {} and instantiating", iconfig.getFqcn() );
- Interceptor ic = ( Interceptor ) Class.forName( iconfig.getFqcn() ).newInstance();
+ LOG.debug( "loading the interceptor class {} and instantiating", interceptorBean.getFqcn() );
+ Interceptor ic = ( Interceptor ) Class.forName( interceptorBean.getFqcn() ).newInstance();
interceptors.add( ic );
}
catch ( Exception e )
@@ -1214,11 +1235,11 @@ public class ConfigPartitionReader
throw e;
}
}
-
+
return interceptors;
}
-
-
+
+
private Map<String, Partition> createPartitions( DN dirServiceDN ) throws Exception
{
AttributeType adsPartitionIdeAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_PARTITION_ID );
@@ -1989,55 +2010,6 @@ public class ConfigPartitionReader
return policyConfig;
}
-
-
- /**
- * internal class used for holding the Interceptor classname and order configuration
- */
- private class InterceptorConfig implements Comparable<InterceptorConfig>
- {
- private String id;
- private String fqcn;
- private int order;
-
-
- public InterceptorConfig( String id, String fqcn, int order )
- {
- if ( order < 1 )
- {
- throw new IllegalArgumentException( I18n.err( I18n.ERR_507 ) );
- }
-
- this.id = id;
- this.fqcn = fqcn;
- this.order = order;
- }
-
-
- public int compareTo( InterceptorConfig o )
- {
- if ( order > o.order )
- {
- return 1;
- }
- else if ( order < o.order )
- {
- return -1;
- }
-
- return 0;
- }
-
-
- /**
- * @return the fqcn
- */
- public String getFqcn()
- {
- return fqcn;
- }
-
- }
private String getString( String attrName, Entry entry ) throws Exception
Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/InterceptorBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/InterceptorBean.java?rev=1021303&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/InterceptorBean.java (added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/InterceptorBean.java Mon Oct 11 11:14:00 2010
@@ -0,0 +1,121 @@
+/*
+ * 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.server.config.beans;
+
+
+/**
+ * A class used to store the Interceptors configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class InterceptorBean implements Comparable<InterceptorBean>
+{
+ /** The Interceptor ID */
+ private String id;
+
+ /** The interceptor FQCN */
+ private String fqcn;
+
+ /** The interceptor position in the chain */
+ private int order;
+
+
+ /**
+ * Creates a new InterceptorBean
+ */
+ public InterceptorBean()
+ {
+ }
+
+
+ /**
+ * Compares the order of the interceptor with the given one
+ * @param o An interceptor
+ * @return -1 if the current interceptor is below the given one, 1 if
+ * it's above, 0 if it's equal
+ */
+ public int compareTo( InterceptorBean o )
+ {
+ if ( order > o.order )
+ {
+ return 1;
+ }
+ else if ( order < o.order )
+ {
+ return -1;
+ }
+
+ return 0;
+ }
+
+
+ /**
+ * @return the id
+ */
+ public String getId()
+ {
+ return id;
+ }
+
+
+ /**
+ * @param id the id to set
+ */
+ public void setId( String id )
+ {
+ this.id = id;
+ }
+
+
+ /**
+ * @return the order
+ */
+ public int getOrder()
+ {
+ return order;
+ }
+
+
+ /**
+ * @param order the order to set
+ */
+ public void setOrder( int order )
+ {
+ this.order = order;
+ }
+
+
+ /**
+ * @return the fqcn
+ */
+ public String getFqcn()
+ {
+ return fqcn;
+ }
+
+
+ /**
+ * @param fqcn the fqcn to set
+ */
+ public void setFqcn( String fqcn )
+ {
+ this.fqcn = fqcn;
+ }
+}