directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r627332 - in /directory/shared/branches/bigbang/ldap/src: main/antlr/ main/java/org/apache/directory/shared/ldap/schema/parser/ test/java/org/apache/directory/shared/ldap/schema/parser/
Date Wed, 13 Feb 2008 09:56:06 GMT
Author: pamarcelot
Date: Wed Feb 13 01:56:05 2008
New Revision: 627332

URL: http://svn.apache.org/viewvc?rev=627332&view=rev
Log:
Fix for DIRSERVER-1129 (Move the OpenLDAP schema file parser to Shared).

Added:
    directory/shared/branches/bigbang/ldap/src/main/antlr/openldap.g
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/AttributeTypeLiteral.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ObjectClassLiteral.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitor.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitorAdapter.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/ConsoleParserMonitor.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java

Added: directory/shared/branches/bigbang/ldap/src/main/antlr/openldap.g
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/antlr/openldap.g?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/antlr/openldap.g (added)
+++ directory/shared/branches/bigbang/ldap/src/main/antlr/openldap.g Wed Feb 13 01:56:05 2008
@@ -0,0 +1,554 @@
+// ============================================================================
+//
+//
+//                    OpenLDAP Schema Parser
+//
+//
+// ============================================================================
+// $Rev$
+// ============================================================================
+
+
+header {
+/*
+ *  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. 
+ *  
+ */
+/*
+ * Keep the semicolon right next to the package name or else there will be a
+ * bug that comes into the foreground in the new antlr release.
+ */
+package org.apache.directory.shared.ldap.schema.parser;
+
+import java.util.* ;
+import org.apache.directory.shared.ldap.schema.*;
+
+}
+
+
+class antlrOpenLdapSchemaLexer extends Lexer ;
+
+options    {
+    k = 7 ;
+    exportVocab=antlrOpenLdapSchema ;
+    charVocabulary = '\3'..'\377' ;
+    caseSensitive = false ;
+    //testLiterals = true ;
+    defaultErrorHandler = false ;
+}
+
+
+WS  :   (   '#' (~'\n')* '\n' { newline(); }
+        |    ' '
+        |   '\t'
+        |   '\r' '\n' { newline(); }
+        |   '\n'      { newline(); }
+        |   '\r'      { newline(); }
+        )
+        {$setType(Token.SKIP);} //ignore this token
+    ;
+
+QUOTE              : '\''
+    ;
+
+DIGIT              : '0' .. '9'
+    ;
+
+DOLLAR             : '$'
+    ;
+
+OPEN_PAREN         : '('
+    ;
+
+CLOSE_PAREN        : ')'
+    ;
+
+OPEN_BRACKET       : '{'
+    ;
+
+CLOSE_BRACKET      : '}'
+    ;
+
+protected NUMERIC_STRING : ('0' .. '9')+
+    ;
+
+NUMERICOID         :
+        NUMERIC_STRING ( '.' NUMERIC_STRING )+
+    ;
+
+IDENTIFIER options { testLiterals=true; }
+    : 
+        ( 'a' .. 'z') ( 'a' .. 'z' | '0' .. '9' | '-' | ';' )*
+    ;
+
+DESC
+    :
+        "desc" WS QUOTE ( ~'\'' )+ QUOTE
+    ;
+
+SYNTAX
+    :
+        "syntax" WS NUMERICOID ( OPEN_BRACKET ( DIGIT )+ CLOSE_BRACKET )?
+    ;
+
+class antlrOpenLdapSchemaParser extends Parser ;
+
+options    {
+    k = 5 ;
+    defaultErrorHandler = false ;
+}
+
+
+{
+    public static final String[] EMPTY = new String[0];
+
+    private List attributeTypes = new ArrayList();
+    private List objectClasses = new ArrayList();
+    private ParserMonitor monitor = null;
+
+
+    // ------------------------------------------------------------------------
+    // Public Methods
+    // ------------------------------------------------------------------------
+
+
+    public void clear()
+    {
+        attributeTypes.clear();
+        objectClasses.clear();
+    }
+
+
+    public List getAttributeTypes()
+    {
+        return Collections.unmodifiableList( attributeTypes );
+    }
+
+
+    public List getObjectClasses()
+    {
+        return Collections.unmodifiableList( objectClasses );
+    }
+
+
+    public void setParserMonitor( ParserMonitor monitor )
+    {
+        this.monitor = monitor;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Private Methods
+    // ------------------------------------------------------------------------
+
+
+    private void matchedProduction( String msg )
+    {
+        if ( null != monitor )
+        {
+            monitor.matchedProduction( msg );
+        }
+    }
+}
+
+
+// ----------------------------------------------------------------------------
+// Main Entry Point Production
+// ----------------------------------------------------------------------------
+
+
+parseSchema
+{
+}
+    :
+    ( attributeType | objectClass )* "END"
+    ;
+
+
+// ----------------------------------------------------------------------------
+// AttributeType Productions
+// ----------------------------------------------------------------------------
+
+
+objectClass
+{
+    matchedProduction( "objectClass()" );
+    ObjectClassLiteral objectClass = null;
+}
+    :
+    "objectclass"
+    OPEN_PAREN oid:NUMERICOID
+    {
+        objectClass = new ObjectClassLiteral( oid.getText() );
+    }
+    ( objectClassNames[objectClass] )?
+    ( objectClassDesc[objectClass] )?
+    ( "OBSOLETE" { objectClass.setObsolete( true ); } )?
+    ( objectClassSuperiors[objectClass] )?
+    ( 
+        "ABSTRACT"   { objectClass.setClassType( ObjectClassTypeEnum.ABSTRACT ); } |
+        "STRUCTURAL" { objectClass.setClassType( ObjectClassTypeEnum.STRUCTURAL ); } |
+        "AUXILIARY"  { objectClass.setClassType( ObjectClassTypeEnum.AUXILIARY ); }
+    )?
+    ( must[objectClass] )?
+    ( may[objectClass] )?
+    CLOSE_PAREN
+    {
+        objectClasses.add( objectClass );
+    }
+    ;
+
+
+may [ObjectClassLiteral objectClass]
+{
+    matchedProduction( "may(ObjectClassLiteral)" ) ;
+    ArrayList list = null;
+}
+    : "MAY" list=woidlist
+    {
+        objectClass.setMay( ( String[] ) list.toArray( EMPTY ) );
+    }
+    ;
+
+
+must [ObjectClassLiteral objectClass]
+{
+    matchedProduction( "must(ObjectClassLiteral)" ) ;
+    ArrayList list = null;
+}
+    : "MUST" list=woidlist
+    {
+        objectClass.setMust( ( String[] ) list.toArray( EMPTY ) );
+    }
+    ;
+
+
+objectClassSuperiors [ObjectClassLiteral objectClass]
+{
+    matchedProduction( "objectClassSuperiors(ObjectClassLiteral)" ) ;
+    ArrayList list = null;
+}
+    : "SUP" list=woidlist
+    {
+        objectClass.setSuperiors( ( String[] ) list.toArray( EMPTY ) );
+    }
+    ;
+
+
+woid returns [String oid]
+{
+    oid = null;
+    matchedProduction( "woid()" ) ;
+}
+    :
+    (
+        opt1:NUMERICOID
+        {
+            oid = opt1.getText();
+        }
+        |
+        opt2:IDENTIFIER
+        {
+            oid = opt2.getText();
+        }
+    )
+    ;
+
+
+woidlist returns [ArrayList list]
+{
+    matchedProduction( "woidlist()" ) ;
+    list = new ArrayList( 2 );
+    String oid = null;
+}
+    :
+    (
+        oid=woid { list.add( oid ); } |
+        (
+            OPEN_PAREN
+            oid=woid { list.add( oid ); } ( DOLLAR oid=woid { list.add( oid ); } )*
+            CLOSE_PAREN
+        )
+    )
+    ;
+
+objectClassDesc [ObjectClassLiteral objectClass]
+{
+    matchedProduction( "desc(ObjectClassLiteral)" ) ;
+}
+    : d:DESC
+    {
+        String desc = d.getText().split( "'" )[1];
+        String[] quoted = desc.split( "\"" );
+
+        if ( quoted.length == 1 )
+        {
+            objectClass.setDescription( desc );
+        }
+        else
+        {
+            StringBuffer buf = new StringBuffer();
+            for ( int ii = 0; ii < quoted.length; ii++ )
+            {
+                if ( ii < quoted.length - 1 )
+                {
+                    buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
+                }
+                else
+                {
+                    buf.append( quoted[ii] );
+                }
+            }
+
+            objectClass.setDescription( buf.toString() );
+        }
+    }
+    ;
+
+
+objectClassNames [ObjectClassLiteral objectClass]
+{
+    matchedProduction( "names(ObjectClassLiteral)" ) ;
+    ArrayList list = new ArrayList();
+}
+    :
+    (
+        "NAME"
+        ( QUOTE id0:IDENTIFIER QUOTE
+        {
+            list.add( id0.getText() );
+        }
+        |
+        ( OPEN_PAREN QUOTE id1:IDENTIFIER
+        {
+            list.add( id1.getText() );
+        } QUOTE
+        ( QUOTE id2:IDENTIFIER QUOTE
+        {
+            list.add( id2.getText() );
+        } )* CLOSE_PAREN )
+        )
+    )
+    {
+        objectClass.setNames( ( String[] ) list.toArray( EMPTY ) );
+    }
+    ;
+
+
+// ----------------------------------------------------------------------------
+// AttributeType Productions
+// ----------------------------------------------------------------------------
+
+
+attributeType
+{
+    matchedProduction( "attributeType()" );
+    AttributeTypeLiteral type = null;
+}
+    :
+    "attributetype"
+    OPEN_PAREN oid:NUMERICOID
+    {
+        type = new AttributeTypeLiteral( oid.getText() );
+    }
+        ( names[type] )?
+        ( desc[type] )?
+        ( "OBSOLETE" { type.setObsolete( true ); } )?
+        ( superior[type] )?
+        ( equality[type] )?
+        ( ordering[type] )?
+        ( substr[type] )?
+        ( syntax[type] )?
+        ( "SINGLE-VALUE" { type.setSingleValue( true ); } )?
+        ( "COLLECTIVE" { type.setCollective( true ); } )?
+        ( "NO-USER-MODIFICATION" { type.setNoUserModification( true ); } )?
+        ( usage[type] )?
+
+    CLOSE_PAREN
+    {
+        attributeTypes.add( type );
+    }
+    ;
+
+
+desc [AttributeTypeLiteral type]
+{
+    matchedProduction( "desc(AttributeTypeLiteral)" ) ;
+}
+    : d:DESC
+    {
+        String desc = d.getText().split( "'" )[1];
+        String[] quoted = desc.split( "\"" );
+
+        if ( quoted.length == 1 )
+        {
+            type.setDescription( desc );
+        }
+        else
+        {
+            StringBuffer buf = new StringBuffer();
+            for ( int ii = 0; ii < quoted.length; ii++ )
+            {
+                if ( ii < quoted.length - 1 )
+                {
+                    buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
+                }
+                else
+                {
+                    buf.append( quoted[ii] );
+                }
+            }
+
+            type.setDescription( buf.toString() );
+        }
+    }
+    ;
+
+
+superior [AttributeTypeLiteral type]
+{
+    matchedProduction( "superior(AttributeTypeLiteral)" ) ;
+}
+    : "SUP"
+    (
+        oid:NUMERICOID
+        {
+            type.setSuperior( oid.getText() );
+        }
+        |
+        id:IDENTIFIER
+        {
+            type.setSuperior( id.getText() );
+        }
+    );
+
+
+equality [AttributeTypeLiteral type]
+{
+    matchedProduction( "equality(AttributeTypeLiteral)" ) ;
+}
+    : "EQUALITY"
+    (
+        oid:NUMERICOID
+        {
+            type.setEquality( oid.getText() );
+        }
+        |
+        id:IDENTIFIER
+        {
+            type.setEquality( id.getText() );
+        }
+    );
+
+
+substr [AttributeTypeLiteral type]
+{
+    matchedProduction( "substr(AttributeTypeLiteral)" ) ;
+}
+    : "SUBSTR"
+    (
+        oid:NUMERICOID
+        {
+            type.setSubstr( oid.getText() );
+        }
+        |
+        id:IDENTIFIER
+        {
+            type.setSubstr( id.getText() );
+        }
+    );
+
+
+ordering [AttributeTypeLiteral type]
+{
+    matchedProduction( "ordering(AttributeTypeLiteral)" ) ;
+}
+    : "ORDERING"
+    (
+        oid:NUMERICOID
+        {
+            type.setOrdering( oid.getText() );
+        }
+        |
+        id:IDENTIFIER
+        {
+            type.setOrdering( id.getText() );
+        }
+    );
+
+
+names [AttributeTypeLiteral type]
+{
+    matchedProduction( "names(AttributeTypeLiteral)" ) ;
+    ArrayList list = new ArrayList();
+}
+    :
+        "NAME"
+    (
+        QUOTE id0:IDENTIFIER QUOTE { list.add( id0.getText() ); } |
+        ( OPEN_PAREN
+            ( QUOTE id1:IDENTIFIER
+                {
+                    list.add( id1.getText() );
+                }
+              QUOTE
+            )+
+        CLOSE_PAREN )
+    )
+    {
+        type.setNames( ( String[] ) list.toArray( EMPTY ) );
+    }
+    ;
+
+
+syntax [AttributeTypeLiteral type]
+{
+    matchedProduction( "syntax(AttributeTypeLiteral)" ) ;
+}
+    : token:SYNTAX
+    {
+        String[] comps = token.getText().split( " " );
+
+        int index = comps[1].indexOf( "{" );
+        if ( index == -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( oid );
+        type.setLength( Integer.parseInt( length ) );
+    }
+    ;
+
+
+usage [AttributeTypeLiteral type]
+{
+    matchedProduction( "usage(AttributeTypeLiteral)" ) ;
+}
+    :
+    "USAGE"
+    (
+        "userApplications" { type.setUsage( UsageEnum.USER_APPLICATIONS ); } |
+        "directoryOperation" { type.setUsage( UsageEnum.DIRECTORY_OPERATION ); } |
+        "distributedOperation" { type.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); } |
+        "dSAOperation" { type.setUsage( UsageEnum.DSA_OPERATION ); }
+    );

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/AttributeTypeLiteral.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/AttributeTypeLiteral.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/AttributeTypeLiteral.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/AttributeTypeLiteral.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,270 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.util.ArrayUtils;
+
+
+/**
+ * A bean used to hold the literal values of an AttributeType parsed out of an
+ * OpenLDAP schema configuration file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 504954 $
+ */
+public class AttributeTypeLiteral
+{
+    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;
+    private String substr;
+    private String syntax;
+
+    private UsageEnum usage = UsageEnum.USER_APPLICATIONS;
+
+    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();
+    }
+
+    /**
+     * Method used to modify the AttributeType OID if it is edited.
+     */
+    public void setOid( String oid )
+    {
+        this.oid = oid;
+    }
+}

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ObjectClassLiteral.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ObjectClassLiteral.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ObjectClassLiteral.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ObjectClassLiteral.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,189 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.util.ArrayUtils;
+
+
+/**
+ * A bean used to encapsulate the literal String values of an ObjectClass
+ * definition found within an OpenLDAP schema configuration file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437016 $
+ */
+public class ObjectClassLiteral
+{
+    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;
+
+    private ObjectClassTypeEnum classType = ObjectClassTypeEnum.STRUCTURAL;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+    public ObjectClassLiteral(String oid)
+    {
+        this.oid = oid;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Accessors and mutators
+    // ------------------------------------------------------------------------
+
+    public boolean isObsolete()
+    {
+        return obsolete;
+    }
+
+
+    public void setObsolete( boolean obsolete )
+    {
+        this.obsolete = obsolete;
+    }
+
+
+    public String getOid()
+    {
+        return oid;
+    }
+
+
+    public void setOid( String oid )
+    {
+        this.oid = oid;
+    }
+
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+
+    public String[] getNames()
+    {
+        return names;
+    }
+
+
+    public void setNames( String[] names )
+    {
+        this.names = names;
+    }
+
+
+    public String[] getSuperiors()
+    {
+        return superiors;
+    }
+
+
+    public void setSuperiors( String[] superiors )
+    {
+        this.superiors = superiors;
+    }
+
+
+    public String[] getMust()
+    {
+        return must;
+    }
+
+
+    public void setMust( String[] must )
+    {
+        this.must = must;
+    }
+
+
+    public String[] getMay()
+    {
+        return may;
+    }
+
+
+    public void setMay( String[] may )
+    {
+        this.may = may;
+    }
+
+
+    public ObjectClassTypeEnum getClassType()
+    {
+        return classType;
+    }
+
+
+    public void setClassType( ObjectClassTypeEnum classType )
+    {
+        this.classType = classType;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Object overrides
+    // ------------------------------------------------------------------------
+
+    public int hashCode()
+    {
+        return getOid().hashCode();
+    }
+
+
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+
+        if ( !( obj instanceof ObjectClassLiteral ) )
+        {
+            return false;
+        }
+
+        return getOid().equals( ( ( ObjectClassLiteral ) obj ).getOid() );
+    }
+
+
+    public String toString()
+    {
+        return getOid();
+    }
+}

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,221 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+
+import org.apache.directory.shared.ldap.schema.parser.antlrOpenLdapSchemaLexer;
+import org.apache.directory.shared.ldap.schema.parser.antlrOpenLdapSchemaParser;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+
+import java.util.List;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.text.ParseException;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A reusable wrapper for antlr generated OpenLDAP schema parsers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 494164 $
+ */
+public class OpenLdapSchemaParser
+{
+    /** the monitor to use for this parser */
+    private ParserMonitor monitor = new ParserMonitorAdapter();
+    /** The antlr generated parser */
+    private antlrOpenLdapSchemaParser parser = null;
+    /** A pipe into the parser */
+    private PipedOutputStream parserIn = null;
+
+
+    /**
+     * Creates a reusable instance of an OpenLdapSchemaParser.
+     *
+     * @throws IOException if the pipe cannot be formed
+     */
+    public OpenLdapSchemaParser() throws IOException
+    {
+        init();
+    }
+
+
+    /**
+     * Initializes a parser and its plumbing.
+     *
+     * @throws IOException if a pipe cannot be formed.
+     */
+    public void init() throws IOException
+    {
+        parserIn = new PipedOutputStream();
+        PipedInputStream in = new PipedInputStream();
+        parserIn.connect( in );
+        antlrOpenLdapSchemaLexer lexer = new antlrOpenLdapSchemaLexer( in );
+        parser = new antlrOpenLdapSchemaParser( lexer );
+    }
+
+
+    public synchronized void clear()
+    {
+        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
+    {
+        if ( schemaObject == null || schemaObject.trim().equals( "" ) )
+        {
+            throw new ParseException( "The schemaObject is either null or is " + "the empty String!", 0 );
+        }
+
+        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
+    {
+        try
+        {
+            monitor.startedParse( "starting parse on:\n" + subject );
+            parser.parseSchema();
+            monitor.finishedParse( "Done parsing!" );
+        }
+        catch ( RecognitionException e )
+        {
+            String msg = "Parser failure on:\n\t" + subject;
+            msg += "\nAntlr exception trace:\n" + ExceptionUtils.getFullStackTrace( e );
+            init();
+            throw new ParseException( msg, e.getColumn() );
+        }
+        catch ( TokenStreamException e2 )
+        {
+            String msg = "Parser failure on:\n\t" + subject;
+            msg += "\nAntlr exception trace:\n" + ExceptionUtils.getFullStackTrace( e2 );
+            init();
+            throw new ParseException( msg, 0 );
+        }
+    }
+
+    byte[] buf = new byte[128];
+    private InputStream schemaIn;
+    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 ) throws IOException, ParseException
+    {
+        this.schemaIn = schemaIn;
+
+        if ( producerThread == null )
+        {
+            producerThread = new Thread( new DataProducer() );
+        }
+
+        producerThread.start();
+        invokeParser( "schema input stream ==> " + schemaIn.toString() );
+    }
+
+
+    /**
+     * Thread safe method parses a file of OpenLDAP schemaObject elements/objects.
+     *
+     * @param schemaFile a file of schema objects
+     */
+    public synchronized void parse( File schemaFile ) throws IOException, ParseException
+    {
+        this.schemaIn = new FileInputStream( schemaFile );
+
+        if ( producerThread == null )
+        {
+            producerThread = new Thread( new DataProducer() );
+        }
+
+        producerThread.start();
+        invokeParser( "schema file ==> " + schemaFile.getAbsolutePath() );
+    }
+
+
+    public void setParserMonitor( ParserMonitor monitor )
+    {
+        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();
+            }
+        }
+    }
+}

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitor.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitor.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitor.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitor.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,38 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+
+/**
+ * A monitor for the OpenLdap parser.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437016 $
+ */
+public interface ParserMonitor
+{
+    void matchedProduction( String prod );
+
+
+    void startedParse( String s );
+
+
+    void finishedParse( String s );
+}

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitorAdapter.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitorAdapter.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitorAdapter.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/ParserMonitorAdapter.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,44 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+
+/**
+ * Document me.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437016 $
+ */
+public class ParserMonitorAdapter implements ParserMonitor
+{
+    public void matchedProduction( String prod )
+    {
+    }
+
+
+    public void startedParse( String s )
+    {
+    }
+
+
+    public void finishedParse( String s )
+    {
+    }
+}

Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/ConsoleParserMonitor.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/ConsoleParserMonitor.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/ConsoleParserMonitor.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/ConsoleParserMonitor.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,62 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+import org.apache.directory.shared.ldap.schema.parser.ParserMonitor;
+
+
+/**
+ * A console reporting monitor.  Add system property 'maven.eve.schema.parser.trace'
+ * to get this monitor to trace parser production execution.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437016 $
+ */
+public class ConsoleParserMonitor implements ParserMonitor
+{
+    public static final String TRACE_KEY = "maven.eve.schema.parser.trace";
+
+
+    public void matchedProduction( String prod )
+    {
+        if ( System.getProperties().containsKey( TRACE_KEY ) )
+        {
+            System.out.println( prod );
+        }
+    }
+
+
+    public void startedParse( String s )
+    {
+        if ( System.getProperties().containsKey( TRACE_KEY ) )
+        {
+            System.out.println( s );
+        }
+    }
+
+
+    public void finishedParse( String s )
+    {
+        if ( System.getProperties().containsKey( TRACE_KEY ) )
+        {
+            System.out.println( s );
+        }
+    }
+}

Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java?rev=627332&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java Wed Feb 13 01:56:05 2008
@@ -0,0 +1,234 @@
+/*
+ *  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.shared.ldap.schema.parser;
+
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.parser.AttributeTypeLiteral;
+import org.apache.directory.shared.ldap.schema.parser.ObjectClassLiteral;
+import org.apache.directory.shared.ldap.schema.parser.OpenLdapSchemaParser;
+
+
+/**
+ * Tests the OpenLDAP schema parser.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437016 $
+ */
+public class OpenLdapSchemaParserTest extends TestCase
+{
+    private OpenLdapSchemaParser parser;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        parser = new OpenLdapSchemaParser();
+        parser.setParserMonitor( new ConsoleParserMonitor() );
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        parser = null;
+    }
+
+
+    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 );
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
+        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() );
+    }
+
+
+    private Map mapAttributeTypes( List attributeTypeList )
+    {
+        Map m = new HashMap();
+        
+        for ( int ii = 0 ; ii < attributeTypeList.size(); ii++ )
+        {
+            AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypeList.get( ii );
+            m.put( type.getOid(), type );
+        }
+        
+        return m;
+    }
+
+
+    public void testSimpleAttributeTypeParse() throws Exception
+    {
+        String attributeTypeData = "# adding a comment  \n" + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n"
+            + "        DESC 'RFC2256: knowledge information'\n" + "        EQUALITY caseIgnoreMatch\n"
+            + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
+        parser.parse( attributeTypeData );
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
+        AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2" );
+
+        assertNotNull( type );
+        assertEquals( "2.5.4.2", type.getOid() );
+        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() );
+        assertEquals( 32768, type.getLength() );
+    }
+
+
+    public void testAttributeTypeParseWithDescQuotes() throws Exception
+    {
+        String attributeTypeData = "# adding a comment  \n" + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n"
+            + "        DESC 'RFC2256: \"knowledge\" information'\n" + "        EQUALITY caseIgnoreMatch\n"
+            + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
+        parser.parse( attributeTypeData );
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
+        AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2" );
+
+        assertNotNull( type );
+        assertEquals( "2.5.4.2", type.getOid() );
+        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() );
+        assertEquals( 32768, type.getLength() );
+    }
+
+
+    public void testComplexAttributeTypeParse() throws Exception
+    {
+        String attributeTypeData = "# adding a comment  \n"
+            + "attributetype ( 2.5.4.2 NAME ( 'knowledgeInformation' 'asdf' ) \n"
+            + "        DESC 'RFC2256: knowledge information'\n" + "        EQUALITY caseIgnoreMatch\n"
+            + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
+        parser.parse( attributeTypeData );
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
+        AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.2" );
+
+        assertNotNull( type );
+        assertEquals( "2.5.4.2", type.getOid() );
+        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() );
+        assertEquals( 32768, type.getLength() );
+    }
+
+
+    private Map mapObjectClasses( List attributeTypeList )
+    {
+        Map m = new HashMap();
+        
+        for ( int ii = 0 ; ii < attributeTypeList.size(); ii++ )
+        {
+            ObjectClassLiteral type = ( ObjectClassLiteral ) attributeTypeList.get( ii );
+            m.put( type.getOid(), type );
+        }
+        
+        return m;
+    }
+
+
+    public void testObjectClassParse() throws Exception
+    {
+        String objectClassData = "objectclass ( 2.5.6.6 NAME 'person'\n" + "        DESC 'RFC2256: a person'\n"
+            + "        SUP top STRUCTURAL\n" + "        MUST ( sn $ cn )\n"
+            + "        MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) )";
+        parser.parse( objectClassData );
+        List objectClassesList = parser.getObjectClassTypes();
+        Map objectClasses = mapObjectClasses( objectClassesList );
+        ObjectClassLiteral objectClass = ( ObjectClassLiteral ) objectClasses.get( "2.5.6.6" );
+
+        assertNotNull( objectClass );
+        assertEquals( "2.5.6.6", objectClass.getOid() );
+        assertEquals( "person", objectClass.getNames()[0] );
+        assertEquals( "RFC2256: a person", objectClass.getDescription() );
+        assertEquals( ObjectClassTypeEnum.STRUCTURAL, objectClass.getClassType() );
+        assertEquals( "sn", objectClass.getMust()[0] );
+        assertEquals( "cn", objectClass.getMust()[1] );
+        assertEquals( "userPassword", objectClass.getMay()[0] );
+        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 );
+        List objectClassesList = parser.getObjectClassTypes();
+        Map objectClasses = mapObjectClasses( objectClassesList );
+        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] );
+
+    }
+}



Mime
View raw message