directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r808228 - in /directory: apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/ apacheds/branches/apacheds-schema/schema-data/src/main/resources/schema/ apacheds/branches/apacheds-schema/schema-loader/...
Date Wed, 26 Aug 2009 23:55:12 GMT
Author: akarasulu
Date: Wed Aug 26 23:55:11 2009
New Revision: 808228

URL: http://svn.apache.org/viewvc?rev=808228&view=rev
Log:
moved and un-abstracted the AbstractSchema to be the DefaultSchema while moving it from apacheds
to shared

Added:
    directory/apacheds/branches/apacheds-schema/schema-loader/src/main/java/org/apache/directory/server/schema/loader/ldif/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/main/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoader.java
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/
    directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchema.java
Removed:
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchema.java
Modified:
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
    directory/apacheds/branches/apacheds-schema/schema-data/src/main/resources/schema/schema.ldif

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java?rev=808228&r1=808227&r2=808228&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
Wed Aug 26 23:55:11 2009
@@ -52,6 +52,7 @@
 import org.apache.directory.shared.ldap.schema.parsers.NormalizerDescription;
 import org.apache.directory.shared.ldap.schema.parsers.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.registries.DefaultSchema;
 import org.apache.directory.shared.ldap.util.Base64;
 
 
@@ -136,7 +137,7 @@
             dependencies = depsSet.toArray( EMPTY_ARRAY );
         }
         
-        return new AbstractSchema( name, owner, dependencies, isDisabled ){};
+        return new DefaultSchema( name, owner, dependencies, isDisabled ){};
     }
     
     

Modified: directory/apacheds/branches/apacheds-schema/schema-data/src/main/resources/schema/schema.ldif
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/schema-data/src/main/resources/schema/schema.ldif?rev=808228&r1=808227&r2=808228&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/schema-data/src/main/resources/schema/schema.ldif
(original)
+++ directory/apacheds/branches/apacheds-schema/schema-data/src/main/resources/schema/schema.ldif
Wed Aug 26 23:55:11 2009
@@ -4,3 +4,5 @@
 objectclass: organizationalUnit
 objectclass: top
 entrycsn: 20090818052725.311000Z#000000#000#000000
+creatorsname: uid=admin,ou=system
+createtimestamp: 20090818022726Z

Added: directory/apacheds/branches/apacheds-schema/schema-loader/src/main/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/schema-loader/src/main/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoader.java?rev=808228&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-schema/schema-loader/src/main/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoader.java
(added)
+++ directory/apacheds/branches/apacheds-schema/schema-loader/src/main/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoader.java
Wed Aug 26 23:55:11 2009
@@ -0,0 +1,175 @@
+/*
+ *  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.loader.ldif;
+
+
+import org.apache.directory.shared.ldap.schema.registries.AbstractSchemaLoader;
+import org.apache.directory.shared.ldap.schema.registries.Schema;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.registries.DefaultSchema;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+
+
+/**
+ * Loads schema data from an LDIF files containing entries representing schema
+ * objects, using the meta schema format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision$
+ */
+public class LdifSchemaLoader extends AbstractSchemaLoader
+{
+    /** static class logger */
+    private static final Logger LOG = LoggerFactory.getLogger( LdifSchemaLoader.class );
+
+    /** Speedup for DEBUG mode */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    private final File baseDirectory;
+    private final Set<Schema> schemas = new HashSet<Schema>();
+    private final FilenameFilter ldifFilter = new FilenameFilter()
+    {
+        @Override
+        public boolean accept( File file, String name )
+        {
+            return name.endsWith( "ldif" );
+        }
+    };
+
+
+    /**
+     * Creates a new LDIF based SchemaLoader. The constructor checks to make
+     * sure the supplied base directory exists and contains a schema.ldif file
+     * and if not complains about it.
+     *
+     * @param baseDirectory the schema LDIF base directory
+     * @throws Exception if the base directory does not exist or does not
+     * a valid schema.ldif file
+     */
+    public LdifSchemaLoader( File baseDirectory ) throws Exception
+    {
+        this.baseDirectory = baseDirectory;
+
+        if ( ! baseDirectory.exists() )
+        {
+            throw new IllegalArgumentException( "Provided baseDirectory '" +
+                    baseDirectory.getAbsolutePath() + "' does not exist." );
+        }
+
+        File schemaLdif = new File( baseDirectory, "schema.ldif" );
+        if ( ! schemaLdif.exists() )
+        {
+            throw new FileNotFoundException( "Expecting to find a schema.ldif file in provided
baseDirectory " +
+                    "path '" + baseDirectory.getAbsolutePath() + "' but no such file found."
);
+        }
+
+        initializeSchemas();
+    }
+
+
+    /**
+     * Scans for LDIF files just describing the various schema contained in
+     * the schema repository.
+     *
+     * @throws Exception
+     */
+    private void initializeSchemas() throws Exception
+    {
+        File schemaDirectory = new File( baseDirectory, "schema" );
+        String[] ldifFiles = schemaDirectory.list( ldifFilter );
+
+        for ( int ii = 0; ii < ldifFiles.length; ii++ )
+        {
+            LdifReader reader = new LdifReader( new File( schemaDirectory, ldifFiles[ii]
) );
+            LdifEntry entry = reader.next();
+            schemas.add( ldifToSchema( entry ) );
+        }
+    }
+
+
+    private Schema ldifToSchema( LdifEntry entry ) throws Exception
+    {
+        String name = entry.get( SchemaConstants.CN_AT ).getString();
+
+        boolean isDisabled = false;
+        if ( entry.get( "m-disabled" ) != null )
+        {
+            isDisabled = Boolean.getBoolean( entry.get( "m-disabled" ).getString() );
+        }
+
+        String[] dependencies = null;
+        if ( entry.get( "m-dependencies" ) != null )
+        {
+            dependencies = new String[ entry.get( "m-dependencies" ).size() ];
+            int ii = 0;
+            Iterator<Value<?>> list = entry.get( "m-dependencies" ).getAll();
+            while ( list.hasNext() )
+            {
+                dependencies[ii] = list.next().getString();
+                ii++;
+            }
+        }
+
+        return new DefaultSchema( name, null, dependencies, isDisabled );
+    }
+
+
+    @Override
+    public Schema getSchema( String schemaName ) throws Exception
+    {
+        return null;
+    }
+
+
+    @Override
+    public Schema getSchema( String schemaName, Properties schemaProperties ) throws Exception
+    {
+        return null;
+    }
+
+
+    @Override
+    public void loadWithDependencies( Collection<Schema> schemas, Registries registries
) throws Exception
+    {
+    }
+
+
+    @Override
+    public void loadWithDependencies( Schema schemas, Registries registries ) throws Exception
+    {
+    }
+
+
+    @Override
+    public void load( Schema schema, Registries registries, boolean isDepLoad ) throws Exception
+    {
+    }
+}

Added: directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java?rev=808228&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
(added)
+++ directory/apacheds/branches/apacheds-schema/schema-loader/src/test/java/org/apache/directory/server/schema/loader/ldif/LdifSchemaLoaderTest.java
Wed Aug 26 23:55:11 2009
@@ -0,0 +1,40 @@
+/*
+ *  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.loader.ldif;
+
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+
+/**
+ * Tests the LdifSchemaLoader.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision$
+ */
+public class LdifSchemaLoaderTest extends TestCase
+{
+    public static void testConstructor() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( new File( "/Users/akarasulu/schema"
) );
+    }
+}

Added: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchema.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchema.java?rev=808228&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchema.java
(added)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchema.java
Wed Aug 26 23:55:11 2009
@@ -0,0 +1,144 @@
+/*
+ *  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.shared.ldap.schema.registries;
+
+
+
+/**
+ * The default Schema interface implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultSchema 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 DefaultSchema( String name )
+    {
+        this( name, null, null, false );
+    }
+    
+        
+    public DefaultSchema( String name, String owner )
+    {
+        this( name, owner, null, false );
+    }
+    
+        
+    public DefaultSchema( String name, String owner, String[] dependencies )
+    {
+        this( name, owner, dependencies, false );
+    }
+    
+        
+    public DefaultSchema( 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;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDisabled()
+    {
+        return disabled;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled()
+    {
+        return !disabled;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void disable()
+    {
+        this.disabled = true;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void enable()
+    {
+        this.disabled = false;
+    }
+}



Mime
View raw message