directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r495733 - in /directory/trunks/shared/convert/src: main/antlr/ main/java/org/apache/directory/shared/converter/schema/ test/java/org/apache/directory/shared/converter/schema/ test/resources/org/apache/directory/shared/converter/schema/
Date Fri, 12 Jan 2007 20:45:27 GMT
Author: elecharny
Date: Fri Jan 12 12:45:26 2007
New Revision: 495733

URL: http://svn.apache.org/viewvc?view=rev&rev=495733
Log:
Improved the generation of Ldif from schema files, but not finished yet. Handling of optional
values is not done.
This checkin is just done to be able to work on this code from home

Added:
    directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElement.java
    directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java
Modified:
    directory/trunks/shared/convert/src/main/antlr/schema.g
    directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java
    directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java
    directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaParser.java
    directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java
    directory/trunks/shared/convert/src/test/java/org/apache/directory/shared/converter/schema/TestSchemaToLdif.java
    directory/trunks/shared/convert/src/test/resources/org/apache/directory/shared/converter/schema/test.schema

Modified: directory/trunks/shared/convert/src/main/antlr/schema.g
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/antlr/schema.g?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/antlr/schema.g (original)
+++ directory/trunks/shared/convert/src/main/antlr/schema.g Fri Jan 12 12:45:26 2007
@@ -37,12 +37,10 @@
 import java.util.List ;
 import java.util.ArrayList ;
 import java.util.Collections;
-import java.io.Writer;
 import java.io.IOException;
 
 import org.apache.directory.shared.ldap.schema.UsageEnum;
-import org.apache.directory.shared.converter.schema.ObjectClassHolder;
-import org.apache.directory.shared.converter.schema.AttributeTypeHolder;
+import org.apache.directory.shared.converter.schema.SchemaElement;
 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
 }
 
@@ -123,36 +121,20 @@
 	
     public static final String[] EMPTY = new String[0];
 
-    private List<AttributeTypeHolder> attributeTypes = new ArrayList<AttributeTypeHolder>();
-    private List<ObjectClassHolder> objectClasses = new ArrayList<ObjectClassHolder>();
-    private Writer schemaOut;
-
+    private List<SchemaElement> schemaElements = new ArrayList<SchemaElement>();
 
     // ------------------------------------------------------------------------
     // Public Methods
     // ------------------------------------------------------------------------
-    public void setOutput( Writer out )
-    {
-        schemaOut = out;
-    }
-
-
     public void clear()
     {
-        attributeTypes.clear();
-        objectClasses.clear();
+        schemaElements.clear();
     }
 
 
-    public List<AttributeTypeHolder> getAttributeTypes()
+    public List<SchemaElement> getSchemaElements()
     {
-        return Collections.unmodifiableList( attributeTypes );
-    }
-
-
-    public List<ObjectClassHolder> getObjectClasses()
-    {
-        return Collections.unmodifiableList( objectClasses );
+        return Collections.unmodifiableList( schemaElements );
     }
 }
 
@@ -196,7 +178,7 @@
     ( may[objectClass] )?
     CLOSE_PAREN
     {
-        objectClasses.add( objectClass );
+        schemaElements.add( objectClass );
     }
     ;
 
@@ -323,7 +305,7 @@
         )
     )
     {
-        objectClass.setNames( ( String[] ) list.toArray( EMPTY ) );
+        objectClass.setNames( list );
     }
     ;
 
@@ -358,7 +340,7 @@
 
     CLOSE_PAREN
     {
-        attributeTypes.add( type );
+        schemaElements.add( type );
     }
     ;
 
@@ -461,7 +443,11 @@
     :
         "NAME"
     (
-        QUOTE id0:IDENTIFIER QUOTE { list.add( id0.getText() ); } |
+        QUOTE id0:IDENTIFIER QUOTE 
+        { 
+            list.add( id0.getText() ); 
+        } 
+        |
         ( OPEN_PAREN
             ( QUOTE id1:IDENTIFIER
                 {
@@ -472,7 +458,7 @@
         CLOSE_PAREN )
     )
     {
-        type.setNames( ( String[] ) list.toArray( EMPTY ) );
+        type.setNames( list );
     }
     ;
 

Modified: directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java
(original)
+++ directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java
Fri Jan 12 12:45:26 2007
@@ -21,7 +21,6 @@
 
 
 import org.apache.directory.shared.ldap.schema.UsageEnum;
-import org.apache.directory.shared.ldap.util.ArrayUtils;
 
 
 /**
@@ -31,15 +30,12 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 476875 $
  */
-public class AttributeTypeHolder
+public class AttributeTypeHolder extends SchemaElementImpl
 {
-    private boolean obsolete = false;
     private boolean singleValue = false;
     private boolean collective = false;
     private boolean noUserModification = false;
 
-    private String oid;
-    private String description;
     private String superior;
     private String equality;
     private String ordering;
@@ -48,8 +44,6 @@
 
     private UsageEnum usage = UsageEnum.USER_APPLICATIONS;
 
-    private String[] names = ArrayUtils.EMPTY_STRING_ARRAY;
-
     private int length = -1;
 
 
@@ -204,18 +198,12 @@
         this.usage = usage;
     }
 
-
-    public String[] getNames()
-    {
-        return names;
-    }
-
-
+    /**
     public void setNames( String[] names )
     {
         this.names = names;
     }
-
+    */
 
     public int getLength()
     {

Modified: directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java
(original)
+++ directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java
Fri Jan 12 12:45:26 2007
@@ -31,14 +31,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 437016 $
  */
-public class ObjectClassHolder
+public class ObjectClassHolder extends SchemaElementImpl
 {
-    private boolean obsolete = false;
 
-    private String oid;
-    private String description;
-
-    private String[] names = ArrayUtils.EMPTY_STRING_ARRAY;
     private String[] superiors = ArrayUtils.EMPTY_STRING_ARRAY;
     private String[] must = ArrayUtils.EMPTY_STRING_ARRAY;
     private String[] may = ArrayUtils.EMPTY_STRING_ARRAY;
@@ -93,18 +88,6 @@
     public void setDescription( String description )
     {
         this.description = description;
-    }
-
-
-    public String[] getNames()
-    {
-        return names;
-    }
-
-
-    public void setNames( String[] names )
-    {
-        this.names = names;
     }
 
 

Added: directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElement.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElement.java?view=auto&rev=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElement.java
(added)
+++ directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElement.java
Fri Jan 12 12:45:26 2007
@@ -0,0 +1,14 @@
+
+package org.apache.directory.shared.converter.schema;
+
+import java.util.List;
+
+public interface SchemaElement
+{
+    boolean isObsolete();
+    String getOid();
+    String getDescription();
+    List<String> getNames();
+    void setNames( List<String> names );
+    String getShortAlias();
+}

Added: directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java?view=auto&rev=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java
(added)
+++ directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java
Fri Jan 12 12:45:26 2007
@@ -0,0 +1,46 @@
+
+package org.apache.directory.shared.converter.schema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SchemaElementImpl implements SchemaElement
+{
+    protected boolean obsolete = false;
+    protected String oid;
+    protected String description;
+    protected List<String> names = new ArrayList<String>();
+    
+    public boolean isObsolete()
+    {
+        return obsolete;
+    }
+    
+    public String getOid()
+    {
+        return oid;
+    }
+    
+    public String getDescription()
+    {
+        return description;
+    }
+    
+    public List<String> getNames()
+    {
+        return names;
+    }
+    
+    public void setNames( List<String> names )
+    {
+        this.names = names;
+    }
+
+
+
+
+    public String getShortAlias()
+    {
+        return ( names.size() == 0 ? "" : names.get( 0 ) );
+    }
+}

Modified: directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaParser.java?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaParser.java
(original)
+++ directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaParser.java
Fri Jan 12 12:45:26 2007
@@ -30,7 +30,6 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 import java.io.Writer;
@@ -54,6 +53,11 @@
     /** A pipe into the parser */
     private PipedOutputStream parserIn = null;
 
+    byte[] buf = new byte[128];
+
+    private InputStream schemaIn;
+    
+    private Thread producerThread;
 
     /**
      * Creates a reusable instance of an SchemaParser.
@@ -86,26 +90,12 @@
         parser.clear();
     }
 
-
-    public List getAttributeTypes()
-    {
-        return parser.getAttributeTypes();
-    }
-
-
-    public List getObjectClassTypes()
-    {
-        return parser.getObjectClasses();
-    }
-
-
-    
     /**
      * Thread safe method parses an OpenLDAP schemaObject element/object.
      *
      * @param schemaObject the String image of a complete schema object
      */
-    public synchronized void parse( String schemaObject ) throws IOException, ParseException
+    public synchronized List<SchemaElement> parse( String schemaObject ) throws IOException,
ParseException
     {
         if ( schemaObject == null || schemaObject.trim().equals( "" ) )
         {
@@ -120,17 +110,17 @@
         }
 
         producerThread.start();
-        invokeParser( schemaObject );
+        return invokeParser( schemaObject );
     }
 
 
-    private void invokeParser( String subject ) throws IOException, ParseException
+    private List<SchemaElement> invokeParser( String subject ) throws IOException,
ParseException
     {
         try
         {
-            parser.setOutput( schemaOut );
-
             parser.parseSchema();
+            
+            return parser.getSchemaElements();
         }
         catch ( RecognitionException e )
         {
@@ -148,21 +138,14 @@
         }
     }
 
-    byte[] buf = new byte[128];
-    private InputStream schemaIn;
-    private Writer schemaOut;
-    private Thread producerThread;
-
-
     /**
      * Thread safe method parses a stream of OpenLDAP schemaObject elements/objects.
      *
      * @param schemaIn a stream of schema objects
      */
-    public synchronized void parse( InputStream schemaIn, Writer out ) throws IOException,
ParseException
+    public synchronized List<SchemaElement> parse( InputStream schemaIn, Writer out
) throws IOException, ParseException
     {
         this.schemaIn = schemaIn;
-        this.schemaOut = out;
 
         if ( producerThread == null )
         {
@@ -171,8 +154,7 @@
 
         producerThread.start();
 
-        invokeParser( "schema input stream ==> " + schemaIn.toString() );
-        out.flush();
+        return invokeParser( "schema input stream ==> " + schemaIn.toString() );
     }
 
 

Modified: directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java
(original)
+++ directory/trunks/shared/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java
Fri Jan 12 12:45:26 2007
@@ -5,7 +5,14 @@
 import java.io.Writer;
 import java.util.List;
 
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
 import org.apache.directory.shared.converter.schema.Schema;
+import org.apache.directory.shared.ldap.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.Rdn;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,6 +78,7 @@
             }
             catch ( Exception e )
             {
+                e.printStackTrace();
                 throw new ParserException( "Failed while generating sources for " + schema.getName()
);
             }
         }
@@ -88,6 +96,61 @@
         Writer out = schema.getOutput();
         
         SchemaParser parser = new SchemaParser();
-        parser.parse( in, out );
+        List<SchemaElement> elements = parser.parse( in, out );
+        
+        out.write( HEADER );
+        
+        for ( SchemaElement element:elements )
+        {
+            Attributes attributes = new AttributesImpl();
+            
+            StringBuilder sb = new StringBuilder();
+            String dn = "m-name=" + Rdn.escapeValue( element.getShortAlias() ) + ", ou="
+ Rdn.escapeValue( schema.getName() ) + ", ou=schema";
+            
+            // First dump the DN only
+            Attribute attribute = new AttributeImpl( "dn", dn );
+            attributes.put( attribute );
+            sb.append( LdifUtils.convertToLdif( attributes ) );
+            
+            if ( element instanceof ObjectClassHolder )
+            {
+                sb.append( "objectclass: MetaObjectClass\n" );
+            }
+            else
+            {
+                sb.append( "objectclass: MetaAttribute\n" );
+            }
+            
+            sb.append( "objectclass: MetaTop\n" );
+            sb.append( "objectClass: top\n" );
+            
+            sb.append( "m-oid: " ).append( element.getOid() ).append( '\n' );
+            sb.append( "m-name: " ).append( element.getShortAlias() ).append( '\n' );
+            
+            attributes = new AttributesImpl();
+            attribute = new AttributeImpl( "m-desc" );
+            attribute.add( element.getDescription() );
+            attributes.put( attribute );
+            
+            if ( element.isObsolete() )
+            {
+                sb.append( "m-obsolete: true\n" );
+            }
+            
+            sb.append( LdifUtils.convertToLdif( attributes ) ).append( '\n' );
+
+            if ( element instanceof ObjectClassHolder )
+            {
+                ObjectClassHolder objectClass = (ObjectClassHolder)element; 
+            }
+            else
+            {
+                AttributeTypeHolder attributeType = (AttributeTypeHolder)element; 
+            }
+
+            out.write(  sb.toString() );
+        }
+        
+        out.flush();
     }
-}
+}
\ No newline at end of file

Modified: directory/trunks/shared/convert/src/test/java/org/apache/directory/shared/converter/schema/TestSchemaToLdif.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/test/java/org/apache/directory/shared/converter/schema/TestSchemaToLdif.java?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/test/java/org/apache/directory/shared/converter/schema/TestSchemaToLdif.java
(original)
+++ directory/trunks/shared/convert/src/test/java/org/apache/directory/shared/converter/schema/TestSchemaToLdif.java
Fri Jan 12 12:45:26 2007
@@ -15,7 +15,7 @@
         
         List<Schema> schemas = new ArrayList<Schema>();
         Schema schema = new Schema();
-        schema.setName( "test.schema" );
+        schema.setName( "test" );
         schema.setInput( getClass().getResourceAsStream( "test.schema" ) );
         schema.setOutput( new OutputStreamWriter( System.out ) );
         schemas.add( schema );

Modified: directory/trunks/shared/convert/src/test/resources/org/apache/directory/shared/converter/schema/test.schema
URL: http://svn.apache.org/viewvc/directory/trunks/shared/convert/src/test/resources/org/apache/directory/shared/converter/schema/test.schema?view=diff&rev=495733&r1=495732&r2=495733
==============================================================================
--- directory/trunks/shared/convert/src/test/resources/org/apache/directory/shared/converter/schema/test.schema
(original)
+++ directory/trunks/shared/convert/src/test/resources/org/apache/directory/shared/converter/schema/test.schema
Fri Jan 12 12:45:26 2007
@@ -153,3 +153,10 @@
 	DESC 'A non-authoritative referral or glue address record'
 	SUP apacheDnsAbstractRecord 
 	MUST ( apacheDnsDomainName $ apacheDnsIpAddress ) )
+	
+objectclass ( 1.3.6.1.4.1.18060.0.4.2.3.12
+	NAME 'lecharny'
+	DESC 'A non-authoritative referral or glue address record'
+	SUP apacheDnsAbstractRecord 
+	MUST ( apacheDnsDomainName $ apacheDnsIpAddress ) )
+	
\ No newline at end of file



Mime
View raw message