Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 44360 invoked from network); 11 Oct 2010 11:14:34 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Oct 2010 11:14:34 -0000 Received: (qmail 75307 invoked by uid 500); 11 Oct 2010 11:14:34 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 75242 invoked by uid 500); 11 Oct 2010 11:14:32 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 75234 invoked by uid 99); 11 Oct 2010 11:14:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Oct 2010 11:14:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Oct 2010 11:14:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 01C6F2388A41; Mon, 11 Oct 2010 11:14:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1021303 - in /directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config: ConfigPartitionReader.java beans/InterceptorBean.java Date: Mon, 11 Oct 2010 11:14:00 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101011111401.01C6F2388A41@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 createInterceptors( DN dirServiceDN ) throws Exception + private Set 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 cursor = se.cursor( dirServiceDN, AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls ); - Set set = new TreeSet(); + Set interceptorBeans = new TreeSet(); 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 interceptors = new ArrayList(); - 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 createInterceptors( DN dirServiceDN ) throws Exception + { + Set interceptorBeans = readInterceptors( dirServiceDN ); + + List interceptors = new ArrayList( 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 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 - { - 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 Apache Directory Project + */ +public class InterceptorBean implements Comparable +{ + /** 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; + } +}