directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r507215 - /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Date Tue, 13 Feb 2007 20:58:20 GMT
Author: ersiner
Date: Tue Feb 13 12:58:19 2007
New Revision: 507215

URL: http://svn.apache.org/viewvc?view=rev&rev=507215
Log:
Fixed DIRSERVER-784 and DIRSERVER-848.

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java?view=diff&rev=507215&r1=507214&r2=507215
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Tue Feb 13 12:58:19 2007
@@ -963,6 +963,7 @@
     public void modify( NextInterceptor next, LdapDN name, int modOp, Attributes mods ) throws
NamingException
     {
         Attributes entry = nexus.lookup( name );
+        Attributes oldEntry = (Attributes) entry.clone();
         Attribute objectClasses = AttributeUtils.getAttribute( entry, objectClassType );
 
         if ( AttributeUtils.containsValueCaseIgnore( objectClasses, "subentry" )  &&
mods.get( "subtreeSpecification" ) != null )
@@ -1030,6 +1031,17 @@
         else
         {
             next.modify( name, modOp, mods );
+            
+            if ( !AttributeUtils.containsValueCaseIgnore( objectClasses, "subentry" ) )
+            {
+	            Attributes newEntry = nexus.lookup( name );
+	            
+	            ModificationItemImpl[] subentriesOpAttrMods =  getModsOnEntryModification(name,
oldEntry, newEntry);
+	            if ( subentriesOpAttrMods.length > 0)
+	            {
+	            	nexus.modify(name, subentriesOpAttrMods);
+	            }
+            }
         }
     }
 
@@ -1037,6 +1049,7 @@
     public void modify( NextInterceptor next, LdapDN name, ModificationItemImpl[] mods )
throws NamingException
     {
         Attributes entry = nexus.lookup( name );
+        Attributes oldEntry = (Attributes) entry.clone();
         Attribute objectClasses = AttributeUtils.getAttribute( entry, objectClassType );
         boolean isSubtreeSpecificationModification = false;
         ModificationItemImpl subtreeMod = null;
@@ -1115,6 +1128,17 @@
         else
         {
             next.modify( name, mods );
+            
+            if ( !AttributeUtils.containsValueCaseIgnore( objectClasses, "subentry" ) )
+            {
+	            Attributes newEntry = nexus.lookup( name );
+	            
+	            ModificationItemImpl[] subentriesOpAttrMods =  getModsOnEntryModification(name,
oldEntry, newEntry);
+	            if ( subentriesOpAttrMods.length > 0)
+	            {
+	            	nexus.modify(name, subentriesOpAttrMods);
+	            }
+            }
         }
     }
 
@@ -1467,4 +1491,65 @@
             return subentryCache.hasSubentry( name.toNormName() );
         }
     }
+    
+    
+    private ModificationItemImpl[] getModsOnEntryModification( LdapDN name, Attributes oldEntry,
Attributes newEntry )
+    throws NamingException
+	{
+	    List<ModificationItemImpl> modList = new ArrayList<ModificationItemImpl>();
+	
+	    Iterator subentries = subentryCache.nameIterator();
+	    while ( subentries.hasNext() )
+	    {
+	        String subentryDn = ( String ) subentries.next();
+	        Name apDn = new LdapDN( subentryDn );
+	        apDn.remove( apDn.size() - 1 );
+	        SubtreeSpecification ss = subentryCache.getSubentry( subentryDn ).getSubtreeSpecification();
+	        boolean isOldEntrySelected = evaluator.evaluate( ss, apDn, name, oldEntry );
+	        boolean isNewEntrySelected = evaluator.evaluate( ss, apDn, name, newEntry );
+	
+	        if ( isOldEntrySelected == isNewEntrySelected )
+	        {
+	            continue;
+	        }
+	
+	        // need to remove references to the subentry
+	        if ( isOldEntrySelected && !isNewEntrySelected )
+	        {
+	            for ( int ii = 0; ii < SUBENTRY_OPATTRS.length; ii++ )
+	            {
+	                int op = DirContext.REPLACE_ATTRIBUTE;
+	                Attribute opAttr = oldEntry.get( SUBENTRY_OPATTRS[ii] );
+	                if ( opAttr != null )
+	                {
+	                    opAttr = ( Attribute ) opAttr.clone();
+	                    opAttr.remove( subentryDn );
+	
+	                    if ( opAttr.size() < 1 )
+	                    {
+	                        op = DirContext.REMOVE_ATTRIBUTE;
+	                    }
+	
+	                    modList.add( new ModificationItemImpl( op, opAttr ) );
+	                }
+	            }
+	        }
+	        // need to add references to the subentry
+	        else if ( isNewEntrySelected && !isOldEntrySelected )
+	        {
+	            for ( int ii = 0; ii < SUBENTRY_OPATTRS.length; ii++ )
+	            {
+	                int op = DirContext.ADD_ATTRIBUTE;
+	                Attribute opAttr = new AttributeImpl( SUBENTRY_OPATTRS[ii] );
+	                opAttr.add( subentryDn );
+	                modList.add( new ModificationItemImpl( op, opAttr ) );
+	            }
+	        }
+	    }
+	
+	    ModificationItemImpl[] mods = new ModificationItemImpl[modList.size()];
+	    mods = modList.toArray( mods );
+	    return mods;
+	}
+
 }



Mime
View raw message