directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r486451 [1/2] - in /directory/trunks/shared/ldap/src: main/antlr/ main/java/org/apache/directory/shared/ldap/schema/syntax/ main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ test/java/org/apache/directory/shared/ldap/schema/s...
Date Wed, 13 Dec 2006 01:53:28 GMT
Author: elecharny
Date: Tue Dec 12 17:53:26 2006
New Revision: 486451

URL: http://svn.apache.org/viewvc?view=rev&rev=486451
Log:
applied Stefan Seelmann patch. Just replaced the inner Enum by existing enums from ldap-name

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescription.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescription.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/AttributeTypeDescriptionSchemaParser.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/LdapSyntaxDescriptionSchemaParser.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxCheckerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxCheckerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserAttributeTypeDescriptionTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserLdapSyntaxDescriptionTest.java
Modified:
    directory/trunks/shared/ldap/src/main/antlr/schema-extension.g
    directory/trunks/shared/ldap/src/main/antlr/schema-value.g
    directory/trunks/shared/ldap/src/main/antlr/schema.g
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassDescription.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ObjectClassDescriptionSchemaParser.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserObjectClassDescriptionTest.java

Modified: directory/trunks/shared/ldap/src/main/antlr/schema-extension.g
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/antlr/schema-extension.g?view=diff&rev=486451&r1=486450&r2=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/antlr/schema-extension.g (original)
+++ directory/trunks/shared/ldap/src/main/antlr/schema-extension.g Tue Dec 12 17:53:26 2006
@@ -81,8 +81,8 @@
      */
 extension returns [AntlrSchemaParser.Extension extension = new AntlrSchemaParser.Extension()]
     :
-    ( xkey:XKEY { extension.setKey(xkey.getText()); } )
-    ( xvalues:XVALUES { extension.setValues(qdstrings(xvalues.getText())); } )
+    ( xkey:XKEY { extension.key = xkey.getText(); } )
+    ( xvalues:XVALUES { extension.values = qdstrings(xvalues.getText()); } )
     ;
     
     

Modified: directory/trunks/shared/ldap/src/main/antlr/schema-value.g
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/antlr/schema-value.g?view=diff&rev=486451&r1=486450&r2=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/antlr/schema-value.g (original)
+++ directory/trunks/shared/ldap/src/main/antlr/schema-value.g Tue Dec 12 17:53:26 2006
@@ -34,7 +34,7 @@
 class AntlrSchemaValueLexer extends Lexer;
 
 options    {
-    k = 2 ;
+    k = 3 ;
     exportVocab=AntlrSchemaValue ;
     charVocabulary = '\3'..'\377' ;
     caseSensitive = true ;
@@ -46,18 +46,17 @@
 
 LPAR : '(' ;
 RPAR : ')' ;
+protected LDIGIT : '1'..'9' ;
+protected DIGIT : '0'..'9' ; 
+protected NUMBER : DIGIT | ( LDIGIT (DIGIT)+ ) ;
 
 QUOTE : '\'' ;
 DOLLAR : '$' ;
-LBRACKET : '{' ;
-RBRACKET : '}' ;
-LEN : LBRACKET (DIGIT)+ RBRACKET ;
-DIGIT : ('0'..'9') ; 
-NUMERICOID : ('0'..'9')+ ( '.' ('0'..'9')+ )+ ;
+LCURLY : '{' ;
+RCURLY : '}' ;
+NUMERICOID : NUMBER ( '.' NUMBER )+ ;
 DESCR : ( 'a'..'z' | 'A'..'Z' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' )* ;
-
-
-
+LEN : LCURLY n:NUMBER RCURLY { setText(n.getText()); } ;
 
 
 /**
@@ -73,6 +72,21 @@
     defaultErrorHandler = false ;
     //buildAST=true ;
 }
+
+
+    /**
+     * noidlen = numericoid [ LCURLY len RCURLY ]
+     * len = number
+     */
+noidlen returns [AntlrSchemaParser.NoidLen noidlen = new AntlrSchemaParser.NoidLen()]
+    :
+    ( 
+      o:NUMERICOID { noidlen.noid = o.getText(); } 
+      (
+        l:LEN { noidlen.len = Integer.parseInt(l.getText()); } 
+      )?
+    )
+    ;
 
 
     /**

Modified: directory/trunks/shared/ldap/src/main/antlr/schema.g
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/antlr/schema.g?view=diff&rev=486451&r1=486450&r2=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/antlr/schema.g (original)
+++ directory/trunks/shared/ldap/src/main/antlr/schema.g Tue Dec 12 17:53:26 2006
@@ -22,6 +22,8 @@
 
 import java.io.* ;
 import java.util.* ;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
 
 }
 
@@ -52,11 +54,6 @@
 
 LEN : LBRACKET ('0'..'9')+ RBRACKET ;
 
-USERAPPLICATIONS : "userApplications" ;
-DIRECTORYOPERATION : "directoryOperation" ;
-DISTRIBUTEDOPERATION : "distributedOperation" ;
-DSAOPERATION : "dSAOperation" ;
-
 SINGLE_VALUE : ( "SINGLE-VALUE" (WHSP)? ) ;
 COLLECTIVE : ( "COLLECTIVE" (WHSP)? ) ;
 NO_USER_MODIFICATION : ( "NO-USER-MODIFICATION" (WHSP)? ) ;
@@ -76,7 +73,6 @@
 ORDERING : ( "ORDERING" WHSP ordering:VALUES ) { setText(ordering.getText().trim()); } ;
 SUBSTR : ( "SUBSTR" WHSP substr:VALUES ) { setText(substr.getText().trim()); } ;
 SYNTAX : ( "SYNTAX" WHSP syntax:VALUES (len:LEN)? ) { setText(syntax.getText().trim() + (len!=null?len.getText().trim():"")); } ;
-USAGE : ( "USAGE" WHSP op:VALUES ) { setText(op.getText().trim()); } ;
 APPLIES : ( "APPLIES" WHSP applies:VALUES ) { setText(applies.getText().trim()); } ;
 EXTENSION : x:( "X-" ( 'a'..'z' | 'A'..'Z' | '-' | '_' )+ WHSP VALUES ) ; 
 
@@ -85,6 +81,11 @@
 protected UNQUOTED_STRING : (options{greedy=true;}: 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' | ';' | '.' )+ ;
 protected QUOTED_STRING : ( QUOTE (~'\'')* QUOTE ) ;
 
+USAGE : ( "USAGE" (WHSP)? ) ;
+USER_APPLICATIONS : ( "userApplications" (WHSP)? ) ;
+DIRECTORY_OPERATION : ( "directoryOperation" (WHSP)? ) ;
+DISTRIBUTED_OPERATION : ( "distributedOperation" (WHSP)? ) ;
+DSA_OPERATION : ( "dSAOperation" (WHSP)? ) ;
 
 /**
  * An antlr generated schema main parser.
@@ -102,43 +103,18 @@
 {
 	static class Extension
 	{
-	
-	    private String key;
-	    
-	    private List<String> values;
-	    
-	    public Extension()
-	    {
-	        this.key = "";
-	        this.values = new ArrayList<String>();
-	    }
-	
-	    public String getKey()
-	    {
-	        return key;
-	    }
-	
-	    public void setKey( String key )
-	    {
-	        this.key = key;
-	    }
-	
-	    public List<String> getValues()
-	    {
-	        return values;
-	    }
-	
-	    public void setValues( List<String> values )
-	    {
-	        this.values = values;
-	    }
-	    
+	    String key = "";
+	    List<String> values = new ArrayList<String>();
 	    
 	    public void addValue( String value )
 	    {
 	        this.values.add( value );
 	    }
-	    
+	}
+	static class NoidLen
+	{
+	    String noid = "";
+	    int len = 0;
 	}
 }
 
@@ -167,7 +143,7 @@
     */
 objectClassDescription returns [ObjectClassDescription ocd = new ObjectClassDescription()]
     :
-    ( oid:STARTNUMERICOID { ocd.setOid(numericoid(oid.getText())); } )
+    ( oid:STARTNUMERICOID { ocd.setNumericOid(numericoid(oid.getText())); } )
     (
 	    ( name:NAME { ocd.setNames(qdescrs(name.getText())); } )
 	    |
@@ -177,11 +153,11 @@
 	    |
 	    ( sup:SUP { ocd.setSuperiorObjectClasses(oids(sup.getText())); } )
 	    |
-	    ( ABSTRACT { ocd.setKind( ObjectClassDescription.Kind.ABSTRACT ); }
+	    ( ABSTRACT { ocd.setKind( ObjectClassTypeEnum.ABSTRACT ); }
 	      |
-	      STRUCTURAL { ocd.setKind( ObjectClassDescription.Kind.STRUCTURAL ); }
+	      STRUCTURAL { ocd.setKind( ObjectClassTypeEnum.STRUCTURAL ); }
 	      |
-	      AUXILIARY { ocd.setKind( ObjectClassDescription.Kind.AUXILIARY ); } 
+	      AUXILIARY { ocd.setKind( ObjectClassTypeEnum.AUXILIARY ); } 
 	    )
 	    |
 	    ( must:MUST { ocd.setMustAttributeTypes(oids(must.getText())); } )
@@ -190,10 +166,125 @@
 	    |
 	    ( extension:EXTENSION { 
 	        Extension ex = extension(extension.getText());
-	        ocd.addExtension(ex.getKey(), ex.getValues()); 
+	        ocd.addExtension(ex.key, ex.values); 
+	     } )
+	)*    
+    RPAR
+    ;
+
+
+    /**
+     * Production for matching attribute type descriptions. It is fault-tolerant
+     * against element ordering.
+     *
+     * <pre>
+     * AttributeTypeDescription = LPAREN WSP
+     *     numericoid                    ; object identifier
+     *     [ SP "NAME" SP qdescrs ]      ; short names (descriptors)
+     *     [ SP "DESC" SP qdstring ]     ; description
+     *     [ SP "OBSOLETE" ]             ; not active
+     *     [ SP "SUP" SP oid ]           ; supertype
+     *     [ SP "EQUALITY" SP oid ]      ; equality matching rule
+     *     [ SP "ORDERING" SP oid ]      ; ordering matching rule
+     *     [ SP "SUBSTR" SP oid ]        ; substrings matching rule
+     *     [ SP "SYNTAX" SP noidlen ]    ; value syntax
+     *     [ SP "SINGLE-VALUE" ]         ; single-value
+     *     [ SP "COLLECTIVE" ]           ; collective
+     *     [ SP "NO-USER-MODIFICATION" ] ; not user modifiable
+     *     [ SP "USAGE" SP usage ]       ; usage
+     *     extensions WSP RPAREN         ; extensions
+     * 
+     * usage = "userApplications"     /  ; user
+     *         "directoryOperation"   /  ; directory operational
+     *         "distributedOperation" /  ; DSA-shared operational
+     *         "dSAOperation"            ; DSA-specific operational     
+     * 
+     * extensions = *( SP xstring SP qdstrings )
+     * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 
+     * </pre>
+    */
+attributeTypeDescription returns [AttributeTypeDescription atd = new AttributeTypeDescription()]
+    :
+    ( oid:STARTNUMERICOID { atd.setNumericOid(numericoid(oid.getText())); } )
+    (
+	    ( name:NAME { atd.setNames(qdescrs(name.getText())); } )
+	    |
+	    ( desc:DESC { atd.setDescription(qdstring(desc.getText())); } )
+	    |
+	    ( OBSOLETE { atd.setObsolete( true ); } )
+	    |
+	    ( sup:SUP { atd.setSuperType(oid(sup.getText())); } )
+	    |
+        ( equality:EQUALITY { atd.setEqualityMatchingRule(oid(equality.getText())); } )
+        |
+        ( ordering:ORDERING { atd.setOrderingMatchingRule(oid(ordering.getText())); } )
+        |
+        ( substr:SUBSTR { atd.setSubstringsMatchingRule(oid(substr.getText())); } )
+        |
+        ( syntax:SYNTAX { 
+            NoidLen noidlen = noidlen(syntax.getText());
+            atd.setSyntax(noidlen.noid); 
+            atd.setSyntaxLength(noidlen.len);
+          } )
+        |
+        ( SINGLE_VALUE { atd.setSingleValued( true ); } )
+        |
+        ( COLLECTIVE { atd.setCollective( true ); } )
+        |
+        ( NO_USER_MODIFICATION { atd.setUserModifiable( false ); } )
+        |
+	    ( USAGE (WHSP)* USER_APPLICATIONS { atd.setUsage( UsageEnum.USER_APPLICATIONS ); }
+	      |
+	      USAGE DIRECTORY_OPERATION { atd.setUsage( UsageEnum.DIRECTORY_OPERATION ); }
+	      |
+	      USAGE DISTRIBUTED_OPERATION { atd.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); } 
+	      |
+	      USAGE DSA_OPERATION { atd.setUsage( UsageEnum.DSA_OPERATION ); } 
+	    )
+	    |
+	    ( extension:EXTENSION { 
+	        Extension ex = extension(extension.getText());
+	        atd.addExtension(ex.key, ex.values); 
 	     } )
 	)*    
     RPAR
+    ;
+
+
+    /**
+     * Production for matching ldap syntax descriptions. It is fault-tolerant
+     * against element ordering.
+     *
+     * <pre>
+     * SyntaxDescription = LPAREN WSP
+     *    numericoid                 ; object identifier
+     *    [ SP "DESC" SP qdstring ]  ; description
+     *    extensions WSP RPAREN      ; extensions
+     * </pre>
+    */
+ldapSyntaxDescription returns [LdapSyntaxDescription lsd = new LdapSyntaxDescription()]
+     :
+    ( oid:STARTNUMERICOID { lsd.setNumericOid(numericoid(oid.getText())); } )
+    (
+	    ( desc:DESC { lsd.setDescription(qdstring(desc.getText())); } )
+	    |
+	    ( extension:EXTENSION { 
+	        Extension ex = extension(extension.getText());
+	        lsd.addExtension(ex.key, ex.values); 
+	     } )
+    )*
+    RPAR
+    ;
+
+
+noidlen [String s] returns [NoidLen noidlen]
+    {
+        noidlen = new NoidLen();
+        AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
+        AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
+        noidlen = parser.noidlen();
+    }
+    :
     ;
 
 

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescription.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescription.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescription.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescription.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,275 @@
+/*
+ *  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.syntax;
+
+ 
+ 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+ 
+ 
+/**
+ * RFC 4512 - 4.1.2. Attribute Types
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AttributeTypeDescription
+{
+    private String numericOid;
+ 
+    private List<String> names;
+ 
+    private String description;
+ 
+    private boolean isObsolete;
+ 
+    private String superType;
+ 
+    private String equalityMatchingRule;
+ 
+    private String orderingMatchingRule;
+ 
+    private String substringsMatchingRule;
+ 
+    private String syntax;
+ 
+    private int syntaxLength;
+ 
+    private boolean isSingleValued;
+ 
+    private boolean isCollective;
+ 
+    private boolean isUserModifiable;
+ 
+    private UsageEnum usage;
+ 
+    private Map<String, List<String>> extensions;
+ 
+ 
+    public AttributeTypeDescription( )
+    {
+        this.numericOid = "";
+        names = new ArrayList<String>();
+        description = "";
+        isObsolete = false;
+        superType = null;
+        equalityMatchingRule = null;
+        orderingMatchingRule = null;
+        substringsMatchingRule = null;
+        syntax = null;
+        syntaxLength = 0;
+        isSingleValued = false;
+        isCollective = false;
+        isUserModifiable = true;
+        usage = UsageEnum.USER_APPLICATIONS;
+        extensions = new LinkedHashMap<String, List<String>>();;
+    }
+ 
+ 
+    public String getDescription()
+    {
+        return description;
+    }
+ 
+ 
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+ 
+ 
+    public String getEqualityMatchingRule()
+    {
+        return equalityMatchingRule;
+    }
+ 
+ 
+    public void setEqualityMatchingRule( String equalityMatchingRule )
+    {
+        this.equalityMatchingRule = equalityMatchingRule;
+    }
+ 
+ 
+    public Map<String, List<String>> getExtensions()
+    {
+        return extensions;
+    }
+ 
+ 
+    public void setExtensions( Map<String, List<String>> extensions )
+    {
+        this.extensions = extensions;
+    }
+ 
+ 
+    public boolean isCollective()
+    {
+        return isCollective;
+    }
+ 
+ 
+    public void setCollective( boolean isCollective )
+    {
+        this.isCollective = isCollective;
+    }
+ 
+ 
+    public boolean isObsolete()
+    {
+        return isObsolete;
+    }
+ 
+ 
+    public void setObsolete( boolean isObsolete )
+    {
+        this.isObsolete = isObsolete;
+    }
+ 
+ 
+    public boolean isUserModifiable()
+    {
+        return isUserModifiable;
+    }
+ 
+ 
+    public void setUserModifiable( boolean isUserModifiable )
+    {
+        this.isUserModifiable = isUserModifiable;
+    }
+ 
+ 
+    public List<String> getNames()
+    {
+        return names;
+    }
+ 
+ 
+    public void setNames( List<String> names )
+    {
+        this.names = names;
+    }
+ 
+ 
+    public String getNumericOid()
+    {
+        return numericOid;
+    }
+ 
+ 
+    public void setNumericOid( String oid )
+    {
+        this.numericOid = oid;
+    }
+ 
+ 
+    public String getOrderingMatchingRule()
+    {
+        return orderingMatchingRule;
+    }
+ 
+ 
+    public void setOrderingMatchingRule( String orderingMatchingRule )
+    {
+        this.orderingMatchingRule = orderingMatchingRule;
+    }
+ 
+ 
+    public boolean isSingleValued()
+    {
+        return isSingleValued;
+    }
+ 
+ 
+    public void setSingleValued( boolean singleValued )
+    {
+        this.isSingleValued = singleValued;
+    }
+ 
+ 
+    public String getSubstringsMatchingRule()
+    {
+        return substringsMatchingRule;
+    }
+ 
+ 
+    public void setSubstringsMatchingRule( String substringsMatchingRule )
+    {
+        this.substringsMatchingRule = substringsMatchingRule;
+    }
+ 
+ 
+    public String getSuperType()
+    {
+        return superType;
+    }
+ 
+ 
+    public void setSuperType( String superType )
+    {
+        this.superType = superType;
+    }
+ 
+ 
+    public String getSyntax()
+    {
+        return syntax;
+    }
+ 
+ 
+    public void setSyntax( String syntax )
+    {
+        this.syntax = syntax;
+    }
+ 
+ 
+    public int getSyntaxLength()
+    {
+        return syntaxLength;
+    }
+ 
+ 
+    public void setSyntaxLength( int syntaxLenght )
+    {
+        this.syntaxLength = syntaxLenght;
+    }
+ 
+ 
+    public UsageEnum getUsage()
+    {
+        return usage;
+    }
+ 
+ 
+    public void setUsage( UsageEnum usage )
+    {
+        this.usage = usage;
+    }
+    
+    public void addExtension( String key, List<String> values )
+    {
+        this.extensions.put( key, values );
+    }
+ 
+}
\ No newline at end of file

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxChecker.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxChecker.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,171 @@
+/*
+ *  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.syntax;
+
+
+import java.text.ParseException;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.schema.syntax.parser.AttributeTypeDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value follows the
+ * attribute type descripton syntax according to RFC 4512, par 4.2.2:
+ * 
+*  <pre>
+ * AttributeTypeDescription = LPAREN WSP
+ *     numericoid                    ; object identifier
+ *     [ SP "NAME" SP qdescrs ]      ; short names (descriptors)
+ *     [ SP "DESC" SP qdstring ]     ; description
+ *     [ SP "OBSOLETE" ]             ; not active
+ *     [ SP "SUP" SP oid ]           ; supertype
+ *     [ SP "EQUALITY" SP oid ]      ; equality matching rule
+ *     [ SP "ORDERING" SP oid ]      ; ordering matching rule
+ *     [ SP "SUBSTR" SP oid ]        ; substrings matching rule
+ *     [ SP "SYNTAX" SP noidlen ]    ; value syntax
+ *     [ SP "SINGLE-VALUE" ]         ; single-value
+ *     [ SP "COLLECTIVE" ]           ; collective
+ *     [ SP "NO-USER-MODIFICATION" ] ; not user modifiable
+ *     [ SP "USAGE" SP usage ]       ; usage
+ *     extensions WSP RPAREN         ; extensions
+ * 
+ * usage = "userApplications"     /  ; user
+ *         "directoryOperation"   /  ; directory operational
+ *         "distributedOperation" /  ; DSA-shared operational
+ *         "dSAOperation"            ; DSA-specific operational     
+ * 
+ * extensions = *( SP xstring SP qdstrings )
+ * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 
+ * 
+ * Each attribute type description must contain at least one of the SUP
+ * or SYNTAX fields. 
+ * 
+ * COLLECTIVE requires usage userApplications.
+ * 
+ * NO-USER-MODIFICATION requires an operational usage.
+ * 
+ * 
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AttributeTypeDescriptionSyntaxChecker implements SyntaxChecker
+{
+
+    /** The Syntax OID, according to RFC 4517, par. 3.3.1 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.3";
+
+	/** The schema parser used to parse the AttributeTypeDescription Syntax */
+    private AttributeTypeDescriptionSchemaParser schemaParser = new AttributeTypeDescriptionSchemaParser();
+
+
+    /**
+     * 
+     * Creates a new instance of AttributeTypeDescriptionSchemaParser.
+     *
+     */
+    public AttributeTypeDescriptionSyntaxChecker()
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+     */
+    public void assertSyntax( Object value ) throws NamingException
+    {
+        if ( !isValidSyntax( value ) )
+        {
+            throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        String strValue;
+
+        if ( value == null )
+        {
+            return false;
+        }
+
+        if ( value instanceof String )
+        {
+            strValue = ( String ) value;
+        }
+        else if ( value instanceof byte[] )
+        {
+            strValue = StringTools.utf8ToString( ( byte[] ) value );
+        }
+        else
+        {
+            strValue = value.toString();
+        }
+
+        try
+        {
+            AttributeTypeDescription atd = schemaParser.parseAttributeTypeDescription( strValue );
+            
+            // SYNTAX or SUP must be contained
+            if ( ( atd.getSyntax() == null ) && ( atd.getSuperType() == null ) ) 
+            {
+                return false;
+            }
+            
+            // COLLECTIVE requires usage userApplications
+            if ( atd.isCollective() && ( atd.getUsage() != UsageEnum.USER_APPLICATIONS ) )
+            {
+                return false;
+            }
+            
+            // NO-USER-MODIFICATION requires an operational usage.
+            if ( !atd.isUserModifiable() && ( atd.getUsage() == UsageEnum.USER_APPLICATIONS ) ) 
+            {
+                return false;
+            }
+                
+            return true;
+        }
+        catch ( ParseException pe )
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescription.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescription.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescription.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescription.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,94 @@
+/*
+ *  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.syntax;
+
+ 
+ 
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+ 
+ 
+/**
+ * RFC 4512 - 4.1.5. LDAP Syntaxes
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapSyntaxDescription
+{
+ 
+    private String numericOid;
+ 
+    private String description;
+ 
+    private Map<String, List<String>> extensions;
+ 
+ 
+    public LdapSyntaxDescription( )
+    {
+        this.numericOid = "";
+        description = "";
+        extensions = new LinkedHashMap<String, List<String>>();
+    }
+ 
+ 
+    public String getDescription()
+    {
+        return description;
+    }
+ 
+ 
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+ 
+ 
+    public Map<String, List<String>> getExtensions()
+    {
+        return extensions;
+    }
+ 
+ 
+    public void setExtensions( Map<String, List<String>> extensions )
+    {
+        this.extensions = extensions;
+    }
+ 
+ 
+    public String getNumericOid()
+    {
+        return numericOid;
+    }
+ 
+ 
+    public void setNumericOid( String oid )
+    {
+        numericOid = oid;
+    }
+ 
+    
+    public void addExtension( String key, List<String> values )
+    {
+        extensions.put( key, values );
+    }
+ 
+}
\ No newline at end of file

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxChecker.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxChecker.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,123 @@
+/*
+ *  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.syntax;
+
+
+import java.text.ParseException;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.schema.syntax.parser.LdapSyntaxDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value follows the
+ * LDAP syntax descripton syntax according to RFC 4512, par 4.2.2:
+ * 
+ * <pre>
+ * SyntaxDescription = LPAREN WSP
+ *    numericoid                 ; object identifier
+ *    [ SP "DESC" SP qdstring ]  ; description
+ *    extensions WSP RPAREN      ; extensions
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LdapSyntaxDescriptionSyntaxChecker implements SyntaxChecker
+{
+
+    /** The Syntax OID, according to RFC 4517, par. 3.3.18 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.54";
+
+	/** The schema parser used to parse the LdapSyntaxDescription Syntax */
+    private LdapSyntaxDescriptionSchemaParser schemaParser = new LdapSyntaxDescriptionSchemaParser();
+
+
+    /**
+     * 
+     * Creates a new instance of AttributeTypeDescriptionSchemaParser.
+     *
+     */
+    public LdapSyntaxDescriptionSyntaxChecker()
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+     */
+    public void assertSyntax( Object value ) throws NamingException
+    {
+        if ( !isValidSyntax( value ) )
+        {
+            throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        String strValue;
+
+        if ( value == null )
+        {
+            return false;
+        }
+
+        if ( value instanceof String )
+        {
+            strValue = ( String ) value;
+        }
+        else if ( value instanceof byte[] )
+        {
+            strValue = StringTools.utf8ToString( ( byte[] ) value );
+        }
+        else
+        {
+            strValue = value.toString();
+        }
+
+        try
+        {
+            schemaParser.parseLdapSyntaxDescription( strValue );
+            return true;
+        }
+        catch ( ParseException pe )
+        {
+            return false;
+        }
+    }
+}

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassDescription.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassDescription.java?view=diff&rev=486451&r1=486450&r2=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassDescription.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassDescription.java Tue Dec 12 17:53:26 2006
@@ -26,6 +26,8 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+
 
 /**
  * RFC 4512 - 4.1.1. Object Class Description
@@ -34,12 +36,7 @@
  */
 public class ObjectClassDescription
 {
-    public static enum Kind
-    {
-        ABSTRACT, STRUCTURAL, AUXILIARY
-    }
-
-    private String oid;
+    private String numericOid;
 
     private List<String> names;
 
@@ -49,7 +46,7 @@
 
     private List<String> superiorObjectClasses;
 
-    private Kind kind;
+    private ObjectClassTypeEnum kind;
 
     private List<String> mustAttributeTypes;
 
@@ -60,12 +57,12 @@
 
     public ObjectClassDescription()
     {
-        this.oid = "";
+        numericOid = "";
         names = new ArrayList<String>();
         description = "";
         isObsolete = false;
         superiorObjectClasses = new ArrayList<String>();
-        kind = Kind.STRUCTURAL;
+        kind = ObjectClassTypeEnum.STRUCTURAL;
         mustAttributeTypes = new ArrayList<String>();
         mayAttributeTypes = new ArrayList<String>();
         extensions = new LinkedHashMap<String, List<String>>();
@@ -146,13 +143,13 @@
 
     public String getNumericOid()
     {
-        return oid;
+        return numericOid;
     }
 
 
-    public void setOid( String oid )
+    public void setNumericOid( String numericOid )
     {
-        this.oid = oid;
+        this.numericOid = numericOid;
     }
 
 
@@ -168,13 +165,13 @@
     }
 
 
-    public Kind getKind()
+    public ObjectClassTypeEnum getKind()
     {
         return kind;
     }
 
 
-    public void setKind( Kind kind )
+    public void setKind( ObjectClassTypeEnum kind )
     {
         this.kind = kind;
     }
@@ -182,25 +179,24 @@
 
     public void addSuperiorObjectClass( String oid )
     {
-        this.superiorObjectClasses.add( oid );
+        superiorObjectClasses.add( oid );
     }
 
 
     public void addMustAttributeType( String oid )
     {
-        this.mustAttributeTypes.add( oid );
+        mustAttributeTypes.add( oid );
     }
 
 
     public void addMayAttributeType( String oid )
     {
-        this.mayAttributeTypes.add( oid );
+        mayAttributeTypes.add( oid );
     }
 
 
     public void addExtension( String key, List<String> values )
     {
-        this.extensions.put( key, values );
+        extensions.put( key, values );
     }
-
 }

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/AttributeTypeDescriptionSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/AttributeTypeDescriptionSchemaParser.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/AttributeTypeDescriptionSchemaParser.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/AttributeTypeDescriptionSchemaParser.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,137 @@
+/*
+ *  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.syntax.parser;
+
+
+import java.io.StringReader;
+import java.text.ParseException;
+
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A parser for RFC 4512 attribute type descriptions.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AttributeTypeDescriptionSchemaParser
+{
+
+    /** the antlr generated parser being wrapped */
+    private ReusableAntlrSchemaParser parser;
+
+    /** the antlr generated lexer being wrapped */
+    private ReusableAntlrSchemaLexer lexer;
+    
+    static
+    {
+    }
+
+
+    /**
+     * Creates a schema parser instance.
+     */
+    public AttributeTypeDescriptionSchemaParser()
+    {
+        lexer = new ReusableAntlrSchemaLexer( new StringReader( "" ) );
+        parser = new ReusableAntlrSchemaParser( lexer );
+    }
+    
+    /**
+     * Initializes the plumbing by creating a pipe and coupling the parser/lexer
+     * pair with it. param spec the specification to be parsed
+     */
+    private void reset( String spec )
+    {
+        StringReader in = new StringReader( spec );
+        lexer.prepareNextInput( in );
+        parser.resetState();
+    }
+
+
+    /**
+     * Parses a attribute type description according to RFC 4512:
+     * 
+     * <pre>
+     * AttributeTypeDescription = LPAREN WSP
+     *     numericoid                    ; object identifier
+     *     [ SP "NAME" SP qdescrs ]      ; short names (descriptors)
+     *     [ SP "DESC" SP qdstring ]     ; description
+     *     [ SP "OBSOLETE" ]             ; not active
+     *     [ SP "SUP" SP oid ]           ; supertype
+     *     [ SP "EQUALITY" SP oid ]      ; equality matching rule
+     *     [ SP "ORDERING" SP oid ]      ; ordering matching rule
+     *     [ SP "SUBSTR" SP oid ]        ; substrings matching rule
+     *     [ SP "SYNTAX" SP noidlen ]    ; value syntax
+     *     [ SP "SINGLE-VALUE" ]         ; single-value
+     *     [ SP "COLLECTIVE" ]           ; collective
+     *     [ SP "NO-USER-MODIFICATION" ] ; not user modifiable
+     *     [ SP "USAGE" SP usage ]       ; usage
+     *     extensions WSP RPAREN         ; extensions
+     * 
+     * usage = "userApplications"     /  ; user
+     *         "directoryOperation"   /  ; directory operational
+     *         "distributedOperation" /  ; DSA-shared operational
+     *         "dSAOperation"            ; DSA-specific operational     
+     * 
+     * extensions = *( SP xstring SP qdstrings )
+     * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE ) 
+     * </pre>
+     * 
+     * @param attributeTypeDescription the attribute type description to be parsed
+     * @return the parsed AttributeTypeDescription bean
+     * @throws ParseException if there are any recognition errors (bad syntax)
+     */
+    public synchronized AttributeTypeDescription parseAttributeTypeDescription( String attributeTypeDescription )
+        throws ParseException
+    {
+
+        if ( attributeTypeDescription == null )
+        {
+            throw new ParseException( "Null", 0 );
+        }
+
+        reset( attributeTypeDescription ); // reset and initialize the parser / lexer pair
+
+        try
+        {
+            AttributeTypeDescription atd = parser.attributeTypeDescription();
+            return atd;
+        }
+        catch ( RecognitionException re )
+        {
+            String msg = "Parser failure on attribute type description:\n\t" + attributeTypeDescription;
+            msg += "\nAntlr message: " + re.getMessage();
+            msg += "\nAntlr column: " + re.getColumn();
+            throw new ParseException( msg, re.getColumn() );
+        }
+        catch ( TokenStreamException tse )
+        {
+            String msg = "Parser failure on attribute type description:\n\t" + attributeTypeDescription;
+            msg += "\nAntlr message: " + tse.getMessage();
+            throw new ParseException( msg, 0 );
+        }
+
+    }
+
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/LdapSyntaxDescriptionSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/LdapSyntaxDescriptionSchemaParser.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/LdapSyntaxDescriptionSchemaParser.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/LdapSyntaxDescriptionSchemaParser.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,118 @@
+/*
+ *  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.syntax.parser;
+
+
+import java.io.StringReader;
+import java.text.ParseException;
+
+import org.apache.directory.shared.ldap.schema.syntax.LdapSyntaxDescription;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A parser for RFC 4512 LDAP syntx descriptions.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapSyntaxDescriptionSchemaParser
+{
+
+    /** the antlr generated parser being wrapped */
+    private ReusableAntlrSchemaParser parser;
+
+    /** the antlr generated lexer being wrapped */
+    private ReusableAntlrSchemaLexer lexer;
+    
+    static
+    {
+    }
+
+
+    /**
+     * Creates a schema parser instance.
+     */
+    public LdapSyntaxDescriptionSchemaParser()
+    {
+        lexer = new ReusableAntlrSchemaLexer( new StringReader( "" ) );
+        parser = new ReusableAntlrSchemaParser( lexer );
+    }
+    
+    /**
+     * Initializes the plumbing by creating a pipe and coupling the parser/lexer
+     * pair with it. param spec the specification to be parsed
+     */
+    private void reset( String spec )
+    {
+        StringReader in = new StringReader( spec );
+        lexer.prepareNextInput( in );
+        parser.resetState();
+    }
+
+
+    /**
+     * Parses a LDAP syntax description according to RFC 4512:
+     * 
+     * <pre>
+     * SyntaxDescription = LPAREN WSP
+     *    numericoid                 ; object identifier
+     *    [ SP "DESC" SP qdstring ]  ; description
+     *    extensions WSP RPAREN      ; extensions
+     * </pre>
+     * 
+     * @param ldapSyntaxDescription the LDAP syntay description to be parsed
+     * @return the parsed LdapSyntaxDescription bean
+     * @throws ParseException if there are any recognition errors (bad syntax)
+     */
+    public synchronized LdapSyntaxDescription parseLdapSyntaxDescription( String ldapSyntaxDescription )
+        throws ParseException
+    {
+
+        if ( ldapSyntaxDescription == null )
+        {
+            throw new ParseException( "Null", 0 );
+        }
+
+        reset( ldapSyntaxDescription ); // reset and initialize the parser / lexer pair
+
+        try
+        {
+            LdapSyntaxDescription lsd = parser.ldapSyntaxDescription();
+            return lsd;
+        }
+        catch ( RecognitionException re )
+        {
+            String msg = "Parser failure on LDAP syntay description:\n\t" + ldapSyntaxDescription;
+            msg += "\nAntlr message: " + re.getMessage();
+            msg += "\nAntlr column: " + re.getColumn();
+            throw new ParseException( msg, re.getColumn() );
+        }
+        catch ( TokenStreamException tse )
+        {
+            String msg = "Parser failure on LDAP syntay description:\n\t" + ldapSyntaxDescription;
+            msg += "\nAntlr message: " + tse.getMessage();
+            throw new ParseException( msg, 0 );
+        }
+
+    }
+
+}

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ObjectClassDescriptionSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ObjectClassDescriptionSchemaParser.java?view=diff&rev=486451&r1=486450&r2=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ObjectClassDescriptionSchemaParser.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ObjectClassDescriptionSchemaParser.java Tue Dec 12 17:53:26 2006
@@ -20,23 +20,17 @@
 package org.apache.directory.shared.ldap.schema.syntax.parser;
 
 
-import java.io.Reader;
 import java.io.StringReader;
 import java.text.ParseException;
 
-import org.apache.directory.shared.ldap.schema.syntax.AntlrSchemaLexer;
-import org.apache.directory.shared.ldap.schema.syntax.AntlrSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
 
-import antlr.CharBuffer;
-import antlr.LexerSharedInputState;
 import antlr.RecognitionException;
-import antlr.TokenStream;
 import antlr.TokenStreamException;
 
 
 /**
- * A parser for RFC 4512 schema objects
+ * A parser for RFC 4512 object class descriptons
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -130,88 +124,5 @@
             throw new ParseException( msg, 0 );
         }
 
-    }
-
-    /**
-     * A reusable lexer class extended from antlr generated lexer for an LDAP
-     * schema as defined in RFC 4512. This class
-     * enables the reuse of the antlr lexer without having to recreate the it every
-     * time as stated in <a
-     * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
-     * a Antlr Interest Group mail</a> .
-     * 
-     * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
-     */
-    private static class ReusableAntlrSchemaLexer extends AntlrSchemaLexer
-    {
-        private boolean savedCaseSensitive;
-
-        private boolean savedCaseSensitiveLiterals;
-
-
-        /**
-         * Creates a ReusableAntlrSchemaLexer instance.
-         * 
-         * @param in
-         *            the input to the lexer
-         */
-        public ReusableAntlrSchemaLexer( Reader in )
-        {
-            super( in );
-            savedCaseSensitive = getCaseSensitive();
-            savedCaseSensitiveLiterals = getCaseSensitiveLiterals();
-        }
-
-
-        /**
-         * Resets the state of an antlr lexer and initializes it with new input.
-         * 
-         * @param in
-         *            the input to the lexer
-         */
-        public void prepareNextInput( Reader in )
-        {
-            CharBuffer buf = new CharBuffer( in );
-            LexerSharedInputState state = new LexerSharedInputState( buf );
-            this.setInputState( state );
-
-            this.setCaseSensitive( savedCaseSensitive );
-
-            // no set method for this protected field.
-            this.caseSensitiveLiterals = savedCaseSensitiveLiterals;
-        }
-    }
-
-    /**
-     * A reusable parser class extended from antlr generated parser for an LDAP
-     * schema as defined in RFC 4512. This class
-     * enables the reuse of the antlr parser without having to recreate the it every
-     * time as stated in <a
-     * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
-     * a Antlr Interest Group mail</a> .
-     * 
-     * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
-     */
-    private static class ReusableAntlrSchemaParser extends AntlrSchemaParser
-    {
-        /**
-         * Creates a ReusableAntlrSchemaParser instance.
-         */
-        public ReusableAntlrSchemaParser( TokenStream lexer )
-        {
-            super( lexer );
-        }
-
-
-        /**
-         * Resets the state of an antlr parser.
-         */
-        public void resetState()
-        {
-            // no set method for this protected field.
-            this.traceDepth = 0;
-
-            this.getInputState().reset();
-        }
     }
 }

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,58 @@
+package org.apache.directory.shared.ldap.schema.syntax.parser;
+
+import java.io.Reader;
+
+import org.apache.directory.shared.ldap.schema.syntax.AntlrSchemaLexer;
+
+import antlr.CharBuffer;
+import antlr.LexerSharedInputState;
+
+/**
+ * A reusable lexer class extended from antlr generated lexer for an LDAP
+ * schema as defined in RFC 4512. This class
+ * enables the reuse of the antlr lexer without having to recreate the it every
+ * time as stated in <a
+ * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
+ * a Antlr Interest Group mail</a> .
+ * 
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ */
+class ReusableAntlrSchemaLexer extends AntlrSchemaLexer
+{
+    private boolean savedCaseSensitive;
+
+    private boolean savedCaseSensitiveLiterals;
+
+
+    /**
+     * Creates a ReusableAntlrSchemaLexer instance.
+     * 
+     * @param in
+     *            the input to the lexer
+     */
+    public ReusableAntlrSchemaLexer( Reader in )
+    {
+        super( in );
+        savedCaseSensitive = getCaseSensitive();
+        savedCaseSensitiveLiterals = getCaseSensitiveLiterals();
+    }
+
+
+    /**
+     * Resets the state of an antlr lexer and initializes it with new input.
+     * 
+     * @param in
+     *            the input to the lexer
+     */
+    public void prepareNextInput( Reader in )
+    {
+        CharBuffer buf = new CharBuffer( in );
+        LexerSharedInputState state = new LexerSharedInputState( buf );
+        this.setInputState( state );
+
+        this.setCaseSensitive( savedCaseSensitive );
+
+        // no set method for this protected field.
+        this.caseSensitiveLiterals = savedCaseSensitiveLiterals;
+    }
+}
\ No newline at end of file

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,38 @@
+package org.apache.directory.shared.ldap.schema.syntax.parser;
+
+import org.apache.directory.shared.ldap.schema.syntax.AntlrSchemaParser;
+
+import antlr.TokenStream;
+
+/**
+ * A reusable parser class extended from antlr generated parser for an LDAP
+ * schema as defined in RFC 4512. This class
+ * enables the reuse of the antlr parser without having to recreate the it every
+ * time as stated in <a
+ * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
+ * a Antlr Interest Group mail</a> .
+ * 
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ */
+class ReusableAntlrSchemaParser extends AntlrSchemaParser
+{
+    /**
+     * Creates a ReusableAntlrSchemaParser instance.
+     */
+    public ReusableAntlrSchemaParser( TokenStream lexer )
+    {
+        super( lexer );
+    }
+
+
+    /**
+     * Resets the state of an antlr parser.
+     */
+    public void resetState()
+    {
+        // no set method for this protected field.
+        this.traceDepth = 0;
+
+        this.getInputState().reset();
+    }
+}
\ No newline at end of file

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxCheckerTest.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/AttributeTypeDescriptionSyntaxCheckerTest.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,126 @@
+/*
+ *  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.syntax;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test cases for AttributeTypeDescriptionSyntaxChecker.
+ * 
+ * There are also many test cases in SchemaParserAttributeTypeDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AttributeTypeDescriptionSyntaxCheckerTest extends TestCase
+{
+    AttributeTypeDescriptionSyntaxChecker checker = new AttributeTypeDescriptionSyntaxChecker();
+
+
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    public void testOneCharString()
+    {
+        assertFalse( checker.isValidSyntax( "A" ) );
+        assertFalse( checker.isValidSyntax( "1" ) );
+        assertFalse( checker.isValidSyntax( "-" ) );
+        assertFalse( checker.isValidSyntax( "(" ) );
+    }
+
+
+    public void testValid()
+    {
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15  )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name  )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name EQUALITY caseIgnoreMatch  )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch  )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE userApplications )" ) );
+
+        // spaces
+        assertTrue( checker.isValidSyntax( "(2.5.4.3 SUP name)" ) );
+        assertTrue( checker.isValidSyntax( "(      2.5.4.3      NAME ('cn'   'commonName')     SYNTAX       1.3.6.1.4.1.1466.115.121.1.15   )" ) );
+        
+        // COLLECTIVE requires usage userApplications
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name COLLECTIVE )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name COLLECTIVE USAGE userApplications )" ) );
+
+        // NO-USER-MODIFICATION requires an operational usage.
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name NO-USER-MODIFICATION USAGE dSAOperation )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name NO-USER-MODIFICATION USAGE directoryOperation )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name NO-USER-MODIFICATION USAGE distributedOperation )" ) );
+
+    }
+
+
+    public void testInvalid()
+    {
+        // missing/invalid OID
+        assertFalse( checker.isValidSyntax( "()" ) );
+        assertFalse( checker.isValidSyntax( "(  )" ) );
+        assertFalse( checker.isValidSyntax( "( . )" ) );
+        assertFalse( checker.isValidSyntax( "( 1 )" ) );
+        assertFalse( checker.isValidSyntax( "( 1. )" ) );
+        assertFalse( checker.isValidSyntax( "( 1.2. )" ) );
+        assertFalse( checker.isValidSyntax( "( 1.A )" ) );
+        assertFalse( checker.isValidSyntax( "( A.B )" ) );
+
+        // missing right parenthesis
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name" ) );
+
+        // missing quotes
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME cn SUP name )" ) );
+
+        // lowercase NAME, SUP
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 name ( 'cn' 'commonName' )  sup name " ) );
+
+        // SYNTAX or SUP must be contained
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by' )" ) );
+        
+        // COLLECTIVE requires usage userApplications
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name COLLECTIVE USAGE dSAOperation)" ) );
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name COLLECTIVE USAGE directoryOperation )" ) );
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name COLLECTIVE USAGE distributedOperation )" ) );
+        
+        // NO-USER-MODIFICATION requires an operational usage.
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name NO-USER-MODIFICATION )" ) );
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME 'cn' SUP name NO-USER-MODIFICATION USAGE userApplications )" ) );
+
+        // invalid characters
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn#' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE userApplications )" ) );
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'common_name' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP name EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE userApplications )" ) );
+        assertFalse( checker.isValidSyntax( "( 2.5.4.3 NAME ( 'cn' 'commonName' ) DESC 'RFC2256: common name(s) for which the entity is known by'  SUP na=me EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE userApplications )" ) );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxCheckerTest.java?view=auto&rev=486451
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/LdapSyntaxDescriptionSyntaxCheckerTest.java Tue Dec 12 17:53:26 2006
@@ -0,0 +1,100 @@
+/*
+ *  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.syntax;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test cases for LdapSyntaxDescriptionSyntaxChecker.
+ * 
+ * There are also many test cases in SchemaParserLdapSyntaxDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LdapSyntaxDescriptionSyntaxCheckerTest extends TestCase
+{
+    LdapSyntaxDescriptionSyntaxChecker checker = new LdapSyntaxDescriptionSyntaxChecker();
+
+
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    public void testOneCharString()
+    {
+        assertFalse( checker.isValidSyntax( "A" ) );
+        assertFalse( checker.isValidSyntax( "1" ) );
+        assertFalse( checker.isValidSyntax( "-" ) );
+        assertFalse( checker.isValidSyntax( "(" ) );
+    }
+
+
+    public void testValid()
+    {
+        assertTrue( checker.isValidSyntax( ( "( 1.3.6.1.4.1.1466.115.121.1.15 )" ) ) );
+        assertTrue( checker.isValidSyntax( ( "( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )" ) ) );
+        assertTrue( checker.isValidSyntax( ( "( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' X-ABC-DEF 'test' )" ) ) );
+
+        // spaces
+        assertTrue( checker.isValidSyntax( "(1.3.6.1.4.1.1466.115.121.1.15)" ) );
+        assertTrue( checker.isValidSyntax( "(      1.3.6.1.4.1.1466.115.121.1.15        DESC 'Directory String' X-ABC-DEF     'test'     )" ) );
+        
+    }
+
+
+    public void testInvalid()
+    {
+        // missing/invalid OID
+        assertFalse( checker.isValidSyntax( "()" ) );
+        assertFalse( checker.isValidSyntax( "(  )" ) );
+        assertFalse( checker.isValidSyntax( "( . )" ) );
+        assertFalse( checker.isValidSyntax( "( 1 )" ) );
+        assertFalse( checker.isValidSyntax( "( 1. )" ) );
+        assertFalse( checker.isValidSyntax( "( 1.2. )" ) );
+        assertFalse( checker.isValidSyntax( "( 1.A )" ) );
+        assertFalse( checker.isValidSyntax( "( A.B )" ) );
+
+        // missing right parenthesis
+        assertFalse( checker.isValidSyntax( "( 1.3.6.1.4.1.1466.115.121.1.15 " ) );
+
+        // missing quotes
+        assertFalse( checker.isValidSyntax( "( 1.3.6.1.4.1.1466.115.121.1.15 DESC Directory String )" ) );
+
+        // lowercase DESC
+        assertFalse( checker.isValidSyntax( "( 1.3.6.1.4.1.1466.115.121.1.15 desc 'Directory String' )" ) );
+
+        // invalid extension
+        assertFalse( checker.isValidSyntax( "( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' X-ABC-DEF )" ) );
+        assertFalse( checker.isValidSyntax( "( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' X-ABC-123 'test' )" ) );
+        
+    }
+
+}



Mime
View raw message