directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r434511 [2/2] - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/directory/server/core/subtree/ core/src/main/java/org/apache/directory/server/core/subtree/ protocol-ldap/src/main/java/org/apache/directory/server/ldap/suppo...
Date Thu, 24 Aug 2006 20:29:56 GMT
Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java?rev=434511&r1=434510&r2=434511&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/subtree/SubentryService.java
Thu Aug 24 13:29:56 2006
@@ -75,15 +75,12 @@
     /** the objectClass OID for a subentry */
     private static final String SUBENTRY_OBJECTCLASS_OID = "2.5.17.0";
 
-    public static final String AUTONOUMOUS_AREA = "autonomousArea";
-    public static final String AUTONOUMOUS_AREA_SUBENTRY = "autonomousAreaSubentry";
-
     public static final String AC_AREA = "accessControlSpecificArea";
     public static final String AC_INNERAREA = "accessControlInnerArea";
-    public static final String AC_SUBENTRY = "accessControlSubentries";
+    public static final String AC_SUBENTRIES = "accessControlSubentries";
 
     public static final String SCHEMA_AREA = "subschemaAdminSpecificArea";
-    public static final String SCHEMA_AREA_SUBENTRY = "subschemaSubentry";
+    public static final String SCHEMA_SUBENTRY = "subschemaSubentry";
 
     public static final String COLLECTIVE_AREA = "collectiveAttributeSpecificArea";
     public static final String COLLECTIVE_INNERAREA = "collectiveAttributeInnerArea";
@@ -94,7 +91,7 @@
     public static final String TRIGGER_SUBENTRIES = "triggerSubentries";
 
     public static final String[] SUBENTRY_OPATTRS =
-        { AUTONOUMOUS_AREA_SUBENTRY, AC_SUBENTRY, SCHEMA_AREA_SUBENTRY, COLLECTIVE_ATTRIBUTE_SUBENTRIES,
TRIGGER_SUBENTRIES };
+        { AC_SUBENTRIES, SCHEMA_SUBENTRY, COLLECTIVE_ATTRIBUTE_SUBENTRIES, TRIGGER_SUBENTRIES
};
 
     private static final Logger log = LoggerFactory.getLogger( SubentryService.class );
 
@@ -186,24 +183,24 @@
                 ResultCodeEnum.OBJECTCLASSVIOLATION );
         }
         
-        if ( oc.contains( AUTONOUMOUS_AREA ) )
+        if ( oc.contains( "accessControlSubentry" ) )
         {
-            types &= Subentry.AUTONOMOUS_AREA_SUBENTRY;
+            types |= Subentry.ACCESS_CONTROL_SUBENTRY;
         }
         
-        if ( oc.contains( AC_AREA ) || oc.contains( AC_INNERAREA ) )
+        if ( oc.contains( "subschema" ) )
         {
-            types &= Subentry.ACCESS_CONTROL_SUBENTRY;
+            types |= Subentry.SCHEMA_SUBENTRY;
         }
         
-        if ( oc.contains( SCHEMA_AREA ) )
+        if ( oc.contains( "collectiveAttributeSubentry" ) )
         {
-            types &= Subentry.SCHEMA_SUBENTRY;
+            types |= Subentry.COLLECTIVE_SUBENTRY;
         }
         
-        if ( oc.contains( COLLECTIVE_AREA ) )
+        if ( oc.contains( "triggerSubentry" ) )
         {
-            types &= Subentry.COLLECTIVE_SUBENTRY;
+            types |= Subentry.TRIGGER_SUBENTRY;
         }
         
         return types;
@@ -310,72 +307,51 @@
             LdapDN subentryDn = new LdapDN( subentryDnStr );
             LdapDN apDn = ( LdapDN ) subentryDn.clone();
             apDn.remove( apDn.size() - 1 );
-            SubtreeSpecification ss = subentryCache.getSubentry( subentryDnStr ).getSubtreeSpecification();
+            Subentry subentry = subentryCache.getSubentry( subentryDnStr );
+            SubtreeSpecification ss = subentry.getSubtreeSpecification();
 
             if ( evaluator.evaluate( ss, apDn, dn, objectClasses ) )
-            {
-                Attribute administrativeRole = nexus.lookup( apDn ).get( "administrativeRole"
);
-                NamingEnumeration roles = administrativeRole.getAll();
-                while ( roles.hasMore() )
+            {                
+                Attribute operational;
+                
+                if ( subentry.isAccessControlSubentry() )
                 {
-                    Attribute operational;
-                    String role = ( String ) roles.next();
-
-                    if ( role.equalsIgnoreCase( AUTONOUMOUS_AREA ) )
+                    operational = subentryAttrs.get( AC_SUBENTRIES );
+                    if ( operational == null )
                     {
-                        operational = subentryAttrs.get( AUTONOUMOUS_AREA_SUBENTRY );
-                        if ( operational == null )
-                        {
-                            operational = new LockableAttributeImpl( AUTONOUMOUS_AREA_SUBENTRY
);
-                            subentryAttrs.put( operational );
-                        }
-                    }
-                    else if ( role.equalsIgnoreCase( AC_AREA ) || role.equalsIgnoreCase(
AC_INNERAREA ) )
-                    {
-                        operational = subentryAttrs.get( AC_SUBENTRY );
-                        if ( operational == null )
-                        {
-                            operational = new LockableAttributeImpl( AC_SUBENTRY );
-                            subentryAttrs.put( operational );
-                        }
-                    }
-                    else if ( role.equalsIgnoreCase( SCHEMA_AREA ) )
-                    {
-                        operational = subentryAttrs.get( SCHEMA_AREA_SUBENTRY );
-                        if ( operational == null )
-                        {
-                            operational = new LockableAttributeImpl( SCHEMA_AREA_SUBENTRY
);
-                            subentryAttrs.put( operational );
-                        }
+                        operational = new LockableAttributeImpl( AC_SUBENTRIES );
+                        subentryAttrs.put( operational );
                     }
-                    else if ( role.equalsIgnoreCase( COLLECTIVE_AREA ) || role.equalsIgnoreCase(
COLLECTIVE_INNERAREA ) )
+                    operational.add( subentryDn.toString() );
+                }
+                if ( subentry.isSchemaSubentry() )
+                {
+                    operational = subentryAttrs.get( SCHEMA_SUBENTRY );
+                    if ( operational == null )
                     {
-                        operational = subentryAttrs.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
-                        if ( operational == null )
-                        {
-                            operational = new LockableAttributeImpl( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
-                            subentryAttrs.put( operational );
-                        }
+                        operational = new LockableAttributeImpl( SCHEMA_SUBENTRY );
+                        subentryAttrs.put( operational );
                     }
-                    else if ( role.equalsIgnoreCase( TRIGGER_AREA ) || role.equalsIgnoreCase(
TRIGGER_INNERAREA ) )
+                    operational.add( subentryDn.toString() );
+                }
+                if ( subentry.isCollectiveSubentry() )
+                {
+                    operational = subentryAttrs.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES );
+                    if ( operational == null )
                     {
-                        operational = subentryAttrs.get( TRIGGER_SUBENTRIES );
-                        if ( operational == null )
-                        {
-                            operational = new LockableAttributeImpl( TRIGGER_SUBENTRIES );
-                            subentryAttrs.put( operational );
-                        }
+                        operational = new LockableAttributeImpl( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
+                        subentryAttrs.put( operational );
                     }
-                    else
+                    operational.add( subentryDn.toString() );
+                } 
+                if ( subentry.isTriggerSubentry() )
+                {
+                    operational = subentryAttrs.get( TRIGGER_SUBENTRIES );
+                    if ( operational == null )
                     {
-                        throw new LdapInvalidAttributeValueException( "Encountered invalid
administrativeRole '" + role
-                            + "' in administrative point of subentry " + subentryDnStr
-                            + ". The values of this attribute"
-                            + " are constrained to autonomousArea, accessControlSpecificArea,
accessControlInnerArea,"
-                            + " subschemaAdminSpecificArea, collectiveAttributeSpecificArea,
collectiveAttributeInnerArea,"
-                            + " triggerSpecificArea and triggerInnerArea.", ResultCodeEnum.CONSTRAINTVIOLATION
);
+                        operational = new LockableAttributeImpl( TRIGGER_SUBENTRIES );
+                        subentryAttrs.put( operational );
                     }
-
                     operational.add( subentryDn.toString() );
                 }
             }
@@ -414,7 +390,9 @@
              * this new subentry.
              * ----------------------------------------------------------------
              */
-            Attributes operational = getSubentryOperatationalAttributes( normName, administrativeRole
);
+            Subentry subentry = new Subentry();
+            subentry.setTypes( getSubentryTypes( entry ) );
+            Attributes operational = getSubentryOperatationalAttributes( normName, subentry
);
 
             /* ----------------------------------------------------------------
              * Parse the subtreeSpecification of the subentry and add it to the
@@ -478,76 +456,51 @@
                 LdapDN subentryDn = new LdapDN( subentryDnStr );
                 LdapDN apDn = ( LdapDN ) subentryDn.clone();
                 apDn.remove( apDn.size() - 1 );
-                SubtreeSpecification ss = subentryCache.getSubentry( subentryDn.toNormName()
).getSubtreeSpecification();
+                Subentry subentry = subentryCache.getSubentry( subentryDnStr );
+                SubtreeSpecification ss = subentry.getSubtreeSpecification();
 
                 if ( evaluator.evaluate( ss, apDn, normName, objectClasses ) )
                 {
-                    Attribute administrativeRole = nexus.lookup( apDn ).get( "administrativeRole"
);
-                    NamingEnumeration roles = administrativeRole.getAll();
-                    while ( roles.hasMore() )
+                    Attribute operational;
+                    
+                    if ( subentry.isAccessControlSubentry() )
                     {
-                        Attribute operational;
-                        String role = ( String ) roles.next();
-
-                        if ( role.equalsIgnoreCase( AUTONOUMOUS_AREA ) )
-                        {
-                            operational = entry.get( AUTONOUMOUS_AREA_SUBENTRY );
-                            if ( operational == null )
-                            {
-                                operational = new LockableAttributeImpl( AUTONOUMOUS_AREA_SUBENTRY
);
-                                entry.put( operational );
-                            }
-                        }
-                        else if ( role.equalsIgnoreCase( AC_AREA ) || role.equalsIgnoreCase(
AC_INNERAREA ) )
-                        {
-                            operational = entry.get( AC_SUBENTRY );
-                            if ( operational == null )
-                            {
-                                operational = new LockableAttributeImpl( AC_SUBENTRY );
-                                entry.put( operational );
-                            }
-                        }
-                        else if ( role.equalsIgnoreCase( SCHEMA_AREA ) )
+                        operational = entry.get( AC_SUBENTRIES );
+                        if ( operational == null )
                         {
-                            operational = entry.get( SCHEMA_AREA_SUBENTRY );
-                            if ( operational == null )
-                            {
-                                operational = new LockableAttributeImpl( SCHEMA_AREA_SUBENTRY
);
-                                entry.put( operational );
-                            }
+                            operational = new LockableAttributeImpl( AC_SUBENTRIES );
+                            entry.put( operational );
                         }
-                        else if ( role.equalsIgnoreCase( COLLECTIVE_AREA )
-                            || role.equalsIgnoreCase( COLLECTIVE_INNERAREA ) )
+                        operational.add( subentryDn.toString() );
+                    }
+                    if ( subentry.isSchemaSubentry() )
+                    {
+                        operational = entry.get( SCHEMA_SUBENTRY );
+                        if ( operational == null )
                         {
-                            operational = entry.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES );
-                            if ( operational == null )
-                            {
-                                operational = new LockableAttributeImpl( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
-                                entry.put( operational );
-                            }
+                            operational = new LockableAttributeImpl( SCHEMA_SUBENTRY );
+                            entry.put( operational );
                         }
-                        else if ( role.equalsIgnoreCase( TRIGGER_AREA ) || role.equalsIgnoreCase(
TRIGGER_INNERAREA ) )
+                        operational.add( subentryDn.toString() );
+                    }
+                    if ( subentry.isCollectiveSubentry() )
+                    {
+                        operational = entry.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES );
+                        if ( operational == null )
                         {
-                            operational = entry.get( TRIGGER_SUBENTRIES );
-                            if ( operational == null )
-                            {
-                                operational = new LockableAttributeImpl( TRIGGER_SUBENTRIES
);
-                                entry.put( operational );
-                            }
+                            operational = new LockableAttributeImpl( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
+                            entry.put( operational );
                         }
-                        else
+                        operational.add( subentryDn.toString() );
+                    }
+                    if ( subentry.isTriggerSubentry() )
+                    {
+                        operational = entry.get( TRIGGER_SUBENTRIES );
+                        if ( operational == null )
                         {
-                            throw new LdapInvalidAttributeValueException(
-                                "Encountered invalid administrativeRole '"
-                                    + role
-                                    + "' in administrative point of subentry "
-                                    + subentryDnStr
-                                    + ". The values of this attribute"
-                                    + " are constrained to autonomousArea, accessControlSpecificArea,
accessControlInnerArea,"
-                                    + " subschemaAdminSpecificArea, collectiveAttributeSpecificArea,
collectiveAttributeInnerArea,"
-                                    + " triggerArea and triggerInnerArea.", ResultCodeEnum.CONSTRAINTVIOLATION
);
+                            operational = new LockableAttributeImpl( TRIGGER_SUBENTRIES );
+                            entry.put( operational );
                         }
-
                         operational.add( subentryDn.toString() );
                     }
                 }
@@ -736,11 +689,11 @@
             rdn.normalize( attrRegistry.getNormalizerMapping() );
             newName.normalize( attrRegistry.getNormalizerMapping() );
 
-            subentryCache.setSubentry( newName.toNormName(), ss, subentry.getTypes() );
+            String newNormName = newName.toNormName();
+            subentryCache.setSubentry( newNormName, ss, subentry.getTypes() );
             next.modifyRn( name, newRn, deleteOldRn );
 
-            Attributes apAttrs = nexus.lookup( apName );
-            Attribute administrativeRole = ServerUtils.getAttribute( administrativeRoleType,
apAttrs );
+            subentry = subentryCache.getSubentry( newNormName );
             ExprNode filter = new PresenceNode( oidRegistry.getOid( "objectclass" ) );
             SearchControls controls = new SearchControls();
             controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
@@ -755,7 +708,7 @@
 
                 if ( evaluator.evaluate( ss, apName, dn, ServerUtils.getAttribute( objectClassType,
candidate ) ) )
                 {
-                    nexus.modify( dn, getOperationalModsForReplace( name, newName, administrativeRole,
candidate ) );
+                    nexus.modify( dn, getOperationalModsForReplace( name, newName, subentry,
candidate ) );
                 }
             }
         }
@@ -807,11 +760,11 @@
             rdn.normalize( attrRegistry.getNormalizerMapping() );
             newName.normalize( attrRegistry.getNormalizerMapping() );
             
-            subentryCache.setSubentry( newName.toNormName(), ss, subentry.getTypes() );
+            String newNormName = newName.toNormName();
+            subentryCache.setSubentry( newNormName, ss, subentry.getTypes() );
             next.move( oriChildName, newParentName, newRn, deleteOldRn );
 
-            Attributes apAttrs = nexus.lookup( apName );
-            Attribute administrativeRole = ServerUtils.getAttribute( administrativeRoleType,
apAttrs );
+            subentry = subentryCache.getSubentry( newNormName );
 
             ExprNode filter = new PresenceNode( oidRegistry.getOid( "objectclass" ) );
             SearchControls controls = new SearchControls();
@@ -827,7 +780,7 @@
 
                 if ( evaluator.evaluate( ss, apName, dn, ServerUtils.getAttribute( objectClassType,
candidate ) ) )
                 {
-                    nexus.modify( dn, getOperationalModsForReplace( oriChildName, newName,
administrativeRole,
+                    nexus.modify( dn, getOperationalModsForReplace( oriChildName, newName,
subentry,
                         candidate ) );
                 }
             }
@@ -874,11 +827,11 @@
             newName.remove( newName.size() - 1 );
             newName.add( newParentName.get( newParentName.size() - 1 ) );
 
-            subentryCache.setSubentry( newName.toString(), ss, subentry.getTypes() );
+            String newNormName = newName.toNormName();
+            subentryCache.setSubentry( newNormName, ss, subentry.getTypes() );
             next.move( oriChildName, newParentName );
 
-            Attributes apAttrs = nexus.lookup( apName );
-            Attribute administrativeRole = apAttrs.get( "administrativeRole" );
+            subentry = subentryCache.getSubentry( newNormName );
 
             ExprNode filter = new PresenceNode( "objectclass" );
             SearchControls controls = new SearchControls();
@@ -895,7 +848,7 @@
 
                 if ( evaluator.evaluate( ss, apName, dn, candidate.get( "objectClass" ) )
)
                 {
-                    nexus.modify( dn, getOperationalModsForReplace( oriChildName, newName,
administrativeRole,
+                    nexus.modify( dn, getOperationalModsForReplace( oriChildName, newName,
subentry,
                         candidate ) );
                 }
             }
@@ -1049,9 +1002,8 @@
             }
 
             // search for all selected entries by the new SS and add references to subentry
-            Attributes apAttrs = nexus.lookup( apName );
-            Attribute administrativeRole = ServerUtils.getAttribute( administrativeRoleType,
apAttrs );
-            Attributes operational = getSubentryOperatationalAttributes( name, administrativeRole
);
+            Subentry subentry = subentryCache.getSubentry( name.toNormName() );
+            Attributes operational = getSubentryOperatationalAttributes( name, subentry );
             LdapDN newBaseDn = ( LdapDN ) apName.clone();
             newBaseDn.addAll( ssNew.getBase() );
             subentries = nexus.search( newBaseDn, factoryCfg.getEnvironment(), filter, controls
);
@@ -1135,9 +1087,8 @@
             }
 
             // search for all selected entries by the new SS and add references to subentry
-            Attributes apAttrs = nexus.lookup( apName );
-            Attribute administrativeRole = apAttrs.get( "administrativeRole" );
-            Attributes operational = getSubentryOperatationalAttributes( name, administrativeRole
);
+            Subentry subentry = subentryCache.getSubentry( name.toNormName() );
+            Attributes operational = getSubentryOperatationalAttributes( name, subentry );
             LdapDN newBaseDn = ( LdapDN ) apName.clone();
             newBaseDn.addAll( ssNew.getBase() );
             subentries = nexus.search( newBaseDn, factoryCfg.getEnvironment(), filter, controls
);
@@ -1165,97 +1116,73 @@
     // Utility Methods
     // -----------------------------------------------------------------------
 
-    private ModificationItem[] getOperationalModsForReplace( Name oldName, Name newName,
Attribute administrativeRole,
+    private ModificationItem[] getOperationalModsForReplace( Name oldName, Name newName,
Subentry subentry,
         Attributes entry ) throws NamingException
     {
         List modList = new ArrayList();
-        NamingEnumeration roles = administrativeRole.getAll();
-        while ( roles.hasMore() )
-        {
-            Attribute operational;
-            String role = ( String ) roles.next();
+        
+        Attribute operational;
 
-            if ( role.equalsIgnoreCase( AUTONOUMOUS_AREA ) )
+        if ( subentry.isAccessControlSubentry() )
+        {
+            operational = ( Attribute ) entry.get( AC_SUBENTRIES ).clone();
+            if ( operational == null )
             {
-                operational = ( Attribute ) entry.get( AUTONOUMOUS_AREA_SUBENTRY ).clone();
-                if ( operational == null )
-                {
-                    operational = new LockableAttributeImpl( AUTONOUMOUS_AREA_SUBENTRY );
-                    operational.add( newName.toString() );
-                }
-                else
-                {
-                    operational.remove( oldName.toString() );
-                    operational.add( newName.toString() );
-                }
+                operational = new LockableAttributeImpl( AC_SUBENTRIES );
+                operational.add( newName.toString() );
             }
-            else if ( role.equalsIgnoreCase( AC_AREA ) || role.equalsIgnoreCase( AC_INNERAREA
) )
+            else
             {
-                operational = ( Attribute ) entry.get( AC_SUBENTRY ).clone();
-                if ( operational == null )
-                {
-                    operational = new LockableAttributeImpl( AC_SUBENTRY );
-                    operational.add( newName.toString() );
-                }
-                else
-                {
-                    operational.remove( oldName.toString() );
-                    operational.add( newName.toString() );
-                }
+                operational.remove( oldName.toString() );
+                operational.add( newName.toString() );
             }
-            else if ( role.equalsIgnoreCase( SCHEMA_AREA ) )
+            modList.add( new ModificationItem( DirContext.REPLACE_ATTRIBUTE, operational
) );
+        }
+        if ( subentry.isSchemaSubentry() )
+        {
+            operational = ( Attribute ) entry.get( SCHEMA_SUBENTRY ).clone();
+            if ( operational == null )
             {
-                operational = ( Attribute ) entry.get( SCHEMA_AREA_SUBENTRY ).clone();
-                if ( operational == null )
-                {
-                    operational = new LockableAttributeImpl( SCHEMA_AREA_SUBENTRY );
-                    operational.add( newName.toString() );
-                }
-                else
-                {
-                    operational.remove( oldName.toString() );
-                    operational.add( newName.toString() );
-                }
+                operational = new LockableAttributeImpl( SCHEMA_SUBENTRY );
+                operational.add( newName.toString() );
             }
-            else if ( role.equalsIgnoreCase( COLLECTIVE_AREA ) || role.equalsIgnoreCase(
COLLECTIVE_INNERAREA ) )
+            else
             {
-                operational = ( Attribute ) entry.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES ).clone();
-                if ( operational == null )
-                {
-                    operational = new LockableAttributeImpl( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
-                    operational.add( newName.toString() );
-                }
-                else
-                {
-                    operational.remove( oldName.toString() );
-                    operational.add( newName.toString() );
-                }
+                operational.remove( oldName.toString() );
+                operational.add( newName.toString() );
             }
-            else if ( role.equalsIgnoreCase( TRIGGER_AREA ) || role.equalsIgnoreCase( TRIGGER_INNERAREA
) )
+            modList.add( new ModificationItem( DirContext.REPLACE_ATTRIBUTE, operational
) );
+        }
+        if ( subentry.isCollectiveSubentry() )
+        {
+            operational = ( Attribute ) entry.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES ).clone();
+            if ( operational == null )
             {
-                operational = ( Attribute ) entry.get( TRIGGER_SUBENTRIES ).clone();
-                if ( operational == null )
-                {
-                    operational = new LockableAttributeImpl( TRIGGER_SUBENTRIES );
-                    operational.add( newName.toString() );
-                }
-                else
-                {
-                    operational.remove( oldName.toString() );
-                    operational.add( newName.toString() );
-                }
+                operational = new LockableAttributeImpl( COLLECTIVE_ATTRIBUTE_SUBENTRIES
);
+                operational.add( newName.toString() );
             }
             else
             {
-                throw new LdapInvalidAttributeValueException( "Encountered invalid administrativeRole
'" + role
-                    + "' in administrative point of subentry " + oldName + ". The values
of this attribute"
-                    + " are constrained to autonomousArea, accessControlSpecificArea, accessControlInnerArea,"
-                    + " subschemaAdminSpecificArea, collectiveAttributeSpecificArea, collectiveAttributeInnerArea,"
-                    + " triggerArea and triggerInnerArea.", ResultCodeEnum.CONSTRAINTVIOLATION
);
+                operational.remove( oldName.toString() );
+                operational.add( newName.toString() );
             }
-
             modList.add( new ModificationItem( DirContext.REPLACE_ATTRIBUTE, operational
) );
         }
+        if ( subentry.isTriggerSubentry() )
+        {
+            operational = ( Attribute ) entry.get( TRIGGER_SUBENTRIES ).clone();
+            if ( operational == null )
+            {
+                operational = new LockableAttributeImpl( TRIGGER_SUBENTRIES );
+                operational.add( newName.toString() );
+            }
+            else
+            {
+                operational.remove( oldName.toString() );
+                operational.add( newName.toString() );
+            }
+            modList.add( new ModificationItem( DirContext.REPLACE_ATTRIBUTE, operational
) );
+        } 
 
         ModificationItem[] mods = new ModificationItem[modList.size()];
         return ( ModificationItem[] ) modList.toArray( mods );
@@ -1271,77 +1198,53 @@
      * @return the set of attributes to be added or removed from entries
      * @throws NamingException if there are problems accessing attributes
      */
-    private Attributes getSubentryOperatationalAttributes( Name name, Attribute administrativeRole
)
+    private Attributes getSubentryOperatationalAttributes( Name name, Subentry subentry )
         throws NamingException
     {
         Attributes operational = new LockableAttributesImpl();
-        NamingEnumeration roles = administrativeRole.getAll();
-        while ( roles.hasMore() )
+        
+        if ( subentry.isAccessControlSubentry() )
         {
-            String role = ( String ) roles.next();
-
-            if ( role.equalsIgnoreCase( AUTONOUMOUS_AREA ) )
+            if ( operational.get( AC_SUBENTRIES ) == null )
             {
-                if ( operational.get( AUTONOUMOUS_AREA_SUBENTRY ) == null )
-                {
-                    operational.put( AUTONOUMOUS_AREA_SUBENTRY, name.toString() );
-                }
-                else
-                {
-                    operational.get( AUTONOUMOUS_AREA_SUBENTRY ).add( name.toString() );
-                }
+                operational.put( AC_SUBENTRIES, name.toString() );
             }
-            else if ( role.equalsIgnoreCase( AC_AREA ) || role.equalsIgnoreCase( AC_INNERAREA
) )
+            else
             {
-                if ( operational.get( AC_SUBENTRY ) == null )
-                {
-                    operational.put( AC_SUBENTRY, name.toString() );
-                }
-                else
-                {
-                    operational.get( AC_SUBENTRY ).add( name.toString() );
-                }
+                operational.get( AC_SUBENTRIES ).add( name.toString() );
             }
-            else if ( role.equalsIgnoreCase( SCHEMA_AREA ) )
+        }
+        if ( subentry.isSchemaSubentry() )
+        {
+            if ( operational.get( SCHEMA_SUBENTRY ) == null )
             {
-                if ( operational.get( SCHEMA_AREA_SUBENTRY ) == null )
-                {
-                    operational.put( SCHEMA_AREA_SUBENTRY, name.toString() );
-                }
-                else
-                {
-                    operational.get( SCHEMA_AREA_SUBENTRY ).add( name.toString() );
-                }
+                operational.put( SCHEMA_SUBENTRY, name.toString() );
             }
-            else if ( role.equalsIgnoreCase( COLLECTIVE_AREA ) || role.equalsIgnoreCase(
COLLECTIVE_INNERAREA ) )
+            else
             {
-                if ( operational.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES ) == null )
-                {
-                    operational.put( COLLECTIVE_ATTRIBUTE_SUBENTRIES, name.toString() );
-                }
-                else
-                {
-                    operational.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES ).add( name.toString()
);
-                }
+                operational.get( SCHEMA_SUBENTRY ).add( name.toString() );
             }
-            else if ( role.equalsIgnoreCase( TRIGGER_AREA ) || role.equalsIgnoreCase( TRIGGER_INNERAREA
) )
+        }
+        if ( subentry.isCollectiveSubentry() )
+        {
+            if ( operational.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES ) == null )
             {
-                if ( operational.get( TRIGGER_SUBENTRIES ) == null )
-                {
-                    operational.put( TRIGGER_SUBENTRIES, name.toString() );
-                }
-                else
-                {
-                    operational.get( TRIGGER_SUBENTRIES ).add( name.toString() );
-                }
+                operational.put( COLLECTIVE_ATTRIBUTE_SUBENTRIES, name.toString() );
+            }
+            else
+            {
+                operational.get( COLLECTIVE_ATTRIBUTE_SUBENTRIES ).add( name.toString() );
+            }
+        }
+        if ( subentry.isTriggerSubentry() )
+        {
+            if ( operational.get( TRIGGER_SUBENTRIES ) == null )
+            {
+                operational.put( TRIGGER_SUBENTRIES, name.toString() );
             }
             else
             {
-                throw new LdapInvalidAttributeValueException( "Encountered invalid administrativeRole
'" + role
-                    + "' in administrative point of subentry " + name + ". The values of
this attribute are"
-                    + " are constrained to autonomousArea, accessControlSpecificArea, accessControlInnerArea,"
-                    + " subschemaAdminSpecificArea, collectiveAttributeSpecificArea, collectiveAttributeInnerArea,"
-                    + " triggerArea and triggerInnerArea.", ResultCodeEnum.CONSTRAINTVIOLATION
);
+                operational.get( TRIGGER_SUBENTRIES ).add( name.toString() );
             }
         }
 

Modified: directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java?rev=434511&r1=434510&r2=434511&view=diff
==============================================================================
--- directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
(original)
+++ directory/trunks/apacheds/protocol-ldap/src/main/java/org/apache/directory/server/ldap/support/extended/JavaStoredProcedureExtendedOperationHandler.java
Thu Aug 24 13:29:56 2006
@@ -17,10 +17,7 @@
 package org.apache.directory.server.ldap.support.extended;
 
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -28,13 +25,13 @@
 
 import javax.naming.NamingException;
 
+import org.apache.commons.lang.SerializationUtils;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.core.sp.LdapClassLoader;
 import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure;
 import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure.StoredProcedureParameter;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.util.ClassUtils;
 import org.apache.directory.shared.ldap.util.DirectoryClassUtils;
 import org.apache.directory.shared.ldap.util.SpringClassUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -59,7 +56,6 @@
         {
             StoredProcedureParameter pPojo = ( StoredProcedureParameter ) it.next();
             
-            // Get type from String even if it holds a primitive type name
             Class type;
             try
             {
@@ -74,45 +70,17 @@
             
             types.add( type );
             
-            byte[] value = pPojo.getValue();
+            byte[] serializedValue = pPojo.getValue();
             
-            /**
-             * If the type name refers to a Java primitive then
-             * we know that the value is encoded as its String representation and
-             * we retrieve the String and initialize a wrapper of the primitive.
-             * 
-             * Note that this is just how we prefer Java Specific Stored Procedures
-             * to handle parameters. Of course we do not have to it this way.
-             */
-            if ( type.isPrimitive() )
+            try
             {
-                values.add( getInitializedPrimitiveWrapperInstance( type, value ) );
+                values.add( SerializationUtils.deserialize( serializedValue ) );
             }
-            /**
-             * If the type is a complex Java type then
-             * just deserialize the object.
-             */
-            else
+            catch ( Exception e )
             {
-                try
-                {
-                    // TODO Irritating syntax! Just wanted to see how it looks like..
-                    values.add
-                    ( 
-                        (
-                            new ObjectInputStream
-                            ( 
-                                new ByteArrayInputStream( value )
-                            ) 
-                        ).readObject()
-                    );
-                }
-                catch ( Exception e )
-                {
-                    NamingException ne = new NamingException();
-                    ne.setRootCause( e );
-                    throw ne;
-                }
+                NamingException ne = new NamingException();
+                ne.setRootCause( e );
+                throw ne;
             }
             
         }
@@ -121,12 +89,11 @@
         Object response = executeProcedure( ctx, StringTools.utf8ToString( pojo.getProcedure()
), 
                 ( Class[] ) types.toArray( EMPTY_CLASS_ARRAY ), values.toArray() );
         
-        ByteArrayOutputStream baos;
+        byte[] serializedResponse = null;
+        
         try
         {
-            baos = new ByteArrayOutputStream();
-            ObjectOutputStream oos = new ObjectOutputStream( baos );
-            oos.writeObject( response );
+            serializedResponse = SerializationUtils.serialize( ( Serializable ) response
);
         }
         catch ( Exception e )
         {
@@ -135,10 +102,9 @@
             throw ne;
         }
         
-        return baos.toByteArray();
+        return serializedResponse;
         
     }
-
     
     public Object executeProcedure( ServerLdapContext ctx, String procedure, Class[] types,
Object[] values ) 
         throws NamingException
@@ -162,21 +128,4 @@
         }
     }
     
-    
-    private Object getInitializedPrimitiveWrapperInstance( Class type, byte[] value )
-    {
-        Object instance = null;
-        try
-        {
-            instance = ClassUtils
-                    .primitiveToWrapper( type )
-                    .getConstructor( new Class[] {String.class} )
-                    .newInstance( new Object[] { StringTools.utf8ToString( value ) } );
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
-        return instance;
-    }
 }



Mime
View raw message