directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r887284 [2/2] - /directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/
Date Fri, 04 Dec 2009 17:34:14 GMT
Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java?rev=887284&r1=887283&r2=887284&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SyntaxSynchronizer.java
Fri Dec  4 17:34:13 2009
@@ -58,42 +58,44 @@
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( SyntaxSynchronizer.class );
 
+
     /**
      * Creates a new instance of SyntaxSynchronizer.
      *
      * @param schemaManager The global schemaManager
      * @throws Exception If the initialization failed
      */
-    public SyntaxSynchronizer( SchemaManager schemaManager ) 
-        throws Exception
+    public SyntaxSynchronizer( SchemaManager schemaManager ) throws Exception
     {
         super( schemaManager );
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
-    public boolean modify( ModifyOperationContext opContext, ServerEntry targetEntry, boolean
cascade ) throws Exception
+    public boolean modify( ModifyOperationContext opContext, ServerEntry targetEntry, boolean
cascade )
+        throws Exception
     {
         LdapDN name = opContext.getDn();
         ServerEntry entry = opContext.getEntry();
         String oid = getOid( entry );
-        LdapSyntax syntax = factory.getSyntax( schemaManager, targetEntry, schemaManager.getRegistries(),
getSchemaName( name ) );
+        LdapSyntax syntax = factory.getSyntax( schemaManager, targetEntry, schemaManager.getRegistries(),
+            getSchemaName( name ) );
         String schemaName = getSchemaName( entry.getDn() );
-        
+
         if ( isSchemaEnabled( schemaName ) )
         {
             schemaManager.unregisterLdapSyntax( oid );
             schemaManager.add( syntax );
-            
+
             return SCHEMA_MODIFIED;
         }
-        
+
         return SCHEMA_UNCHANGED;
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
@@ -108,10 +110,10 @@
 
         // The new schemaObject's OID must not already exist
         checkOidIsUnique( entry );
-        
+
         // Build the new Syntax from the given entry
         String schemaName = getSchemaName( dn );
-        
+
         LdapSyntax syntax = factory.getSyntax( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
 
         // At this point, the constructed Syntax has not been checked against the 
@@ -119,31 +121,31 @@
         // there, if the schema and the Syntax are both enabled.
         Schema schema = schemaManager.getLoadedSchema( schemaName );
         List<Throwable> errors = new ArrayList<Throwable>();
-        
+
         if ( schema.isEnabled() && syntax.isEnabled() )
         {
             // As we may break the registries, work on a cloned registries
             Registries clonedRegistries = schemaManager.getRegistries().clone();
-            
+
             // Inject the newly created Syntax in the cloned registries
             clonedRegistries.add( errors, syntax );
-            
+
             // Remove the cloned registries
             clonedRegistries.clear();
-            
+
             // If we didn't get any error, apply the addition to the real retistries
             if ( errors.isEmpty() )
             {
                 // Apply the addition to the real registries
-            	schemaManager.getRegistries().add( errors, syntax );
+                schemaManager.getRegistries().add( errors, syntax );
 
                 LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
             }
             else
             {
                 // We have some error : reject the addition and get out
-                String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + " into
the registries, "+
-                    "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
+                String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + " into
the registries, "
+                    + "the resulting registries would be inconsistent :" + StringTools.listToString(
errors );
                 LOG.info( msg );
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
@@ -152,20 +154,28 @@
         {
             // At least, we register the OID in the globalOidRegistry, and associates it
with the
             // schema
-            schemaManager.getRegistries().associateWithSchema( syntax );
+            schemaManager.getRegistries().associateWithSchema( errors, syntax );
+
+            if ( !errors.isEmpty() )
+            {
+                String msg = "Cannot add the Syntax " + entry.getDn().getUpName() + " into
the registries, "
+                    + "we have got some errors :" + StringTools.listToString( errors );
+
+                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+            }
 
             LOG.debug( "The Syntax {} cannot be added in schema {}", dn.getUpName(), schemaName
);
         }
     }
 
-    
+
     /**
      * Check if a syntax is used by an AT or a MR
      */
     private List<SchemaObject> checkInUse( String oid )
     {
         List<SchemaObject> dependees = new ArrayList<SchemaObject>();
-        
+
         for ( AttributeType attributeType : schemaManager.getAttributeTypeRegistry() )
         {
             if ( oid.equals( attributeType.getSyntax().getOid() ) )
@@ -173,7 +183,7 @@
                 dependees.add( attributeType );
             }
         }
-        
+
         for ( MatchingRule matchingRule : schemaManager.getMatchingRuleRegistry() )
         {
             if ( oid.equals( matchingRule.getSyntax().getOid() ) )
@@ -181,11 +191,11 @@
                 dependees.add( matchingRule );
             }
         }
-        
+
         return dependees;
     }
-    
-    
+
+
     /**
      * Get the list of SchemaObject's name using a given syntax
      */
@@ -193,7 +203,7 @@
     {
         StringBuilder sb = new StringBuilder();
         boolean isFirst = true;
-        
+
         for ( SchemaObject schemaObject : schemaObjects )
         {
             if ( isFirst )
@@ -204,14 +214,14 @@
             {
                 sb.append( ", " );
             }
-            
-            sb.append(  schemaObject.getName() );
+
+            sb.append( schemaObject.getName() );
         }
-        
+
         return sb.toString();
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
@@ -220,14 +230,14 @@
         LdapDN dn = entry.getDn();
         LdapDN parentDn = ( LdapDN ) dn.clone();
         parentDn.remove( parentDn.size() - 1 );
-        
+
         // The parent DN must be ou=syntaxes,cn=<schemaName>,ou=schema
         checkParent( parentDn, schemaManager, SchemaConstants.SYNTAX );
-        
+
         // Get the Syntax from the given entry ( it has been grabbed from the server earlier)
         String schemaName = getSchemaName( entry.getDn() );
         LdapSyntax syntax = factory.getSyntax( schemaManager, entry, schemaManager.getRegistries(),
schemaName );
-        
+
         // Applies the Registries to this Syntax 
         Schema schema = schemaManager.getLoadedSchema( schemaName );
 
@@ -237,18 +247,18 @@
         }
 
         String oid = syntax.getOid();
-        
+
         if ( isSchemaEnabled( schemaName ) )
         {
             if ( schemaManager.getRegistries().isReferenced( syntax ) )
             {
-                String msg = "Cannot delete " + entry.getDn().getUpName() + ", as there are
some " +
-                    " dependant SchemaObjects :\n" + getReferenced( syntax );
+                String msg = "Cannot delete " + entry.getDn().getUpName() + ", as there are
some "
+                    + " dependant SchemaObjects :\n" + getReferenced( syntax );
                 LOG.warn( msg );
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
         }
-        
+
         deleteFromSchema( syntax, schemaName );
 
         if ( schemaManager.getLdapSyntaxRegistry().contains( oid ) )
@@ -256,10 +266,10 @@
             // Update the references.
             // The SyntaxChecker
             schemaManager.getRegistries().delReference( syntax, syntax.getSyntaxChecker()
);
-            
+
             // Update the Registry
             schemaManager.unregisterLdapSyntax( oid );
-            
+
             LOG.debug( "Removed {} from the enabled schema {}", syntax, schemaName );
         }
         else
@@ -269,7 +279,7 @@
         }
     }
 
-    
+
     /**
      * {@inheritDoc}
      */
@@ -280,23 +290,23 @@
 
         // Check that this syntax is not used by an AttributeType
         List<SchemaObject> dependees = checkInUse( oldOid );
-        
+
         if ( dependees.size() != 0 )
         {
-            throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid

-              + " cannot be deleted until all entities" 
-              + " using this syntax have also been deleted.  The following dependees exist:
" 
-              + getNames( dependees ), 
-              ResultCodeEnum.UNWILLING_TO_PERFORM );
+            throw new LdapOperationNotSupportedException(
+                "The syntax with OID " + oldOid + " cannot be deleted until all entities"
+                    + " using this syntax have also been deleted.  The following dependees
exist: "
+                    + getNames( dependees ), ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
 
         ServerEntry targetEntry = ( ServerEntry ) entry.clone();
         String newOid = ( String ) newRdn.getValue();
         checkOidIsUnique( newOid );
-        
+
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
-        LdapSyntax syntax = factory.getSyntax( schemaManager, targetEntry, schemaManager.getRegistries(),
getSchemaName( entry.getDn() ) );
-        
+        LdapSyntax syntax = factory.getSyntax( schemaManager, targetEntry, schemaManager.getRegistries(),
+            getSchemaName( entry.getDn() ) );
+
         if ( isSchemaEnabled( schemaName ) )
         {
             schemaManager.unregisterLdapSyntax( oldOid );
@@ -322,22 +332,22 @@
 
         // Check that this syntax is not used by an AttributeType
         List<SchemaObject> dependees = checkInUse( oldOid );
-        
+
         if ( dependees.size() != 0 )
         {
-            throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid

-              + " cannot be deleted until all entities" 
-              + " using this syntax have also been deleted.  The following dependees exist:
" 
-              + getNames( dependees ), 
-              ResultCodeEnum.UNWILLING_TO_PERFORM );
+            throw new LdapOperationNotSupportedException(
+                "The syntax with OID " + oldOid + " cannot be deleted until all entities"
+                    + " using this syntax have also been deleted.  The following dependees
exist: "
+                    + getNames( dependees ), ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
 
         ServerEntry targetEntry = ( ServerEntry ) entry.clone();
         String newOid = ( String ) newRn.getValue();
         checkOidIsUnique( newOid );
-        
+
         targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );
-        LdapSyntax syntax = factory.getSyntax( schemaManager, targetEntry, schemaManager.getRegistries(),
getSchemaName( newParentName ) );
+        LdapSyntax syntax = factory.getSyntax( schemaManager, targetEntry, schemaManager.getRegistries(),
+            getSchemaName( newParentName ) );
 
         if ( isSchemaEnabled( oldSchemaName ) )
         {
@@ -360,8 +370,7 @@
     }
 
 
-    public void move( LdapDN oriChildName, LdapDN newParentName, ServerEntry entry, boolean
cascade ) 
-        throws Exception
+    public void move( LdapDN oriChildName, LdapDN newParentName, ServerEntry entry, boolean
cascade ) throws Exception
     {
         checkNewParent( newParentName );
         String oid = getOid( entry );
@@ -369,20 +378,21 @@
         String newSchemaName = getSchemaName( newParentName );
 
         // schema dep check before delete to be handled by the SchemaPartition
-//        
-//        Set<ServerEntry> dependees = dao.listSyntaxDependents( oid );
-//        
-//        if ( dependees != null && dependees.size() > 0 )
-//        {
-//            throw new LdapOperationNotSupportedException( "The syntax with OID " + oid

-//                + " cannot be deleted until all entities" 
-//                + " using this syntax have also been deleted.  The following dependees
exist: " 
-//                + getOids( dependees ), 
-//                ResultCodeEnum.UNWILLING_TO_PERFORM );
-//        }
-        
-        LdapSyntax syntax = factory.getSyntax( schemaManager, entry, schemaManager.getRegistries(),
getSchemaName( newParentName ) );
-        
+        //        
+        //        Set<ServerEntry> dependees = dao.listSyntaxDependents( oid );
+        //        
+        //        if ( dependees != null && dependees.size() > 0 )
+        //        {
+        //            throw new LdapOperationNotSupportedException( "The syntax with OID
" + oid 
+        //                + " cannot be deleted until all entities" 
+        //                + " using this syntax have also been deleted.  The following dependees
exist: " 
+        //                + getOids( dependees ), 
+        //                ResultCodeEnum.UNWILLING_TO_PERFORM );
+        //        }
+
+        LdapSyntax syntax = factory.getSyntax( schemaManager, entry, schemaManager.getRegistries(),
+            getSchemaName( newParentName ) );
+
         if ( isSchemaEnabled( oldSchemaName ) )
         {
             schemaManager.unregisterLdapSyntax( oid );
@@ -391,7 +401,7 @@
         {
             unregisterOids( syntax );
         }
-        
+
         if ( isSchemaEnabled( newSchemaName ) )
         {
             schemaManager.add( syntax );
@@ -401,28 +411,29 @@
             registerOids( syntax );
         }
     }
-    
-    
+
+
     private void checkNewParent( LdapDN newParent ) throws NamingException
     {
         if ( newParent.size() != 3 )
         {
-            throw new LdapInvalidNameException( 
-                "The parent dn of a syntax should be at most 3 name components in length.",

+            throw new LdapInvalidNameException(
+                "The parent dn of a syntax should be at most 3 name components in length.",
                 ResultCodeEnum.NAMING_VIOLATION );
         }
-        
+
         Rdn rdn = newParent.getRdn();
-        if ( ! schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals(
SchemaConstants.OU_AT_OID ) )
+        if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals(
+            SchemaConstants.OU_AT_OID ) )
         {
-            throw new LdapInvalidNameException( "The parent entry of a syntax should be an
organizationalUnit.", 
+            throw new LdapInvalidNameException( "The parent entry of a syntax should be an
organizationalUnit.",
                 ResultCodeEnum.NAMING_VIOLATION );
         }
-        
-        if ( ! ( ( String ) rdn.getValue() ).equalsIgnoreCase( "syntaxes" ) )
+
+        if ( !( ( String ) rdn.getValue() ).equalsIgnoreCase( "syntaxes" ) )
         {
-            throw new LdapInvalidNameException( 
-                "The parent entry of a syntax should have a relative name of ou=syntaxes.",

+            throw new LdapInvalidNameException(
+                "The parent entry of a syntax should have a relative name of ou=syntaxes.",
                 ResultCodeEnum.NAMING_VIOLATION );
         }
     }



Mime
View raw message