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/16 20:02:13 UTC
svn commit: r487858 - in /directory/branches/trunks/schema/apacheds:
bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/
bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/
core-shared...
Author: akarasulu
Date: Sat Dec 16 11:02:12 2006
New Revision: 487858
URL: http://svn.apache.org/viewvc?view=rev&rev=487858
Log:
changes ...
o adding new attributes for using in schema entries:
m-depenedencies
m-owner
o added abstract schema class
o added a partition based schema loader but it is not fully complete yet
o added test case for partition schema loader
o added utility method to save schema objects into dit in plugin
o added more functionality to load schema from the dit
Added:
directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchema.java
directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
directory/branches/trunks/schema/apacheds/core/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java
Removed:
directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/core/
Modified:
directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/AbstractBootstrapSchema.java
directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/Schema.java
directory/branches/trunks/schema/apacheds/core/pom.xml
directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema
Modified: directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java (original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java Sat Dec 16 11:02:12 2006
@@ -103,13 +103,22 @@
}
+ /**
+ * Gets the user indices WITHOUT the system indices.
+ *
+ * @return set of user index names
+ */
public Set<String> getIndexedAttributes()
{
Set<String> attributes = new HashSet<String>();
Iterator<String> ii = iterator();
while( ii.hasNext() )
{
- attributes.add( getIndexAttributeName( ii.next() ) );
+ String name = ii.next();
+ if ( name2type.get( name ) == DbFileType.USER_INDEX )
+ {
+ attributes.add( getIndexAttributeName( name ) );
+ }
}
return attributes;
}
Modified: directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java (original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java Sat Dec 16 11:02:12 2006
@@ -17,10 +17,10 @@
* under the License.
*
*/
-package org.apache.directory.server.core.bootstrap.plugin;
+package org.apache.directory.server.core.bootstrap.plugin;
-import java.util.Comparator;
+import java.util.Comparator;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
@@ -28,6 +28,8 @@
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
+import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.DITContentRule;
import org.apache.directory.shared.ldap.schema.DITStructureRule;
@@ -50,6 +52,7 @@
*/
public class AttributesFactory
{
+ private static final Object META_SCHEMA_OC = "metaSchema";
private static final String META_OBJECT_CLASS_OC = "metaObjectClass";
private static final String META_ATTRIBUTE_TYPE_OC = "metaAttributeType";
private static final String META_MATCHING_RULE_OC = "metaMatchingRule";
@@ -96,6 +99,7 @@
private static final String M_USAGE_AT = "m-usage";
// private static final String M_EXTENSION_ATTRIBUTE_TYPE_AT = "m-extensionAttributeType";
private static final String M_SUP_OBJECT_CLASS_AT = "m-supObjectClass";
+ private static final String M_IS_DISABLED_AT = null;
/*
@@ -107,6 +111,33 @@
private static final String _AT = "";
private static final String _AT = "";
*/
+
+
+ public Attributes getAttributes( Schema schema )
+ {
+ BasicAttributes entry = new BasicAttributes( OBJECT_CLASS_AT, "top", true );
+ entry.get( OBJECT_CLASS_AT ).add( META_SCHEMA_OC );
+ entry.put( "cn", schema.getSchemaName() );
+ entry.put( "m-owner", schema.getOwner() );
+
+ if ( schema.isDisabled() )
+ {
+ entry.put( M_IS_DISABLED_AT, "TRUE" );
+ }
+
+ if ( schema.getDependencies() != null && schema.getDependencies().length > 0 )
+ {
+ Attribute attr = new LockableAttributeImpl( "m-dependencies" );
+ for ( String dep : schema.getDependencies() )
+ {
+ attr.add( dep );
+ }
+ entry.put( attr );
+ }
+
+ return entry;
+ }
+
public Attributes getAttributes( SyntaxChecker syntaxChecker )
{
Modified: directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java (original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/BootstrapPlugin.java Sat Dec 16 11:02:12 2006
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.directory.server.core.bootstrap.plugin;
+package org.apache.directory.server.core.bootstrap.plugin;
import java.io.File;
@@ -25,8 +25,10 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import javax.naming.NamingException;
@@ -44,6 +46,7 @@
import org.apache.directory.server.schema.bootstrap.BootstrapSchema;
import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
import org.apache.directory.server.schema.bootstrap.CoreSchema;
+import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.bootstrap.SystemSchema;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.ComparatorRegistry;
@@ -135,6 +138,9 @@
/** The store to load schema entities into. */
private JdbmStore store = new JdbmStore();
+ /** Map of schemas by name */
+ private Map schemas = new HashMap();
+
/**
* Loads a bunch of bootstrap classes into memory then adds them to a new
@@ -189,7 +195,6 @@
addAttributeTypes();
addObjectClasses();
- // by default we disable these schemas
if ( disabledSchemas != null && disabledSchemas.length > 0 )
{
getLog().info( "------------------------------------------------------------------------" );
@@ -498,11 +503,17 @@
// -------------------------------------------------------------------
// always include these core bootstrap schemas
- Set<BootstrapSchema> schemas = new HashSet<BootstrapSchema>();
- schemas.add( new SystemSchema() );
- schemas.add( new ApacheSchema() );
- schemas.add( new ApachemetaSchema() );
- schemas.add( new CoreSchema() );
+ BootstrapSchema schema = new SystemSchema();
+ schemas.put( schema.getSchemaName(), schema );
+
+ schema = new ApacheSchema();
+ schemas.put( schema.getSchemaName(), schema );
+
+ schema = new ApachemetaSchema();
+ schemas.put( schema.getSchemaName(), schema );
+
+ schema = new CoreSchema();
+ schemas.put( schema.getSchemaName(), schema );
getLog().info( "------------------------------------------------------------------------" );
getLog().info( "Found bootstrap schemas: " );
@@ -515,7 +526,8 @@
try
{
Class schemaClass = Class.forName( schemaClassName );
- schemas.add( ( BootstrapSchema ) schemaClass.newInstance() );
+ schema = ( BootstrapSchema ) schemaClass.newInstance();
+ schemas.put( schema.getSchemaName(), schema );
}
catch ( ClassNotFoundException e )
{
@@ -541,7 +553,7 @@
BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
try
{
- loader.load( schemas, ( DefaultRegistries ) registries );
+ loader.load( schemas.values(), registries );
}
catch ( NamingException e )
{
@@ -568,6 +580,7 @@
private LdapDN checkCreateSchema( String schemaName ) throws NamingException
{
+ Schema schema = ( Schema ) schemas.get( schemaName );
LdapDN dn = new LdapDN( "cn=" + schemaName + ",ou=schema" );
dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
@@ -576,11 +589,7 @@
return dn;
}
- Attributes entry = new LockableAttributesImpl();
- entry.put( "objectClass", "top" );
- entry.get( "objectClass" ).add( "metaTop" );
- entry.get( "objectClass" ).add( "metaSchema" );
- entry.put( "cn", schemaName );
+ Attributes entry = attributesFactory.getAttributes( schema );
store.add( dn, entry );
return dn;
}
Modified: directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/AbstractBootstrapSchema.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/AbstractBootstrapSchema.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/AbstractBootstrapSchema.java (original)
+++ directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/AbstractBootstrapSchema.java Sat Dec 16 11:02:12 2006
@@ -191,4 +191,10 @@
{
return schemaNameCapped + "Schema";
}
+
+
+ public boolean isDisabled()
+ {
+ return false;
+ }
}
Modified: directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/Schema.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/Schema.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/Schema.java (original)
+++ directory/branches/trunks/schema/apacheds/core-shared/src/main/java/org/apache/directory/server/schema/bootstrap/Schema.java Sat Dec 16 11:02:12 2006
@@ -29,6 +29,13 @@
public interface Schema
{
/**
+ * Checks whether or not this schema is enabled or disabled.
+ *
+ * @return true if this schema is disabled, false otherwise
+ */
+ boolean isDisabled();
+
+ /**
* Gets the name of the owner of the schema objects within this
* Schema.
*
Modified: directory/branches/trunks/schema/apacheds/core/pom.xml
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/pom.xml?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/pom.xml (original)
+++ directory/branches/trunks/schema/apacheds/core/pom.xml Sat Dec 16 11:02:12 2006
@@ -67,6 +67,20 @@
</dependency>
</dependencies>
<build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>workingDirectory</name>
+ <value>${basedir}/target/server-work</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
Modified: directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Sat Dec 16 11:02:12 2006
@@ -776,7 +776,7 @@
SchemaPartitionExtractor extractor = null;
try
{
- extractor = new SchemaPartitionExtractor( startupConfiguration.getWorkingDirectory() );
+ extractor = new SchemaPartitionExtractor( startupConfiguration.getWorkingDirectory() );
extractor.extract();
}
catch ( IOException e )
Added: directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchema.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchema.java?view=auto&rev=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchema.java (added)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchema.java Sat Dec 16 11:02:12 2006
@@ -0,0 +1,116 @@
+/*
+ * 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.core.schema;
+
+
+import org.apache.directory.server.schema.bootstrap.Schema;
+
+
+/**
+ * An abstract schema class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class AbstractSchema implements Schema
+{
+ private static final String[] NONE = new String[0];
+ private static final String DEFAULT_OWNER = "uid=admin,ou=system";
+
+ private boolean disabled;
+ private String[] dependencies;
+ private String owner;
+ private String name;
+
+
+ public AbstractSchema( String name )
+ {
+ this( name, null, null, false );
+ }
+
+
+ public AbstractSchema( String name, String owner )
+ {
+ this( name, owner, null, false );
+ }
+
+
+ public AbstractSchema( String name, String owner, String[] dependencies )
+ {
+ this( name, owner, dependencies, false );
+ }
+
+
+ public AbstractSchema( String name, String owner, String[] dependencies, boolean disabled )
+ {
+ if ( name == null )
+ {
+ throw new NullPointerException( "name cannot be null" );
+ }
+
+ this.name = name;
+
+ if ( owner != null )
+ {
+ this.owner = owner;
+ }
+ else
+ {
+ this.owner = DEFAULT_OWNER;
+ }
+
+ if ( dependencies != null )
+ {
+ this.dependencies = dependencies;
+ }
+ else
+ {
+ this.dependencies = NONE;
+ }
+
+ this.disabled = disabled;
+ }
+
+
+ public String[] getDependencies()
+ {
+ String[] copy = new String[dependencies.length];
+ System.arraycopy( dependencies, 0, copy, 0, dependencies.length );
+ return copy;
+ }
+
+
+ public String getOwner()
+ {
+ return owner;
+ }
+
+
+ public String getSchemaName()
+ {
+ return name;
+ }
+
+
+ public boolean isDisabled()
+ {
+ return disabled;
+ }
+}
Added: 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=auto&rev=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java (added)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java Sat Dec 16 11:02:12 2006
@@ -0,0 +1,102 @@
+/*
+ * 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.core.schema;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.server.schema.registries.OidRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.SimpleNode;
+import org.apache.directory.shared.ldap.name.LdapDN;
+
+
+/**
+ * A class that loads schemas from a partition.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PartitionSchemaLoader
+{
+ private SchemaEntityFactory factory;
+ private Partition partition;
+ private OidRegistry oidRegistry;
+ private AttributeTypeRegistry attrRegistry;
+
+
+ public PartitionSchemaLoader( Partition partition, Registries bootstrapRegiistries )
+ {
+ this.factory = new SchemaEntityFactory( bootstrapRegiistries );
+ this.partition = partition;
+ this.oidRegistry = bootstrapRegiistries.getOidRegistry();
+ this.attrRegistry = bootstrapRegiistries.getAttributeTypeRegistry();
+ }
+
+
+ public Set<Schema> getSchemas() throws NamingException
+ {
+ Set<Schema> schemas = new HashSet<Schema>();
+ NamingEnumeration list = listSchemas();
+ while( list.hasMore() )
+ {
+ SearchResult sr = ( SearchResult ) list.next();
+ schemas.add( factory.getSchema( sr.getAttributes() ) );
+ }
+
+ return schemas;
+ }
+
+
+ public Set<String> getSchemaNames() throws NamingException
+ {
+ Set<String> schemaNames = new HashSet<String>();
+ NamingEnumeration list = listSchemas();
+ while( list.hasMore() )
+ {
+ SearchResult sr = ( SearchResult ) list.next();
+ schemaNames.add( ( String ) sr.getAttributes().get( "cn" ).get() );
+ }
+
+ return schemaNames;
+ }
+
+
+ private NamingEnumeration listSchemas() throws NamingException
+ {
+ LdapDN base = new LdapDN( "ou=schema" );
+ base.normalize( attrRegistry.getNormalizerMapping() );
+ ExprNode filter = new SimpleNode( oidRegistry.getOid( "objectClass" ), "metaSchema", SimpleNode.EQUALITY );
+ SearchControls searchControls = new SearchControls();
+ searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ return partition.search( base, new HashMap(), filter, searchControls );
+ }
+}
Modified: directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java (original)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java Sat Dec 16 11:02:12 2006
@@ -21,14 +21,19 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
+import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+
/**
* Showing how it's done ...
*
@@ -39,6 +44,8 @@
{
/** Used for looking up the setRegistries(Registries) method */
private final static Class[] parameterTypes = new Class[] { Registries.class };
+
+ private static final String[] NONE = new String[0];
/** Used for dependency injection of Registries via setter into schema objects */
private final Registries registries;
@@ -53,6 +60,53 @@
}
+
+ public Schema getSchema( Attributes entry ) throws NamingException
+ {
+ String name;
+ String owner;
+ String[] dependencies = NONE;
+ boolean isDisabled = false;
+
+ if ( entry == null )
+ {
+ throw new NullPointerException( "entry cannot be null" );
+ }
+
+ if ( entry.get( "cn" ) == null )
+ {
+ throw new NullPointerException( "entry must have a valid cn attribute" );
+ }
+ name = ( String ) entry.get( "cn" ).get();
+
+ if ( entry.get( "m-owner" ) == null )
+ {
+ throw new NullPointerException( "entry must have a valid m-owner attribute" );
+ }
+ owner = ( String ) entry.get( "m-owner" ).get();
+
+ if ( entry.get( "m-disabled" ) != null )
+ {
+ String value = ( String ) entry.get( "m-disabled" ).get();
+ value = value.toUpperCase();
+ isDisabled = value.equals( "TRUE" );
+ }
+
+ if ( entry.get( "m-dependencies" ) != null )
+ {
+ Set<String> depsSet = new HashSet<String>();
+ Attribute depsAttr = entry.get( "m-dependencies" );
+ for ( int ii = 0; ii < depsAttr.size(); ii++ )
+ {
+ depsSet.add( ( String ) depsAttr.get( ii ) );
+ }
+ dependencies = depsSet.toArray( NONE );
+ }
+
+ return new AbstractSchema( name, owner, dependencies, isDisabled ){};
+ }
+
+
/**
* Example of how to retrieve and load a syntaxChecker class from the DIT.
*
Added: directory/branches/trunks/schema/apacheds/core/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java?view=auto&rev=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java (added)
+++ directory/branches/trunks/schema/apacheds/core/src/test/java/org/apache/directory/server/core/schema/PartitionSchemaLoaderTest.java Sat Dec 16 11:02:12 2006
@@ -0,0 +1,229 @@
+/*
+ * 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.core.schema;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.server.core.DirectoryServiceListener;
+import org.apache.directory.server.core.configuration.MutablePartitionConfiguration;
+import org.apache.directory.server.core.configuration.MutableStartupConfiguration;
+import org.apache.directory.server.core.configuration.StartupConfiguration;
+import org.apache.directory.server.core.interceptor.InterceptorChain;
+import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.schema.bootstrap.ApacheSchema;
+import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
+import org.apache.directory.server.schema.bootstrap.BootstrapSchema;
+import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
+import org.apache.directory.server.schema.bootstrap.CoreSchema;
+import org.apache.directory.server.schema.bootstrap.SystemSchema;
+import org.apache.directory.server.schema.bootstrap.partition.SchemaPartitionExtractor;
+import org.apache.directory.server.schema.registries.DefaultRegistries;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests the partition schema loader.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PartitionSchemaLoaderTest extends TestCase
+{
+ private Registries registries;
+ private MutableStartupConfiguration startupConfiguration = new MutableStartupConfiguration();
+ private DirectoryServiceConfiguration configuration;
+ private JdbmPartition schemaPartition;
+
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ // setup working directory
+ File workingDirectory = new File( System.getProperty( "workingDirectory" ) );
+ if ( workingDirectory.exists() )
+ {
+ FileUtils.deleteDirectory( workingDirectory );
+ }
+ workingDirectory.mkdirs();
+ startupConfiguration.setWorkingDirectory( workingDirectory );
+
+ // --------------------------------------------------------------------
+ // Load the bootstrap schemas to start up the schema partition
+ // --------------------------------------------------------------------
+
+ // setup temporary loader and temp registry
+ registries = new DefaultRegistries();
+ BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+
+ // load essential bootstrap schemas
+ Set<BootstrapSchema> bootstrapSchemas = new HashSet<BootstrapSchema>();
+ bootstrapSchemas.add( new ApachemetaSchema() );
+ bootstrapSchemas.add( new ApacheSchema() );
+ bootstrapSchemas.add( new CoreSchema() );
+ bootstrapSchemas.add( new SystemSchema() );
+ loader.load( bootstrapSchemas, registries );
+
+ // run referential integrity tests
+ java.util.List errors = registries.checkRefInteg();
+ if ( !errors.isEmpty() )
+ {
+ NamingException e = new NamingException();
+ e.setRootCause( ( Throwable ) errors.get( 0 ) );
+ throw e;
+ }
+
+ configuration = new TestConfiguration( registries, startupConfiguration );
+
+ // --------------------------------------------------------------------
+ // If not present extract schema partition from jar
+ // --------------------------------------------------------------------
+
+ SchemaPartitionExtractor extractor = null;
+ try
+ {
+ extractor = new SchemaPartitionExtractor( startupConfiguration.getWorkingDirectory() );
+ extractor.extract();
+ }
+ catch ( IOException e )
+ {
+ NamingException ne = new NamingException( "Failed to extract pre-loaded schema partition." );
+ ne.setRootCause( e );
+ throw ne;
+ }
+
+ // --------------------------------------------------------------------
+ // Initialize schema partition
+ // --------------------------------------------------------------------
+
+ MutablePartitionConfiguration pc = new MutablePartitionConfiguration();
+ pc.setName( "schema" );
+ pc.setCacheSize( 1000 );
+ pc.setIndexedAttributes( extractor.getDbFileListing().getIndexedAttributes() );
+ pc.setOptimizerEnabled( true );
+ pc.setSuffix( "ou=schema" );
+
+ Attributes entry = new LockableAttributesImpl();
+ entry.put( "objectClass", "top" );
+ entry.get( "objectClass" ).add( "organizationalUnit" );
+ entry.put( "ou", "schema" );
+ pc.setContextEntry( entry );
+ schemaPartition = new JdbmPartition();
+ schemaPartition.init( configuration, pc );
+ }
+
+
+ public void testGetSchemaNames() throws NamingException
+ {
+ PartitionSchemaLoader loader = new PartitionSchemaLoader( schemaPartition, registries );
+ Set<String> schemaNames = loader.getSchemaNames();
+ assertTrue( schemaNames.contains( "mozilla" ) );
+ assertTrue( schemaNames.contains( "core" ) );
+ assertTrue( schemaNames.contains( "apachedns" ) );
+ assertTrue( schemaNames.contains( "autofs" ) );
+ assertTrue( schemaNames.contains( "apache" ) );
+ assertTrue( schemaNames.contains( "cosine" ) );
+ assertTrue( schemaNames.contains( "krb5kdc" ) );
+ assertTrue( schemaNames.contains( "samba" ) );
+ assertTrue( schemaNames.contains( "collective" ) );
+ assertTrue( schemaNames.contains( "java" ) );
+ assertTrue( schemaNames.contains( "dhcp" ) );
+ assertTrue( schemaNames.contains( "corba" ) );
+ assertTrue( schemaNames.contains( "nis" ) );
+ assertTrue( schemaNames.contains( "inetorgperson" ) );
+ assertTrue( schemaNames.contains( "system" ) );
+ assertTrue( schemaNames.contains( "apachemeta" ) );
+ }
+
+
+ class TestConfiguration implements DirectoryServiceConfiguration
+ {
+ Registries registries;
+ StartupConfiguration startupConfiguration;
+
+
+ public TestConfiguration( Registries registries, StartupConfiguration startupConfiguration )
+ {
+ this.registries = registries;
+ this.startupConfiguration = startupConfiguration;
+ }
+
+ public Hashtable getEnvironment()
+ {
+ return new Hashtable();
+ }
+
+ public String getInstanceId()
+ {
+ return "default";
+ }
+
+ public InterceptorChain getInterceptorChain()
+ {
+ return null;
+ }
+
+ public PartitionNexus getPartitionNexus()
+ {
+ return null;
+ }
+
+ public Registries getRegistries()
+ {
+ return registries;
+ }
+
+ public DirectoryService getService()
+ {
+ return null;
+ }
+
+ public DirectoryServiceListener getServiceListener()
+ {
+ return null;
+ }
+
+ public StartupConfiguration getStartupConfiguration()
+ {
+ return startupConfiguration;
+ }
+
+ public boolean isFirstStart()
+ {
+ return false;
+ }
+
+ }
+}
Modified: directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema?view=diff&rev=487858&r1=487857&r2=487858
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema (original)
+++ directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema Sat Dec 16 11:02:12 2006
@@ -79,6 +79,9 @@
# | 1.3.6.1.4.1.18060.0.4.0.2.34 | m-humanReadible |
# | 1.3.6.1.4.1.18060.0.4.0.2.35 | m-extensionSyntax |
# | 1.3.6.1.4.1.18060.0.4.0.2.36 | m-extensionMatchingRule |
+# | 1.3.6.1.4.1.18060.0.4.0.2.37 | m-disabled |
+# | 1.3.6.1.4.1.18060.0.4.0.2.38 | m-dependencies |
+# | 1.3.6.1.4.1.18060.0.4.0.2.39 | m-owner |
# +------------------------------+-----------------------------+
#
# +------------------------------+-----------------------------+
@@ -319,8 +322,8 @@
DESC 'A schema object under which meta schema definitions are found'
SUP metaTop
STRUCTURAL
- MUST cn
- MAY m-disabled
+ MUST ( cn $ m-owner )
+ MAY ( m-disabled $ m-dependencies )
)
# --- metaNormalizer objectclass ----------------------------------------------
@@ -619,6 +622,23 @@
DESC 'Used as a marker for schemas to enable or disable them.'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
+ SINGLE-VALUE
+)
+
+# --- m-dependencies AttributeType -----------------------------------
+attributetype ( 1.3.6.1.4.1.18060.0.4.0.2.38 NAME 'm-dependencies'
+ DESC 'The dependencies of a schema: other schema names.'
+ EQUALITY caseIgnoreMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
)
+
+# --- m-owner AttributeType -----------------------------------
+attributetype ( 1.3.6.1.4.1.18060.0.4.0.2.39 NAME 'm-owner'
+ DESC 'The owner of this schema.'
+ EQUALITY distinguishedNameMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
+ SINGLE-VALUE
+)
+