directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r581856 - in /directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap: message/ModificationItemImpl.java schema/SchemaUtils.java util/AttributeUtils.java
Date Thu, 04 Oct 2007 11:41:03 GMT
Author: elecharny
Date: Thu Oct  4 04:41:02 2007
New Revision: 581856

URL: http://svn.apache.org/viewvc?rev=581856&view=rev
Log:
- Added a flag in ModificationItemImpl for operationalAttribute added by the server
- Modified the Utils class to handle List of modificationItemp instead of array

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java?rev=581856&r1=581855&r2=581856&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
Thu Oct  4 04:41:02 2007
@@ -40,6 +40,9 @@
 public class ModificationItemImpl extends ModificationItem
 {
     private static final long serialVersionUID = 1L;
+    
+    /** A flag set when the server has created this item */
+    private boolean serverModified;
 
     /**
      * Create a modificationItemImpl
@@ -52,6 +55,8 @@
     public ModificationItemImpl( int modificationOp, Attribute attribute ) 
     {
         super( modificationOp, AttributeUtils.toAttributeImpl( attribute ) );
+        
+        serverModified = false;
     }
     
     /**
@@ -66,6 +71,8 @@
     {
         super( modification.getModificationOp(), 
             AttributeUtils.toAttributeImpl( modification.getAttribute() ) );
+        
+        serverModified = false;
     }
     
     /**
@@ -76,6 +83,8 @@
     {
         super( modification.getModificationOp(), 
             AttributeUtils.toAttributeImpl( modification.getAttribute() ) );
+        
+        serverModified = false;
     }
     
     /**
@@ -104,6 +113,31 @@
         return new ModificationItemImpl( getModificationOp(), (Attribute)getAttribute().clone()
); 
     }
     
+    
+    
+    /**
+     * 
+     * Tells if this modification has been created by the server or not
+     *
+     * @return <code>true</code> if the server has created this modifictionItem
+     */
+    public boolean isServerModified()
+    {
+        return serverModified;
+    }
+
+    
+    /**
+     * Set the serverModified item
+     *
+     * @param serverModified 
+     */
+    public void setServerModified()
+    {
+        serverModified = true;
+    }
+    
+    
     /**
      * @see Object#toString()
      */
@@ -111,7 +145,14 @@
     {
         StringBuffer sb = new StringBuffer();
         
-        sb.append( "ModificationItem : \n" );
+        sb.append( "ModificationItem" );
+        
+        if ( serverModified )
+        {
+            sb.append( "[op]" );
+        }
+        
+        sb.append( " : \n" );
         
         switch ( getModificationOp() )
         {

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java?rev=581856&r1=581855&r2=581856&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
Thu Oct  4 04:41:02 2007
@@ -28,9 +28,9 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
 
 import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.schema.syntax.AbstractAdsSchemaDescription;
 import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
 import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
@@ -53,21 +53,23 @@
      * @return the resultant entry after the modifications have taken place
      * @throws NamingException if there are problems accessing attributes
      */
-    public static Attributes getTargetEntry( ModificationItemImpl[] mods, Attributes entry
) throws NamingException
+    public static Attributes getTargetEntry( List<ModificationItem> mods, Attributes
entry ) throws NamingException
     {
         Attributes targetEntry = ( Attributes ) entry.clone();
-        for ( int ii = 0; ii < mods.length; ii++ )
+        
+        for ( ModificationItem mod:mods )
         {
-            String id = mods[ii].getAttribute().getID();
+            String id = mod.getAttribute().getID();
 
-            switch ( mods[ii].getModificationOp() )
+            switch ( mod.getModificationOp() )
             {
                 case( DirContext.REPLACE_ATTRIBUTE ):
-                    targetEntry.put( mods[ii].getAttribute() );
+                    targetEntry.put( mod.getAttribute() );
                     break;
+                    
                 case( DirContext.ADD_ATTRIBUTE ):
                     Attribute combined = new AttributeImpl( id );
-                    Attribute toBeAdded = mods[ii].getAttribute();
+                    Attribute toBeAdded = mod.getAttribute();
                     Attribute existing = entry.get( id );
                     
                     if ( existing != null )
@@ -85,8 +87,9 @@
                     
                     targetEntry.put( combined );
                     break;
+                    
                 case( DirContext.REMOVE_ATTRIBUTE ):
-                    Attribute toBeRemoved = mods[ii].getAttribute();
+                    Attribute toBeRemoved = mod.getAttribute();
                     
                     if ( toBeRemoved.size() == 0 )
                     {
@@ -104,9 +107,11 @@
                             }
                         }
                     }
+                    
                     break;
+                    
                 default:
-                    throw new IllegalStateException( "undefined modification type: " + mods[ii].getModificationOp()
);
+                    throw new IllegalStateException( "undefined modification type: " + mod.getModificationOp()
);
             }
         }
         

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?rev=581856&r1=581855&r2=581856&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Thu Oct  4 04:41:02 2007
@@ -22,10 +22,10 @@
 
 import java.text.ParseException;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
@@ -34,6 +34,7 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.ModificationItem;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 
@@ -263,7 +264,7 @@
      * @param type the attributeType spec of the Attribute to extract
      * @return the modification item on the attributeType specified
      */
-    public final static ModificationItemImpl getModificationItem( ModificationItemImpl[]
mods, AttributeType type )
+    public final static ModificationItem getModificationItem( ModificationItem[] mods, AttributeType
type )
     {
         // optimization bypass to avoid cost of the loop below
         if ( type.getNames().length == 1 )
@@ -303,22 +304,91 @@
     
     
     /**
+     * Utility method to extract a modification item from an array of modifications.
+     * 
+     * @param mods the array of ModificationItems to extract the Attribute from.
+     * @param type the attributeType spec of the Attribute to extract
+     * @return the modification item on the attributeType specified
+     */
+    public final static ModificationItem getModificationItem( List<ModificationItem>
mods, AttributeType type )
+    {
+        // optimization bypass to avoid cost of the loop below
+        if ( type.getNames().length == 1 )
+        {
+            for ( ModificationItem mod:mods )
+            {
+                if ( mod.getAttribute().getID().equalsIgnoreCase( type.getNames()[0] ) )
+                {
+                    return mod;
+                }
+            }
+        }
+        
+        // check if the attribute's OID is used
+        for ( ModificationItem mod:mods )
+        {
+            if ( mod.getAttribute().getID().equals( type.getOid() ) )
+            {
+                return mod;
+            }
+        }
+        
+        // iterate through aliases
+        for ( int ii = 0; ii < type.getNames().length; ii++ )
+        {
+            for ( ModificationItem mod:mods )
+            {
+                if ( mod.getAttribute().getID().equalsIgnoreCase( type.getNames()[ii] ) )
+                {
+                    return mod;
+                }
+            }
+        }
+        
+        return null;
+    }
+
+    
+    /**
      * Utility method to extract an attribute from an array of modifications.
      * 
      * @param mods the array of ModificationItems to extract the Attribute from.
      * @param type the attributeType spec of the Attribute to extract
      * @return the extract Attribute or null if no such attribute exists
      */
-    public final static Attribute getAttribute( ModificationItemImpl[] mods, AttributeType
type )
+    public final static Attribute getAttribute( ModificationItem[] mods, AttributeType type
)
     {
-        ModificationItemImpl mod = getModificationItem( mods, type );
+        ModificationItem mod = getModificationItem( mods, type );
+        
         if ( mod != null )
         {
             return mod.getAttribute();
         }
+        
         return null;
     }
     
+
+    /**
+     * Utility method to extract an attribute from a list of modifications.
+     * 
+     * @param mods the list of ModificationItems to extract the Attribute from.
+     * @param type the attributeType spec of the Attribute to extract
+     * @return the extract Attribute or null if no such attribute exists
+     */
+    public final static Attribute getAttribute( List<ModificationItem> mods, AttributeType
type )
+    {
+        ModificationItem mod = getModificationItem( mods, type );
+        
+        if ( mod != null )
+        {
+            return mod.getAttribute();
+        }
+        
+        return null;
+    }
+    
+
     /**
      * Check if an attribute contains a specific value, using the associated matchingRule
for that
      *



Mime
View raw message