From commits-return-23807-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Dec 04 13:40:21 2009 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 69612 invoked from network); 4 Dec 2009 13:40:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Dec 2009 13:40:21 -0000 Received: (qmail 23387 invoked by uid 500); 4 Dec 2009 13:40:21 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 23345 invoked by uid 500); 4 Dec 2009 13:40:21 -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 23336 invoked by uid 99); 4 Dec 2009 13:40:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Dec 2009 13:40:21 +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; Fri, 04 Dec 2009 13:40:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 77AE02388962; Fri, 4 Dec 2009 13:39:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r887189 - /directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java Date: Fri, 04 Dec 2009 13:39:47 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091204133947.77AE02388962@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Fri Dec 4 13:39:46 2009 New Revision: 887189 URL: http://svn.apache.org/viewvc?rev=887189&view=rev Log: Injected the SchemaManager into the Normalizers Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java?rev=887189&r1=887188&r2=887189&view=diff ============================================================================== --- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java (original) +++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java Fri Dec 4 13:39:46 2009 @@ -72,28 +72,30 @@ */ public class SchemaEntityFactory implements EntityFactory { - /** Slf4j logger */ - private final static Logger LOG = LoggerFactory.getLogger( SchemaEntityFactory.class ); + /** Slf4j logger */ + private final static Logger LOG = LoggerFactory.getLogger( SchemaEntityFactory.class ); + + /** for fast debug checks */ + private static final boolean IS_DEBUG = LOG.isDebugEnabled(); - /** for fast debug checks */ - private static final boolean IS_DEBUG = LOG.isDebugEnabled(); - /** Used for looking up the setRegistries(Registries) method */ - private final static Class[] parameterTypes = new Class[] { Registries.class }; - + private final static Class[] parameterTypes = new Class[] + { Registries.class }; + private static final List EMPTY_LIST = new ArrayList(); - private static final String[] EMPTY_ARRAY = new String[] {}; - + private static final String[] EMPTY_ARRAY = new String[] + {}; + /** A special ClassLoader that loads a class from the bytecode attribute */ private final AttributeClassLoader classLoader; - - + + public SchemaEntityFactory() throws Exception { this.classLoader = new AttributeClassLoader(); } - - + + /** * Get an OID from an entry. Handles the bad cases (null OID, * not a valid OID, ...) @@ -102,29 +104,28 @@ { // The OID EntryAttribute mOid = entry.get( MetaSchemaConstants.M_OID_AT ); - + if ( mOid == null ) { - String msg = objectType + " entry must have a valid " - + MetaSchemaConstants.M_OID_AT + " attribute, it's null"; + String msg = objectType + " entry must have a valid " + MetaSchemaConstants.M_OID_AT + + " attribute, it's null"; LOG.warn( msg ); throw new NullPointerException( msg ); } String oid = mOid.getString(); - + if ( !OID.isOID( oid ) ) { - String msg = "Comparator OID " + oid + " is not a valid OID "; + String msg = "Comparator OID " + oid + " is not a valid OID "; LOG.warn( msg ); - throw new LdapInvalidAttributeValueException( msg, - ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX ); + throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX ); } - + return oid; } - - + + /** * Get an OID from an entry. Handles the bad cases (null OID, * not a valid OID, ...) @@ -133,27 +134,26 @@ { // The OID String oid = description.getOid(); - + if ( oid == null ) { - String msg = objectType + " entry must have a valid " - + MetaSchemaConstants.M_OID_AT + " attribute, it's null"; + String msg = objectType + " entry must have a valid " + MetaSchemaConstants.M_OID_AT + + " attribute, it's null"; LOG.warn( msg ); throw new NullPointerException( msg ); } if ( !OID.isOID( oid ) ) { - String msg = "Comparator OID " + oid + " is not a valid OID "; + String msg = "Comparator OID " + oid + " is not a valid OID "; LOG.warn( msg ); - throw new LdapInvalidAttributeValueException( msg, - ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX ); + throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX ); } - + return oid; } - + /** * Check that the Entry is not null */ @@ -167,7 +167,7 @@ } } - + /** * Check that the Description is not null */ @@ -181,7 +181,7 @@ } } - + /** * Get the schema from its name. Return the Other reference if there * is no schema name. Throws a NPE if the schema is not loaded. @@ -194,17 +194,17 @@ } Schema schema = registries.getLoadedSchema( schemaName ); - + if ( schema == null ) { String msg = "The schema " + schemaName + " does not exists or is not loaded"; LOG.error( msg ); } - + return schema; } - + /** * {@inheritDoc} */ @@ -214,55 +214,55 @@ String owner; String[] dependencies = EMPTY_ARRAY; boolean isDisabled = false; - + if ( entry == null ) { throw new NullPointerException( "entry cannot be null" ); } - + if ( entry.get( SchemaConstants.CN_AT ) == null ) { throw new NullPointerException( "entry must have a valid cn attribute" ); } - + name = entry.get( SchemaConstants.CN_AT ).getString(); - + if ( entry.get( SchemaConstants.CREATORS_NAME_AT ) == null ) { - throw new NullPointerException( "entry must have a valid " - + SchemaConstants.CREATORS_NAME_AT + " attribute" ); + throw new NullPointerException( "entry must have a valid " + SchemaConstants.CREATORS_NAME_AT + + " attribute" ); } - + owner = entry.get( SchemaConstants.CREATORS_NAME_AT ).getString(); - + if ( entry.get( MetaSchemaConstants.M_DISABLED_AT ) != null ) { String value = entry.get( MetaSchemaConstants.M_DISABLED_AT ).getString(); value = value.toUpperCase(); isDisabled = value.equals( "TRUE" ); } - + if ( entry.get( MetaSchemaConstants.M_DEPENDENCIES_AT ) != null ) { Set depsSet = new HashSet(); EntryAttribute depsAttr = entry.get( MetaSchemaConstants.M_DEPENDENCIES_AT ); - - for ( Value value:depsAttr ) + + for ( Value value : depsAttr ) { depsSet.add( value.getString() ); } dependencies = depsSet.toArray( EMPTY_ARRAY ); } - + return new DefaultSchema( name, owner, dependencies, isDisabled ); } - - + + /** * Class load a syntaxChecker instance */ - private SyntaxChecker classLoadSyntaxChecker( SchemaManager schemaManager, String oid, String className, + private SyntaxChecker classLoadSyntaxChecker( SchemaManager schemaManager, String oid, String className, EntryAttribute byteCode, Registries targetRegistries ) throws Exception { // Try to class load the syntaxChecker @@ -280,28 +280,29 @@ clazz = classLoader.loadClass( className ); byteCodeStr = new String( Base64.encode( byteCode.getBytes() ) ); } - + // Create the syntaxChecker instance syntaxChecker = ( SyntaxChecker ) clazz.newInstance(); - + // Update the common fields syntaxChecker.setBytecode( byteCodeStr ); syntaxChecker.setFqcn( className ); - + // Inject the new OID, as the loaded syntaxChecker might have its own syntaxChecker.setOid( oid ); return syntaxChecker; } - - + + /** * {@inheritDoc} */ - public SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName ) throws Exception + public SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws Exception { checkEntry( entry, SchemaConstants.SYNTAX_CHECKER ); - + // The SyntaxChecker OID String oid = getOid( entry, SchemaConstants.SYNTAX_CHECKER ); @@ -309,84 +310,84 @@ if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded. We can't create the requested Normalizer - String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } // The FQCN String className = getFqcn( entry, SchemaConstants.SYNTAX_CHECKER ); - + // The ByteCode EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT ); - + // Class load the syntaxChecker SyntaxChecker syntaxChecker = classLoadSyntaxChecker( schemaManager, oid, className, byteCode, targetRegistries ); - + // Update the common fields setSchemaObjectProperties( syntaxChecker, entry, schema ); - + // return the resulting syntaxChecker return syntaxChecker; } - - + + /** * {@inheritDoc} */ - public SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription, - Registries targetRegistries, String schemaName ) throws Exception + public SyntaxChecker getSyntaxChecker( SchemaManager schemaManager, + SyntaxCheckerDescription syntaxCheckerDescription, Registries targetRegistries, String schemaName ) + throws Exception { checkDescription( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER ); - + // The Comparator OID String oid = getOid( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER ); - + // Get the schema Schema schema = getSchema( schemaName, targetRegistries ); if ( schema == null ) { // The schema is not loaded. We can't create the requested SyntaxChecker - String msg = "Cannot add the SyntaxChecker " + syntaxCheckerDescription.getName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the SyntaxChecker " + syntaxCheckerDescription.getName() + + ", as the associated schema (" + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + // The FQCN String fqcn = getFqcn( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER ); - + // get the byteCode EntryAttribute byteCode = getByteCode( syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER ); - + // Class load the SyntaxChecker - SyntaxChecker syntaxChecker = classLoadSyntaxChecker( schemaManager, oid, - fqcn, byteCode, targetRegistries ); - + SyntaxChecker syntaxChecker = classLoadSyntaxChecker( schemaManager, oid, fqcn, byteCode, targetRegistries ); + // Update the common fields setSchemaObjectProperties( syntaxChecker, syntaxCheckerDescription, schema ); - + return syntaxChecker; } - - + + /** * Class load a comparator instances */ - private LdapComparator classLoadComparator( SchemaManager schemaManager, String oid, String className, + private LdapComparator classLoadComparator( SchemaManager schemaManager, String oid, String className, EntryAttribute byteCode, Registries targetRegistries ) throws Exception { // Try to class load the comparator @@ -394,7 +395,7 @@ Class clazz = null; String byteCodeStr = StringTools.EMPTY; - if ( byteCode == null ) + if ( byteCode == null ) { clazz = Class.forName( className ); } @@ -404,136 +405,134 @@ clazz = classLoader.loadClass( className ); byteCodeStr = new String( Base64.encode( byteCode.getBytes() ) ); } - + // Create the comparator instance. Either we have a no argument constructor, // or we have one which takes an OID. Lets try the one with an OID argument first try { - Constructor constructor = clazz.getConstructor( new Class[]{String.class} ); - comparator = ( LdapComparator )constructor.newInstance( new Object[]{ oid } ); + Constructor constructor = clazz.getConstructor( new Class[] + { String.class } ); + comparator = ( LdapComparator ) constructor.newInstance( new Object[] + { oid } ); } catch ( NoSuchMethodException nsme ) { // Ok, let's try with the constructor without argument Constructor constructor = clazz.getConstructor(); - comparator = ( LdapComparator )clazz.newInstance(); + comparator = ( LdapComparator ) clazz.newInstance(); } // Update the loadable fields comparator.setBytecode( byteCodeStr ); comparator.setFqcn( className ); - - // Inject the SchemaManager for the comparator who need it + + // Inject the SchemaManager for the comparator who needs it comparator.setSchemaManager( schemaManager ); - - // Inject the new OID, as the loaded comparator might have its own - //comparator.setOid( oid ); - + return comparator; } - - + + /** * {@inheritDoc} */ - public LdapComparator getLdapComparator( SchemaManager schemaManager, - LdapComparatorDescription comparatorDescription, - Registries targetRegistries, String schemaName ) throws Exception + public LdapComparator getLdapComparator( SchemaManager schemaManager, + LdapComparatorDescription comparatorDescription, Registries targetRegistries, String schemaName ) + throws Exception { checkDescription( comparatorDescription, SchemaConstants.COMPARATOR ); - + // The Comparator OID String oid = getOid( comparatorDescription, SchemaConstants.COMPARATOR ); - + // Get the schema Schema schema = getSchema( schemaName, targetRegistries ); if ( schema == null ) { // The schema is not loaded. We can't create the requested Comparator - String msg = "Cannot add the Comparator " + comparatorDescription.getName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the Comparator " + comparatorDescription.getName() + + ", as the associated schema (" + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } // The FQCN String fqcn = getFqcn( comparatorDescription, SchemaConstants.COMPARATOR ); - + // get the byteCode EntryAttribute byteCode = getByteCode( comparatorDescription, SchemaConstants.COMPARATOR ); - + // Class load the comparator - LdapComparator comparator = classLoadComparator( schemaManager, oid, - fqcn, byteCode, targetRegistries ); - + LdapComparator comparator = classLoadComparator( schemaManager, oid, fqcn, byteCode, targetRegistries ); + // Update the common fields setSchemaObjectProperties( comparator, comparatorDescription, schema ); - + return comparator; } - - + + /** * {@inheritDoc} */ - public LdapComparator getLdapComparator( SchemaManager schemaManager, - Entry entry, Registries targetRegistries, String schemaName ) throws Exception + public LdapComparator getLdapComparator( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws Exception { checkEntry( entry, SchemaConstants.COMPARATOR ); - + // The Comparator OID String oid = getOid( entry, SchemaConstants.COMPARATOR ); - + // Get the schema if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded. We can't create the requested Comparator - String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); - + if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } // The FQCN String fqcn = getFqcn( entry, SchemaConstants.COMPARATOR ); - + // The ByteCode EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT ); - + // Class load the comparator LdapComparator comparator = classLoadComparator( schemaManager, oid, fqcn, byteCode, targetRegistries ); - + // Update the common fields setSchemaObjectProperties( comparator, entry, schema ); - + // return the resulting comparator return comparator; } - - + + /** * Class load a normalizer instances */ - private Normalizer classLoadNormalizer( SchemaManager schemaManager, String oid, String className, + private Normalizer classLoadNormalizer( SchemaManager schemaManager, String oid, String className, EntryAttribute byteCode, Registries targetRegistries ) throws Exception { // Try to class load the normalizer Class clazz = null; Normalizer normalizer = null; String byteCodeStr = StringTools.EMPTY; - + if ( byteCode == null ) { clazz = Class.forName( className ); @@ -551,62 +550,64 @@ // Update the common fields normalizer.setBytecode( byteCodeStr ); normalizer.setFqcn( className ); - + // Inject the new OID, as the loaded normalizer might have its own normalizer.setOid( oid ); - + + // Inject the SchemaManager for the normalizer who needs it + normalizer.setSchemaManager( schemaManager ); + return normalizer; } - + /** * {@inheritDoc} */ - public Normalizer getNormalizer( SchemaManager schemaManager, - NormalizerDescription normalizerDescription, + public Normalizer getNormalizer( SchemaManager schemaManager, NormalizerDescription normalizerDescription, Registries targetRegistries, String schemaName ) throws Exception { checkDescription( normalizerDescription, SchemaConstants.NORMALIZER ); - + // The Comparator OID String oid = getOid( normalizerDescription, SchemaConstants.NORMALIZER ); - + // Get the schema Schema schema = getSchema( schemaName, targetRegistries ); if ( schema == null ) { // The schema is not loaded. We can't create the requested Normalizer - String msg = "Cannot add the Normalizer " + normalizerDescription.getName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the Normalizer " + normalizerDescription.getName() + + ", as the associated schema (" + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + // The FQCN String fqcn = getFqcn( normalizerDescription, SchemaConstants.NORMALIZER ); - + // get the byteCode EntryAttribute byteCode = getByteCode( normalizerDescription, SchemaConstants.NORMALIZER ); // Class load the normalizer Normalizer normalizer = classLoadNormalizer( schemaManager, oid, fqcn, byteCode, targetRegistries ); - + // Update the common fields setSchemaObjectProperties( normalizer, normalizerDescription, schema ); - + return normalizer; } - - + + /** * {@inheritDoc} */ - public Normalizer getNormalizer( SchemaManager schemaManager, Entry entry, - Registries targetRegistries, String schemaName ) throws Exception + public Normalizer getNormalizer( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws Exception { checkEntry( entry, SchemaConstants.NORMALIZER ); - + // The Normalizer OID String oid = getOid( entry, SchemaConstants.NORMALIZER ); @@ -614,40 +615,40 @@ if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded. We can't create the requested Normalizer - String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the Normalizer " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } - + // The FQCN String className = getFqcn( entry, SchemaConstants.NORMALIZER ); - + // The ByteCode EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT ); - + // Class load the Normalizer Normalizer normalizer = classLoadNormalizer( schemaManager, oid, className, byteCode, targetRegistries ); - + // Update the common fields setSchemaObjectProperties( normalizer, entry, schema ); - + // return the resulting Normalizer return normalizer; } - - + + /** * Uses reflection to see if a setRegistries( Registries ) method exists on the * object's class. If so then the registries are dependency injected into the @@ -658,27 +659,28 @@ private void injectRegistries( Object obj, Registries targetRegistries ) throws Exception { Method method = null; - + try { - method = obj.getClass().getMethod( "setRegistries", parameterTypes ); + method = obj.getClass().getMethod( "setRegistries", parameterTypes ); } catch ( NoSuchMethodException e ) { - if ( IS_DEBUG ) - { - LOG.debug( obj.getClass() + " has no setRegistries() method." ); - } - - return; + if ( IS_DEBUG ) + { + LOG.debug( obj.getClass() + " has no setRegistries() method." ); + } + + return; } - + if ( method == null ) { return; } - - Object[] args = new Object[] { targetRegistries }; + + Object[] args = new Object[] + { targetRegistries }; method.invoke( obj, args ); } @@ -686,7 +688,8 @@ /** * {@inheritDoc} */ - public LdapSyntax getSyntax( SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName ) throws NamingException + public LdapSyntax getSyntax( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws NamingException { checkEntry( entry, SchemaConstants.SYNTAX ); @@ -697,29 +700,29 @@ if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded. We can't create the requested Syntax - String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the SyntaxChecker " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } // Create the new LdapSyntax instance LdapSyntax syntax = new LdapSyntax( oid ); - + // The isHumanReadable field EntryAttribute mHumanReadable = entry.get( MetaSchemaConstants.X_HUMAN_READABLE_AT ); - + if ( mHumanReadable != null ) { String val = mHumanReadable.getString(); @@ -728,16 +731,16 @@ // Common properties setSchemaObjectProperties( syntax, entry, schema ); - + return syntax; } - + /** * {@inheritDoc} */ - public MatchingRule getMatchingRule( SchemaManager schemaManager, Entry entry, - Registries targetRegistries, String schemaName ) throws NamingException + public MatchingRule getMatchingRule( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws NamingException { checkEntry( entry, SchemaConstants.MATCHING_RULE ); @@ -748,19 +751,19 @@ if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded. We can't create the requested MatchingRule - String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); - + if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the MatchingRule " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } @@ -769,7 +772,7 @@ // The syntax field EntryAttribute mSyntax = entry.get( MetaSchemaConstants.M_SYNTAX_AT ); - + if ( mSyntax != null ) { matchingRule.setSyntaxOid( mSyntax.getString() ); @@ -780,11 +783,11 @@ // Common properties setSchemaObjectProperties( matchingRule, entry, schema ); - + return matchingRule; } - - + + /** * Create a list of string from a multivalued attribute's values */ @@ -794,23 +797,23 @@ { return EMPTY_LIST; } - + List strings = new ArrayList( attr.size() ); - - for ( Value value:attr ) + + for ( Value value : attr ) { strings.add( value.getString() ); } - + return strings; } - - + + /** * {@inheritDoc} */ - public ObjectClass getObjectClass( SchemaManager schemaManager, Entry entry, - Registries targetRegistries, String schemaName ) throws Exception + public ObjectClass getObjectClass( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws Exception { checkEntry( entry, SchemaConstants.OBJECT_CLASS ); @@ -821,74 +824,74 @@ if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded. We can't create the requested ObjectClass - String msg = "Cannot add the ObjectClass " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the ObjectClass " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); - + if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the ObjectClass " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the ObjectClass " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } // Create the ObjectClass instance ObjectClass oc = new ObjectClass( oid ); - + // The Sup field EntryAttribute mSuperiors = entry.get( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT ); - + if ( mSuperiors != null ) { oc.setSuperiorOids( getStrings( mSuperiors ) ); } - + // The May field EntryAttribute mMay = entry.get( MetaSchemaConstants.M_MAY_AT ); - + if ( mMay != null ) { oc.setMayAttributeTypeOids( getStrings( mMay ) ); } - + // The Must field EntryAttribute mMust = entry.get( MetaSchemaConstants.M_MUST_AT ); - + if ( mMust != null ) { oc.setMustAttributeTypeOids( getStrings( mMust ) ); } - + // The objectClassType field EntryAttribute mTypeObjectClass = entry.get( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT ); - + if ( mTypeObjectClass != null ) { String type = mTypeObjectClass.getString(); oc.setType( ObjectClassTypeEnum.getClassType( type ) ); } - + // Common properties setSchemaObjectProperties( oc, entry, schema ); - + return oc; } - - + + /** * {@inheritDoc} */ - public AttributeType getAttributeType( SchemaManager schemaManager, Entry entry, - Registries targetRegistries, String schemaName ) throws NamingException + public AttributeType getAttributeType( SchemaManager schemaManager, Entry entry, Registries targetRegistries, + String schemaName ) throws NamingException { checkEntry( entry, SchemaConstants.ATTRIBUTE_TYPE ); - + // The AttributeType OID String oid = getOid( entry, SchemaConstants.ATTRIBUTE_TYPE ); @@ -896,117 +899,116 @@ if ( !schemaManager.isSchemaLoaded( schemaName ) ) { // The schema is not loaded, this is an error - String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + ", as the associated schema (" + - schemaName + " is not loaded"; + String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + ", as the associated schema (" + + schemaName + " is not loaded"; LOG.warn( msg ); throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM ); } - + Schema schema = getSchema( schemaName, targetRegistries ); - + if ( schema == null ) { // The schema is disabled. We still have to update the backend - String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + " into the registries, "+ - "as the associated schema (" + schemaName + ") is disabled"; + String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + " into the registries, " + + "as the associated schema (" + schemaName + ") is disabled"; LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName ); } // Create the new AttributeType AttributeType attributeType = new AttributeType( oid ); - + // Syntax EntryAttribute mSyntax = entry.get( MetaSchemaConstants.M_SYNTAX_AT ); - + if ( mSyntax != null ) { attributeType.setSyntaxOid( mSyntax.getString() ); } - + // Syntax Length EntryAttribute mSyntaxLength = entry.get( MetaSchemaConstants.M_LENGTH_AT ); - + if ( mSyntaxLength != null ) { attributeType.setSyntaxLength( Integer.parseInt( mSyntaxLength.getString() ) ); } - // Equality EntryAttribute mEquality = entry.get( MetaSchemaConstants.M_EQUALITY_AT ); - + if ( mEquality != null ) { - attributeType.setEqualityOid( mEquality.getString() ); + attributeType.setEqualityOid( mEquality.getString() ); } - + // Ordering - EntryAttribute mOrdering = entry.get( MetaSchemaConstants.M_ORDERING_AT ); - + EntryAttribute mOrdering = entry.get( MetaSchemaConstants.M_ORDERING_AT ); + if ( mOrdering != null ) { attributeType.setOrderingOid( mOrdering.getString() ); } - + // Substr EntryAttribute mSubstr = entry.get( MetaSchemaConstants.M_SUBSTR_AT ); - + if ( mSubstr != null ) { attributeType.setSubstringOid( mSubstr.getString() ); } - + EntryAttribute mSupAttributeType = entry.get( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT ); - + // Sup if ( mSupAttributeType != null ) { - attributeType.setSuperiorOid( mSupAttributeType.getString() ); + attributeType.setSuperiorOid( mSupAttributeType.getString() ); } - + // isCollective EntryAttribute mCollective = entry.get( MetaSchemaConstants.M_COLLECTIVE_AT ); - + if ( mCollective != null ) { String val = mCollective.getString(); attributeType.setCollective( val.equalsIgnoreCase( "TRUE" ) ); } - + // isSingleValued EntryAttribute mSingleValued = entry.get( MetaSchemaConstants.M_SINGLE_VALUE_AT ); - + if ( mSingleValued != null ) { String val = mSingleValued.getString(); attributeType.setSingleValued( val.equalsIgnoreCase( "TRUE" ) ); } - + // isReadOnly EntryAttribute mNoUserModification = entry.get( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT ); - + if ( mNoUserModification != null ) { String val = mNoUserModification.getString(); - attributeType.setUserModifiable( ! val.equalsIgnoreCase( "TRUE" ) ); + attributeType.setUserModifiable( !val.equalsIgnoreCase( "TRUE" ) ); } - + // Usage EntryAttribute mUsage = entry.get( MetaSchemaConstants.M_USAGE_AT ); - + if ( mUsage != null ) { attributeType.setUsage( UsageEnum.getUsage( mUsage.getString() ) ); } - + // Common properties setSchemaObjectProperties( attributeType, entry, schema ); - + return attributeType; } - - + + /** * Process the FQCN attribute */ @@ -1014,19 +1016,18 @@ { // The FQCN EntryAttribute mFqcn = entry.get( MetaSchemaConstants.M_FQCN_AT ); - + if ( mFqcn == null ) { - String msg = objectType + " entry must have a valid " - + MetaSchemaConstants.M_FQCN_AT + " attribute"; + String msg = objectType + " entry must have a valid " + MetaSchemaConstants.M_FQCN_AT + " attribute"; LOG.warn( msg ); throw new NullPointerException( msg ); } - + return mFqcn.getString(); } - - + + /** * Process the FQCN attribute */ @@ -1034,37 +1035,35 @@ { // The FQCN String mFqcn = description.getFqcn(); - + if ( mFqcn == null ) { - String msg = objectType + " entry must have a valid " - + MetaSchemaConstants.M_FQCN_AT + " attribute"; + String msg = objectType + " entry must have a valid " + MetaSchemaConstants.M_FQCN_AT + " attribute"; LOG.warn( msg ); throw new NullPointerException( msg ); } - + return mFqcn; } - - + + /** * Process the ByteCode attribute */ private EntryAttribute getByteCode( Entry entry, String objectType ) throws NamingException { EntryAttribute byteCode = entry.get( MetaSchemaConstants.M_BYTECODE_AT ); - + if ( byteCode == null ) { - String msg = objectType + " entry must have a valid " - + MetaSchemaConstants.M_BYTECODE_AT + " attribute"; + String msg = objectType + " entry must have a valid " + MetaSchemaConstants.M_BYTECODE_AT + " attribute"; LOG.warn( msg ); throw new NullPointerException( msg ); } - + return byteCode; } - + /** * Process the ByteCode attribute @@ -1072,21 +1071,20 @@ private EntryAttribute getByteCode( LoadableSchemaObject description, String objectType ) throws NamingException { String byteCodeString = description.getBytecode(); - + if ( byteCodeString == null ) { - String msg = objectType + " entry must have a valid " - + MetaSchemaConstants.M_BYTECODE_AT + " attribute"; + String msg = objectType + " entry must have a valid " + MetaSchemaConstants.M_BYTECODE_AT + " attribute"; LOG.warn( msg ); throw new NullPointerException( msg ); } byte[] bytecode = Base64.decode( byteCodeString.toCharArray() ); EntryAttribute attr = new DefaultClientAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode ); - + return attr; } - + /** * Process the common attributes to all SchemaObjects : @@ -1099,55 +1097,56 @@ * - isReadOnly * - isEnabled */ - private void setSchemaObjectProperties( SchemaObject schemaObject, Entry entry, Schema schema ) throws NamingException + private void setSchemaObjectProperties( SchemaObject schemaObject, Entry entry, Schema schema ) + throws NamingException { // The isObsolete field EntryAttribute mObsolete = entry.get( MetaSchemaConstants.M_OBSOLETE_AT ); - + if ( mObsolete != null ) { String val = mObsolete.getString(); schemaObject.setObsolete( val.equalsIgnoreCase( "TRUE" ) ); } - + // The description field EntryAttribute mDescription = entry.get( MetaSchemaConstants.M_DESCRIPTION_AT ); - + if ( mDescription != null ) { - schemaObject.setDescription( mDescription.getString() ); + schemaObject.setDescription( mDescription.getString() ); } // The names field EntryAttribute names = entry.get( MetaSchemaConstants.M_NAME_AT ); - + if ( names != null ) { List values = new ArrayList(); - - for ( Value name:names ) + + for ( Value name : names ) { values.add( name.getString() ); } - + schemaObject.setNames( values ); } - + // The isEnabled field EntryAttribute mDisabled = entry.get( MetaSchemaConstants.M_DISABLED_AT ); - + // If the SchemaObject has an explicit m-disabled attribute, then use it. // Otherwise, inherit it from the schema if ( mDisabled != null ) { String val = mDisabled.getString(); - schemaObject.setEnabled( ! val.equalsIgnoreCase( "TRUE" ) ); + schemaObject.setEnabled( !val.equalsIgnoreCase( "TRUE" ) ); } else { schemaObject.setEnabled( schema != null && schema.isEnabled() ); } - + // The isReadOnly field EntryAttribute mIsReadOnly = entry.get( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT ); @@ -1156,7 +1155,7 @@ String val = mIsReadOnly.getString(); schemaObject.setReadOnly( val.equalsIgnoreCase( "TRUE" ) ); } - + // The specification field /* * TODO : create the M_SPECIFICATION_AT @@ -1167,10 +1166,10 @@ so.setSpecification( mSpecification.getString() ); } */ - + // The schemaName field schemaObject.setSchemaName( schema.getSchemaName() ); - + // The extensions field /* * TODO create the M_EXTENSION_AT AT @@ -1202,21 +1201,22 @@ * - isReadOnly * - isEnabled */ - private void setSchemaObjectProperties( SchemaObject schemaObject, SchemaObject description, Schema schema ) throws NamingException + private void setSchemaObjectProperties( SchemaObject schemaObject, SchemaObject description, Schema schema ) + throws NamingException { // The isObsolete field schemaObject.setObsolete( description.isObsolete() ); - + // The description field schemaObject.setDescription( description.getDescription() ); // The names field schemaObject.setNames( description.getNames() ); - + // The isEnabled field. Has the description does not hold a // Disable field, we will inherit from the schema enable field schemaObject.setEnabled( schema.isEnabled() ); - + // The isReadOnly field. We don't have this data in the description, // so set it to false // TODO : should it be a X-READONLY extension ? @@ -1224,10 +1224,10 @@ // The specification field schemaObject.setSpecification( description.getSpecification() ); - + // The schemaName field schemaObject.setSchemaName( schema.getSchemaName() ); - + // The extensions field schemaObject.setExtensions( description.getExtensions() ); }