You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/01/31 01:23:18 UTC
svn commit: r501653 - in /directory/apacheds/trunk:
core-unit/src/test/java/org/apache/directory/server/core/schema/
core/src/main/java/org/apache/directory/server/core/schema/
schema-registries/src/main/java/org/apache/directory/server/schema/registries/
Author: akarasulu
Date: Tue Jan 30 16:23:16 2007
New Revision: 501653
URL: http://svn.apache.org/viewvc?view=rev&rev=501653
Log:
Filling in more of the MetaSchemaHandler's functionality:
o schema adds actually add the schema to the map of loaded schemas in the
registries
o schema deletes now check to make sure the schema does not have any dependents
o schema disable operations make sure no enabled dependents exist to prevent
them from becoming inconsistent when a schema they depend on disappears
o cleaned up some naming conventions to code
o added much more javadocs and general in line documentation
Modified:
directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java
Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java (original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java Tue Jan 30 16:23:16 2007
@@ -20,13 +20,19 @@
package org.apache.directory.server.core.schema;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
+import org.apache.directory.server.constants.MetaSchemaConstants;
import org.apache.directory.server.core.unit.AbstractAdminTestCase;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
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.message.ResultCodeEnum;
/**
@@ -42,8 +48,230 @@
private static final String TEST_SCHEMA = "nis";
/** a test attribute in the test schema: uidNumber in nis schema */
private static final String TEST_ATTR_OID = "1.3.6.1.1.1.1.0";
+ /** the name of the dummy schema to test metaSchema adds/deletes with */
+ private static final String DUMMY_SCHEMA = "dummy";
+ // -----------------------------------------------------------------------
+ // Schema Add Tests
+ // -----------------------------------------------------------------------
+
+
+ /**
+ * Tests the addition of a new metaSchema object that is disabled
+ * on addition and has no dependencies.
+ */
+ public void testAddDisabledSchemaNoDeps() throws Exception
+ {
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ dummySchema.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+
+ assertNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNotNull( schemaRoot.lookup( "cn=" + DUMMY_SCHEMA ) );
+ }
+
+
+ /**
+ * Tests the addition of a new metaSchema object that is disabled
+ * on addition and has dependencies.
+ */
+ public void testAddDisabledSchemaWithDeps() throws Exception
+ {
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ dummySchema.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, TEST_SCHEMA );
+ dummySchema.get( MetaSchemaConstants.M_DEPENDENCIES_AT ).add( "core" );
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+
+ assertNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNotNull( schemaRoot.lookup( "cn=" + DUMMY_SCHEMA ) );
+ }
+
+
+ /**
+ * Tests the rejection of a new metaSchema object that is disabled
+ * on addition and has missing dependencies.
+ */
+ public void testRejectDisabledSchemaAddWithMissingDeps() throws Exception
+ {
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ dummySchema.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "missing" );
+ dummySchema.get( MetaSchemaConstants.M_DEPENDENCIES_AT ).add( "core" );
+
+ try
+ {
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ }
+ catch( LdapOperationNotSupportedException e )
+ {
+ assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
+ }
+
+ assertNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ try
+ {
+ schemaRoot.lookup( "cn=" + DUMMY_SCHEMA );
+ fail( "schema should not be added to schema partition" );
+ }
+ catch( NamingException e )
+ {
+ }
+ }
+
+
+ /**
+ * Tests the addition of a new metaSchema object that is enabled
+ * on addition and has no dependencies.
+ */
+ public void testAddEnabledSchemaNoDeps() throws Exception
+ {
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+
+ assertNotNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNotNull( schemaRoot.lookup( "cn=" + DUMMY_SCHEMA ) );
+ }
+
+
+ /**
+ * Tests the rejection of a metaSchema object add that is enabled
+ * on addition yet has disabled dependencies.
+ */
+ public void testRejectEnabledSchemaAddWithDisabledDeps() throws Exception
+ {
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, TEST_SCHEMA );
+
+ try
+ {
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ fail( "should not be able to add enabled schema with deps on disabled schemas" );
+ }
+ catch( LdapOperationNotSupportedException e )
+ {
+ assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
+ }
+
+ assertNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ try
+ {
+ schemaRoot.lookup( "cn=" + DUMMY_SCHEMA );
+ fail( "schema should not be added to schema partition" );
+ }
+ catch( NamingException e )
+ {
+ }
+ }
+
+
+ // -----------------------------------------------------------------------
+ // Schema Delete Tests
+ // -----------------------------------------------------------------------
+
+
+ /**
+ * Makes sure we can delete schemas that have no dependents.
+ */
+ public void testDeleteSchemaNoDependents() throws Exception
+ {
+ // add the dummy schema enabled
+ testAddEnabledSchemaNoDeps();
+ assertNotNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ // delete it now
+ schemaRoot.destroySubcontext( "cn=" + DUMMY_SCHEMA );
+ assertNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ }
+
+
+ /**
+ * Makes sure we can NOT delete schemas that have dependents.
+ */
+ public void testRejectSchemaDeleteWithDependents() throws Exception
+ {
+ // add the dummy schema enabled
+ testAddEnabledSchemaNoDeps();
+ assertNotNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ // make the nis schema depend on the dummy schema
+ ModificationItemImpl[] mods = new ModificationItemImpl[1];
+ mods[0] = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, new AttributeImpl( MetaSchemaConstants.M_DEPENDENCIES_AT, DUMMY_SCHEMA ) );
+ schemaRoot.modifyAttributes( "cn=" + TEST_SCHEMA, mods );
+
+ // attempt to delete it now & it should fail
+ try
+ {
+ schemaRoot.destroySubcontext( "cn=" + DUMMY_SCHEMA );
+ fail( "should not be able to delete a schema with dependents" );
+ }
+ catch ( LdapOperationNotSupportedException e )
+ {
+ assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
+ }
+
+ assertNotNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ }
+
+
+ /**
+ * Tests the rejection of a new metaSchema object that is enabled
+ * on addition and missing dependencies.
+ */
+ public void testRejectEnabledSchemaAddWithMisingDeps() throws Exception
+ {
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "missing" );
+
+ try
+ {
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ fail( "should not be able to add enabled schema with deps on missing schemas" );
+ }
+ catch( LdapOperationNotSupportedException e )
+ {
+ assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
+ }
+
+ assertNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ try
+ {
+ schemaRoot.lookup( "cn=" + DUMMY_SCHEMA );
+ fail( "schema should not be added to schema partition" );
+ }
+ catch( NamingException e )
+ {
+ }
+ }
+
+
+ // -----------------------------------------------------------------------
+ // Enable/Disable Schema Tests
+ // -----------------------------------------------------------------------
+
+
/**
* Checks to make sure updates enabling a metaSchema object in
* the schema partition triggers the loading of that schema into
@@ -76,9 +304,8 @@
/**
- * Checks to make sure updates disabling a metaSchema object in
- * the schema partition triggers the unloading of that schema from
- * the global registries.
+ * Checks to make sure an attempt to disable a metaSchema fails if
+ * that schema has dependents which are enabled.
*/
public void testDisableSchema() throws Exception
{
@@ -106,5 +333,62 @@
// double check and make sure the test attribute from the test
// schema is now NOT loaded and present within the attr registry
assertFalse( atr.hasAttributeType( TEST_ATTR_OID ) );
+ }
+
+
+ /**
+ * Checks to make sure updates disabling a metaSchema object in
+ * the schema partition triggers the unloading of that schema from
+ * the global registries.
+ */
+ public void testDisableSchemaWithEnabledDependents() throws Exception
+ {
+ // let's enable the test schema and add the dummy schema
+ // as enabled by default and dependends on the test schema
+
+// // enables the test schema
+ testEnableSchema();
+
+ // adds enabled dummy schema that depends on the test schema
+ Attributes dummySchema = new AttributesImpl( "objectClass", "top" );
+ dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
+ dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_OWNER_AT, "uid=admin,ou=system" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, TEST_SCHEMA );
+ super.schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+
+ // check that the nis schema is loaded and the dummy schema is loaded
+ assertNotNull( registries.getLoadedSchemas().get( TEST_SCHEMA ) );
+ assertNotNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ AttributeTypeRegistry atr = registries.getAttributeTypeRegistry();
+
+ // double check and make sure an attribute from that schema is
+ // in the AttributeTypeRegistry
+ assertTrue( atr.hasAttributeType( TEST_ATTR_OID ) );
+
+ // now try to disable the test schema which should fail
+ // since it's dependent, the dummy schema, is enabled
+ ModificationItemImpl[] mods = new ModificationItemImpl[1];
+ Attribute attr = new AttributeImpl( "m-disabled", "TRUE" );
+ mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+
+ try
+ {
+ super.schemaRoot.modifyAttributes( "cn=nis", mods );
+ fail( "attempt to disable schema with enabled dependents should fail" );
+ }
+ catch ( LdapOperationNotSupportedException e )
+ {
+ assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
+ }
+
+ // now test that both schema are still loaded
+ assertNotNull( registries.getLoadedSchemas().get( TEST_SCHEMA ) );
+ assertNotNull( registries.getLoadedSchemas().get( DUMMY_SCHEMA ) );
+
+ // double check and make sure the test attribute from the test
+ // schema is still loaded and present within the attr registry
+ assertTrue( atr.hasAttributeType( TEST_ATTR_OID ) );
}
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java Tue Jan 30 16:23:16 2007
@@ -102,7 +102,7 @@
{
Schema schema = getSchema( name );
AttributeType at = factory.getAttributeType( entry, targetRegistries, schema.getSchemaName() );
- Set<SearchResult> dependees = dao.listAttributeTypeDependees( at );
+ Set<SearchResult> dependees = dao.listAttributeTypeDependents( at );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The attributeType with OID " + at.getOid()
@@ -124,7 +124,7 @@
{
Schema schema = getSchema( name );
AttributeType oldAt = factory.getAttributeType( entry, targetRegistries, schema.getSchemaName() );
- Set<SearchResult> dependees = dao.listAttributeTypeDependees( oldAt );
+ Set<SearchResult> dependees = dao.listAttributeTypeDependents( oldAt );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The attributeType with OID " + oldAt.getOid()
@@ -159,7 +159,7 @@
checkNewParent( newParentName );
Schema oldSchema = getSchema( oriChildName );
AttributeType oldAt = factory.getAttributeType( entry, targetRegistries, oldSchema.getSchemaName() );
- Set<SearchResult> dependees = dao.listAttributeTypeDependees( oldAt );
+ Set<SearchResult> dependees = dao.listAttributeTypeDependents( oldAt );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The attributeType with OID " + oldAt.getOid()
@@ -198,7 +198,7 @@
checkNewParent( newParentName );
Schema oldSchema = getSchema( oriChildName );
AttributeType oldAt = factory.getAttributeType( entry, targetRegistries, oldSchema.getSchemaName() );
- Set<SearchResult> dependees = dao.listAttributeTypeDependees( oldAt );
+ Set<SearchResult> dependees = dao.listAttributeTypeDependents( oldAt );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The attributeType with OID " + oldAt.getOid()
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java Tue Jan 30 16:23:16 2007
@@ -101,7 +101,7 @@
{
Schema schema = getSchema( name );
MatchingRule mr = factory.getMatchingRule( entry, targetRegistries, schema.getSchemaName() );
- Set<SearchResult> dependees = dao.listMatchingRuleDependees( mr );
+ Set<SearchResult> dependees = dao.listMatchingRuleDependents( mr );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The matchingRule with OID " + mr.getOid()
@@ -123,7 +123,7 @@
{
Schema schema = getSchema( name );
MatchingRule oldMr = factory.getMatchingRule( entry, targetRegistries, schema.getSchemaName() );
- Set<SearchResult> dependees = dao.listMatchingRuleDependees( oldMr );
+ Set<SearchResult> dependees = dao.listMatchingRuleDependents( oldMr );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The matchingRule with OID " + oldMr.getOid()
@@ -158,7 +158,7 @@
checkNewParent( newParentName );
Schema oldSchema = getSchema( oriChildName );
MatchingRule oldMr = factory.getMatchingRule( entry, targetRegistries, oldSchema.getSchemaName() );
- Set<SearchResult> dependees = dao.listMatchingRuleDependees( oldMr );
+ Set<SearchResult> dependees = dao.listMatchingRuleDependents( oldMr );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The matchingRule with OID " + oldMr.getOid()
@@ -197,7 +197,7 @@
checkNewParent( newParentName );
Schema oldSchema = getSchema( oriChildName );
MatchingRule oldMr = factory.getMatchingRule( entry, targetRegistries, oldSchema.getSchemaName() );
- Set<SearchResult> dependees = dao.listMatchingRuleDependees( oldMr );
+ Set<SearchResult> dependees = dao.listMatchingRuleDependents( oldMr );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The matchingRule with OID " + oldMr.getOid()
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java Tue Jan 30 16:23:16 2007
@@ -101,7 +101,7 @@
{
Schema schema = getSchema( name );
ObjectClass oc = factory.getObjectClass( entry, targetRegistries, schema.getSchemaName() );
- Set<SearchResult> dependees = dao.listObjectClassDependees( oc );
+ Set<SearchResult> dependees = dao.listObjectClassDependents( oc );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The objectClass with OID " + oc.getOid()
@@ -124,7 +124,7 @@
{
Schema schema = getSchema( name );
ObjectClass oldOc = factory.getObjectClass( entry, targetRegistries, schema.getSchemaName() );
- Set<SearchResult> dependees = dao.listObjectClassDependees( oldOc );
+ Set<SearchResult> dependees = dao.listObjectClassDependents( oldOc );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The objectClass with OID " + oldOc.getOid()
@@ -159,7 +159,7 @@
checkNewParent( newParentName );
Schema oldSchema = getSchema( oriChildName );
ObjectClass oldOc = factory.getObjectClass( entry, targetRegistries, oldSchema.getSchemaName() );
- Set<SearchResult> dependees = dao.listObjectClassDependees( oldOc );
+ Set<SearchResult> dependees = dao.listObjectClassDependents( oldOc );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The objectClass with OID " + oldOc.getOid()
@@ -198,7 +198,7 @@
checkNewParent( newParentName );
Schema oldSchema = getSchema( oriChildName );
ObjectClass oldAt = factory.getObjectClass( entry, targetRegistries, oldSchema.getSchemaName() );
- Set<SearchResult> dependees = dao.listObjectClassDependees( oldAt );
+ Set<SearchResult> dependees = dao.listObjectClassDependents( oldAt );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The objectClass with OID " + oldAt.getOid()
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java Tue Jan 30 16:23:16 2007
@@ -20,6 +20,9 @@
package org.apache.directory.server.core.schema;
+import java.util.Map;
+import java.util.Set;
+
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
@@ -27,6 +30,7 @@
import org.apache.directory.server.constants.CoreSchemaConstants;
import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.constants.SystemSchemaConstants;
import org.apache.directory.server.core.ServerUtils;
import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.registries.OidRegistry;
@@ -38,6 +42,7 @@
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
/**
@@ -48,23 +53,38 @@
*/
public class MetaSchemaHandler implements SchemaChangeHandler
{
+ private final SchemaEntityFactory factory;
private final PartitionSchemaLoader loader;
private final Registries globalRegistries;
private final AttributeType disabledAT;
private final String OU_OID;
-
+ private final AttributeType cnAT;
+ private final AttributeType dependenciesAT;
- public MetaSchemaHandler( Registries globalRegistries, PartitionSchemaLoader loader )
- throws NamingException
+
+ public MetaSchemaHandler( Registries globalRegistries, PartitionSchemaLoader loader ) throws NamingException
{
this.globalRegistries = globalRegistries;
- this.disabledAT = globalRegistries.getAttributeTypeRegistry()
- .lookup( MetaSchemaConstants.M_DISABLED_AT );
+ this.disabledAT = globalRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_DISABLED_AT );
this.loader = loader;
this.OU_OID = globalRegistries.getOidRegistry().getOid( CoreSchemaConstants.OU_AT );
+ this.factory = new SchemaEntityFactory( globalRegistries );
+ this.cnAT = globalRegistries.getAttributeTypeRegistry().lookup( SystemSchemaConstants.CN_AT );
+ this.dependenciesAT = globalRegistries.getAttributeTypeRegistry()
+ .lookup( MetaSchemaConstants.M_DEPENDENCIES_AT );
}
-
+
+ /**
+ * Reacts to modification of a metaSchema object. At this point the
+ * only considerable changes are to the m-disabled and the
+ * m-dependencies attributes.
+ *
+ * @param name the dn of the metaSchema object modified
+ * @param modOp the type of modification operation being performed
+ * @param mods the attribute modifications as an Attributes object
+ * @param entry the entry after the modifications have been applied
+ */
public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes targetEntry )
throws NamingException
{
@@ -72,13 +92,172 @@
if ( disabledInMods != null )
{
disable( name, modOp, disabledInMods, ServerUtils.getAttribute( disabledAT, entry ) );
- return;
+ }
+ }
+
+
+ /**
+ * Reacts to modification of a metaSchema object. At this point the
+ * only considerable changes are to the m-disabled and the
+ * m-dependencies attributes.
+ *
+ * @param name the dn of the metaSchema object modified
+ * @param mods the attribute modifications as an ModificationItem arry
+ * @param entry the entry after the modifications have been applied
+ */
+ public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes targetEntry )
+ throws NamingException
+ {
+ OidRegistry registry = globalRegistries.getOidRegistry();
+ Attribute disabledInEntry = AttributeUtils.getAttribute( entry, disabledAT );
+
+ for ( int ii = 0; ii < mods.length; ii++ )
+ {
+ String id = registry.getOid( mods[ii].getAttribute().getID() );
+ if ( id.equals( disabledAT.getOid() ) )
+ {
+ disable( name, mods[ii].getModificationOp(), mods[ii].getAttribute(), disabledInEntry );
+ }
+ }
+ }
+
+
+ /**
+ * Handles the addition of a metaSchema object to the schema partition.
+ *
+ * @param name the dn of the new metaSchema object
+ * @param entry the attributes of the new metaSchema object
+ */
+ public void add( LdapDN name, Attributes entry ) throws NamingException
+ {
+ LdapDN parentDn = ( LdapDN ) name.clone();
+ parentDn.remove( parentDn.size() - 1 );
+ parentDn.normalize( globalRegistries.getAttributeTypeRegistry().getNormalizerMapping() );
+ if ( !parentDn.toNormName().equals( OU_OID + "=schema" ) )
+ {
+ throw new LdapInvalidNameException( "The parent dn of a schema should be " + OU_OID + "=schema and not: "
+ + parentDn.toNormName(), ResultCodeEnum.NAMING_VIOLATION );
+ }
+
+ // check if the new schema is enabled or disabled
+ boolean isEnabled = false;
+ Attribute disabled = AttributeUtils.getAttribute( entry, this.disabledAT );
+ if ( disabled == null )
+ {
+ isEnabled = true;
+ }
+ else if ( ! disabled.get().equals( "TRUE" ) )
+ {
+ isEnabled = true;
}
+ // check to see that all dependencies are resolved and loaded if this
+ // schema is enabled, otherwise check that the dependency schemas exist
+ checkForDependencies( isEnabled, entry );
+
+ /*
+ * There's a slight problem that may result when adding a metaSchema
+ * object if the addition of the physical entry fails. If the schema
+ * is enabled when added in the condition tested below, that schema
+ * is added to the global registries. We need to add this so subsequent
+ * schema entity additions are loaded into the registries as they are
+ * added to the schema partition. However if the metaSchema object
+ * addition fails then we're left with this schema object looking like
+ * it is enabled in the registries object's schema hash. The effects
+ * of this are unpredicatable.
+ *
+ * This whole problem is due to the inability of these handlers to
+ * react to a failed operation. To fix this we would need some way
+ * for these handlers to respond to failed operations and revert their
+ * effects on the registries.
+ *
+ * TODO: might want to add a set of failedOnXXX methods to the adapter
+ * where on failure the schema service calls the schema manager and it
+ * calls the appropriate methods on the respective handler. This way
+ * the schema manager can rollback registry changes when LDAP operations
+ * fail.
+ */
+
+ if ( isEnabled )
+ {
+ Schema schema = factory.getSchema( entry );
+ globalRegistries.addToLoadedSet( schema );
+ }
+ }
+
+
+ /**
+ * Called to react to the deletion of a metaSchema object. This method
+ * simply removes the schema from the loaded schema map of the global
+ * registries.
+ *
+ * @param name the dn of the metaSchema object being deleted
+ * @param entry the attributes of the metaSchema object
+ */
+ public void delete( LdapDN name, Attributes entry ) throws NamingException
+ {
+ Attribute cn = AttributeUtils.getAttribute( entry, cnAT );
+ String schemaName = ( String ) cn.get();
+
+ // Before allowing a schema object to be deleted we must check
+ // to make sure it's not depended upon by another schema
+ Set<String> dependents = loader.listDependentSchemaNames( schemaName );
+ if ( ! dependents.isEmpty() )
+ {
+ throw new LdapOperationNotSupportedException(
+ "Cannot delete schema that has dependents: " + dependents,
+ ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
+
+ // no need to check if schema is enabled or disabled here
+ // if not in the loaded set there will be no negative effect
+ globalRegistries.removeFromLoadedSet( schemaName );
+ }
+
+
+ /**
+ * Responds to the rdn (commonName) of the metaSchema object being
+ * changed. Changes all the schema entities associated with the
+ * renamed schema so they now map to a new schema name.
+ *
+ * @param name the dn of the metaSchema object renamed
+ * @param entry the entry of the metaSchema object before the rename
+ * @param the new commonName of the metaSchema object
+ */
+ public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
+ {
throw new NotImplementedException();
}
+ /**
+ * Moves are not allowed for metaSchema objects so this always throws an
+ * UNWILLING_TO_PERFORM LdapException.
+ */
+ public void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn, Attributes entry )
+ throws NamingException
+ {
+ throw new LdapOperationNotSupportedException( "Moving around schemas is not allowed.",
+ ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
+
+
+ /**
+ * Moves are not allowed for metaSchema objects so this always throws an
+ * UNWILLING_TO_PERFORM LdapException.
+ */
+ public void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) throws NamingException
+ {
+ throw new LdapOperationNotSupportedException( "Moving around schemas is not allowed.",
+ ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
+
+
+ // -----------------------------------------------------------------------
+ // private utility methods
+ // -----------------------------------------------------------------------
+
+
private void disable( LdapDN name, int modOp, Attribute disabledInMods, Attribute disabledInEntry )
throws NamingException
{
@@ -88,7 +267,7 @@
* If the user is adding a new m-disabled attribute to an enabled schema,
* we check that the value is "TRUE" and disable that schema if so.
*/
- case ( DirContext.ADD_ATTRIBUTE ):
+ case ( DirContext.ADD_ATTRIBUTE ):
if ( disabledInEntry == null )
{
if ( "TRUE".equalsIgnoreCase( ( String ) disabledInMods.get() ) )
@@ -102,7 +281,7 @@
* If the user is removing the m-disabled attribute we check if the schema is currently
* disabled. If so we enable the schema.
*/
- case ( DirContext.REMOVE_ATTRIBUTE ):
+ case ( DirContext.REMOVE_ATTRIBUTE ):
if ( "TRUE".equalsIgnoreCase( ( String ) disabledInEntry.get() ) )
{
enableSchema( getSchemaName( name ) );
@@ -114,7 +293,7 @@
* currently disabled and enable it if the new state has it as enabled. If the
* schema is not disabled we disable it if the mods set m-disabled to true.
*/
- case ( DirContext.REPLACE_ATTRIBUTE ):
+ case ( DirContext.REPLACE_ATTRIBUTE ):
boolean isCurrentlyDisabled = "TRUE".equalsIgnoreCase( ( String ) disabledInEntry.get() );
boolean isNewStateDisabled = "TRUE".equalsIgnoreCase( ( String ) disabledInMods.get() );
@@ -134,15 +313,23 @@
}
}
-
+
private final String getSchemaName( LdapDN schema ) throws NamingException
{
return ( String ) schema.getRdn().getValue();
}
-
+
private void disableSchema( String schemaName ) throws NamingException
{
+ Set<String> dependents = loader.listEnabledDependentSchemaNames( schemaName );
+ if ( ! dependents.isEmpty() )
+ {
+ throw new LdapOperationNotSupportedException(
+ "Cannot disable schema with enabled dependents: " + dependents,
+ ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
+
globalRegistries.unload( schemaName );
}
@@ -158,66 +345,58 @@
// TODO log warning: schemaName + " was already loaded"
return;
}
-
+
Schema schema = loader.getSchema( schemaName );
loader.load( schema, globalRegistries );
}
- public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes targetEntry )
- throws NamingException
+ /**
+ * Checks to make sure the dependencies either exist for disabled metaSchemas,
+ * or exist and are loaded (enabled) for enabled metaSchemas being added.
+ *
+ * @param isEnabled whether or not the new metaSchema is enabled
+ * @param entry the Attributes for the new metaSchema object
+ * @throws NamingException if the dependencies do not resolve or are not
+ * loaded (enabled)
+ */
+ private void checkForDependencies( boolean isEnabled, Attributes entry ) throws NamingException
{
- OidRegistry registry = globalRegistries.getOidRegistry();
- Attribute disabledInEntry = ServerUtils.getAttribute( disabledAT, entry );
+ Attribute dependencies = AttributeUtils.getAttribute( entry, this.dependenciesAT );
+
+ if ( dependencies == null )
+ {
+ return;
+ }
- for ( int ii = 0; ii < mods.length; ii++ )
+ if ( isEnabled )
{
- String id = registry.getOid( mods[ii].getAttribute().getID() );
- if ( id.equals( disabledAT.getOid() ) )
+ // check to make sure all the dependencies are also enabled
+ Map<String,Schema> loaded = globalRegistries.getLoadedSchemas();
+ for ( int ii = 0; ii < dependencies.size(); ii++ )
{
- disable( name, mods[ii].getModificationOp(),
- mods[ii].getAttribute(), disabledInEntry );
+ String dependency = ( String ) dependencies.get( ii );
+ if ( ! loaded.containsKey( dependency ) )
+ {
+ throw new LdapOperationNotSupportedException(
+ "Unwilling to add enabled schema with disabled or missing dependencies: " + dependency,
+ ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
}
}
- }
-
-
- public void add( LdapDN name, Attributes entry ) throws NamingException
- {
- LdapDN parentDn = ( LdapDN ) name.clone();
- parentDn.remove( parentDn.size() - 1 );
- parentDn.normalize( globalRegistries.getAttributeTypeRegistry().getNormalizerMapping() );
- if ( ! parentDn.toNormName().equals( OU_OID + "=schema" ) )
+ else
{
- throw new LdapInvalidNameException( "The parent dn of a schema should be " + OU_OID
- + "=schema and not: " + parentDn.toNormName(),
- ResultCodeEnum.NAMING_VIOLATION );
+ Set<String> allSchemas = loader.getSchemaNames();
+ for ( int ii = 0; ii < dependencies.size(); ii++ )
+ {
+ String dependency = ( String ) dependencies.get( ii );
+ if ( ! allSchemas.contains( dependency ) )
+ {
+ throw new LdapOperationNotSupportedException(
+ "Unwilling to add schema with missing dependencies: " + dependency,
+ ResultCodeEnum.UNWILLING_TO_PERFORM );
+ }
+ }
}
- }
-
-
- public void delete( LdapDN name, Attributes entry ) throws NamingException
- {
- }
-
-
- public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
- {
- throw new NotImplementedException();
- }
-
-
- public void move( LdapDN oriChildName, LdapDN newParentName, String newRn, boolean deleteOldRn, Attributes entry )
- throws NamingException
- {
- throw new LdapOperationNotSupportedException( "Moving around schemas is not allowed.",
- ResultCodeEnum.UNWILLING_TO_PERFORM );
- }
-
-
- public void move( LdapDN oriChildName, LdapDN newParentName, Attributes entry ) throws NamingException
- {
- throw new LdapOperationNotSupportedException( "Moving around schemas is not allowed.",
- ResultCodeEnum.UNWILLING_TO_PERFORM );
}
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java Tue Jan 30 16:23:16 2007
@@ -102,7 +102,7 @@
{
String oid = getOid( entry );
- Set<SearchResult> dependees = dao.listSyntaxDependies( oid );
+ Set<SearchResult> dependees = dao.listSyntaxDependents( oid );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The syntax with OID " + oid
@@ -127,7 +127,7 @@
{
String oldOid = getOid( entry );
- Set<SearchResult> dependees = dao.listSyntaxDependies( oldOid );
+ Set<SearchResult> dependees = dao.listSyntaxDependents( oldOid );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid
@@ -165,7 +165,7 @@
checkNewParent( newParentName );
String oldOid = getOid( entry );
- Set<SearchResult> dependees = dao.listSyntaxDependies( oldOid );
+ Set<SearchResult> dependees = dao.listSyntaxDependents( oldOid );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The syntax with OID " + oldOid
@@ -207,7 +207,7 @@
checkNewParent( newParentName );
String oid = getOid( entry );
- Set<SearchResult> dependees = dao.listSyntaxDependies( oid );
+ Set<SearchResult> dependees = dao.listSyntaxDependents( oid );
if ( dependees != null && dependees.size() > 0 )
{
throw new LdapOperationNotSupportedException( "The syntax with OID " + oid
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java Tue Jan 30 16:23:16 2007
@@ -38,6 +38,7 @@
import javax.naming.directory.SearchResult;
import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.constants.SystemSchemaConstants;
import org.apache.directory.server.core.partition.Partition;
import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.registries.AbstractSchemaLoader;
@@ -73,6 +74,7 @@
private AttributeTypeRegistry attrRegistry;
private final AttributeType mOidAT;
private final AttributeType mNameAT;
+ private final AttributeType cnAT;
public PartitionSchemaLoader( Partition partition, Registries bootstrapRegistries ) throws NamingException
@@ -84,6 +86,7 @@
dao = new SchemaPartitionDao( this.partition, bootstrapRegistries );
mOidAT = bootstrapRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT );
mNameAT = bootstrapRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_NAME_AT );
+ cnAT = bootstrapRegistries.getAttributeTypeRegistry().lookup( SystemSchemaConstants.CN_AT );
}
@@ -147,6 +150,61 @@
}
loadWithDependencies( enabledSchemaSet, targetRegistries );
+ }
+
+
+ /**
+ * Lists the names of the schemas that depend on the schema name provided.
+ *
+ * @param schemaName the name of the schema to find dependents for
+ * @return a set of schemas (String names) that depend on the schema
+ * @throws NamingException if there are problems searching the schema partition
+ */
+ public Set<String> listDependentSchemaNames( String schemaName ) throws NamingException
+ {
+ Set<String> dependees = new HashSet<String>();
+ Set<SearchResult> results = dao.listSchemaDependents( schemaName );
+
+ if ( results.isEmpty() )
+ {
+ return dependees;
+ }
+
+ for ( SearchResult sr: results )
+ {
+ Attribute cn = AttributeUtils.getAttribute( sr.getAttributes(), cnAT );
+ dependees.add( ( String ) cn.get() );
+ }
+
+ return dependees;
+ }
+
+
+ /**
+ * Lists the names of the enabled schemas that depend on the schema name
+ * provided.
+ *
+ * @param schemaName the name of the schema to find dependents for
+ * @return a set of enabled schemas (String names) that depend on the schema
+ * @throws NamingException if there are problems searching the schema partition
+ */
+ public Set<String> listEnabledDependentSchemaNames( String schemaName ) throws NamingException
+ {
+ Set<String> dependees = new HashSet<String>();
+ Set<SearchResult> results = dao.listEnabledSchemaDependents( schemaName );
+
+ if ( results.isEmpty() )
+ {
+ return dependees;
+ }
+
+ for ( SearchResult sr: results )
+ {
+ Attribute cn = AttributeUtils.getAttribute( sr.getAttributes(), cnAT );
+ dependees.add( ( String ) cn.get() );
+ }
+
+ return dependees;
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java Tue Jan 30 16:23:16 2007
@@ -55,6 +55,7 @@
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.ObjectClass;
import org.apache.directory.shared.ldap.schema.syntax.NumericOidSyntaxChecker;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -94,6 +95,8 @@
private final String M_AUX_OID;
private final String M_OC_OID;
private final String M_SUP_OBJECT_CLASS_OID;
+ private final String M_DEPENDENCIES_OID;
+ private final String M_DISABLED_OID;
private final AttributeType disabledAttributeType;
@@ -127,6 +130,8 @@
this.M_AUX_OID = oidRegistry.getOid( MetaSchemaConstants.M_AUX_AT );
this.M_OC_OID = oidRegistry.getOid( MetaSchemaConstants.M_OC_AT );
this.M_SUP_OBJECT_CLASS_OID = oidRegistry.getOid( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT );
+ this.M_DEPENDENCIES_OID = oidRegistry.getOid( MetaSchemaConstants.M_DEPENDENCIES_AT );
+ this.M_DISABLED_OID = oidRegistry.getOid( MetaSchemaConstants.M_DISABLED_AT );
}
@@ -355,7 +360,7 @@
* @param numericOid the numeric identifier for the entity
* @return
*/
- public Set<SearchResult> listSyntaxDependies( String numericOid ) throws NamingException
+ public Set<SearchResult> listSyntaxDependents( String numericOid ) throws NamingException
{
Set<SearchResult> set = new HashSet<SearchResult>( );
BranchNode filter = new BranchNode( AssertionEnum.AND );
@@ -395,7 +400,7 @@
}
- public Set<SearchResult> listMatchingRuleDependees( MatchingRule mr ) throws NamingException
+ public Set<SearchResult> listMatchingRuleDependents( MatchingRule mr ) throws NamingException
{
Set<SearchResult> set = new HashSet<SearchResult>( );
BranchNode filter = new BranchNode( AssertionEnum.AND );
@@ -457,7 +462,7 @@
}
- public Set<SearchResult> listAttributeTypeDependees( AttributeType at ) throws NamingException
+ public Set<SearchResult> listAttributeTypeDependents( AttributeType at ) throws NamingException
{
/*
* Right now the following inefficient filter is being used:
@@ -519,7 +524,107 @@
}
- public Set<SearchResult> listObjectClassDependees( ObjectClass oc ) throws NamingException
+ /**
+ * Lists the SearchResults of metaSchema objects that depend on a schema.
+ *
+ * @param schemaName the name of the schema to search for dependees
+ * @return a set of SearchResults over the schemas whose m-dependency attribute contains schemaName
+ * @throws NamingException if there is a problem while searching the schema partition
+ */
+ public Set<SearchResult> listSchemaDependents( String schemaName ) throws NamingException
+ {
+ /*
+ * The following filter is being used:
+ *
+ * ( & ( objectClass = metaSchema ) ( m-dependencies = $schemaName ) )
+ */
+
+ Set<SearchResult> set = new HashSet<SearchResult>( );
+ BranchNode filter = new BranchNode( AssertionEnum.AND );
+
+ filter.addNode( new SimpleNode( OBJECTCLASS_OID,
+ MetaSchemaConstants.META_SCHEMA_OC.toLowerCase(), AssertionEnum.EQUALITY ) );
+ filter.addNode( new SimpleNode( M_DEPENDENCIES_OID,
+ schemaName.toLowerCase(), AssertionEnum.EQUALITY ) );
+
+ SearchControls searchControls = new SearchControls();
+ searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ NamingEnumeration<SearchResult> ne = null;
+
+ try
+ {
+ ne = partition.search( partition.getSuffix(), new HashMap(), filter, searchControls );
+ while( ne.hasMore() )
+ {
+ set.add( ne.next() );
+ }
+ }
+ finally
+ {
+ if ( ne != null )
+ {
+ ne.close();
+ }
+ }
+
+ return set;
+ }
+
+
+ /**
+ * Lists the SearchResults of metaSchema objects that depend on a schema.
+ *
+ * @param schemaName the name of the schema to search for dependees
+ * @return a set of SearchResults over the schemas whose m-dependency attribute contains schemaName
+ * @throws NamingException if there is a problem while searching the schema partition
+ */
+ public Set<SearchResult> listEnabledSchemaDependents( String schemaName ) throws NamingException
+ {
+ Set<SearchResult> set = new HashSet<SearchResult>( );
+ BranchNode filter = new BranchNode( AssertionEnum.AND );
+
+ filter.addNode( new SimpleNode( OBJECTCLASS_OID,
+ MetaSchemaConstants.META_SCHEMA_OC.toLowerCase(), AssertionEnum.EQUALITY ) );
+ filter.addNode( new SimpleNode( M_DEPENDENCIES_OID,
+ schemaName.toLowerCase(), AssertionEnum.EQUALITY ) );
+
+ SearchControls searchControls = new SearchControls();
+ searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ NamingEnumeration<SearchResult> ne = null;
+
+ try
+ {
+ ne = partition.search( partition.getSuffix(), new HashMap(), filter, searchControls );
+ while( ne.hasMore() )
+ {
+ SearchResult sr = ne.next();
+ Attribute disabled = AttributeUtils.getAttribute( sr.getAttributes(), disabledAttributeType );
+
+ if ( disabled == null )
+ {
+ set.add( sr );
+ }
+ else if ( disabled.get().equals( "FALSE" ) )
+ {
+ set.add( sr );
+ }
+
+ set.add( ne.next() );
+ }
+ }
+ finally
+ {
+ if ( ne != null )
+ {
+ ne.close();
+ }
+ }
+
+ return set;
+ }
+
+
+ public Set<SearchResult> listObjectClassDependents( ObjectClass oc ) throws NamingException
{
/*
* Right now the following inefficient filter is being used:
Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java (original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java Tue Jan 30 16:23:16 2007
@@ -57,7 +57,7 @@
private OidRegistry oidRegistry;
private DefaultSyntaxCheckerRegistry syntaxCheckerRegistry;
private DefaultSyntaxRegistry syntaxRegistry;
- private Map<String,Schema> byName = new HashMap<String, Schema>();
+ private Map<String,Schema> loadedByName = new HashMap<String, Schema>();
private final SchemaLoader schemaLoader;
private final String name;
@@ -69,7 +69,7 @@
this.schemaLoader.setListener( new SchemaLoaderListener() {
public void schemaLoaded( Schema schema )
{
- byName.put( schema.getSchemaName(), schema );
+ loadedByName.put( schema.getSchemaName(), schema );
}
});
oidRegistry = registry;
@@ -487,7 +487,7 @@
*/
public Map<String, Schema> getLoadedSchemas()
{
- return new HashMap<String,Schema>( byName );
+ return new HashMap<String,Schema>( loadedByName );
}
@@ -505,7 +505,7 @@
throw new NamingException( "Disabled schemas cannot be loaded into registries." );
}
- byName.put( schema.getSchemaName(), schema );
+ loadedByName.put( schema.getSchemaName(), schema );
schemaLoader.load( schema, this );
}
@@ -524,7 +524,7 @@
normalizerRegistry.unregisterSchemaElements( schemaName );
comparatorRegistry.unregisterSchemaElements( schemaName );
syntaxCheckerRegistry.unregisterSchemaElements( schemaName );
- byName.remove( schemaName );
+ loadedByName.remove( schemaName );
}
@@ -556,6 +556,18 @@
public Schema getSchema( String schemaName )
{
- return this.byName.get( schemaName );
+ return this.loadedByName.get( schemaName );
+ }
+
+
+ public void addToLoadedSet( Schema schema )
+ {
+ loadedByName.put( schema.getSchemaName(), schema );
+ }
+
+
+ public void removeFromLoadedSet( String schemaName )
+ {
+ loadedByName.remove( schemaName );
}
}
Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java?view=diff&rev=501653&r1=501652&r2=501653
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java (original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java Tue Jan 30 16:23:16 2007
@@ -76,4 +76,23 @@
List checkRefInteg();
Schema getSchema( String schemaName );
+
+ /**
+ * Removes a schema from the loaded set without unloading the schema.
+ * This should be used ONLY when an enabled schema is deleted.
+ *
+ * @param schemaName the name of the schema to remove
+ */
+ void removeFromLoadedSet( String schemaName );
+
+ /**
+ * Adds a schema to the loaded set but does not load the schema in
+ * question. This may be a temporary fix for new schemas being added
+ * which are enabled yet do not have any schema entities associated
+ * with them to load. In this case all objects added under this
+ * schema will load when added instead of in bulk.
+ *
+ * @param schema the schema object to add to the loaded set.
+ */
+ void addToLoadedSet( Schema schema );
}