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 2006/12/17 03:38:11 UTC
svn commit: r487930 - in /directory/branches/trunks/schema/apacheds:
core/src/main/java/org/apache/directory/server/core/schema/
schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/
schema-registries/src/main/java/org/apache/dir...
Author: akarasulu
Date: Sat Dec 16 18:38:11 2006
New Revision: 487930
URL: http://svn.apache.org/viewvc?view=rev&rev=487930
Log:
changes ...
o added new SchemaLoaderListener interface to notify of newly loaded schemas
this should be used by registries to update it's own set of loaded schemas
o added setListener() interface for the schema loader listeners
o added abstract class that contains utility methods for resolving dependencies
and not getting caught in cycles while doing so
o extending the abstract schema loader in both the partition and bootstrap
schema loaders
NOTE: still need to implement loader methods for the partition loader
Added:
directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AbstractSchemaLoader.java
directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoaderListener.java
Modified:
directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java
directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoader.java
Modified: directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java?view=diff&rev=487930&r1=487929&r2=487930
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java (original)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java Sat Dec 16 18:38:11 2006
@@ -20,10 +20,14 @@
package org.apache.directory.server.core.schema;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
+import java.util.Stack;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -31,7 +35,9 @@
import javax.naming.directory.SearchResult;
import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.schema.bootstrap.BootstrapSchema;
import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.registries.AbstractSchemaLoader;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.OidRegistry;
import org.apache.directory.server.schema.registries.Registries;
@@ -46,7 +52,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class PartitionSchemaLoader
+public class PartitionSchemaLoader extends AbstractSchemaLoader
{
private SchemaEntityFactory factory;
private Partition partition;
@@ -63,13 +69,19 @@
}
+ /**
+ * Utility method to load all enabled schemas into this registry.
+ *
+ * @param registries
+ * @throws NamingException
+ */
public void loadEnabled( Registries registries ) throws NamingException
{
}
- public Map<String,Schema> getSchemas() throws NamingException
+ Map<String,Schema> getSchemas() throws NamingException
{
Map<String,Schema> schemas = new HashMap<String,Schema>();
NamingEnumeration list = listSchemas();
@@ -84,7 +96,7 @@
}
- public Set<String> getSchemaNames() throws NamingException
+ Set<String> getSchemaNames() throws NamingException
{
Set<String> schemaNames = new HashSet<String>();
NamingEnumeration list = listSchemas();
@@ -106,5 +118,49 @@
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
return partition.search( base, new HashMap(), filter, searchControls );
+ }
+
+
+ public Schema getSchema( String schemaName ) throws NamingException
+ {
+ LdapDN dn = new LdapDN( "cn=" + schemaName + ",ou=schema" );
+ dn.normalize( attrRegistry.getNormalizerMapping() );
+ return factory.getSchema( partition.lookup( dn ) );
+ }
+
+
+ public Schema getSchema( String schemaName, Properties schemaProperties ) throws NamingException
+ {
+ return getSchema( schemaName );
+ }
+
+
+ public final void load( Collection<Schema> schemas, Registries registries ) throws NamingException
+ {
+ HashMap<String,Schema> notLoaded = new HashMap<String,Schema>();
+ Iterator<Schema> list = schemas.iterator();
+ while ( list.hasNext() )
+ {
+ Schema schema = list.next();
+ notLoaded.put( schema.getSchemaName(), schema );
+ }
+
+ list = notLoaded.values().iterator();
+ while ( list.hasNext() )
+ {
+ Schema schema = ( BootstrapSchema ) list.next();
+ loadDepsFirst( new Stack<String>(), notLoaded, schema, registries, null );
+ list = notLoaded.values().iterator();
+ }
+ }
+
+
+ public final void load( Schema schema, Registries registries ) throws NamingException
+ {
+ // TODO Auto-generated method stub: NOT FINISHED YET!!!!!!!!!!!!!
+
+ // load the schema entities here ....
+
+ notifyListenerOrRegistries( schema, registries );
}
}
Modified: directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java?view=diff&rev=487930&r1=487929&r2=487930
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java (original)
+++ directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/BootstrapSchemaLoader.java Sat Dec 16 18:38:11 2006
@@ -32,6 +32,7 @@
import org.apache.directory.server.schema.bootstrap.SystemSchema;
import org.apache.directory.server.schema.bootstrap.BootstrapSchema;
import org.apache.directory.server.schema.bootstrap.ProducerTypeEnum;
+import org.apache.directory.server.schema.registries.AbstractSchemaLoader;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.ComparatorRegistry;
import org.apache.directory.server.schema.registries.DITContentRuleRegistry;
@@ -43,7 +44,6 @@
import org.apache.directory.server.schema.registries.NormalizerRegistry;
import org.apache.directory.server.schema.registries.ObjectClassRegistry;
import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.schema.registries.SchemaLoader;
import org.apache.directory.server.schema.registries.SyntaxCheckerRegistry;
import org.apache.directory.server.schema.registries.SyntaxRegistry;
import org.apache.directory.shared.ldap.schema.AttributeType;
@@ -56,6 +56,7 @@
import org.apache.directory.shared.ldap.schema.ObjectClass;
import org.apache.directory.shared.ldap.schema.Syntax;
import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,7 +67,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class BootstrapSchemaLoader implements SchemaLoader
+public class BootstrapSchemaLoader extends AbstractSchemaLoader
{
private static final Logger log = LoggerFactory.getLogger( BootstrapSchemaLoader.class );
@@ -107,8 +108,8 @@
{
BootstrapSchema[] schemas = new BootstrapSchema[bootstrapSchemas.size()];
schemas = ( BootstrapSchema[] ) bootstrapSchemas.toArray( schemas );
- HashMap<String,BootstrapSchema> loaded = new HashMap<String,BootstrapSchema>();
- HashMap<String,BootstrapSchema> notLoaded = new HashMap<String,BootstrapSchema>();
+ HashMap<String,Schema> loaded = new HashMap<String,Schema>();
+ HashMap<String,Schema> notLoaded = new HashMap<String,Schema>();
for ( int ii = 0; ii < schemas.length; ii++ )
{
@@ -128,87 +129,38 @@
while ( list.hasNext() )
{
schema = ( BootstrapSchema ) list.next();
- loadDepsFirst( new Stack<String>(), notLoaded, schema, registries );
+ Properties props = new Properties();
+ props.put( "package", schema.getPackageName() );
+ loadDepsFirst( new Stack<String>(), notLoaded, schema, registries, props );
list = notLoaded.values().iterator();
}
}
/**
- * Recursive method which loads schema's with their dependent schemas first
- * and tracks what schemas it has seen so the recursion does not go out of
- * control with depenency cycle detection.
- *
- * @param beenthere stack of schema names we have visited and have yet to load
- * @param notLoaded hash of schemas keyed by name which have yet to be loaded
- * @param schema the current schema we are attempting to load
- * @param registries the set of registries to use while loading
- * @throws NamingException if there is a cycle detected and/or another
- * failure results while loading, producing and or registering schema objects
- */
- public final void loadDepsFirst( Stack<String> beenthere, HashMap notLoaded, BootstrapSchema schema,
- Registries registries ) throws NamingException
- {
- beenthere.push( schema.getSchemaName() );
- String[] deps = schema.getDependencies();
-
- // if no deps then load this guy and return
- if ( deps == null || deps.length == 0 )
- {
- load( schema, registries );
- notLoaded.remove( schema.getSchemaName() );
- beenthere.pop();
- return;
- }
-
- /*
- * We got deps and need to load them before this schema. We go through
- * all deps loading them with their deps first if they have not been
- * loaded.
- */
- for ( int ii = 0; ii < deps.length; ii++ )
- {
- if ( !notLoaded.containsKey( deps[ii] ) )
- {
- continue;
- }
-
- BootstrapSchema dep = ( BootstrapSchema ) notLoaded.get( deps[ii] );
-
- if ( beenthere.contains( dep.getSchemaName() ) )
- {
- // push again so we show the cycle in output
- beenthere.push( dep.getSchemaName() );
- throw new NamingException( "schema dependency cycle detected: " + beenthere );
- }
-
- loadDepsFirst( beenthere, notLoaded, dep, registries );
- }
-
- // We have loaded all our deps so we can load this schema
- load( schema, registries );
- notLoaded.remove( schema.getSchemaName() );
- beenthere.pop();
- }
-
-
- /**
* Loads a schema by loading and running all producers for te schema.
*
* @param schema the schema to load
* @param registries the registries to fill with producer created objects
* @throws NamingException if there are any failures during this process
*/
- public final void load( BootstrapSchema schema, Registries registries ) throws NamingException
+ public final void load( Schema schema, Registries registries ) throws NamingException
{
+ if ( ! ( schema instanceof BootstrapSchema ) )
+ {
+ throw new NamingException( "Expecting schema to be of sub-type BootstrapSchema" );
+ }
+
this.registries.set( registries );
- this.schemas.set( schema );
+ this.schemas.set( ( BootstrapSchema ) schema );
for ( ProducerTypeEnum producerType:ProducerTypeEnum.getList() )
{
- BootstrapProducer producer = getProducer( schema, producerType.getName() );
+ BootstrapProducer producer = getProducer( ( BootstrapSchema ) schema, producerType.getName() );
producer.produce( registries, cb );
}
+
+ notifyListenerOrRegistries( schema, registries );
}
@@ -439,10 +391,5 @@
}
return schema;
- }
-
-
- public void load( Schema schema, Registries registries ) throws NamingException
- {
}
}
Added: directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AbstractSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AbstractSchemaLoader.java?view=auto&rev=487930
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AbstractSchemaLoader.java (added)
+++ directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/AbstractSchemaLoader.java Sat Dec 16 18:38:11 2006
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.schema.registries;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.Stack;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.schema.bootstrap.Schema;
+
+
+
+/**
+ * An abstract class with a utility method and setListener() implemented.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class AbstractSchemaLoader implements SchemaLoader
+{
+ protected SchemaLoaderListener listener;
+
+
+ public void setListener( SchemaLoaderListener listener )
+ {
+ this.listener = listener;
+ }
+
+
+ protected final void notifyListenerOrRegistries( Schema schema, Registries registries )
+ {
+ if ( listener != null )
+ {
+ listener.schemaLoaded( schema );
+ }
+
+ if ( registries instanceof SchemaLoaderListener )
+ {
+ if ( registries != listener )
+ {
+ SchemaLoaderListener listener = ( SchemaLoaderListener ) registries;
+ listener.schemaLoaded( schema );
+ }
+ }
+ }
+
+
+ /**
+ * Recursive method which loads schema's with their dependent schemas first
+ * and tracks what schemas it has seen so the recursion does not go out of
+ * control with depenency cycle detection.
+ *
+ * @param beenthere stack of schema names we have visited and have yet to load
+ * @param notLoaded hash of schemas keyed by name which have yet to be loaded
+ * @param schema the current schema we are attempting to load
+ * @param registries the set of registries to use while loading
+ * @param properties to use while trying resolve other schemas
+ * @throws NamingException if there is a cycle detected and/or another
+ * failure results while loading, producing and or registering schema objects
+ */
+ protected final void loadDepsFirst( Stack<String> beenthere, Map<String,Schema> notLoaded, Schema schema,
+ Registries registries, Properties props ) throws NamingException
+ {
+ beenthere.push( schema.getSchemaName() );
+ String[] deps = schema.getDependencies();
+
+ // if no deps then load this guy and return
+ if ( deps == null || deps.length == 0 )
+ {
+ load( schema, registries );
+ notLoaded.remove( schema.getSchemaName() );
+ beenthere.pop();
+ return;
+ }
+
+ /*
+ * We got deps and need to load them before this schema. We go through
+ * all deps loading them with their deps first if they have not been
+ * loaded.
+ */
+ for ( int ii = 0; ii < deps.length; ii++ )
+ {
+ if ( !notLoaded.containsKey( deps[ii] ) )
+ {
+ continue;
+ }
+
+ Schema dep = notLoaded.get( deps[ii] );
+
+ // dep is not in the set of schema objects we need to try to resolve it
+ if ( dep == null )
+ {
+ // try to load dependency with the provided properties default
+ dep = getSchema( deps[ii], props );
+ }
+
+ if ( beenthere.contains( dep.getSchemaName() ) )
+ {
+ // push again so we show the cycle in output
+ beenthere.push( dep.getSchemaName() );
+ throw new NamingException( "schema dependency cycle detected: " + beenthere );
+ }
+
+ loadDepsFirst( beenthere, notLoaded, dep, registries, props );
+ }
+
+ // We have loaded all our deps so we can load this schema
+ load( schema, registries );
+ notLoaded.remove( schema.getSchemaName() );
+ beenthere.pop();
+ }
+}
Modified: directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java?view=diff&rev=487930&r1=487929&r2=487930
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java (original)
+++ directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java Sat Dec 16 18:38:11 2006
@@ -63,6 +63,12 @@
public DefaultRegistries( SchemaLoader schemaLoader )
{
this.schemaLoader = schemaLoader;
+ this.schemaLoader.setListener( new SchemaLoaderListener() {
+ public void schemaLoaded( Schema schema )
+ {
+ byName.put( schema.getSchemaName(), schema );
+ }
+ });
oidRegistry = new DefaultOidRegistry();
normalizerRegistry = new DefaultNormalizerRegistry();
comparatorRegistry = new DefaultComparatorRegistry();
Modified: directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoader.java?view=diff&rev=487930&r1=487929&r2=487930
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoader.java (original)
+++ directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoader.java Sat Dec 16 18:38:11 2006
@@ -37,6 +37,14 @@
public interface SchemaLoader
{
/**
+ * Sets listener used to notify of newly loaded schemas.
+ *
+ * @param listener the listener to notify (only one is enough for us)
+ * @NOTE probably should have used the observer pattern here
+ */
+ public void setListener( SchemaLoaderListener listener );
+
+ /**
* Gets a schema object based on it's name.
*
* @param schemaName the name of the schema to load
Added: directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoaderListener.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoaderListener.java?view=auto&rev=487930
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoaderListener.java (added)
+++ directory/branches/trunks/schema/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/registries/SchemaLoaderListener.java Sat Dec 16 18:38:11 2006
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.schema.registries;
+
+import org.apache.directory.server.schema.bootstrap.Schema;
+
+
+/**
+ * A listener to the schema loader for events like a new schema being loaded.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface SchemaLoaderListener
+{
+ void schemaLoaded( Schema schema );
+}