directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 54238 - in incubator/directory/eve/trunk/backend/tools/src: antlr java/org/apache/eve/tools/schema test/org/apache/eve/tools/schema
Date Sun, 10 Oct 2004 10:56:02 GMT
Author: akarasulu
Date: Sun Oct 10 03:56:01 2004
New Revision: 54238

Modified:
   incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g
   incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/OpenLdapSchemaParser.java
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/OpenLdapSchemaParserTest.java
Log:
Commit changes ...

 o corrected bugs in grammar around name productions on all entities
 o added more specific point tests
 o tested and passed all OpenLDAP schema file parses

Notes ...

 o found several errors that do not comply with RFC in schema files - I double
   tripple checked these with rfc 2252 description syntaxes
 o the primary problems were the occasional term order confusion and there were
   just one or two typos
 o the OpenLDAP server must just ignore term ordering or must ignore malformed
   descriptions

Corrected several bugs in grammar with processing names and added a


Modified: incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g	(original)
+++ incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g	Sun Oct 10 03:56:01 2004
@@ -100,7 +100,7 @@
 
 SYNTAX
     :
-        "syntax" WS NUMERICOID OPEN_BRACKET ( DIGIT )+ CLOSE_BRACKET
+        "syntax" WS NUMERICOID ( OPEN_BRACKET ( DIGIT )+ CLOSE_BRACKET )?
     ;
 
 class antlrOpenLdapSchemaParser extends Parser ;
@@ -302,7 +302,8 @@
 }
     :
     (
-        "NAME" QUOTE id0:IDENTIFIER QUOTE
+        "NAME"
+        ( QUOTE id0:IDENTIFIER QUOTE
         {
             list.add( id0.getText() );
         }
@@ -315,6 +316,7 @@
         {
             list.add( id2.getText() );
         } )* CLOSE_PAREN )
+        )
     )
     {
         objectClass.setNames( ( String[] ) list.toArray( EMPTY ) );
@@ -337,6 +339,7 @@
     OPEN_PAREN oid:NUMERICOID
     {
         type = new AttributeTypeLiteral( oid.getText() );
+        System.out.println( oid.getText() );
     }
         ( names[type] )?
         ( desc[type] )?
@@ -365,6 +368,7 @@
     : d:DESC
     {
         type.setDescription( d.getText().split( "'" )[1] );
+        System.out.println( d.getText() );
     }
     ;
 

Modified: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/OpenLdapSchemaParser.java
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/OpenLdapSchemaParser.java
(original)
+++ incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/OpenLdapSchemaParser.java
Sun Oct 10 03:56:01 2004
@@ -35,8 +35,6 @@
  */
 public class OpenLdapSchemaParser
 {
-    /** a buffer to use while streaming data into the parser */
-    private byte[] buf = new byte[128];
     /** the monitor to use for this parser */
     private ParserMonitor monitor = new ParserMonitorAdapter();
     /** The antlr generated parser */
@@ -102,20 +100,23 @@
                 + "the empty String!", 0 );
         }
 
-        parserIn.write( schemaObject.getBytes() );
+        this.schemaIn = new ByteArrayInputStream( schemaObject.getBytes() );
+
+        if ( producerThread == null )
+        {
+            producerThread = new Thread( new DataProducer() );
+        }
+
+        producerThread.start();
         invokeParser( schemaObject );
     }
 
 
     private void invokeParser( String subject ) throws IOException, ParseException
     {
-        // using an input termination token END - need extra space to return
-        parserIn.write( "END ".getBytes() );
-        parserIn.flush();
-
         try
         {
-            monitor.startedParse( "starting parse ..." );
+            monitor.startedParse( "starting parse on:\n" + subject );
             parser.parseSchema();
             monitor.finishedParse( "Done parsing!" );
         }
@@ -136,6 +137,10 @@
     }
 
 
+    byte[] buf = new byte[128];
+    private InputStream schemaIn;
+    private Thread producerThread;
+
     /**
      * Thread safe method parses a stream of OpenLDAP schemaObject elements/objects.
      *
@@ -143,12 +148,14 @@
      */
     public synchronized void parse( InputStream schemaIn ) throws IOException, ParseException
     {
-        int count = -1;
-        while ( ( count = schemaIn.read( buf ) ) != -1 )
+        this.schemaIn = schemaIn;
+
+        if ( producerThread == null )
         {
-            parserIn.write( buf, 0, count );
+            producerThread = new Thread( new DataProducer() );
         }
 
+        producerThread.start();
         invokeParser( "schema input stream ==> " + schemaIn.toString() );
     }
 
@@ -160,14 +167,14 @@
      */
     public synchronized void parse( File schemaFile ) throws IOException, ParseException
     {
-        FileInputStream schemaIn = new FileInputStream( schemaFile );
+        this.schemaIn = new FileInputStream( schemaFile );
 
-        int count = -1;
-        while ( ( count = schemaIn.read( buf ) ) != -1 )
+        if ( producerThread == null )
         {
-            parserIn.write( buf, 0, count );
+            producerThread = new Thread( new DataProducer() );
         }
 
+        producerThread.start();
         invokeParser( "schema file ==> " + schemaFile.getAbsolutePath() );
     }
 
@@ -176,5 +183,30 @@
     {
         this.monitor = monitor ;
         this.parser.setParserMonitor( monitor );
+    }
+
+
+    class DataProducer implements Runnable
+    {
+        public void run()
+        {
+            int count = -1;
+
+            try
+            {
+                while ( ( count = schemaIn.read( buf ) ) != -1 )
+                {
+                    parserIn.write( buf, 0, count );
+                    parserIn.flush();
+                }
+
+                // using an input termination token END - need extra space to return
+                parserIn.write( "END ".getBytes() );
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace();
+            }
+        }
     }
 }

Modified: incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/OpenLdapSchemaParserTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/OpenLdapSchemaParserTest.java
(original)
+++ incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/OpenLdapSchemaParserTest.java
Sun Oct 10 03:56:01 2004
@@ -18,6 +18,7 @@
 
 
 import java.util.Map;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 import org.apache.ldap.common.schema.ObjectClassTypeEnum;
@@ -50,6 +51,24 @@
     }
 
 
+    public void testSimpleAttributeTypeNoLength() throws Exception
+    {
+        String attributeTypeData = "attributetype ( 2.5.4.14 NAME 'searchGuide'\n" +
+            "        DESC 'RFC2256: search guide, obsoleted by enhancedSearchGuide'\n" +
+            "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.25 )";
+
+        parser.parse( attributeTypeData );
+        Map attributeTypes = parser.getAttributeTypes();
+        AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.14"
);
+
+        assertNotNull( type );
+        assertEquals( "2.5.4.14", type.getOid() );
+        assertEquals( "searchGuide", type.getNames()[0] );
+        assertEquals( "RFC2256: search guide, obsoleted by enhancedSearchGuide", type.getDescription()
);
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.25", type.getSyntax() );
+    }
+
+
     public void testSimpleAttributeTypeParse() throws Exception
     {
         String attributeTypeData = "# adding a comment  \n" +
@@ -112,5 +131,109 @@
         assertEquals( "telephoneNumber", objectClass.getMay()[1] );
         assertEquals( "seeAlso", objectClass.getMay()[2] );
         assertEquals( "description", objectClass.getMay()[3] );
+    }
+
+
+    public void testObjectClassMultipleNames() throws Exception
+    {
+        String objectClassData = "objectclass ( 0.9.2342.19200300.100.4.4\n" +
+            "\tNAME ( 'pilotPerson' 'newPilotPerson' )\n" +
+            "\tSUP person STRUCTURAL\n" +
+            "\tMAY ( userid $ textEncodedORAddress $ rfc822Mailbox $\n" +
+            "\t\tfavouriteDrink $ roomNumber $ userClass $\n" +
+            "\t\thomeTelephoneNumber $ homePostalAddress $ secretary $\n" +
+            "\t\tpersonalTitle $ preferredDeliveryMethod $ businessCategory $\n" +
+            "\t\tjanetMailbox $ otherMailbox $ mobileTelephoneNumber $\n" +
+            "\t\tpagerTelephoneNumber $ organizationalStatus $\n" +
+            "\t\tmailPreferenceOption $ personalSignature )\n" +
+            "\t)";
+        parser.parse( objectClassData );
+        Map objectClasses = parser.getObjectClassTypes();
+        ObjectClassLiteral objectClass = ( ObjectClassLiteral )
+            objectClasses.get( "0.9.2342.19200300.100.4.4" );
+
+        assertNotNull( objectClass );
+        assertEquals( "0.9.2342.19200300.100.4.4", objectClass.getOid() );
+        assertEquals( "pilotPerson", objectClass.getNames()[0] );
+        assertEquals( "newPilotPerson", objectClass.getNames()[1] );
+        assertEquals( ObjectClassTypeEnum.STRUCTURAL, objectClass.getClassType() );
+        assertEquals( "person", objectClass.getSuperiors()[0] );
+
+        assertEquals( "userid", objectClass.getMay()[0] );
+        assertEquals( "textEncodedORAddress", objectClass.getMay()[1] );
+        assertEquals( "rfc822Mailbox", objectClass.getMay()[2] );
+        assertEquals( "favouriteDrink", objectClass.getMay()[3] );
+        assertEquals( "roomNumber", objectClass.getMay()[4] );
+        assertEquals( "userClass", objectClass.getMay()[5] );
+        assertEquals( "homeTelephoneNumber", objectClass.getMay()[6] );
+        assertEquals( "homePostalAddress", objectClass.getMay()[7] );
+        assertEquals( "secretary", objectClass.getMay()[8] );
+        assertEquals( "personalTitle", objectClass.getMay()[9] );
+        assertEquals( "preferredDeliveryMethod", objectClass.getMay()[10] );
+        assertEquals( "businessCategory", objectClass.getMay()[11] );
+        assertEquals( "janetMailbox", objectClass.getMay()[12] );
+        assertEquals( "otherMailbox", objectClass.getMay()[13] );
+        assertEquals( "mobileTelephoneNumber", objectClass.getMay()[14] );
+        assertEquals( "pagerTelephoneNumber", objectClass.getMay()[15] );
+        assertEquals( "organizationalStatus", objectClass.getMay()[16] );
+        assertEquals( "mailPreferenceOption", objectClass.getMay()[17] );
+        assertEquals( "personalSignature", objectClass.getMay()[18] );
+
+    }
+
+
+    public void testAutoFsSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "autofs.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testCoreSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "core.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testCorbaSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "corba.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testCosineSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "cosine.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testInetOrgPersonSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "inetorgperson.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testJavaSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "java.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testMiscSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "misc.schema" );
+        parser.parse( in );
+    }
+
+
+    public void testNisSchemaFile() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "nis.schema" );
+        parser.parse( in );
     }
 }

Mime
View raw message