directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r949506 - in /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core: collective/ operational/ schema/ subtree/
Date Sun, 30 May 2010 12:04:20 GMT
Author: elecharny
Date: Sun May 30 12:04:20 2010
New Revision: 949506

URL: http://svn.apache.org/viewvc?rev=949506&view=rev
Log:
o Removing some more useless lookups
o Small improvements 
o Added some missing Javadoc, minor code refactoring

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java?rev=949506&r1=949505&r2=949506&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java Sun May 30 12:04:20 2010
@@ -23,6 +23,8 @@ package org.apache.directory.server.core
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.filtering.EntryFilter;
@@ -40,8 +42,8 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.partition.PartitionNexus;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
@@ -64,33 +66,32 @@ public class CollectiveAttributeIntercep
 {
     /** The SchemaManager */
     private SchemaManager schemaManager;
-    
+
     private PartitionNexus nexus;
-    
-    private CollectiveAttributesSchemaChecker collectiveAttributesSchemaChecker;
 
+    private CollectiveAttributesSchemaChecker collectiveAttributesSchemaChecker;
 
     /**
      * the search result filter to use for collective attribute injection
      */
     private final EntryFilter SEARCH_FILTER = new EntryFilter()
     {
-        public boolean accept( SearchingOperationContext operation, ClonedServerEntry result )
-            throws Exception
+        public boolean accept( SearchingOperationContext operation, ClonedServerEntry result ) throws Exception
         {
             DN name = result.getDn();
-            
+
             if ( name.isNormalized() == false )
             {
                 name = DN.normalize( name, schemaManager.getNormalizerMapping() );
             }
-            
+
             String[] retAttrs = operation.getSearchControls().getReturningAttributes();
             addCollectiveAttributes( operation, result, retAttrs );
             return true;
         }
     };
 
+
     public void init( DirectoryService directoryService ) throws Exception
     {
         super.init( directoryService );
@@ -112,12 +113,11 @@ public class CollectiveAttributeIntercep
      * @param retAttrs array or attribute type to be specifically included in the result entry(s)
      * @throws NamingException if there are problems accessing subentries
      */
-    private void addCollectiveAttributes( OperationContext opContext, Entry entry, 
-        String[] retAttrs ) throws Exception
+    private void addCollectiveAttributes( OperationContext opContext, Entry entry, String[] retAttrs ) throws Exception
     {
-        EntryAttribute collectiveAttributeSubentries = 
-            ((ClonedServerEntry)entry).getOriginalEntry().get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
-        
+        EntryAttribute collectiveAttributeSubentries = ( ( ClonedServerEntry ) entry ).getOriginalEntry().get(
+            SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
+
         /*
          * If there are no collective attribute subentries referenced then we 
          * have no collective attributes to inject to this entry.
@@ -126,22 +126,21 @@ public class CollectiveAttributeIntercep
         {
             return;
         }
-    
+
         /*
          * Before we proceed we need to lookup the exclusions within the entry 
          * and build a set of exclusions for rapid lookup.  We use OID values 
          * in the exclusions set instead of regular names that may have case 
          * variance.
          */
-        EntryAttribute collectiveExclusions = 
-            ((ClonedServerEntry)entry).getOriginalEntry().get( SchemaConstants.COLLECTIVE_EXCLUSIONS_AT );
+        EntryAttribute collectiveExclusions = ( ( ClonedServerEntry ) entry ).getOriginalEntry().get(
+            SchemaConstants.COLLECTIVE_EXCLUSIONS_AT );
         Set<String> exclusions = new HashSet<String>();
-        
+
         if ( collectiveExclusions != null )
         {
             if ( collectiveExclusions.contains( SchemaConstants.EXCLUDE_ALL_COLLECTIVE_ATTRIBUTES_AT_OID )
-                 || 
-                 collectiveExclusions.contains( SchemaConstants.EXCLUDE_ALL_COLLECTIVE_ATTRIBUTES_AT  ) )
+                || collectiveExclusions.contains( SchemaConstants.EXCLUDE_ALL_COLLECTIVE_ATTRIBUTES_AT ) )
             {
                 /*
                  * This entry does not allow any collective attributes
@@ -151,14 +150,14 @@ public class CollectiveAttributeIntercep
             }
 
             exclusions = new HashSet<String>();
-            
-            for ( Value<?> value:collectiveExclusions )
+
+            for ( Value<?> value : collectiveExclusions )
             {
                 AttributeType attrType = schemaManager.lookupAttributeTypeRegistry( value.getString() );
                 exclusions.add( attrType.getOid() );
             }
         }
-        
+
         /*
          * If no attributes are requested specifically
          * then it means all user attributes are requested.
@@ -168,16 +167,16 @@ public class CollectiveAttributeIntercep
         {
             retAttrs = SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY;
         }
-        
+
         /*
          * Construct a set of requested attributes for easier tracking.
-         */ 
+         */
         Set<String> retIdsSet = new HashSet<String>( retAttrs.length );
-        
-        for ( String retAttr:retAttrs )
+
+        for ( String retAttr : retAttrs )
         {
-            if ( retAttr.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) ||
-                retAttr.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
+            if ( retAttr.equals( SchemaConstants.ALL_USER_ATTRIBUTES )
+                || retAttr.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
             {
                 retIdsSet.add( retAttr );
             }
@@ -192,29 +191,29 @@ public class CollectiveAttributeIntercep
          * attributes of the subentry and copy collective attributes from the
          * subentry into the entry.
          */
-        for ( Value<?> value:collectiveAttributeSubentries )
+        for ( Value<?> value : collectiveAttributeSubentries )
         {
             String subentryDnStr = value.getString();
             DN subentryDn = new DN( subentryDnStr );
-            
+
             /*
              * TODO - Instead of hitting disk here can't we leverage the 
              * SubentryService to get us cached sub-entries so we're not
              * wasting time with a lookup here? It is ridiculous to waste
              * time looking up this sub-entry. 
              */
-            
+
             Entry subentry = opContext.lookup( subentryDn, ByPassConstants.LOOKUP_COLLECTIVE_BYPASS );
-            
-            for ( AttributeType attributeType:subentry.getAttributeTypes() )
+
+            for ( AttributeType attributeType : subentry.getAttributeTypes() )
             {
                 String attrId = attributeType.getName();
-                
+
                 if ( !attributeType.isCollective() )
                 {
                     continue;
                 }
-                
+
                 /*
                  * Skip the addition of this collective attribute if it is excluded
                  * in the 'collectiveAttributes' attribute.
@@ -223,12 +222,13 @@ public class CollectiveAttributeIntercep
                 {
                     continue;
                 }
-                
+
                 Set<AttributeType> allSuperTypes = getAllSuperTypes( attributeType );
 
                 for ( String retId : retIdsSet )
                 {
-                    if ( retId.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) || retId.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
+                    if ( retId.equals( SchemaConstants.ALL_USER_ATTRIBUTES )
+                        || retId.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
                     {
                         continue;
                     }
@@ -246,12 +246,12 @@ public class CollectiveAttributeIntercep
                  * If not all attributes or this collective attribute requested specifically
                  * then bypass the inclusion process.
                  */
-                if ( !( retIdsSet.contains( SchemaConstants.ALL_USER_ATTRIBUTES ) || 
-                    retIdsSet.contains( schemaManager.lookupAttributeTypeRegistry( attrId ).getOid() ) ) )
+                if ( !( retIdsSet.contains( SchemaConstants.ALL_USER_ATTRIBUTES ) || retIdsSet.contains( schemaManager
+                    .lookupAttributeTypeRegistry( attrId ).getOid() ) ) )
                 {
                     continue;
                 }
-                
+
                 EntryAttribute subentryColAttr = subentry.get( attrId );
                 EntryAttribute entryColAttr = entry.get( attrId );
 
@@ -260,7 +260,8 @@ public class CollectiveAttributeIntercep
                  */
                 if ( entryColAttr == null )
                 {
-                    entryColAttr = new DefaultEntryAttribute( attrId, schemaManager.lookupAttributeTypeRegistry( attrId ) );
+                    entryColAttr = new DefaultEntryAttribute( attrId, schemaManager
+                        .lookupAttributeTypeRegistry( attrId ) );
                     entry.put( entryColAttr );
                 }
 
@@ -268,30 +269,30 @@ public class CollectiveAttributeIntercep
                  *  Add all the collective attribute values in the subentry
                  *  to the currently processed collective attribute in the entry.
                  */
-                for ( Value<?> subentryColVal:subentryColAttr )
+                for ( Value<?> subentryColVal : subentryColAttr )
                 {
                     entryColAttr.add( subentryColVal.getString() );
                 }
             }
         }
     }
-    
-    
+
+
     private Set<AttributeType> getAllSuperTypes( AttributeType id ) throws Exception
     {
         Set<AttributeType> allSuperTypes = new HashSet<AttributeType>();
         AttributeType superType = id;
-        
+
         while ( superType != null )
         {
             superType = superType.getSuperior();
-            
+
             if ( superType != null )
             {
                 allSuperTypes.add( superType );
             }
         }
-        
+
         return allSuperTypes;
     }
 
@@ -300,18 +301,16 @@ public class CollectiveAttributeIntercep
     // Interceptor Method Overrides
     // ------------------------------------------------------------------------
 
-    
-    public Entry lookup( NextInterceptor nextInterceptor, LookupOperationContext opContext ) 
-        throws Exception
+    public Entry lookup( NextInterceptor nextInterceptor, LookupOperationContext opContext ) throws Exception
     {
         Entry result = nextInterceptor.lookup( opContext );
-        
+
         if ( result == null )
         {
             return null;
         }
-        
-        if ( ( opContext.getAttrsId() == null ) || ( opContext.getAttrsId().size() == 0 ) ) 
+
+        if ( ( opContext.getAttrsId() == null ) || ( opContext.getAttrsId().size() == 0 ) )
         {
             addCollectiveAttributes( opContext, result, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
         }
@@ -324,7 +323,8 @@ public class CollectiveAttributeIntercep
     }
 
 
-    public EntryFilteringCursor list( NextInterceptor nextInterceptor, ListOperationContext opContext ) throws Exception
+    public EntryFilteringCursor list( NextInterceptor nextInterceptor, ListOperationContext opContext )
+        throws Exception
     {
         EntryFilteringCursor cursor = nextInterceptor.list( opContext );
         cursor.addEntryFilter( SEARCH_FILTER );
@@ -332,30 +332,30 @@ public class CollectiveAttributeIntercep
     }
 
 
-    public EntryFilteringCursor search( NextInterceptor nextInterceptor, SearchOperationContext opContext ) throws Exception
+    public EntryFilteringCursor search( NextInterceptor nextInterceptor, SearchOperationContext opContext )
+        throws Exception
     {
         EntryFilteringCursor cursor = nextInterceptor.search( opContext );
         cursor.addEntryFilter( SEARCH_FILTER );
         return cursor;
     }
 
-    
+
     // ------------------------------------------------------------------------
     // Partial Schema Checking
     // ------------------------------------------------------------------------
-    
-    
+
     public void add( NextInterceptor next, AddOperationContext opContext ) throws Exception
     {
         collectiveAttributesSchemaChecker.checkAdd( opContext.getDn(), opContext.getEntry() );
-        
+
         next.add( opContext );
     }
 
 
     public void modify( NextInterceptor next, ModifyOperationContext opContext ) throws Exception
     {
-        collectiveAttributesSchemaChecker.checkModify( opContext,opContext.getDn(), opContext.getModItems() );
+        collectiveAttributesSchemaChecker.checkModify( opContext );
 
         next.modify( opContext );
     }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java?rev=949506&r1=949505&r2=949506&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java Sun May 30 12:04:20 2010
@@ -25,8 +25,7 @@ import java.util.Set;
 
 import javax.naming.NamingException;
 
-import org.apache.directory.server.core.interceptor.context.OperationContext;
-import org.apache.directory.server.core.partition.ByPassConstants;
+import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
 import org.apache.directory.server.core.partition.PartitionNexus;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -53,19 +52,21 @@ import org.apache.directory.shared.ldap.
 public class CollectiveAttributesSchemaChecker
 {
     private SchemaManager schemaManager = null;
-    
+
+
     public CollectiveAttributesSchemaChecker( PartitionNexus nexus, SchemaManager schemaManager )
     {
         this.schemaManager = schemaManager;
     }
-    
-    /* package scope*/ void checkAdd( DN normName, Entry entry ) throws Exception
+
+
+    /* package scope*/void checkAdd( DN normName, Entry entry ) throws Exception
     {
         if ( entry.hasObjectClass( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRY_OC ) )
         {
             return;
         }
-        
+
         if ( containsAnyCollectiveAttributes( entry ) )
         {
             /*
@@ -74,39 +75,41 @@ public class CollectiveAttributesSchemaC
             throw new LdapSchemaViolationException( ResultCodeEnum.OTHER, I18n.err( I18n.ERR_241 ) );
         }
     }
-    
-    
-    public void checkModify( OperationContext opContext, DN normName, List<Modification> mods ) throws Exception
+
+
+    public void checkModify( ModifyOperationContext opContext ) throws Exception
     {
-        Entry originalEntry = opContext.lookup( normName, ByPassConstants.LOOKUP_BYPASS );
-        Entry targetEntry = (Entry)SchemaUtils.getTargetEntry( mods, originalEntry );
-        
+        List<Modification> mods = opContext.getModItems();
+        Entry originalEntry = opContext.getEntry();
+        Entry targetEntry = ( Entry ) SchemaUtils.getTargetEntry( mods, originalEntry );
+
         EntryAttribute targetObjectClasses = targetEntry.get( SchemaConstants.OBJECT_CLASS_AT );
-        
+
         if ( targetObjectClasses == null )
         {
             // This is not allowed 
-            throw new LdapSchemaViolationException( ResultCodeEnum.OTHER, I18n.err( I18n.ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS, originalEntry.getDn() ));
+            throw new LdapSchemaViolationException( ResultCodeEnum.OTHER, I18n.err(
+                I18n.ERR_272_MODIFY_LEAVES_NO_STRUCTURAL_OBJECT_CLASS, originalEntry.getDn() ) );
         }
-        
+
         if ( targetObjectClasses.contains( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRY_OC ) )
         {
             return;
         }
-        
+
         if ( addsAnyCollectiveAttributes( mods ) )
         {
             /*
              * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
              */
-            throw new LdapSchemaViolationException( ResultCodeEnum.OTHER, I18n.err( I18n.ERR_242 ));
+            throw new LdapSchemaViolationException( ResultCodeEnum.OTHER, I18n.err( I18n.ERR_242 ) );
         }
     }
-    
-    
+
+
     private boolean addsAnyCollectiveAttributes( List<Modification> mods ) throws LdapException
     {
-        for ( Modification mod:mods )
+        for ( Modification mod : mods )
         {
             // TODO: handle http://issues.apache.org/jira/browse/DIRSERVER-1198
             EntryAttribute attr = mod.getAttribute();
@@ -114,42 +117,41 @@ public class CollectiveAttributesSchemaC
 
             if ( attrType == null )
             {
-                if ( !schemaManager.getAttributeTypeRegistry().contains( attr.getUpId() ) )
+                try
                 {
-                    throw new LdapInvalidAttributeTypeException();
+                    attrType = schemaManager.lookupAttributeTypeRegistry( attr.getUpId() );
                 }
-                else
+                catch ( LdapException le )
                 {
-                    attrType = schemaManager.lookupAttributeTypeRegistry( attr.getUpId() );
+                    throw new LdapInvalidAttributeTypeException();
                 }
             }
-            
-            
+
             ModificationOperation modOp = mod.getOperation();
-            
-            if ( ( ( modOp == ModificationOperation.ADD_ATTRIBUTE ) || ( modOp == ModificationOperation.REPLACE_ATTRIBUTE ) ) &&
-                attrType.isCollective() )
+
+            if ( ( ( modOp == ModificationOperation.ADD_ATTRIBUTE ) || ( modOp == ModificationOperation.REPLACE_ATTRIBUTE ) )
+                && attrType.isCollective() )
             {
                 return true;
             }
         }
-        
+
         return false;
     }
-    
-    
+
+
     private boolean containsAnyCollectiveAttributes( Entry entry ) throws NamingException
     {
         Set<AttributeType> attributeTypes = entry.getAttributeTypes();
-        
-        for ( AttributeType attributeType:attributeTypes )
+
+        for ( AttributeType attributeType : attributeTypes )
         {
             if ( attributeType.isCollective() )
             {
                 return true;
             }
         }
-        
+
         return false;
     }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=949506&r1=949505&r2=949506&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java Sun May 30 12:04:20 2010
@@ -66,7 +66,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.util.DateUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
- 
+
 
 /**
  * An {@link Interceptor} that adds or modifies the default attributes
@@ -86,14 +86,13 @@ public class OperationalAttributeInterce
 
     private final EntryFilter DENORMALIZING_SEARCH_FILTER = new EntryFilter()
     {
-        public boolean accept( SearchingOperationContext operation, ClonedServerEntry serverEntry ) 
-            throws Exception
+        public boolean accept( SearchingOperationContext operation, ClonedServerEntry serverEntry ) throws Exception
         {
             if ( operation.getSearchControls().getReturningAttributes() == null )
             {
                 return true;
             }
-            
+
             return filterDenormalized( serverEntry );
         }
     };
@@ -103,22 +102,24 @@ public class OperationalAttributeInterce
      */
     private final EntryFilter SEARCH_FILTER = new EntryFilter()
     {
-        public boolean accept( SearchingOperationContext operation, ClonedServerEntry entry )
-            throws Exception
+        public boolean accept( SearchingOperationContext operation, ClonedServerEntry entry ) throws Exception
         {
-            return operation.getSearchControls().getReturningAttributes() != null 
+            return operation.getSearchControls().getReturningAttributes() != null
                 || filterOperationalAttributes( entry );
         }
     };
 
-
     private DirectoryService service;
 
+    /** The subschemasubentry DN */
     private DN subschemaSubentryDn;
-    
+
+    /** The admin DN */
+    private DN adminDn;
+
     /** The schemaManager */
     private SchemaManager schemaManager;
-    
+
     private static AttributeType MODIFIERS_NAME_ATTRIBUTE_TYPE;
     private static AttributeType MODIFY_TIMESTAMP_ATTRIBUTE_TYPE;
 
@@ -137,13 +138,18 @@ public class OperationalAttributeInterce
         schemaManager = directoryService.getSchemaManager();
 
         // stuff for dealing with subentries (garbage for now)
-        Value<?> subschemaSubentry = service.getPartitionNexus()
-                .getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
+        Value<?> subschemaSubentry = service.getPartitionNexus().getRootDSE( null ).get(
+            SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
         subschemaSubentryDn = new DN( subschemaSubentry.getString() );
         subschemaSubentryDn.normalize( schemaManager.getNormalizerMapping() );
-        
+
+        // Create the Admin DN 
+        adminDn = new DN( ServerDNConstants.ADMIN_SYSTEM_DN );
+        adminDn.normalize( schemaManager.getNormalizerMapping() );
+
         MODIFIERS_NAME_ATTRIBUTE_TYPE = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.MODIFIERS_NAME_AT );
-        MODIFY_TIMESTAMP_ATTRIBUTE_TYPE = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.MODIFY_TIMESTAMP_AT );
+        MODIFY_TIMESTAMP_ATTRIBUTE_TYPE = schemaManager
+            .lookupAttributeTypeRegistry( SchemaConstants.MODIFY_TIMESTAMP_AT );
     }
 
 
@@ -161,18 +167,17 @@ public class OperationalAttributeInterce
      * - entryCSN
      * - entryUUID 
      */
-    public void add( NextInterceptor nextInterceptor, AddOperationContext opContext )
-        throws Exception
+    public void add( NextInterceptor nextInterceptor, AddOperationContext opContext ) throws Exception
     {
         String principal = getPrincipal().getName();
-        
+
         Entry entry = opContext.getEntry();
 
         // If we are using replication, the below four OAs may already be present and we retain
         // those values if the user is admin.
-        boolean isAdmin = opContext.getSession().getAuthenticatedPrincipal().getName().equals( 
+        boolean isAdmin = opContext.getSession().getAuthenticatedPrincipal().getName().equals(
             ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
-        
+
         if ( entry.containsAttribute( SchemaConstants.ENTRY_UUID_AT ) )
         {
             if ( !isAdmin )
@@ -187,13 +192,13 @@ public class OperationalAttributeInterce
         {
             entry.put( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
         }
-            
+
         if ( entry.containsAttribute( SchemaConstants.ENTRY_CSN_AT ) )
         {
             if ( !isAdmin )
             {
                 // Wrong !
-                String message =  I18n.err( I18n.ERR_30, SchemaConstants.ENTRY_CSN_AT );
+                String message = I18n.err( I18n.ERR_30, SchemaConstants.ENTRY_CSN_AT );
                 LOG.error( message );
                 throw new LdapNoPermissionException( message );
             }
@@ -208,7 +213,7 @@ public class OperationalAttributeInterce
             if ( !isAdmin )
             {
                 // Wrong !
-                String message =  I18n.err( I18n.ERR_30, SchemaConstants.CREATORS_NAME_AT );
+                String message = I18n.err( I18n.ERR_30, SchemaConstants.CREATORS_NAME_AT );
                 LOG.error( message );
                 throw new LdapNoPermissionException( message );
             }
@@ -223,7 +228,7 @@ public class OperationalAttributeInterce
             if ( !isAdmin )
             {
                 // Wrong !
-                String message =  I18n.err( I18n.ERR_30, SchemaConstants.CREATE_TIMESTAMP_AT );
+                String message = I18n.err( I18n.ERR_30, SchemaConstants.CREATE_TIMESTAMP_AT );
                 LOG.error( message );
                 throw new LdapNoPermissionException( message );
             }
@@ -232,13 +237,15 @@ public class OperationalAttributeInterce
         {
             entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
         }
-        
+
         nextInterceptor.add( opContext );
     }
 
 
-    public void modify( NextInterceptor nextInterceptor, ModifyOperationContext opContext )
-        throws Exception
+    /**
+     * {@inheritDoc}
+     */
+    public void modify( NextInterceptor nextInterceptor, ModifyOperationContext opContext ) throws Exception
     {
         // We must check that the user hasn't injected either the modifiersName
         // or the modifyTimestamp operational attributes : they are not supposed to be
@@ -246,20 +253,19 @@ public class OperationalAttributeInterce
         // If so, remove them, and if there are no more attributes, simply return.
         // otherwise, inject those values into the list of modifications
         List<Modification> mods = opContext.getModItems();
-        
-        boolean isAdmin = opContext.getSession().getAuthenticatedPrincipal().getName().equals( 
-            ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
-        
+
+        boolean isAdmin = opContext.getSession().getAuthenticatedPrincipal().getDN().equals( adminDn );
+
         boolean modifierAtPresent = false;
         boolean modifiedTimeAtPresent = false;
-        
-        for ( Modification modification: mods )
+
+        for ( Modification modification : mods )
         {
             AttributeType attributeType = modification.getAttribute().getAttributeType();
-            
+
             if ( attributeType.equals( MODIFIERS_NAME_ATTRIBUTE_TYPE ) )
             {
-                if( ! isAdmin )
+                if ( !isAdmin )
                 {
                     String message = I18n.err( I18n.ERR_31 );
                     LOG.error( message );
@@ -273,7 +279,7 @@ public class OperationalAttributeInterce
 
             if ( attributeType.equals( MODIFY_TIMESTAMP_ATTRIBUTE_TYPE ) )
             {
-                if( ! isAdmin )
+                if ( !isAdmin )
                 {
                     String message = I18n.err( I18n.ERR_32 );
                     LOG.error( message );
@@ -286,25 +292,23 @@ public class OperationalAttributeInterce
             }
         }
 
-        if ( ! modifierAtPresent )
+        if ( !modifierAtPresent )
         {
             // Inject the ModifiersName AT if it's not present
-            EntryAttribute attribute = new DefaultEntryAttribute( 
-                MODIFIERS_NAME_ATTRIBUTE_TYPE, 
-                getPrincipal().getName());
+            EntryAttribute attribute = new DefaultEntryAttribute( MODIFIERS_NAME_ATTRIBUTE_TYPE, getPrincipal()
+                .getName() );
 
             Modification modifiersName = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
 
             mods.add( modifiersName );
         }
 
-        if ( ! modifiedTimeAtPresent )
+        if ( !modifiedTimeAtPresent )
         {
             // Inject the ModifyTimestamp AT if it's not present
-            EntryAttribute attribute = new DefaultEntryAttribute( 
-                MODIFY_TIMESTAMP_ATTRIBUTE_TYPE,
-                DateUtils.getGeneralizedTime() );
-            
+            EntryAttribute attribute = new DefaultEntryAttribute( MODIFY_TIMESTAMP_ATTRIBUTE_TYPE, DateUtils
+                .getGeneralizedTime() );
+
             Modification timestamp = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
 
             mods.add( timestamp );
@@ -312,64 +316,26 @@ public class OperationalAttributeInterce
 
         // Go down in the chain
         nextInterceptor.modify( opContext );
-        
-        if ( opContext.getDn().getNormName().equals( subschemaSubentryDn.getNormName() ) ) 
-        {
-            return;
-        }
-
-        // -------------------------------------------------------------------
-        // Add the operational attributes for the modifier first
-        // -------------------------------------------------------------------
-        // TODO : Why can't we add those elements on teh original modifications ???
-        // Or into the context ?
-        /*
-        List<Modification> modItemList = new ArrayList<Modification>(2);
-        
-        AttributeType modifiersNameAt = atRegistry.lookup( SchemaConstants.MODIFIERS_NAME_AT );
-        ServerAttribute attribute = new DefaultServerAttribute( 
-            modifiersNameAt, 
-            getPrincipal().getName());
-
-        Modification modifiers = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
-        modItemList.add( modifiers );
-        
-        AttributeType modifyTimeStampAt = atRegistry.lookup( SchemaConstants.MODIFY_TIMESTAMP_AT );
-        attribute = new DefaultServerAttribute( 
-            modifyTimeStampAt,
-            DateUtils.getGeneralizedTime() );
-        
-        Modification timestamp = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
-        modItemList.add( timestamp );
-
-        // -------------------------------------------------------------------
-        // Make the modify() call happen
-        // -------------------------------------------------------------------
-        ModifyOperationContext newModify = new ModifyOperationContext( opContext.getSession(), 
-            opContext.getDn(), modItemList );
-        newModify.setEntry( opContext.getAlteredEntry() );
-        service.getPartitionNexus().modify( newModify );
-        */
     }
 
 
-    public void rename( NextInterceptor nextInterceptor, RenameOperationContext opContext )
-        throws Exception
+    public void rename( NextInterceptor nextInterceptor, RenameOperationContext opContext ) throws Exception
     {
         nextInterceptor.rename( opContext );
 
         DN newDn = opContext.getNewDn();
-        
+
         // add operational attributes after call in case the operation fails
         Entry serverEntry = new DefaultEntry( schemaManager, newDn );
         serverEntry.put( SchemaConstants.MODIFIERS_NAME_AT, getPrincipal().getName() );
         serverEntry.put( SchemaConstants.MODIFY_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
 
-        List<Modification> items = ModifyOperationContext.createModItems( serverEntry, ModificationOperation.REPLACE_ATTRIBUTE );
+        List<Modification> items = ModifyOperationContext.createModItems( serverEntry,
+            ModificationOperation.REPLACE_ATTRIBUTE );
 
         ModifyOperationContext newModify = new ModifyOperationContext( opContext.getSession(), newDn, items );
         newModify.setEntry( opContext.getAlteredEntry() );
-        
+
         service.getPartitionNexus().modify( newModify );
     }
 
@@ -383,12 +349,12 @@ public class OperationalAttributeInterce
         serverEntry.put( SchemaConstants.MODIFIERS_NAME_AT, getPrincipal().getName() );
         serverEntry.put( SchemaConstants.MODIFY_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
 
-        List<Modification> items = ModifyOperationContext.createModItems( serverEntry, ModificationOperation.REPLACE_ATTRIBUTE );
+        List<Modification> items = ModifyOperationContext.createModItems( serverEntry,
+            ModificationOperation.REPLACE_ATTRIBUTE );
 
+        ModifyOperationContext newModify = new ModifyOperationContext( opContext.getSession(), opContext.getParent(),
+            items );
 
-        ModifyOperationContext newModify = 
-            new ModifyOperationContext( opContext.getSession(), opContext.getParent(), items );
-        
         service.getPartitionNexus().modify( newModify );
     }
 
@@ -403,11 +369,12 @@ public class OperationalAttributeInterce
         serverEntry.put( SchemaConstants.MODIFIERS_NAME_AT, getPrincipal().getName() );
         serverEntry.put( SchemaConstants.MODIFY_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
 
-        List<Modification> items = ModifyOperationContext.createModItems( serverEntry, ModificationOperation.REPLACE_ATTRIBUTE );
+        List<Modification> items = ModifyOperationContext.createModItems( serverEntry,
+            ModificationOperation.REPLACE_ATTRIBUTE );
+
+        ModifyOperationContext newModify = new ModifyOperationContext( opContext.getSession(), opContext.getParent(),
+            items );
 
-        ModifyOperationContext newModify = 
-            new ModifyOperationContext( opContext.getSession(), opContext.getParent(), items );
-        
         service.getPartitionNexus().modify( newModify );
     }
 
@@ -415,7 +382,7 @@ public class OperationalAttributeInterce
     public Entry lookup( NextInterceptor nextInterceptor, LookupOperationContext opContext ) throws Exception
     {
         Entry result = nextInterceptor.lookup( opContext );
-        
+
         if ( result == null )
         {
             return null;
@@ -429,13 +396,14 @@ public class OperationalAttributeInterce
         {
             filter( opContext, result );
         }
-        
+
         denormalizeEntryOpAttrs( result );
         return result;
     }
 
 
-    public EntryFilteringCursor list( NextInterceptor nextInterceptor, ListOperationContext opContext ) throws Exception
+    public EntryFilteringCursor list( NextInterceptor nextInterceptor, ListOperationContext opContext )
+        throws Exception
     {
         EntryFilteringCursor cursor = nextInterceptor.list( opContext );
         cursor.addEntryFilter( SEARCH_FILTER );
@@ -443,18 +411,19 @@ public class OperationalAttributeInterce
     }
 
 
-    public EntryFilteringCursor search( NextInterceptor nextInterceptor, SearchOperationContext opContext ) throws Exception
+    public EntryFilteringCursor search( NextInterceptor nextInterceptor, SearchOperationContext opContext )
+        throws Exception
     {
         EntryFilteringCursor cursor = nextInterceptor.search( opContext );
-        
-        if ( opContext.isAllOperationalAttributes() || 
-             ( opContext.getReturningAttributes() != null && ! opContext.getReturningAttributes().isEmpty() ) )
+
+        if ( opContext.isAllOperationalAttributes()
+            || ( opContext.getReturningAttributes() != null && !opContext.getReturningAttributes().isEmpty() ) )
         {
             if ( service.isDenormalizeOpAttrsEnabled() )
             {
                 cursor.addEntryFilter( DENORMALIZING_SEARCH_FILTER );
             }
-                
+
             return cursor;
         }
 
@@ -476,20 +445,20 @@ public class OperationalAttributeInterce
         Set<AttributeType> removedAttributes = new HashSet<AttributeType>();
 
         // Build a list of attributeType to remove
-        for ( AttributeType attributeType:attributes.getAttributeTypes() )
+        for ( AttributeType attributeType : attributes.getAttributeTypes() )
         {
             if ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS )
             {
                 removedAttributes.add( attributeType );
             }
         }
-        
+
         // Now remove the attributes which are not USERs
-        for ( AttributeType attributeType:removedAttributes )
+        for ( AttributeType attributeType : removedAttributes )
         {
             attributes.removeAttributes( attributeType );
         }
-        
+
         return true;
     }
 
@@ -498,7 +467,7 @@ public class OperationalAttributeInterce
     {
         DN dn = lookupContext.getDn();
         List<String> ids = lookupContext.getAttrsId();
-        
+
         // still need to protect against returning op attrs when ids is null
         if ( ids == null || ids.isEmpty() )
         {
@@ -510,7 +479,7 @@ public class OperationalAttributeInterce
 
         if ( dn.size() == 0 )
         {
-            for ( AttributeType attributeType:attributeTypes )
+            for ( AttributeType attributeType : attributeTypes )
             {
                 if ( !ids.contains( attributeType.getOid() ) )
                 {
@@ -520,13 +489,13 @@ public class OperationalAttributeInterce
         }
 
         denormalizeEntryOpAttrs( entry );
-        
+
         // do nothing past here since this explicity specifies which
         // attributes to include - backends will automatically populate
         // with right set of attributes using ids array
     }
 
-    
+
     public void denormalizeEntryOpAttrs( Entry entry ) throws Exception
     {
         if ( service.isDenormalizeOpAttrsEnabled() )
@@ -536,13 +505,13 @@ public class OperationalAttributeInterce
             if ( attr != null )
             {
                 DN creatorsName = new DN( attr.getString() );
-                
+
                 attr.clear();
                 attr.add( denormalizeTypes( creatorsName ).getName() );
             }
-            
+
             attr = entry.get( SchemaConstants.MODIFIERS_NAME_AT );
-            
+
             if ( attr != null )
             {
                 DN modifiersName = new DN( attr.getString() );
@@ -552,7 +521,7 @@ public class OperationalAttributeInterce
             }
 
             attr = entry.get( ApacheSchemaConstants.SCHEMA_MODIFIERS_NAME_AT );
-            
+
             if ( attr != null )
             {
                 DN modifiersName = new DN( attr.getString() );
@@ -563,7 +532,7 @@ public class OperationalAttributeInterce
         }
     }
 
-    
+
     /**
      * Does not create a new DN but alters existing DN by using the first
      * short name for an attributeType definition.
@@ -575,7 +544,7 @@ public class OperationalAttributeInterce
     public DN denormalizeTypes( DN dn ) throws Exception
     {
         DN newDn = new DN();
-        
+
         for ( int ii = 0; ii < dn.size(); ii++ )
         {
             RDN rdn = dn.getRdn( ii );
@@ -587,29 +556,29 @@ public class OperationalAttributeInterce
             else if ( rdn.size() == 1 )
             {
                 String name = schemaManager.lookupAttributeTypeRegistry( rdn.getNormType() ).getName();
-                String value = rdn.getAtav().getNormValue().getString(); 
+                String value = rdn.getAtav().getNormValue().getString();
                 newDn.add( new RDN( name, name, value, value ) );
                 continue;
             }
 
             // below we only process multi-valued rdns
             StringBuffer buf = new StringBuffer();
-        
-            for ( Iterator<AVA> atavs = rdn.iterator(); atavs.hasNext(); /**/ )
+
+            for ( Iterator<AVA> atavs = rdn.iterator(); atavs.hasNext(); /**/)
             {
                 AVA atav = atavs.next();
                 String type = schemaManager.lookupAttributeTypeRegistry( rdn.getNormType() ).getName();
                 buf.append( type ).append( '=' ).append( atav.getNormValue() );
-                
+
                 if ( atavs.hasNext() )
                 {
                     buf.append( '+' );
                 }
             }
-            
-            newDn.add( new RDN(buf.toString()) );
+
+            newDn.add( new RDN( buf.toString() ) );
         }
-        
+
         return newDn;
     }
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=949506&r1=949505&r2=949506&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Sun May 30 12:04:20 2010
@@ -171,6 +171,7 @@ public class SchemaInterceptor extends B
     private static AttributeType MODIFIERS_NAME_ATTRIBUTE_TYPE;
     private static AttributeType MODIFY_TIMESTAMP_ATTRIBUTE_TYPE;
 
+
     /**
      * Initialize the Schema Service
      *
@@ -206,14 +207,15 @@ public class SchemaInterceptor extends B
         schemaModificationAttributesDN.normalize( schemaManager.getNormalizerMapping() );
 
         computeSuperiors();
-        
+
         // Initialize the schema manager
         SchemaLoader loader = schemaService.getSchemaPartition().getSchemaManager().getLoader();
         schemaSubEntryManager = new SchemaSubentryManager( schemaManager, loader );
 
         MODIFIERS_NAME_ATTRIBUTE_TYPE = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.MODIFIERS_NAME_AT );
-        MODIFY_TIMESTAMP_ATTRIBUTE_TYPE = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.MODIFY_TIMESTAMP_AT );
-        
+        MODIFY_TIMESTAMP_ATTRIBUTE_TYPE = schemaManager
+            .lookupAttributeTypeRegistry( SchemaConstants.MODIFY_TIMESTAMP_AT );
+
         if ( IS_DEBUG )
         {
             LOG.debug( "SchemaInterceptor Initialized !" );
@@ -366,7 +368,7 @@ public class SchemaInterceptor extends B
 
         superiors.put( objectClass.getName(), ocSuperiors );
     }
-    
+
 
     /**
      * Compute all ObjectClasses superiors, MAY and MUST attributes.
@@ -753,8 +755,8 @@ public class SchemaInterceptor extends B
                     // call.setBypass( true );
                     Entry serverEntry = schemaService.getSubschemaEntry( searchCtls.getReturningAttributes() );
                     serverEntry.setDn( base );
-                    EntryFilteringCursor cursor = new BaseEntryFilteringCursor( new SingletonCursor<Entry>(
-                        serverEntry ), opContext );
+                    EntryFilteringCursor cursor = new BaseEntryFilteringCursor(
+                        new SingletonCursor<Entry>( serverEntry ), opContext );
                     return cursor;
                 }
             }
@@ -768,8 +770,7 @@ public class SchemaInterceptor extends B
     /**
      * Search for an entry, using its DN. Binary attributes and ObjectClass attribute are removed.
      */
-    public Entry lookup( NextInterceptor nextInterceptor, LookupOperationContext opContext )
-        throws Exception
+    public Entry lookup( NextInterceptor nextInterceptor, LookupOperationContext opContext ) throws Exception
     {
         Entry result = nextInterceptor.lookup( opContext );
 
@@ -968,7 +969,7 @@ public class SchemaInterceptor extends B
         DN oldDn = opContext.getDn();
         RDN newRdn = opContext.getNewRdn();
         boolean deleteOldRn = opContext.getDelOldDn();
-        Entry entry =  (Entry)opContext.getEntry().getClonedEntry();
+        Entry entry = ( Entry ) opContext.getEntry().getClonedEntry();
 
         /*
          *  Note: This is only a consistency checks, to the ensure that all
@@ -989,7 +990,7 @@ public class SchemaInterceptor extends B
                 AttributeType type = schemaManager.lookupAttributeTypeRegistry( atav.getUpType() );
                 tmpEntry.remove( type, atav.getUpValue() );
             }
-            
+
             for ( AVA atav : newRdn )
             {
                 AttributeType type = schemaManager.lookupAttributeTypeRegistry( atav.getUpType() );
@@ -1027,7 +1028,7 @@ public class SchemaInterceptor extends B
     private EntryAttribute createNewAttribute( EntryAttribute attribute )
     {
         AttributeType attributeType = attribute.getAttributeType();
-        
+
         // Create the new Attribute
         EntryAttribute newAttribute = new DefaultEntryAttribute( attribute.getUpId(), attributeType );
 
@@ -1038,8 +1039,8 @@ public class SchemaInterceptor extends B
 
         return newAttribute;
     }
-    
-    
+
+
     /**
      * Modify an entry, applying the given modifications, and check if it's OK
      */
@@ -1050,38 +1051,38 @@ public class SchemaInterceptor extends B
         // - The value is syntaxically correct
         //
         // While doing that, we will apply the modification to a copy of the current entry
-        Entry tempEntry = (Entry)currentEntry.clone();
-        
+        Entry tempEntry = ( Entry ) currentEntry.clone();
+
         // Now, apply each mod one by one
-        for ( Modification mod:mods )
+        for ( Modification mod : mods )
         {
             EntryAttribute attribute = mod.getAttribute();
             AttributeType attributeType = attribute.getAttributeType();
-            
+
             // We don't allow modification of operational attributes
-            if ( !attributeType.isUserModifiable() && ( !attributeType.equals( MODIFIERS_NAME_ATTRIBUTE_TYPE ) &&
-                     !attributeType.equals( MODIFY_TIMESTAMP_ATTRIBUTE_TYPE ) ) )
+            if ( !attributeType.isUserModifiable()
+                && ( !attributeType.equals( MODIFIERS_NAME_ATTRIBUTE_TYPE ) && !attributeType
+                    .equals( MODIFY_TIMESTAMP_ATTRIBUTE_TYPE ) ) )
             {
                 String msg = I18n.err( I18n.ERR_52, attributeType );
                 LOG.error( msg );
                 throw new LdapNoPermissionException( msg );
             }
-            
+
             switch ( mod.getOperation() )
             {
-                case ADD_ATTRIBUTE :
+                case ADD_ATTRIBUTE:
                     // Check the syntax here
                     if ( !attribute.isValid() )
                     {
                         // The value syntax is incorrect : this is an error
                         String msg = I18n.err( I18n.ERR_53, attributeType );
                         LOG.error( msg );
-                        throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, 
-                            msg );
+                        throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg );
                     }
 
                     EntryAttribute currentAttribute = tempEntry.get( attributeType );
-                    
+
                     // First check if the added Attribute is already present in the entry
                     // If not, we have to create the entry
                     if ( currentAttribute != null )
@@ -1091,14 +1092,14 @@ public class SchemaInterceptor extends B
                             // At this point, we know that the attribute's syntax is correct
                             // We just have to check that the current attribute does not 
                             // contains the value already
-                            if ( currentAttribute.contains( value ))
+                            if ( currentAttribute.contains( value ) )
                             {
                                 // This is an error. 
                                 String msg = I18n.err( I18n.ERR_54, value );
                                 LOG.error( msg );
                                 throw new LdapAttributeInUseException( msg );
                             }
-                            
+
                             currentAttribute.add( value );
                         }
                     }
@@ -1111,10 +1112,10 @@ public class SchemaInterceptor extends B
 
                         tempEntry.put( newAttribute );
                     }
-                    
+
                     break;
-                    
-                case REMOVE_ATTRIBUTE :
+
+                case REMOVE_ATTRIBUTE:
                     // First check that the removed attribute exists
                     if ( !tempEntry.containsAttribute( attributeType ) )
                     {
@@ -1132,9 +1133,9 @@ public class SchemaInterceptor extends B
                     else
                     {
                         currentAttribute = tempEntry.get( attributeType );
-                        
+
                         // Now remove all the values
-                        for ( Value<?> value:attribute )
+                        for ( Value<?> value : attribute )
                         {
                             // We can only remove existing values.
                             if ( currentAttribute.contains( value ) )
@@ -1149,7 +1150,6 @@ public class SchemaInterceptor extends B
                             }
                         }
 
-                        
                         // If the current attribute is empty, we have to remove
                         // it from the entry
                         if ( currentAttribute.size() == 0 )
@@ -1159,8 +1159,8 @@ public class SchemaInterceptor extends B
                     }
 
                     break;
-                
-                case REPLACE_ATTRIBUTE :
+
+                case REPLACE_ATTRIBUTE:
                     // The replaced attribute might not exist, it will then be a Add
                     // If there is no value, then the attribute will be removed
                     if ( !tempEntry.containsAttribute( attributeType ) )
@@ -1198,11 +1198,11 @@ public class SchemaInterceptor extends B
                             tempEntry.put( newAttribute );
                         }
                     }
-                    
+
                     break;
             }
         }
-        
+
         // Ok, we have created the modified entry. We now have to check that it's a valid 
         // entry wrt the schema.
         // We have to check that :
@@ -1215,7 +1215,7 @@ public class SchemaInterceptor extends B
         check( dn, tempEntry );
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
@@ -1233,45 +1233,46 @@ public class SchemaInterceptor extends B
         // - We have to update the registries
         // - We have to modify the ou=schemaModifications entry
         //
-        
+
         // First, check that the entry is either a subschemaSubentry or a schema element.
         // This is the case if it's a child of cn=schema or ou=schema
         DN dn = opContext.getDn();
-        
+
         // Gets the stored entry on which the modification must be applied
         if ( dn.equals( subschemaSubentryDn ) )
         {
             LOG.debug( "Modification attempt on schema subentry {}: \n{}", dn, opContext );
-            
+
             // We can get rid of the modifiersName and modifyTimestamp, they are useless.
             List<Modification> mods = opContext.getModItems();
-            List<Modification> cleanMods = new ArrayList<Modification>(); 
-            
-            for ( Modification mod:mods )
-            {
-                AttributeType at = ( (DefaultModification)mod).getAttribute().getAttributeType();
-                
-                if ( !MODIFIERS_NAME_ATTRIBUTE_TYPE.equals( at ) && !MODIFY_TIMESTAMP_ATTRIBUTE_TYPE.equals( at ) ) 
+            List<Modification> cleanMods = new ArrayList<Modification>();
+
+            for ( Modification mod : mods )
+            {
+                AttributeType at = ( ( DefaultModification ) mod ).getAttribute().getAttributeType();
+
+                if ( !MODIFIERS_NAME_ATTRIBUTE_TYPE.equals( at ) && !MODIFY_TIMESTAMP_ATTRIBUTE_TYPE.equals( at ) )
                 {
                     cleanMods.add( mod );
                 }
             }
-            
+
             opContext.setModItems( cleanMods );
-            
+
             // Now that the entry has been modified, update the SSSE
-            schemaSubEntryManager.modifySchemaSubentry(  opContext, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
-            
+            schemaSubEntryManager.modifySchemaSubentry( opContext, opContext
+                .hasRequestControl( CascadeControl.CONTROL_OID ) );
+
             return;
         }
 
         Entry entry = opContext.getEntry();
         List<Modification> modifications = opContext.getModItems();
         checkModifyEntry( dn, entry, modifications );
-        
+
         next.modify( opContext );
     }
-    
+
 
     /**
      * Filter the attributes by removing the ones which are not allowed
@@ -1334,12 +1335,11 @@ public class SchemaInterceptor extends B
                 for ( Value<?> value : attribute )
                 {
                     attribute.add( value );
-                    binaries.add( new BinaryValue( attribute.getAttributeType(),
-                        value.getBytes() ) );
+                    binaries.add( new BinaryValue( attribute.getAttributeType(), value.getBytes() ) );
                 }
 
                 attribute.clear();
-                
+
                 for ( Value<?> value : binaries )
                 {
                     attribute.add( value );
@@ -1393,8 +1393,7 @@ public class SchemaInterceptor extends B
         {
             if ( !schemaManager.getAttributeTypeRegistry().contains( attributeType.getName() ) )
             {
-                throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_275, 
-                    attributeType.getName() ) );
+                throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_275, attributeType.getName() ) );
             }
         }
 
@@ -1442,8 +1441,8 @@ public class SchemaInterceptor extends B
 
         // Now check the syntaxes
         assertSyntaxes( entry );
-        
-        assertRdn ( dn, entry );
+
+        assertRdn( dn, entry );
     }
 
 
@@ -1451,50 +1450,50 @@ public class SchemaInterceptor extends B
     {
         // handle the m-supObjectClass meta attribute
         EntryAttribute supOC = entry.get( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT );
-        
+
         if ( supOC != null )
         {
             ObjectClassTypeEnum ocType = ObjectClassTypeEnum.STRUCTURAL;
-            
+
             if ( entry.get( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT ) != null )
             {
                 String type = entry.get( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT ).getString();
                 ocType = ObjectClassTypeEnum.getClassType( type );
             }
-            
+
             // First check that the inheritence scheme is correct.
             // 1) If the ocType is ABSTRACT, it should not have any other SUP not ABSTRACT
-            for ( Value<?> sup:supOC )
+            for ( Value<?> sup : supOC )
             {
                 try
                 {
                     String supName = sup.getString();
-                    
+
                     ObjectClass superior = schemaManager.getObjectClassRegistry().lookup( supName );
 
                     switch ( ocType )
                     {
-                        case ABSTRACT :
+                        case ABSTRACT:
                             if ( !superior.isAbstract() )
                             {
                                 String message = I18n.err( I18n.ERR_57 );
                                 LOG.error( message );
                                 throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, message );
                             }
-                            
+
                             break;
-    
-                        case AUXILIARY :
-                            if ( !superior.isAbstract() && ! superior.isAuxiliary() )
+
+                        case AUXILIARY:
+                            if ( !superior.isAbstract() && !superior.isAuxiliary() )
                             {
                                 String message = I18n.err( I18n.ERR_58 );
                                 LOG.error( message );
                                 throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, message );
                             }
-                            
+
                             break;
 
-                        case STRUCTURAL :
+                        case STRUCTURAL:
                             break;
                     }
                 }
@@ -1545,7 +1544,7 @@ public class SchemaInterceptor extends B
 
                 // Update the structures now that the schema element has been added
                 Schema schema = schemaManager.getLoadedSchema( schemaName );
-                
+
                 if ( ( schema != null ) && schema.isEnabled() )
                 {
                     String ocName = entry.get( MetaSchemaConstants.M_NAME_AT ).getString();
@@ -1555,7 +1554,7 @@ public class SchemaInterceptor extends B
             }
             else if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.META_ATTRIBUTE_TYPE_OC ) )
             {
-                
+
                 // This is an AttributeType addition
                 next.add( addContext );
             }
@@ -1563,22 +1562,22 @@ public class SchemaInterceptor extends B
             {
                 next.add( addContext );
             }
-            
+
         }
         else
         {
             next.add( addContext );
         }
     }
-    
-    
+
+
     private String getSchemaName( DN dn ) throws LdapException
     {
         if ( dn.size() < 2 )
         {
             throw new LdapException( I18n.err( I18n.ERR_276 ) );
         }
-        
+
         RDN rdn = dn.getRdn( 1 );
         return ( String ) rdn.getNormValue();
     }
@@ -1608,11 +1607,11 @@ public class SchemaInterceptor extends B
 
             AttributeType attributeType = attribute.getAttributeType();
 
-            if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) &&
-                !allowed.contains( attrOid ) )
+            if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
+                && !allowed.contains( attrOid ) )
             {
-                throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277, attribute.getUpId(),
-                        dn.getName() ) );
+                throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277,
+                    attribute.getUpId(), dn.getName() ) );
             }
         }
     }
@@ -1633,12 +1632,13 @@ public class SchemaInterceptor extends B
     /**
      * Checks to see numbers of values of attributes conforms to the schema
      */
-    private void assertNumberOfAttributeValuesValid( EntryAttribute attribute ) throws LdapInvalidAttributeValueException
+    private void assertNumberOfAttributeValuesValid( EntryAttribute attribute )
+        throws LdapInvalidAttributeValueException
     {
         if ( attribute.size() > 1 && attribute.getAttributeType().isSingleValued() )
         {
-            throw new LdapInvalidAttributeValueException( ResultCodeEnum.CONSTRAINT_VIOLATION,
-                I18n.err( I18n.ERR_278, attribute.getUpId() ) );
+            throw new LdapInvalidAttributeValueException( ResultCodeEnum.CONSTRAINT_VIOLATION, I18n.err( I18n.ERR_278,
+                attribute.getUpId() ) );
         }
     }
 
@@ -1655,8 +1655,8 @@ public class SchemaInterceptor extends B
 
         if ( must.size() != 0 )
         {
-            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION,
-                I18n.err( I18n.ERR_279, must, dn.getName() ) );
+            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_279,
+                must, dn.getName() ) );
         }
     }
 
@@ -1710,7 +1710,7 @@ public class SchemaInterceptor extends B
 
         Set<ObjectClass> remaining = new HashSet<ObjectClass>( structuralObjectClasses.size() );
         remaining.addAll( structuralObjectClasses );
-        
+
         for ( ObjectClass oc : structuralObjectClasses )
         {
             if ( oc.getSuperiors() != null )
@@ -1761,7 +1761,7 @@ public class SchemaInterceptor extends B
                     // No need to validate something which is already ok
                     continue;
                 }
-                
+
                 try
                 {
                     syntaxChecker.assertSyntax( value.get() );
@@ -1776,14 +1776,14 @@ public class SchemaInterceptor extends B
             }
         }
     }
-    
-    
+
+
     private void assertRdn( DN dn, Entry entry ) throws Exception
     {
         for ( AVA atav : dn.getRdn() )
         {
             EntryAttribute attribute = entry.get( atav.getNormType() );
-            
+
             if ( ( attribute == null ) || ( !attribute.contains( atav.getNormValue() ) ) )
             {
                 String message = I18n.err( I18n.ERR_62, dn, atav.getUpType() );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=949506&r1=949505&r2=949506&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Sun May 30 12:04:20 2010
@@ -1029,31 +1029,34 @@ public class SubentryInterceptor extends
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void modify( NextInterceptor next, ModifyOperationContext opContext ) throws Exception
     {
-        DN name = opContext.getDn();
+        DN dn = opContext.getDn();
         List<Modification> mods = opContext.getModItems();
 
-        Entry entry = opContext.lookup( name, ByPassConstants.LOOKUP_BYPASS );
-        //        Entry entry = opContext.getEntry();
+        Entry entry = opContext.getEntry();
 
-        Entry oldEntry = ( Entry ) entry.clone();
         EntryAttribute objectClasses = entry.get( objectClassType );
         boolean isSubtreeSpecificationModification = false;
         Modification subtreeMod = null;
 
+        // Find the subtreeSpecification
         for ( Modification mod : mods )
         {
             if ( SchemaConstants.SUBTREE_SPECIFICATION_AT.equalsIgnoreCase( mod.getAttribute().getId() ) )
             {
                 isSubtreeSpecificationModification = true;
                 subtreeMod = mod;
+                break;
             }
         }
 
         if ( objectClasses.contains( SchemaConstants.SUBENTRY_OC ) && isSubtreeSpecificationModification )
         {
-            SubtreeSpecification ssOld = subentryCache.removeSubentry( name.getNormName() ).getSubtreeSpecification();
+            SubtreeSpecification ssOld = subentryCache.removeSubentry( dn.getNormName() ).getSubtreeSpecification();
             SubtreeSpecification ssNew;
 
             try
@@ -1067,11 +1070,11 @@ public class SubentryInterceptor extends
                 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg );
             }
 
-            subentryCache.setSubentry( name.getNormName(), ssNew, getSubentryTypes( entry, mods ) );
+            subentryCache.setSubentry( dn.getNormName(), ssNew, getSubentryTypes( entry, mods ) );
             next.modify( opContext );
 
             // search for all entries selected by the old SS and remove references to subentry
-            DN apName = ( DN ) name.clone();
+            DN apName = ( DN ) dn.clone();
             apName.remove( apName.size() - 1 );
             DN oldBaseDn = ( DN ) apName.clone();
             oldBaseDn.addAll( ssOld.getBase() );
@@ -1091,19 +1094,19 @@ public class SubentryInterceptor extends
             while ( subentries.next() )
             {
                 Entry candidate = subentries.get();
-                DN dn = candidate.getDn();
-                dn.normalize( schemaManager.getNormalizerMapping() );
+                DN candidateDn = candidate.getDn();
+                candidateDn.normalize( schemaManager.getNormalizerMapping() );
 
-                if ( evaluator.evaluate( ssOld, apName, dn, candidate ) )
+                if ( evaluator.evaluate( ssOld, apName, candidateDn, candidate ) )
                 {
-                    nexus.modify( new ModifyOperationContext( opContext.getSession(), dn, getOperationalModsForRemove(
-                        name, candidate ) ) );
+                    nexus.modify( new ModifyOperationContext( opContext.getSession(), candidateDn,
+                        getOperationalModsForRemove( dn, candidate ) ) );
                 }
             }
 
             // search for all selected entries by the new SS and add references to subentry
-            Subentry subentry = subentryCache.getSubentry( name.getNormName() );
-            Entry operational = getSubentryOperatationalAttributes( name, subentry );
+            Subentry subentry = subentryCache.getSubentry( dn.getNormName() );
+            Entry operational = getSubentryOperatationalAttributes( dn, subentry );
             DN newBaseDn = ( DN ) apName.clone();
             newBaseDn.addAll( ssNew.getBase() );
 
@@ -1115,13 +1118,13 @@ public class SubentryInterceptor extends
             while ( subentries.next() )
             {
                 Entry candidate = subentries.get();
-                DN dn = candidate.getDn();
-                dn.normalize( schemaManager.getNormalizerMapping() );
+                DN candidateDn = candidate.getDn();
+                candidateDn.normalize( schemaManager.getNormalizerMapping() );
 
-                if ( evaluator.evaluate( ssNew, apName, dn, candidate ) )
+                if ( evaluator.evaluate( ssNew, apName, candidateDn, candidate ) )
                 {
-                    nexus.modify( new ModifyOperationContext( opContext.getSession(), dn, getOperationalModsForAdd(
-                        candidate, operational ) ) );
+                    nexus.modify( new ModifyOperationContext( opContext.getSession(), candidateDn,
+                        getOperationalModsForAdd( candidate, operational ) ) );
                 }
             }
         }
@@ -1131,13 +1134,13 @@ public class SubentryInterceptor extends
 
             if ( !objectClasses.contains( SchemaConstants.SUBENTRY_OC ) )
             {
-                Entry newEntry = opContext.lookup( name, ByPassConstants.LOOKUP_BYPASS );
+                Entry newEntry = opContext.lookup( dn, ByPassConstants.LOOKUP_BYPASS );
 
-                List<Modification> subentriesOpAttrMods = getModsOnEntryModification( name, oldEntry, newEntry );
+                List<Modification> subentriesOpAttrMods = getModsOnEntryModification( dn, entry, newEntry );
 
                 if ( subentriesOpAttrMods.size() > 0 )
                 {
-                    nexus.modify( new ModifyOperationContext( opContext.getSession(), name, subentriesOpAttrMods ) );
+                    nexus.modify( new ModifyOperationContext( opContext.getSession(), dn, subentriesOpAttrMods ) );
                 }
             }
         }



Mime
View raw message