directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 54217 - 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 05:35:00 GMT
Author: akarasulu
Date: Sat Oct  9 22:34:59 2004
New Revision: 54217

Added:
   incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypeLiteral.java
  (contents, props changed)
Modified:
   incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
Log:
PROBLEM
=======

The parser was trying to do far too much.  First off it was trying to handle
name to OID resolution while trying to create all the dependent objects.  This
presented a few problems:

 o OID resolution requires mappings of names to OIDs across all schemas so
   all schemas would need to be parsed with dependent schemas coming first
 o OID resolution also used eve server classes dealing with schemas 
 o Intra schema dependencies were introduced since dependencies needed to be
   parsed before dependent attributes and this is not how OpenLDAP files are
   structured.  Order is arbitray in OL schema files!

Yeah it was an ugly situation leaving several questions unanswered and 
intermingled with Eve server side schema object dependency resolution.  

SOLUTION
========

We took a totally literal capture of all entities.  Meaning there's no attempt
to resolve OIDs for names and to resolved dependencies.  Beans like 
AttributeTypeLiteral are simply used to encapsulate the parsed String values.

This leaves the task of resolution setup up to the code generation piece and
the runtime operation of the schema configuration set objects.  This makes 
sense since these objects are part of the Eve backend subsystem within the
schema facilities.  This is where dependency resolution for schema objects
should take place not in the OpenLDAP schema parser.  The schema parser should
be simple doing only what it needs to do and no more.  



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	Sat Oct  9 22:34:59 2004
@@ -34,7 +34,6 @@
 
 import java.util.* ;
 import org.apache.ldap.common.schema.*;
-import org.apache.eve.schema.*;
 
 }
 
@@ -115,7 +114,6 @@
     private Map attributeTypes = new HashMap();
     private Map objectClasses = new HashMap();
     private ParserMonitor monitor = null;
-    private OidRegistry registry = null;
 
 
     // ------------------------------------------------------------------------
@@ -141,35 +139,11 @@
     }
 
 
-    public void setOidRegistry( OidRegistry registry )
-    {
-        this.registry = registry;
-    }
-
-
     // ------------------------------------------------------------------------
     // Private Methods
     // ------------------------------------------------------------------------
 
 
-    private final String resolve( String name )
-    {
-        String oid = null;
-
-        try
-        {
-            oid = registry.getOid( name );
-        }
-        catch( Exception e )
-        {
-            e.printStackTrace();
-            throw new RuntimeException( "could not find the oid: " + e.getMessage() );
-        }
-
-        return oid;
-    }
-
-
     private void matchedProduction( String msg )
     {
         if ( null != monitor )
@@ -177,128 +151,6 @@
             monitor.matchedProduction( msg );
         }
     }
-
-
-    // ------------------------------------------------------------------------
-    // Static Classes
-    // ------------------------------------------------------------------------
-
-
-    private static class MutableAttributeType extends BaseAttributeType
-    {
-        public MutableAttributeType( String oid )
-        {
-            super( oid );
-        }
-
-        public void setSuperior( AttributeType superior )
-        {
-            super.setSuperior( superior );
-        }
-
-        public void setAllNames( String[] nameArray )
-        {
-            super.setAllNames( nameArray );
-        }
-
-        public void setEquality( MatchingRule equality )
-        {
-            super.setEquality( equality );
-        }
-
-        public void setSubstr( MatchingRule substr )
-        {
-            super.setSubstr( substr );
-        }
-
-        public void setOrdering( MatchingRule ordering )
-        {
-            super.setOrdering( ordering );
-        }
-
-        public void setSyntax( Syntax syntax )
-        {
-            super.setSyntax( syntax );
-        }
-
-        public void setSingleValue( boolean singleValue )
-        {
-            super.setSingleValue( singleValue );
-        }
-
-        public void setDescription( String description )
-        {
-            super.setDescription( description );
-        }
-
-        public void setCollective( boolean collective )
-        {
-            super.setCollective( collective );
-        }
-
-        public void setCanUserModify( boolean canUserModify )
-        {
-            super.setCanUserModify( canUserModify );
-        }
-
-        public void setObsolete( boolean obsolete )
-        {
-            super.setObsolete( obsolete );
-        }
-
-        public void setUsage( UsageEnum usage )
-        {
-            super.setUsage( usage );
-        }
-
-        public void setLength( int length )
-        {
-            super.setLength( length );
-        }
-
-        public String getSuperiorOid()
-        {
-            return super.getSuperior() != null ? super.getSuperior().getOid() : null;
-        }
-
-        public String getSubstrOid()
-        {
-            return super.getSubstr() != null ? super.getSubstr().getOid() : null;
-        }
-
-        public String getOrderingOid()
-        {
-            return super.getOrdering() != null ? super.getOrdering().getOid() : null;
-        }
-
-        public String getEqualityOid()
-        {
-            return super.getEquality() != null ? super.getEquality().getOid() : null;
-        }
-
-        public String getSyntaxOid()
-        {
-            return super.getSyntax() != null ? super.getSyntax().getOid() : null;
-        }
-    }
-
-
-    private static class MutableMatchingRule extends BaseMatchingRule
-    {
-        public MutableMatchingRule( String oid )
-        {
-            super( oid ) ;
-        }
-    }
-
-
-    private static class MutableSyntax extends BaseSyntax
-    {
-        public MutableSyntax( String oid )
-        {
-            super( oid ) ;
-        }
-    }
 }
 
 
@@ -312,14 +164,14 @@
 attributeType
 {
     matchedProduction( "attributeType()" );
-    MutableAttributeType type = null;
+    AttributeTypeLiteral type = null;
     UsageEnum usageEnum;
 }
     :
     "attributetype"
     OPEN_PAREN oid:NUMERICOID
     {
-        type = new MutableAttributeType( oid.getText() );
+        type = new AttributeTypeLiteral( oid.getText() );
     }
         ( names[type] )?
         ( desc[type] )?
@@ -331,7 +183,7 @@
         ( syntax[type] )?
         ( "SINGLE-VALUE" { type.setSingleValue( true ); } )?
         ( "COLLECTIVE" { type.setCollective( true ); } )?
-        ( "NO-USER-MODIFICATION" { type.setCanUserModify( true ); } )?
+        ( "NO-USER-MODIFICATION" { type.setNoUserModification( true ); } )?
         ( usage[type] )?
 
     CLOSE_PAREN
@@ -341,7 +193,7 @@
     ;
 
 
-desc [MutableAttributeType type]
+desc [AttributeTypeLiteral type]
 {
 }
     : d:DESC
@@ -350,7 +202,8 @@
     }
     ;
 
-superior [MutableAttributeType type]
+
+superior [AttributeTypeLiteral type]
 {
     matchedProduction( "superior()" ) ;
 }
@@ -358,18 +211,17 @@
     (
         oid:NUMERICOID
         {
-            type.setSuperior( new MutableAttributeType( oid.getText() ) );
+            type.setSuperior( oid.getText() );
         }
         |
         id:IDENTIFIER
         {
-            String soid = resolve( id.getText() );
-            type.setSuperior( new MutableAttributeType( soid ) );
+            type.setSuperior( id.getText() );
         }
     );
 
 
-equality [MutableAttributeType type]
+equality [AttributeTypeLiteral type]
 {
     matchedProduction( "equality()" ) ;
 }
@@ -377,18 +229,17 @@
     (
         oid:NUMERICOID
         {
-            type.setEquality( new MutableMatchingRule( oid.getText() ) );
+            type.setEquality( oid.getText() );
         }
         |
         id:IDENTIFIER
         {
-            String soid = resolve( id.getText() );
-            type.setEquality( new MutableMatchingRule( soid ) );
+            type.setEquality( id.getText() );
         }
     );
 
 
-substr [MutableAttributeType type]
+substr [AttributeTypeLiteral type]
 {
     matchedProduction( "substr()" ) ;
 }
@@ -396,18 +247,17 @@
     (
         oid:NUMERICOID
         {
-            type.setSubstr( new MutableMatchingRule( oid.getText() ) );
+            type.setSubstr( oid.getText() );
         }
         |
         id:IDENTIFIER
         {
-            String soid = resolve( id.getText() );
-            type.setSubstr( new MutableMatchingRule( soid ) );
+            type.setSubstr( id.getText() );
         }
     );
 
 
-ordering [MutableAttributeType type]
+ordering [AttributeTypeLiteral type]
 {
     matchedProduction( "ordering()" ) ;
 }
@@ -415,18 +265,17 @@
     (
         oid:NUMERICOID
         {
-            type.setOrdering( new MutableMatchingRule( oid.getText() ) );
+            type.setOrdering( oid.getText() );
         }
         |
         id:IDENTIFIER
         {
-            String soid = resolve( id.getText() );
-            type.setOrdering( new MutableMatchingRule( soid ) );
+            type.setOrdering( id.getText() );
         }
     );
 
 
-names [MutableAttributeType type]
+names [AttributeTypeLiteral type]
 {
     matchedProduction( "names()" ) ;
     ArrayList list = new ArrayList();
@@ -436,27 +285,24 @@
         "NAME" QUOTE id0:IDENTIFIER QUOTE
         {
             list.add( id0.getText() );
-            registry.register( id0.getText(), type.getOid() );
         }
         |
         ( OPEN_PAREN QUOTE id1:IDENTIFIER
         {
             list.add( id1.getText() );
-            registry.register( id1.getText(), type.getOid() );
         } QUOTE
         ( QUOTE id2:IDENTIFIER QUOTE
         {
             list.add( id2.getText() );
-            registry.register( id2.getText(), type.getOid() );
         } )* CLOSE_PAREN )
     )
     {
-        type.setAllNames( ( String[] ) list.toArray( EMPTY ) );
+        type.setNames( ( String[] ) list.toArray( EMPTY ) );
     }
     ;
 
 
-syntax [MutableAttributeType type]
+syntax [AttributeTypeLiteral type]
 {
     matchedProduction( "syntax()" ) ;
 }
@@ -467,19 +313,20 @@
         int index = comps[1].indexOf( "{" );
         if ( index == -1 )
         {
-            type.setSyntax( new MutableSyntax( comps[1] ) );
+            type.setSyntax( comps[1] );
             return;
         }
 
         String oid = comps[1].substring( 0, index );
         String length = comps[1].substring( index + 1, comps[1].length() - 1 );
 
-        type.setSyntax( new MutableSyntax( oid ) );
+        type.setSyntax( oid );
         type.setLength( Integer.parseInt( length ) );
     }
     ;
 
-usage [MutableAttributeType type]
+
+usage [AttributeTypeLiteral type]
 {
     matchedProduction( "usage()" ) ;
 }

Added: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypeLiteral.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/AttributeTypeLiteral.java
Sat Oct  9 22:34:59 2004
@@ -0,0 +1,233 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.eve.tools.schema;
+
+import org.apache.ldap.common.schema.UsageEnum;
+import org.apache.ldap.common.util.ArrayUtils;
+
+/**
+ * Document me.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AttributeTypeLiteral
+{
+    private boolean obsolete = false;
+    private boolean singleValue = false;
+    private boolean collective = false;
+    private boolean noUserModification = false;
+
+    private final String oid;
+    private String description;
+    private String superior;
+    private String equality;
+    private String ordering;
+    private String substr;
+    private String syntax;
+
+    private UsageEnum usage = UsageEnum.USERAPPLICATIONS;
+
+    private String[] names = ArrayUtils.EMPTY_STRING_ARRAY;
+
+    private int length = -1;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+
+    public AttributeTypeLiteral( String oid )
+    {
+        this.oid = oid;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Accessors and mutators
+    // ------------------------------------------------------------------------
+
+
+    public boolean isObsolete()
+    {
+        return obsolete;
+    }
+
+    public void setObsolete( boolean obsolete )
+    {
+        this.obsolete = obsolete;
+    }
+
+    public boolean isSingleValue()
+    {
+        return singleValue;
+    }
+
+    public void setSingleValue( boolean singleValue )
+    {
+        this.singleValue = singleValue;
+    }
+
+    public boolean isCollective()
+    {
+        return collective;
+    }
+
+    public void setCollective( boolean collective )
+    {
+        this.collective = collective;
+    }
+
+    public boolean isNoUserModification()
+    {
+        return noUserModification;
+    }
+
+    public void setNoUserModification( boolean noUserModification )
+    {
+        this.noUserModification = noUserModification;
+    }
+
+    public String getOid()
+    {
+        return oid;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    public String getSuperior()
+    {
+        return superior;
+    }
+
+    public void setSuperior( String superior )
+    {
+        this.superior = superior;
+    }
+
+    public String getEquality()
+    {
+        return equality;
+    }
+
+    public void setEquality( String equality )
+    {
+        this.equality = equality;
+    }
+
+    public String getOrdering()
+    {
+        return ordering;
+    }
+
+    public void setOrdering( String ordering )
+    {
+        this.ordering = ordering;
+    }
+
+    public String getSubstr()
+    {
+        return substr;
+    }
+
+    public void setSubstr( String substr )
+    {
+        this.substr = substr;
+    }
+
+    public String getSyntax()
+    {
+        return syntax;
+    }
+
+    public void setSyntax( String syntax )
+    {
+        this.syntax = syntax;
+    }
+
+    public UsageEnum getUsage()
+    {
+        return usage;
+    }
+
+    public void setUsage( UsageEnum usage )
+    {
+        this.usage = usage;
+    }
+
+    public String[] getNames()
+    {
+        return names;
+    }
+
+    public void setNames( String[] names )
+    {
+        this.names = names;
+    }
+
+    public int getLength()
+    {
+        return length;
+    }
+
+    public void setLength( int length )
+    {
+        this.length = length;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Object overrides
+    // ------------------------------------------------------------------------
+
+
+    public int hashCode()
+    {
+        return getOid().hashCode();
+    }
+
+
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+
+        if ( ! ( obj instanceof AttributeTypeLiteral ) )
+        {
+            return false;
+        }
+
+        return getOid().equals( ( ( AttributeTypeLiteral ) obj ).getOid() );
+    }
+
+
+    public String toString()
+    {
+        return getOid();
+    }
+}

Modified: incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
(original)
+++ incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
Sat Oct  9 22:34:59 2004
@@ -22,9 +22,6 @@
 import java.util.Map;
 import java.io.ByteArrayInputStream;
 
-import org.apache.eve.schema.DefaultOidRegistry;
-import org.apache.ldap.common.schema.AttributeType;
-
 
 /**
  * Tests the parser for AttributeTypes.
@@ -52,20 +49,15 @@
             }
         });
 
-        DefaultOidRegistry registry = new DefaultOidRegistry();
-        registry.register( "caseIgnoreMatch", "1.1.1.1.1.1" );
-        parser.setOidRegistry( registry );
-
         Map attributeTypes = parser.getAttributeTypes();
         parser.attributeType();
-        AttributeType type = ( AttributeType ) attributeTypes.get( "2.5.4.2" );
+        AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2"
);
 
         assertNotNull( type );
         assertEquals( "2.5.4.2", type.getOid() );
-        assertEquals( "knowledgeInformation", type.getName() );
+        assertEquals( "knowledgeInformation", type.getNames()[0] );
         assertEquals( "RFC2256: knowledge information", type.getDescription() );
-        assertEquals( "1.3.6.1.4.1.1466.115.121.1.15",
-            type.getSyntax().getOid() );
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.15", type.getSyntax() );
         assertEquals( 32768, type.getLength() );
     }
 }

Mime
View raw message