directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r893813 [2/2] - in /directory: apacheds/branches/apacheds-schema/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/ apacheds/branches/apacheds-schema/core-entry/src/test/java/org/apache/directory/server/core/entry/ ...
Date Thu, 24 Dec 2009 22:00:16 GMT
Copied: directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
(from r893672, directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java)
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java?p2=directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java&p1=directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java&r1=893672&r2=893813&rev=893813&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractor.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/DefaultSchemaLdifExtractor.java
Thu Dec 24 21:59:42 2009
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.ldap.schema.ldif.extractor;
+package org.apache.directory.shared.ldap.schema.ldif.extractor.impl;
 
 
 import java.io.BufferedReader;
@@ -35,6 +35,9 @@
 import java.util.Map.Entry;
 import java.util.regex.Pattern;
 
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.ResourceMap;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.UniqueResourceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,20 +48,67 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664295 $
  */
-public class SchemaLdifExtractor
+public class DefaultSchemaLdifExtractor implements SchemaLdifExtractor
 {
     private static final String BASE_PATH = "";
 
-    private static final Logger LOG = LoggerFactory.getLogger( SchemaLdifExtractor.class
);
-    
+    private static final String SCHEMA_SUBDIR = "schema";
+
+    private static final Logger LOG = LoggerFactory.getLogger( DefaultSchemaLdifExtractor.class
);
+
+    private boolean extracted;
+
     private File outputDirectory;
 
+    private File schemaDirectory;
 
-    public SchemaLdifExtractor( File outputDirectory ) throws IOException
+
+    /**
+     * Creates an extractor which deposits files into the specified output
+     * directory.
+     *
+     * @param outputDirectory the directory where the schema root is extracted
+     */
+    public DefaultSchemaLdifExtractor( File outputDirectory )
     {
-        LOG.debug( "BASE_PATH set to {}, outputDirectory set to {}", 
-            BASE_PATH, outputDirectory );
+        LOG.debug( "BASE_PATH set to {}, outputDirectory set to {}", BASE_PATH, outputDirectory
);
         this.outputDirectory = outputDirectory;
+        this.schemaDirectory = new File( outputDirectory, SCHEMA_SUBDIR );
+
+        if ( ! outputDirectory.exists() )
+        {
+            LOG.debug( "Creating output directory: {}", outputDirectory );
+            if( ! outputDirectory.mkdir() )
+            {
+                LOG.error( "Failed to create outputDirectory: {}", outputDirectory );
+            }
+        }
+        else
+        {
+            LOG.debug( "Output directory exists: no need to create." );
+        }
+
+        if ( ! schemaDirectory.exists() )
+        {
+            LOG.info( "Schema directory '{}' does NOT exist: extracted state set to false.",
schemaDirectory );
+            extracted = false;
+        }
+        else
+        {
+            LOG.info( "Schema directory '{}' does exist: extracted state set to true.", schemaDirectory
);
+            extracted = true;
+        }
+    }
+
+
+    /**
+     * Gets whether or not schema folder has been created or not.
+     *
+     * @return true if schema folder has already been extracted.
+     */
+    public boolean isExtracted()
+    {
+        return extracted;
     }
 
 
@@ -68,6 +118,7 @@
      * @param overwrite over write extracted structure if true, false otherwise
      * @throws IOException if schema already extracted and on IO errors
      */
+    @Override
     public void extractOrCopy( boolean overwrite ) throws IOException
     {
         if ( ! outputDirectory.exists() )
@@ -75,7 +126,7 @@
             outputDirectory.mkdir();
         }
 
-        File schemaDirectory = new File( outputDirectory, "schema" );
+        File schemaDirectory = new File( outputDirectory, SCHEMA_SUBDIR );
 
         if ( ! schemaDirectory.exists() )
         {
@@ -112,6 +163,7 @@
      *
      * @throws IOException if schema already extracted and on IO errors
      */
+    @Override
     public void extractOrCopy() throws IOException
     {
         extractOrCopy( false );
@@ -261,7 +313,7 @@
     public static URL getUniqueResource( String resourceName, String resourceDescription
)
             throws IOException
     {
-        Enumeration<URL> resources = SchemaLdifExtractor.class.getClassLoader().getResources(
resourceName );
+        Enumeration<URL> resources = DefaultSchemaLdifExtractor.class.getClassLoader().getResources(
resourceName );
         if ( !resources.hasMoreElements() )
         {
             throw new UniqueResourceException( resourceName, resourceDescription );
@@ -284,7 +336,7 @@
     private void extractFromJar( String resource ) throws IOException
     {
         byte[] buf = new byte[512];
-        InputStream in = SchemaLdifExtractor.getUniqueResourceAsStream( resource, 
+        InputStream in = DefaultSchemaLdifExtractor.getUniqueResourceAsStream( resource,
             "LDIF file in schema repository" );
 
         try

Copied: directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/ResourceMap.java
(from r893561, directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/ResourceMap.java)
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/ResourceMap.java?p2=directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/ResourceMap.java&p1=directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/ResourceMap.java&r1=893561&r2=893813&rev=893813&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/ResourceMap.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/ldif/extractor/impl/ResourceMap.java
Thu Dec 24 21:59:42 2009
@@ -17,7 +17,7 @@
  *   under the License.
  *
  */
-package org.apache.directory.shared.ldap.schema.ldif.extractor;
+package org.apache.directory.shared.ldap.schema.ldif.extractor.impl;
 
 
 import java.io.File;

Modified: directory/shared/branches/shared-schema/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractorTest.java?rev=893813&r1=893812&r2=893813&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractorTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/ldif/extractor/SchemaLdifExtractorTest.java
Thu Dec 24 21:59:42 2009
@@ -24,13 +24,14 @@
 import java.io.IOException;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
  
 /**
- * Tests the SchemaLdifExtractor class.
+ * Tests the DefaultSchemaLdifExtractor class.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -68,7 +69,7 @@
     @Test
     public void testExtract() throws Exception
     {
-        SchemaLdifExtractor extractor = new SchemaLdifExtractor( 
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(
             new File( workingDirectory ) );
         extractor.extractOrCopy();
     }



Mime
View raw message