directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r487719 - in /directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org: ./ apache/ apache/directory/ apache/directory/server/ apache/directory/server/schema/ apache/directory/server/schema/bootstrap/ apache/directory/...
Date Fri, 15 Dec 2006 23:39:40 GMT
Author: akarasulu
Date: Fri Dec 15 15:39:39 2006
New Revision: 487719

URL: http://svn.apache.org/viewvc?view=rev&rev=487719
Log:
experimental self extracting schema partition setup

Added:
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/
    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-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileType.java
    directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java

Added: 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=auto&rev=487719
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
(added)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileListing.java
Fri Dec 15 15:39:39 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.schema.bootstrap.partition;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ * Parses the dbfile listing file within this jar. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DbFileListing
+{
+    Map<String, DbFileType> name2type = new HashMap<String, DbFileType>(); 
+    
+    
+    public DbFileListing() throws IOException 
+    {
+        init();
+    }
+    
+    
+    private void init() throws IOException
+    {
+        BufferedReader in = new BufferedReader( new InputStreamReader( getClass().getResourceAsStream(
"DBFILES" ) ) );
+        boolean userIndexMode = false;
+        String line = null;
+        while ( ( line = in.readLine() ) != null )
+        {
+            if ( line.indexOf( "master.db" ) != -1 )
+            {
+                name2type.put( line.trim(), DbFileType.MASTER_FILE );
+                continue;
+            }
+            
+            if ( line.indexOf( "USER INDICES" ) != -1 )
+            {
+                userIndexMode = true;
+                continue;
+            }
+            
+            if ( userIndexMode )
+            {
+                name2type.put( line, DbFileType.USER_INDEX );
+            }
+            else
+            {
+                name2type.put( line, DbFileType.SYSTEM_INDEX );
+            }
+        }
+    }
+    
+    
+    public DbFileType getType( String dbfile )
+    {
+        return name2type.get( dbfile );
+    }
+    
+    
+    public Iterator<String> iterator()
+    {
+        return name2type.keySet().iterator();
+    }
+    
+    
+    public String getIndexAttributeName( String dbfile )
+    {
+        if ( dbfile.length() < 10 )
+        {
+            throw new IllegalArgumentException( "db file must have a relative jar path name
of over 10 characters" );
+        }
+        
+        // remove 'schema/'
+        String dbfileName = dbfile.substring( 7 );
+        return dbfileName.substring( 0, dbfileName.length() - 3 );
+    }
+}

Added: directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileType.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileType.java?view=auto&rev=487719
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileType.java
(added)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/DbFileType.java
Fri Dec 15 15:39:39 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.bootstrap.partition;
+
+
+/**
+ * The type of the dbfile.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public enum DbFileType
+{
+    MASTER_FILE,
+    SYSTEM_INDEX,
+    USER_INDEX
+}

Added: directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java?view=auto&rev=487719
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
(added)
+++ directory/branches/trunks/schema/apacheds/bootstrap-partition/src/main/java/org/apache/directory/server/schema/bootstrap/partition/SchemaPartitionExtractor.java
Fri Dec 15 15:39:39 2006
@@ -0,0 +1,97 @@
+/*
+ *  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.bootstrap.partition;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+ * Extracts dbfiles for the schema partition onto a destination directory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SchemaPartitionExtractor
+{
+    private DbFileListing listing;
+    private File outputDirectory; 
+    
+    
+    public SchemaPartitionExtractor( File outputDirectory ) throws IOException
+    {
+        this.outputDirectory = outputDirectory;
+        this.listing = new DbFileListing();
+    }
+    
+    
+    public void extract() throws IOException
+    {
+        if ( ! outputDirectory.exists() )
+        {
+            outputDirectory.mkdirs();
+        }
+
+        Iterator<String> ii = listing.iterator();
+        while ( ii.hasNext() )
+        {
+            extract( ii.next() );
+        }
+    }
+    
+    
+    public DbFileListing getDbFileListing()
+    {
+        return listing;
+    }
+    
+    
+    private void extract( String resource ) throws IOException
+    {
+        byte[] buf = new byte[512];
+        InputStream in = getClass().getResourceAsStream( resource );
+        FileOutputStream out = null;
+
+        try
+        {
+            out = new FileOutputStream( new File( outputDirectory, resource ) );
+            while( in.available() > 0 )
+            {
+                int readCount = in.read( buf );
+                out.write( buf, 0, readCount );
+            }
+            out.flush();
+        }
+        finally
+        {
+            if ( out != null )
+            {
+                out.close();
+            }
+            
+            if ( in != null )
+            {
+                in.close();
+            }
+        }
+    }
+}



Mime
View raw message