directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r488036 [1/2] - in /directory/trunks/shared/ldap/src: 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/syntax/
Date Sun, 17 Dec 2006 19:57:49 GMT
Author: ersiner
Date: Sun Dec 17 11:57:47 2006
New Revision: 488036

URL: http://svn.apache.org/viewvc?view=rev&rev=488036
Log:
Forgot to commit new files from Stefan's latest patch, my fault.

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescription.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescription.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescription.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITContentRuleDescriptionSchemaParser.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITStructureRuleDescriptionSchemaParser.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/NameFormDescriptionSchemaParser.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxCheckerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxCheckerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxCheckerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITContentRuleDescriptionTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITStructureRuleDescriptionTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserNameFormDescriptionTest.java

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescription.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescription.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescription.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescription.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,125 @@
+/*
+ *  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.List;
+
+
+/**
+ * RFC 4512 - 4.1.6.  DIT Content Rule Description
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DITContentRuleDescription extends AbstractSchemaDescription
+{
+
+    private List<String> auxiliaryObjectClasses;
+
+    private List<String> mustAttributeTypes;
+
+    private List<String> mayAttributeTypes;
+
+    private List<String> notAttributeTypes;
+
+
+    public DITContentRuleDescription()
+    {
+        auxiliaryObjectClasses = new ArrayList<String>();
+        mustAttributeTypes = new ArrayList<String>();
+        mayAttributeTypes = new ArrayList<String>();
+        notAttributeTypes = new ArrayList<String>();
+    }
+
+
+    public List<String> getMayAttributeTypes()
+    {
+        return mayAttributeTypes;
+    }
+
+
+    public void setMayAttributeTypes( List<String> mayAttributeTypes )
+    {
+        this.mayAttributeTypes = mayAttributeTypes;
+    }
+
+
+    public List<String> getMustAttributeTypes()
+    {
+        return mustAttributeTypes;
+    }
+
+
+    public void setMustAttributeTypes( List<String> mustAttributeTypes )
+    {
+        this.mustAttributeTypes = mustAttributeTypes;
+    }
+
+
+    public List<String> getAuxiliaryObjectClasses()
+    {
+        return auxiliaryObjectClasses;
+    }
+
+
+    public void setAuxiliaryObjectClasses( List<String> auxiliaryObjectClasses )
+    {
+        this.auxiliaryObjectClasses = auxiliaryObjectClasses;
+    }
+
+
+    public List<String> getNotAttributeTypes()
+    {
+        return notAttributeTypes;
+    }
+
+
+    public void setNotAttributeTypes( List<String> notAttributeTypes )
+    {
+        this.notAttributeTypes = notAttributeTypes;
+    }
+
+
+    public void addAuxiliaryAttributeType( String oid )
+    {
+        auxiliaryObjectClasses.add( oid );
+    }
+
+
+    public void addMustAttributeType( String oid )
+    {
+        mustAttributeTypes.add( oid );
+    }
+
+
+    public void addMayAttributeType( String oid )
+    {
+        mayAttributeTypes.add( oid );
+    }
+
+
+    public void addNotAttributeType( String oid )
+    {
+        notAttributeTypes.add( oid );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxChecker.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxChecker.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,129 @@
+/*
+ *  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.DITContentRuleDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value follows the
+ * DIT content rule descripton syntax according to RFC 4512, par 4.2.6:
+ * 
+ * <pre>
+ * DITContentRuleDescription = LPAREN WSP
+ *    numericoid                 ; object identifier
+ *    [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+ *    [ SP "DESC" SP qdstring ]  ; description
+ *    [ SP "OBSOLETE" ]          ; not active
+ *    [ SP "AUX" SP oids ]       ; auxiliary object classes
+ *    [ SP "MUST" SP oids ]      ; attribute types
+ *    [ SP "MAY" SP oids ]       ; attribute types
+ *    [ SP "NOT" SP oids ]       ; attribute types
+ *    extensions WSP RPAREN      ; extensions
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DITContentRuleDescriptionSyntaxChecker implements SyntaxChecker
+{
+
+    /** The Syntax OID, according to RFC 4517, par. 3.3.7 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.16";
+
+    /** The schema parser used to parse the DITContentRuleDescription Syntax */
+    private DITContentRuleDescriptionSchemaParser schemaParser = new DITContentRuleDescriptionSchemaParser();
+
+
+    /**
+     * 
+     * Creates a new instance of DITContentRuleDescriptionSyntaxChecker.
+     *
+     */
+    public DITContentRuleDescriptionSyntaxChecker()
+    {
+    }
+
+
+    /* (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.parseDITContentRuleDescription( strValue );
+            return true;
+        }
+        catch ( ParseException pe )
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescription.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescription.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescription.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescription.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,93 @@
+/*
+ *  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.List;
+
+
+/**
+ * RFC 4512 - 4.1.7.  DIT Structure Rule Description
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DITStructureRuleDescription extends AbstractSchemaDescription
+{
+
+    private Integer ruleId;
+    
+    private String form;
+
+    private List<Integer> superRules;
+
+
+    public DITStructureRuleDescription()
+    {
+        ruleId = 0;
+        form = null;
+        superRules = new ArrayList<Integer>();
+    }
+
+
+    public String getForm()
+    {
+        return form;
+    }
+
+
+    public void setForm( String form )
+    {
+        this.form = form;
+    }
+
+
+
+    public Integer getRuleId()
+    {
+        return ruleId;
+    }
+
+
+    public void setRuleId( Integer ruleId )
+    {
+        this.ruleId = ruleId;
+    }
+
+
+    public List<Integer> getSuperRules()
+    {
+        return superRules;
+    }
+
+
+    public void setSuperRules( List<Integer> superRules )
+    {
+        this.superRules = superRules;
+    }
+
+    
+    public void addSuperRule( Integer superRule )
+    {
+        superRules.add( superRule );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxChecker.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxChecker.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,131 @@
+/*
+ *  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.DITStructureRuleDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value follows the
+ * DIT structure rule descripton syntax according to RFC 4512, par 4.2.7.1:
+ * 
+ * <pre>
+ * DITStructureRuleDescription = LPAREN WSP
+ *   ruleid                     ; rule identifier
+ *   [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+ *   [ SP "DESC" SP qdstring ]  ; description
+ *   [ SP "OBSOLETE" ]          ; not active
+ *   SP "FORM" SP oid           ; NameForm
+ *   [ SP "SUP" ruleids ]       ; superior rules
+ *   extensions WSP RPAREN      ; extensions
+ *
+ * ruleids = ruleid / ( LPAREN WSP ruleidlist WSP RPAREN )
+ * ruleidlist = ruleid *( SP ruleid )
+ * ruleid = numbers
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DITStructureRuleDescriptionSyntaxChecker implements SyntaxChecker
+{
+
+    /** The Syntax OID, according to RFC 4517, par. 3.3.8 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.17";
+
+    /** The schema parser used to parse the DITContentRuleDescription Syntax */
+    private DITStructureRuleDescriptionSchemaParser schemaParser = new DITStructureRuleDescriptionSchemaParser();
+
+
+    /**
+     * 
+     * Creates a new instance of DITContentRuleDescriptionSyntaxChecker.
+     *
+     */
+    public DITStructureRuleDescriptionSyntaxChecker()
+    {
+    }
+
+
+    /* (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.parseDITStructureRuleDescription( strValue );
+            return true;
+        }
+        catch ( ParseException pe )
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescription.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescription.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescription.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescription.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,98 @@
+/*
+ *  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.List;
+
+
+/**
+ * RFC 4512 - 4.1.7.2.  Name Form Description
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class NameFormDescription extends AbstractSchemaDescription
+{
+
+    private String structuralObjectClass;
+    
+    private List<String> mustAttributeTypes;
+
+    private List<String> mayAttributeTypes;
+
+
+    public NameFormDescription()
+    {
+        structuralObjectClass = null;
+        mustAttributeTypes = new ArrayList<String>();
+        mayAttributeTypes = new ArrayList<String>();
+    }
+
+
+    public List<String> getMayAttributeTypes()
+    {
+        return mayAttributeTypes;
+    }
+
+
+    public void setMayAttributeTypes( List<String> mayAttributeTypes )
+    {
+        this.mayAttributeTypes = mayAttributeTypes;
+    }
+
+
+    public List<String> getMustAttributeTypes()
+    {
+        return mustAttributeTypes;
+    }
+
+
+    public void setMustAttributeTypes( List<String> mustAttributeTypes )
+    {
+        this.mustAttributeTypes = mustAttributeTypes;
+    }
+
+
+    public void addMustAttributeType( String oid )
+    {
+        mustAttributeTypes.add( oid );
+    }
+
+
+    public void addMayAttributeType( String oid )
+    {
+        mayAttributeTypes.add( oid );
+    }
+
+
+    public String getStructuralObjectClass()
+    {
+        return structuralObjectClass;
+    }
+
+
+    public void setStructuralObjectClass( String structuralObjectClass )
+    {
+        this.structuralObjectClass = structuralObjectClass;
+    }
+
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxChecker.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxChecker.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,128 @@
+/*
+ *  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.NameFormDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value follows the
+ * name descripton syntax according to RFC 4512, par 4.2.7.2:
+ * 
+ * <pre>
+ * NameFormDescription = LPAREN WSP
+ *    numericoid                 ; object identifier
+ *    [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+ *    [ SP "DESC" SP qdstring ]  ; description
+ *    [ SP "OBSOLETE" ]          ; not active
+ *    SP "OC" SP oid             ; structural object class
+ *    SP "MUST" SP oids          ; attribute types
+ *    [ SP "MAY" SP oids ]       ; attribute types
+ *    extensions WSP RPAREN      ; extensions
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NameFormDescriptionSyntaxChecker implements SyntaxChecker
+{
+
+    /** The Syntax OID, according to RFC 4517, par. 3.3.22 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.35";
+
+    /** The schema parser used to parse the DITContentRuleDescription Syntax */
+    private NameFormDescriptionSchemaParser schemaParser = new NameFormDescriptionSchemaParser();
+
+
+    /**
+     * 
+     * Creates a new instance of DITContentRuleDescriptionSyntaxChecker.
+     *
+     */
+    public NameFormDescriptionSyntaxChecker()
+    {
+    }
+
+
+    /* (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.parseNameFormDescription( strValue );
+            return true;
+        }
+        catch ( ParseException pe )
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITContentRuleDescriptionSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITContentRuleDescriptionSchemaParser.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITContentRuleDescriptionSchemaParser.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITContentRuleDescriptionSchemaParser.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,107 @@
+/*
+ *  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.text.ParseException;
+
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.syntax.DITContentRuleDescription;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A parser for RFC 4512 DIT content rule descriptons
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DITContentRuleDescriptionSchemaParser extends AbstractSchemaParser
+{
+
+    /**
+     * Creates a schema parser instance.
+     */
+    public DITContentRuleDescriptionSchemaParser()
+    {
+        super();
+    }
+
+
+    /**
+     * Parses a DIT content rule description according to RFC 4512:
+     * 
+     * <pre>
+     * DITContentRuleDescription = LPAREN WSP
+     *    numericoid                 ; object identifier
+     *    [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+     *    [ SP "DESC" SP qdstring ]  ; description
+     *    [ SP "OBSOLETE" ]          ; not active
+     *    [ SP "AUX" SP oids ]       ; auxiliary object classes
+     *    [ SP "MUST" SP oids ]      ; attribute types
+     *    [ SP "MAY" SP oids ]       ; attribute types
+     *    [ SP "NOT" SP oids ]       ; attribute types
+     *    extensions WSP RPAREN      ; extensions
+     * </pre>
+     * 
+     * @param ditContentRuleDescription the DIT content rule description to be parsed
+     * @return the parsed DITContentRuleDescription bean
+     * @throws ParseException if there are any recognition errors (bad syntax)
+     */
+    public synchronized DITContentRuleDescription parseDITContentRuleDescription( String ditContentRuleDescription )
+        throws ParseException
+    {
+
+        if ( ditContentRuleDescription == null )
+        {
+            throw new ParseException( "Null", 0 );
+        }
+
+        reset( ditContentRuleDescription ); // reset and initialize the parser / lexer pair
+
+        try
+        {
+            DITContentRuleDescription dcrd = parser.ditContentRuleDescription();
+            return dcrd;
+        }
+        catch ( RecognitionException re )
+        {
+            String msg = "Parser failure on DIT content rule description:\n\t" + ditContentRuleDescription;
+            msg += "\nAntlr message: " + re.getMessage();
+            msg += "\nAntlr column: " + re.getColumn();
+            throw new ParseException( msg, re.getColumn() );
+        }
+        catch ( TokenStreamException tse )
+        {
+            String msg = "Parser failure on DIT content rule description:\n\t" + ditContentRuleDescription;
+            msg += "\nAntlr message: " + tse.getMessage();
+            throw new ParseException( msg, 0 );
+        }
+
+    }
+
+
+    public AbstractSchemaDescription parse( String schemaDescription ) throws ParseException
+    {
+        return parseDITContentRuleDescription( schemaDescription );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITStructureRuleDescriptionSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITStructureRuleDescriptionSchemaParser.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITStructureRuleDescriptionSchemaParser.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/DITStructureRuleDescriptionSchemaParser.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,109 @@
+/*
+ *  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.text.ParseException;
+
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.syntax.DITStructureRuleDescription;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A parser for RFC 4512 DIT structure rule descriptons
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DITStructureRuleDescriptionSchemaParser extends AbstractSchemaParser
+{
+
+    /**
+     * Creates a schema parser instance.
+     */
+    public DITStructureRuleDescriptionSchemaParser()
+    {
+        super();
+    }
+
+
+    /**
+     * Parses a DIT structure rule description according to RFC 4512:
+     * 
+     * <pre>
+     * DITStructureRuleDescription = LPAREN WSP
+     *   ruleid                     ; rule identifier
+     *   [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+     *   [ SP "DESC" SP qdstring ]  ; description
+     *   [ SP "OBSOLETE" ]          ; not active
+     *   SP "FORM" SP oid           ; NameForm
+     *   [ SP "SUP" ruleids ]       ; superior rules
+     *   extensions WSP RPAREN      ; extensions
+     *
+     * ruleids = ruleid / ( LPAREN WSP ruleidlist WSP RPAREN )
+     * ruleidlist = ruleid *( SP ruleid )
+     * ruleid = numbers
+     * </pre>
+     * 
+     * @param ditStructureRuleDescription the DIT structure rule description to be parsed
+     * @return the parsed DITStructureRuleDescription bean
+     * @throws ParseException if there are any recognition errors (bad syntax)
+     */
+    public synchronized DITStructureRuleDescription parseDITStructureRuleDescription( String ditStructureRuleDescription )
+        throws ParseException
+    {
+
+        if ( ditStructureRuleDescription == null )
+        {
+            throw new ParseException( "Null", 0 );
+        }
+
+        reset( ditStructureRuleDescription ); // reset and initialize the parser / lexer pair
+
+        try
+        {
+            DITStructureRuleDescription dsrd = parser.ditStructureRuleDescription();
+            return dsrd;
+        }
+        catch ( RecognitionException re )
+        {
+            String msg = "Parser failure on DIT structure rule description:\n\t" + ditStructureRuleDescription;
+            msg += "\nAntlr message: " + re.getMessage();
+            msg += "\nAntlr column: " + re.getColumn();
+            throw new ParseException( msg, re.getColumn() );
+        }
+        catch ( TokenStreamException tse )
+        {
+            String msg = "Parser failure on DIT structure rule description:\n\t" + ditStructureRuleDescription;
+            msg += "\nAntlr message: " + tse.getMessage();
+            throw new ParseException( msg, 0 );
+        }
+
+    }
+
+
+    public AbstractSchemaDescription parse( String schemaDescription ) throws ParseException
+    {
+        return parseDITStructureRuleDescription( schemaDescription );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/NameFormDescriptionSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/NameFormDescriptionSchemaParser.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/NameFormDescriptionSchemaParser.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/NameFormDescriptionSchemaParser.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,106 @@
+/*
+ *  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.text.ParseException;
+
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.syntax.NameFormDescription;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
+
+/**
+ * A parser for RFC 4512 name form descriptons
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class NameFormDescriptionSchemaParser extends AbstractSchemaParser
+{
+
+    /**
+     * Creates a schema parser instance.
+     */
+    public NameFormDescriptionSchemaParser()
+    {
+        super();
+    }
+
+
+    /**
+     * Parses a name form description according to RFC 4512:
+     * 
+     * <pre>
+     * NameFormDescription = LPAREN WSP
+     *    numericoid                 ; object identifier
+     *    [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+     *    [ SP "DESC" SP qdstring ]  ; description
+     *    [ SP "OBSOLETE" ]          ; not active
+     *    SP "OC" SP oid             ; structural object class
+     *    SP "MUST" SP oids          ; attribute types
+     *    [ SP "MAY" SP oids ]       ; attribute types
+     *    extensions WSP RPAREN      ; extensions
+     * </pre>
+     * 
+     * @param nameFormDescription the name form description to be parsed
+     * @return the parsed NameFormDescription bean
+     * @throws ParseException if there are any recognition errors (bad syntax)
+     */
+    public synchronized NameFormDescription parseNameFormDescription( String nameFormDescription )
+        throws ParseException
+    {
+
+        if ( nameFormDescription == null )
+        {
+            throw new ParseException( "Null", 0 );
+        }
+
+        reset( nameFormDescription ); // reset and initialize the parser / lexer pair
+
+        try
+        {
+            NameFormDescription nfd = parser.nameFormDescription();
+            return nfd;
+        }
+        catch ( RecognitionException re )
+        {
+            String msg = "Parser failure on name form description:\n\t" + nameFormDescription;
+            msg += "\nAntlr message: " + re.getMessage();
+            msg += "\nAntlr column: " + re.getColumn();
+            throw new ParseException( msg, re.getColumn() );
+        }
+        catch ( TokenStreamException tse )
+        {
+            String msg = "Parser failure on name form description:\n\t" + nameFormDescription;
+            msg += "\nAntlr message: " + tse.getMessage();
+            throw new ParseException( msg, 0 );
+        }
+
+    }
+
+
+    public AbstractSchemaDescription parse( String schemaDescription ) throws ParseException
+    {
+        return parseNameFormDescription( schemaDescription );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxCheckerTest.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITContentRuleDescriptionSyntaxCheckerTest.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,83 @@
+/*
+ *  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 DITContentRuleDescriptionSyntaxChecker.
+ * 
+ * There are also many test cases in SchemaParserDITContentRuleDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DITContentRuleDescriptionSyntaxCheckerTest extends TestCase
+{
+    private DITContentRuleDescriptionSyntaxChecker checker = new DITContentRuleDescriptionSyntaxChecker();
+
+    public void testValid()
+    {
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' DESC 'content rule for organization' )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' DESC 'content rule for organization' OBSOLETE )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' DESC 'content rule for organization' OBSOLETE AUX ( pilotOrganization $  2.5.6.5 ) )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' DESC 'content rule for organization' OBSOLETE AUX ( pilotOrganization $  2.5.6.5 ) MUST ( objectClass $ o ) )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' DESC 'content rule for organization' OBSOLETE AUX ( pilotOrganization $  2.5.6.5 ) MUST ( objectClass $ o ) MAY ( l $ st )  )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.6.4 NAME 'organization' DESC 'content rule for organization' OBSOLETE AUX ( pilotOrganization $  2.5.6.5 ) MUST ( objectClass $ o ) MAY ( l $ st ) NOT ( 1.2.3.4.5.6.7.8.9.0 $ ou ) )" ) );
+        
+
+        assertTrue( checker.isValidSyntax( "(2.5.6.4)" ) );
+        assertTrue( checker.isValidSyntax( "(   2.5.6.4     NAME   'organization'   DESC   'content rule for organization' OBSOLETE AUX ( pilotOrganization $  2.5.6.5 ) MUST ( objectClass $ o )     MAY    (    l   $   st   ) NOT (1.2.3.4.5.6.7.8.9.0 $ ou))" ) );
+    }
+
+    public void testInvalid()
+    {
+        // null 
+        assertFalse( checker.isValidSyntax( null ) );
+        
+        // empty 
+        assertFalse( checker.isValidSyntax( "" ) );
+        
+        // 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.6.4 NAME 'organization'" ) );
+
+        // missing quotes
+        assertFalse( checker.isValidSyntax( "( 2.5.6.4 NAME organization )" ) );
+
+        // lowercase NAME, DESC, AUX
+        assertFalse( checker.isValidSyntax( "( 2.5.6.4 name 'organization' desc 'content rule for organization' aux ( pilotOrganization $  2.5.6.5 ) )" ) );
+
+    }
+
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxCheckerTest.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/DITStructureRuleDescriptionSyntaxCheckerTest.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,82 @@
+/*
+ *  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 DITStructureRuleDescriptionSyntaxChecker.
+ * 
+ * There are also many test cases in SchemaParserDITStructureRuleDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DITStructureRuleDescriptionSyntaxCheckerTest extends TestCase
+{
+    private DITStructureRuleDescriptionSyntaxChecker checker = new DITStructureRuleDescriptionSyntaxChecker();
+
+    public void testValid()
+    {
+        assertTrue( checker.isValidSyntax( "( 2 FORM 2.5.15.3 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2 NAME 'organization' FORM 2.5.15.3 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2 NAME 'organization' DESC 'organization structure rule' FORM 2.5.15.3 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2 NAME 'organization' DESC 'organization structure rule' OBSOLETE FORM 2.5.15.3 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2 NAME 'organization' DESC 'organization structure rule' OBSOLETE FORM 2.5.15.3 SUP 1 )" ) );
+        assertTrue( checker.isValidSyntax( "( 2 NAME 'organization' DESC 'organization structure rule' OBSOLETE FORM 2.5.15.3 SUP ( 1 ) )" ) );
+        assertTrue( checker.isValidSyntax( "( 2 NAME 'organization' DESC 'organization structure rule' OBSOLETE FORM 2.5.15.3 SUP ( 1 1234567890 5 ) )" ) );
+
+        assertTrue( checker.isValidSyntax( "(2 FORM 2.5.15.3)" ) );
+        assertTrue( checker.isValidSyntax( "(   2   NAME    'organization'    DESC    'organization structure rule'    OBSOLETE   FORM   2.5.15.3    SUP   (1 1234567890        5   ))" ) );
+    }
+
+    public void testInvalid()
+    {
+        // null 
+        assertFalse( checker.isValidSyntax( null ) );
+        
+        // empty 
+        assertFalse( checker.isValidSyntax( "" ) );
+        
+        // missing/invalid ruleid
+        assertFalse( checker.isValidSyntax( "()" ) );
+        assertFalse( checker.isValidSyntax( "(  )" ) );
+        assertFalse( checker.isValidSyntax( "( . )" ) );
+        assertFalse( checker.isValidSyntax( "( 1 )" ) );
+        assertFalse( checker.isValidSyntax( "( 1.2 )" ) );
+        assertFalse( checker.isValidSyntax( "( A )" ) );
+        assertFalse( checker.isValidSyntax( "( A.B )" ) );
+
+        // missing right parenthesis
+        assertFalse( checker.isValidSyntax( "( 2 FORM 2.5.15.3" ) );
+
+        // missing quotes
+        assertFalse( checker.isValidSyntax( "( 2 NAME organization FORM 2.5.15.3 )" ) );
+
+        // lowercase NAME, DESC, FORM
+        assertFalse( checker.isValidSyntax( "( 2 name 'organization' desc 'organization structure rule' form 2.5.15.3 )" ) );
+
+        // missing FORM
+        assertFalse( checker.isValidSyntax( "( 2 NAME 'organization' DESC 'organization structure rule' )" ) );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxCheckerTest.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/NameFormDescriptionSyntaxCheckerTest.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,84 @@
+/*
+ *  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 NameFormDescriptionSyntaxChecker.
+ * 
+ * There are also many test cases in SchemaParserNameFormDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NameFormDescriptionSyntaxCheckerTest extends TestCase
+{
+    private NameFormDescriptionSyntaxChecker checker = new NameFormDescriptionSyntaxChecker();
+
+    public void testValid()
+    {
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 OC o MUST m )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 OC o MUST m NAME 'orgNameForm' )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 OC o MUST m NAME 'orgNameForm' DESC 'orgNameForm' )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 MUST m NAME 'orgNameForm' DESC 'orgNameForm' OC organization )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 NAME 'orgNameForm' DESC 'orgNameForm' OC organization MUST o )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 NAME 'orgNameForm' DESC 'orgNameForm' OC organization MUST ( o ) MAY ( ou $ cn ) )" ) );
+        assertTrue( checker.isValidSyntax( "( 2.5.15.3 NAME 'orgNameForm' DESC 'orgNameForm' OC organization MUST ( o ) MAY ( ou $ cn ) )" ) );
+       
+
+        assertTrue( checker.isValidSyntax( "(2.5.15.3 OC o MUST m)" ) );
+        assertTrue( checker.isValidSyntax( "(   2.5.15.3   NAME   'orgNameForm'    DESC    'orgNameForm'   OC   organization   MUST   (o)   MAY   (ou$cn))" ) );
+    }
+
+    public void testInvalid()
+    {
+        // null 
+        assertFalse( checker.isValidSyntax( null ) );
+        
+        // empty 
+        assertFalse( checker.isValidSyntax( "" ) );
+        
+        // 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.15.3 NAME 'orgNameForm'" ) );
+
+        // missing quotes
+        assertFalse( checker.isValidSyntax( "( 2.5.15.3 NAME orgNameForm )" ) );
+
+        // lowercase NAME, DESC, AUX
+        assertFalse( checker.isValidSyntax( "( 2.5.15.3 name 'orgNameForm' desc 'orgNameForm' oc o )" ) );
+
+        assertFalse( checker.isValidSyntax( "( 2.5.15.3 )" ) );
+        assertFalse( checker.isValidSyntax( "( 2.5.15.3 NAME 'orgNameForm' )" ) );
+    }
+
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITContentRuleDescriptionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITContentRuleDescriptionTest.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITContentRuleDescriptionTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITContentRuleDescriptionTest.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,490 @@
+/*
+ *  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 junit.framework.TestCase;
+
+import org.apache.directory.shared.ldap.schema.syntax.parser.DITContentRuleDescriptionSchemaParser;
+
+
+/**
+ * Tests the DITContentRuleDescriptionSchemaParser class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaParserDITContentRuleDescriptionTest extends TestCase
+{
+    /** the parser instance */
+    private DITContentRuleDescriptionSchemaParser parser;
+
+
+    protected void setUp() throws Exception
+    {
+        parser = new DITContentRuleDescriptionSchemaParser();
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        parser = null;
+    }
+
+
+    /**
+     * Test numericoid
+     * 
+     * @throws ParseException
+     */
+    public void testNumericOid() throws ParseException
+    {
+        SchemaParserTestUtils.testNumericOid( parser, "" );
+    }
+
+
+    /**
+     * Tests NAME and its values
+     * 
+     * @throws ParseException
+     */
+    public void testNames() throws ParseException
+    {
+        SchemaParserTestUtils.testNames( parser, "1.1", "" );
+    }
+
+
+    /**
+     * Tests DESC
+     * 
+     * @throws ParseException
+     */
+    public void testDescription() throws ParseException
+    {
+        SchemaParserTestUtils.testDescription( parser, "1.1", "" );
+    }
+
+
+    /**
+     * Tests OBSOLETE
+     * 
+     * @throws ParseException
+     */
+    public void testObsolete() throws ParseException
+    {
+        SchemaParserTestUtils.testObsolete( parser, "1.1", "" );
+    }
+
+
+    /**
+     * Test AUX and its values.
+     * 
+     * @throws ParseException
+     */
+    public void testAux() throws ParseException
+    {
+        String value = null;
+        DITContentRuleDescription dcrd = null;
+
+        // no AUX
+        value = "( 1.1 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 0, dcrd.getAuxiliaryObjectClasses().size() );
+
+        // AUX simple numericoid
+        value = "( 1.1 AUX 1.2.3 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "1.2.3", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+
+        // AUX simple descr
+        value = "( 1.1 AUX top )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "top", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+
+        // AUX single numericoid
+        value = "( 1.1 AUX ( 1.2.3.4.5 ) )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "1.2.3.4.5", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+
+        // AUX single descr
+        value = "( 1.1 AUX ( A-Z-0-9 ) )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "A-Z-0-9", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+
+        // AUX multi numericoid
+        value = "( 1.1 AUX ( 1.2.3 $ 1.2.3.4.5 ) )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 2, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "1.2.3", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+        assertEquals( "1.2.3.4.5", dcrd.getAuxiliaryObjectClasses().get( 1 ) );
+
+        // AUX multi descr
+        value = "( 1.1 AUX ( top1 $ top2 ) )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 2, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "top1", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+        assertEquals( "top2", dcrd.getAuxiliaryObjectClasses().get( 1 ) );
+
+        // AUX multi mixed
+        value = "( 1.1 AUX ( top1 $ 1.2.3.4 $ top2 ) )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 3, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "top1", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+        assertEquals( "1.2.3.4", dcrd.getAuxiliaryObjectClasses().get( 1 ) );
+        assertEquals( "top2", dcrd.getAuxiliaryObjectClasses().get( 2 ) );
+
+        // AUX multi mixed no space
+        value = "( 1.1 AUX (TOP-1$1.2.3.4$TOP-2) )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 3, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "TOP-1", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+        assertEquals( "1.2.3.4", dcrd.getAuxiliaryObjectClasses().get( 1 ) );
+        assertEquals( "TOP-2", dcrd.getAuxiliaryObjectClasses().get( 2 ) );
+
+        // AUX multi mixed many spaces
+        value = "(          1.1          AUX          (          top1          $          1.2.3.4$top2          )          )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 3, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "top1", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+        assertEquals( "1.2.3.4", dcrd.getAuxiliaryObjectClasses().get( 1 ) );
+        assertEquals( "top2", dcrd.getAuxiliaryObjectClasses().get( 2 ) );
+
+        // no quote allowed
+        value = "( 1.1 AUX 'top' )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid AUX 'top' (quoted)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // no quote allowed
+        value = "( 1.1 AUX '1.2.3.4' )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid AUX '1.2.3.4' (quoted)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // invalid character
+        value = "( 1.1 AUX 1.2.3.4.A )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid AUX '1.2.3.4.A' (invalid character)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // invalid start
+        value = "( 1.1 AUX ( top1 $ -top2 ) )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid AUX '-top' (starts with hypen)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // invalid separator
+        value = "( 1.1 AUX ( top1 top2 ) )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid separator (no DOLLAR)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // empty AUX
+        value = "( 1.1 AUX )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, no AUX value" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+    }
+
+
+    /**
+     * Test MUST and its values.
+     * Very similar to AUX, so here are less test cases. 
+     * 
+     * @throws ParseException
+     */
+    public void testMust() throws ParseException
+    {
+        String value = null;
+        DITContentRuleDescription dcrd = null;
+        
+        // no MUST
+        value = "( 1.1 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 0, dcrd.getMustAttributeTypes().size() );
+
+        // MUST simple numericoid
+        value = "( 1.1 MUST 1.2.3 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getMustAttributeTypes().size() );
+        assertEquals( "1.2.3", dcrd.getMustAttributeTypes().get( 0 ) );
+
+        // MUST mulitple
+        value = "(1.1 MUST (cn$sn       $11.22.33.44.55         $  objectClass   ))";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 4, dcrd.getMustAttributeTypes().size() );
+        assertEquals( "cn", dcrd.getMustAttributeTypes().get( 0 ) );
+        assertEquals( "sn", dcrd.getMustAttributeTypes().get( 1 ) );
+        assertEquals( "11.22.33.44.55", dcrd.getMustAttributeTypes().get( 2 ) );
+        assertEquals( "objectClass", dcrd.getMustAttributeTypes().get( 3 ) );
+
+        // invalid value
+        value = "( 1.1 MUST ( c_n ) )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid value c_n" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // no MUST values
+        value = "( 1.1 MUST )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, no MUST value" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+    }
+
+
+    /**
+     * Test MAY and its values.
+     * Very similar to AUX, so here are less test cases. 
+     * 
+     * @throws ParseException
+     */
+    public void testMay() throws ParseException
+    {
+        String value = null;
+        DITContentRuleDescription dcrd = null;
+
+        // no MAY
+        value = "( 1.1 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 0, dcrd.getMayAttributeTypes().size() );
+
+        // MAY simple numericoid
+        value = "( 1.1 MAY 1.2.3 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getMayAttributeTypes().size() );
+        assertEquals( "1.2.3", dcrd.getMayAttributeTypes().get( 0 ) );
+
+        // MAY mulitple
+        value = "(1.1 MAY (cn$sn       $11.22.33.44.55         $  objectClass   ))";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 4, dcrd.getMayAttributeTypes().size() );
+        assertEquals( "cn", dcrd.getMayAttributeTypes().get( 0 ) );
+        assertEquals( "sn", dcrd.getMayAttributeTypes().get( 1 ) );
+        assertEquals( "11.22.33.44.55", dcrd.getMayAttributeTypes().get( 2 ) );
+        assertEquals( "objectClass", dcrd.getMayAttributeTypes().get( 3 ) );
+
+        // invalid value
+        value = "( 1.1 MAY ( c_n ) )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid value c_n" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+    }
+
+    /**
+     * Test NOT and its values.
+     * Very similar to AUX, so here are less test cases. 
+     * 
+     * @throws ParseException
+     */
+    public void testNot() throws ParseException
+    {
+        String value = null;
+        DITContentRuleDescription dcrd = null;
+
+        // no MAY
+        value = "( 1.1 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 0, dcrd.getNotAttributeTypes().size() );
+
+        // MAY simple numericoid
+        value = "( 1.1 NOT 1.2.3 )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 1, dcrd.getNotAttributeTypes().size() );
+        assertEquals( "1.2.3", dcrd.getNotAttributeTypes().get( 0 ) );
+
+        // MAY mulitple
+        value = "(1.1 NOT (cn$sn       $11.22.33.44.55         $  objectClass   ))";
+        dcrd = parser.parseDITContentRuleDescription( value );
+        assertEquals( 4, dcrd.getNotAttributeTypes().size() );
+        assertEquals( "cn", dcrd.getNotAttributeTypes().get( 0 ) );
+        assertEquals( "sn", dcrd.getNotAttributeTypes().get( 1 ) );
+        assertEquals( "11.22.33.44.55", dcrd.getNotAttributeTypes().get( 2 ) );
+        assertEquals( "objectClass", dcrd.getNotAttributeTypes().get( 3 ) );
+
+        // invalid value
+        value = "( 1.1 NOT ( c_n ) )";
+        try
+        {
+            dcrd = parser.parseDITContentRuleDescription( value );
+            fail( "Exception expected, invalid value c_n" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+    }
+    
+
+    /**
+     * Test extensions.
+     * 
+     * @throws ParseException
+     */
+    public void testExtensions() throws ParseException
+    {
+        SchemaParserTestUtils.testExtensions( parser, "1.1", "" );
+
+    }
+
+
+    /**
+     * Test full object class description.
+     * 
+     * @throws ParseException
+     */
+    public void testFull() throws ParseException
+    {
+        String value = null;
+        DITContentRuleDescription dcrd = null;
+
+        value = "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüß 部長' OBSOLETE AUX ( 2.3.4.5.6.7.8.9.0.1 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) MUST ( 3.4.5.6.7.8.9.0.1.2 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) MAY ( 4.5.6.7.8.9.0.1.2.3 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) NOT ( 5.6.7.8.9.0.1.2.3.4 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
+        dcrd = parser.parseDITContentRuleDescription( value );
+
+        assertEquals( "1.2.3.4.5.6.7.8.9.0", dcrd.getNumericOid() );
+        assertEquals( 2, dcrd.getNames().size() );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dcrd.getNames().get( 0 ) );
+        assertEquals( "test", dcrd.getNames().get( 1 ) );
+        assertEquals( "Descripton äöüß 部長", dcrd.getDescription() );
+        assertTrue( dcrd.isObsolete() );
+        assertEquals( 2, dcrd.getAuxiliaryObjectClasses().size() );
+        assertEquals( "2.3.4.5.6.7.8.9.0.1", dcrd.getAuxiliaryObjectClasses().get( 0 ) );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dcrd
+            .getAuxiliaryObjectClasses().get( 1 ) );
+        assertEquals( 2, dcrd.getMustAttributeTypes().size() );
+        assertEquals( "3.4.5.6.7.8.9.0.1.2", dcrd.getMustAttributeTypes().get( 0 ) );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dcrd.getMustAttributeTypes()
+            .get( 1 ) );
+        assertEquals( 2, dcrd.getMayAttributeTypes().size() );
+        assertEquals( "4.5.6.7.8.9.0.1.2.3", dcrd.getMayAttributeTypes().get( 0 ) );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dcrd.getMayAttributeTypes()
+            .get( 1 ) );
+        assertEquals( 2, dcrd.getNotAttributeTypes().size() );
+        assertEquals( "5.6.7.8.9.0.1.2.3.4", dcrd.getNotAttributeTypes().get( 0 ) );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dcrd.getNotAttributeTypes()
+            .get( 1 ) );
+        assertEquals( 2, dcrd.getExtensions().size() );
+        assertNotNull( dcrd.getExtensions().get( "X-TEST-a" ) );
+        assertEquals( 2, dcrd.getExtensions().get( "X-TEST-a" ).size() );
+        assertEquals( "test1-1", dcrd.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+        assertEquals( "test1-2", dcrd.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+        assertNotNull( dcrd.getExtensions().get( "X-TEST-b" ) );
+        assertEquals( 2, dcrd.getExtensions().get( "X-TEST-b" ).size() );
+        assertEquals( "test2-1", dcrd.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+        assertEquals( "test2-2", dcrd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+    }
+
+    
+    /**
+     * Test unique elements.
+     * 
+     * @throws ParseException
+     */
+    public void testUniqueElements() throws ParseException
+    {
+        String[] testValues = new String[]
+            { 
+                "( 1.1 NAME 'test1' NAME 'test2' )", 
+                "( 1.1 DESC 'test1' DESC 'test2' )",
+                "( 1.1 OBSOLETE OBSOLETE )", 
+                "( 1.1 AUX test1 AUX test2 )",
+                "( 1.1 MUST test1 MUST test2 )",
+                "( 1.1 MAY test1 MAY test2 )",
+                "( 1.1 NOT test1 NOT test2 )",
+                "( 1.1 X-TEST 'test1' X-TEST 'test2' )" 
+            };
+        SchemaParserTestUtils.testUnique( parser, testValues );
+    }
+    
+    
+    /**
+     * Tests the multithreaded use of a single parser.
+     */
+    public void testMultiThreaded() throws Exception
+    {
+        String[] testValues = new String[]
+            {
+                "( 1.1 )",
+                "( 2.5.6.4 DESC 'content rule for organization' NOT ( x121Address $ telexNumber ) )",
+                "( 2.5.6.4 DESC 'content rule for organization' NOT ( x121Address $ telexNumber ) )",
+                "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüß 部長' OBSOLETE AUX ( 2.3.4.5.6.7.8.9.0.1 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) MUST ( 3.4.5.6.7.8.9.0.1.2 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) MAY ( 4.5.6.7.8.9.0.1.2.3 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) NOT ( 5.6.7.8.9.0.1.2.3.4 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )" };
+        SchemaParserTestUtils.testMultiThreaded( parser, testValues );
+
+    }
+
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITStructureRuleDescriptionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITStructureRuleDescriptionTest.java?view=auto&rev=488036
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITStructureRuleDescriptionTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserDITStructureRuleDescriptionTest.java Sun Dec 17 11:57:47 2006
@@ -0,0 +1,434 @@
+/*
+ *  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 junit.framework.TestCase;
+
+import org.apache.directory.shared.ldap.schema.syntax.parser.DITStructureRuleDescriptionSchemaParser;
+
+
+/**
+ * Tests the DITStructureRuleDescriptionSchemaParser class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaParserDITStructureRuleDescriptionTest extends TestCase
+{
+    /** the parser instance */
+    private DITStructureRuleDescriptionSchemaParser parser;
+
+
+    protected void setUp() throws Exception
+    {
+        parser = new DITStructureRuleDescriptionSchemaParser();
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        parser = null;
+    }
+
+
+    /**
+     * Test ruleid
+     * 
+     * @throws ParseException
+     */
+    public void testNumericRuleId() throws ParseException
+    {
+        String value = null;
+        DITStructureRuleDescription dsrd = null;
+
+        // null test
+        value = null;
+        try
+        {
+            parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, null" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // no ruleid
+        value = "( )";
+        try
+        {
+            parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, no ruleid" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // simple
+        value = "( 1 FORM 1.1 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( new Integer( 1 ), dsrd.getRuleId() );
+
+        // simple
+        value = "( 1234567890 FORM 1.1 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( new Integer( 1234567890 ), dsrd.getRuleId() );
+
+        // simple with spaces
+        value = "(      1234567890   FORM   1.1     )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( new Integer( 1234567890 ), dsrd.getRuleId() );
+
+        // non-numeric not allowed
+        value = "( test FORM 1.1 )";
+        try
+        {
+            parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid ruleid test (non-numeric)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // oid not allowed
+        value = "( 1.2.3.4 FORM 1.1 )";
+        try
+        {
+            parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid ruleid 1.2.3.4 (oid)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // quotes not allowed
+        value = "( '1234567890' FORM 1.1 )";
+        try
+        {
+            parser.parse( value );
+            TestCase.fail( "Exception expected, invalid ruleid '1234567890' (quoted)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+    }
+
+
+    /**
+     * Tests NAME and its values
+     * 
+     * @throws ParseException
+     */
+    public void testNames() throws ParseException
+    {
+        SchemaParserTestUtils.testNames( parser, "1", "FORM 1.1" );
+    }
+
+
+    /**
+     * Tests DESC
+     * 
+     * @throws ParseException
+     */
+    public void testDescription() throws ParseException
+    {
+        SchemaParserTestUtils.testDescription( parser, "1", "FORM 1.1" );
+    }
+
+
+    /**
+     * Tests OBSOLETE
+     * 
+     * @throws ParseException
+     */
+    public void testObsolete() throws ParseException
+    {
+        SchemaParserTestUtils.testObsolete( parser, "1", "FORM 1.1" );
+    }
+
+
+    /**
+     * Tests FORM
+     * 
+     * @throws ParseException
+     */
+    public void testForm() throws ParseException
+    {
+        String value = null;
+        DITStructureRuleDescription dsrd = null;
+
+        // numeric oid
+        value = "( 1 FORM 1.2.3.4.5.6.7.8.9.0 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( "1.2.3.4.5.6.7.8.9.0", dsrd.getForm() );
+
+        // numeric oid
+        value = "(   1    FORM    123.4567.890    )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( "123.4567.890", dsrd.getForm() );
+
+        // descr
+        value = "( 1 FORM abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dsrd.getForm() );
+
+        // no quote allowed
+        value = "( 1 FORM '1.2.3.4.5.6.7.8.9.0' )";
+        try
+        {
+            dsrd = parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid FORM '1.2.3.4.5.6.7.8.9.0' (quoted)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // no quote allowed
+        value = "( 1 FORM 'test' )";
+        try
+        {
+            dsrd = parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid FORM 'test' (quoted)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // invalid character
+        value = "( 1 FORM 1.2.3.4.A )";
+        try
+        {
+            dsrd = parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid FORM 1.2.3.4.A (invalid character)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // invalid start
+        value = "( 1 FORM -test ) )";
+        try
+        {
+            dsrd = parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid FORM '-test' (starts with hypen)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // no multi value
+        value = "( 1 FORM ( test1 test2 ) )";
+        try
+        {
+            dsrd = parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, FORM must be single valued" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+    }
+
+
+    /**
+     * Tests SUP
+     * 
+     * @throws ParseException
+     */
+    public void testSup() throws ParseException
+    {
+        String value = null;
+        DITStructureRuleDescription dsrd = null;
+
+        // no SUP
+        value = "( 1 FORM 1.1 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( 0, dsrd.getSuperRules().size() );
+
+        // SUP simple number
+        value = "( 1 FORM 1.1 SUP 1 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( 1, dsrd.getSuperRules().size() );
+        assertEquals( new Integer( 1 ), dsrd.getSuperRules().get( 0 ) );
+
+        // SUP single number
+        value = "( 1 FORM 1.1 SUP ( 1 ) )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( 1, dsrd.getSuperRules().size() );
+        assertEquals( new Integer( 1 ), dsrd.getSuperRules().get( 0 ) );
+
+        // SUP multi number
+        value = "( 1 FORM 1.1 SUP (12345 67890) )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertEquals( 2, dsrd.getSuperRules().size() );
+        assertEquals( new Integer( 12345 ), dsrd.getSuperRules().get( 0 ) );
+        assertEquals( new Integer( 67890 ), dsrd.getSuperRules().get( 1 ) );
+
+        // non-numeric not allowed
+        value = "( 1 FORM 1.1 SUP test )";
+        try
+        {
+            parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid SUP test (non-numeric)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+        // oid not allowed
+        value = "( 1 FORM 1.1 SUP 1.2.3.4 )";
+        try
+        {
+            parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, invalid SUP 1.2.3.4 (oid)" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+
+    }
+
+
+    /**
+     * Test extensions.
+     * 
+     * @throws ParseException
+     */
+    public void testExtensions() throws ParseException
+    {
+        SchemaParserTestUtils.testExtensions( parser, "1", "FORM 1.1" );
+
+    }
+
+
+    /**
+     * Test full object class description.
+     * 
+     * @throws ParseException
+     */
+    public void testFull() throws ParseException
+    {
+        String value = null;
+        DITStructureRuleDescription dsrd = null;
+
+        value = "( 1234567890 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüß 部長' OBSOLETE FORM 2.3.4.5.6.7.8.9.0.1 SUP ( 1 1234567890 5 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+
+        assertEquals( new Integer( 1234567890 ), dsrd.getRuleId() );
+        assertEquals( 2, dsrd.getNames().size() );
+        assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", dsrd.getNames().get( 0 ) );
+        assertEquals( "test", dsrd.getNames().get( 1 ) );
+        assertEquals( "Descripton äöüß 部長", dsrd.getDescription() );
+        assertTrue( dsrd.isObsolete() );
+        assertEquals( "2.3.4.5.6.7.8.9.0.1", dsrd.getForm() );
+        assertEquals( 3, dsrd.getSuperRules().size() );
+        assertEquals( new Integer(1), dsrd.getSuperRules().get( 0 ) );
+        assertEquals( new Integer(1234567890), dsrd.getSuperRules().get( 1 ) );
+        assertEquals( new Integer(5), dsrd.getSuperRules().get( 2 ) );
+        assertEquals( 2, dsrd.getExtensions().size() );
+        assertNotNull( dsrd.getExtensions().get( "X-TEST-a" ) );
+        assertEquals( 2, dsrd.getExtensions().get( "X-TEST-a" ).size() );
+        assertEquals( "test1-1", dsrd.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+        assertEquals( "test1-2", dsrd.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+        assertNotNull( dsrd.getExtensions().get( "X-TEST-b" ) );
+        assertEquals( 2, dsrd.getExtensions().get( "X-TEST-b" ).size() );
+        assertEquals( "test2-1", dsrd.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+        assertEquals( "test2-2", dsrd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+    }
+
+    
+    /**
+     * Test unique elements.
+     * 
+     * @throws ParseException
+     */
+    public void testUniqueElements() throws ParseException
+    {
+        String[] testValues = new String[]
+            { 
+                "( 1 FORM 1.1 NAME 'test1' NAME 'test2' )", 
+                "( 1 FORM 1.1 DESC 'test1' DESC 'test2' )",
+                "( 1 FORM 1.1 OBSOLETE OBSOLETE )", 
+                "( 1 FORM 1.1 FORM test1 FORM test2 )",
+                "( 1 FORM 1.1 SUP 1 SUP 2 )",
+                "( 1 FORM 1.1 X-TEST 'test1' X-TEST 'test2' )" 
+            };
+        SchemaParserTestUtils.testUnique( parser, testValues );
+    }
+    
+    
+    /**
+     * Test required elements.
+     * 
+     * @throws ParseException
+     */
+    public void testRequiredElements() throws ParseException
+    {
+        String value = null;
+        DITStructureRuleDescription dsrd = null;
+
+        value = "( 1 FORM 1.1 )";
+        dsrd = parser.parseDITStructureRuleDescription( value );
+        assertNotNull( dsrd.getForm() );
+
+        value = "( 1 )";
+        try
+        {
+            dsrd = parser.parseDITStructureRuleDescription( value );
+            fail( "Exception expected, FORM is required" );
+        }
+        catch ( ParseException pe )
+        {
+            // expected
+        }
+        
+    }
+
+
+    /**
+     * Tests the multithreaded use of a single parser.
+     */
+    public void testMultiThreaded() throws Exception
+    {
+        String[] testValues = new String[]
+            {
+                "( 1 FORM 1.1 )",
+                "( 2 DESC 'organization structure rule' FORM 2.5.15.3 )",
+                "( 2 DESC 'organization structure rule' FORM 2.5.15.3 )",
+                "( 1234567890 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüß 部長' OBSOLETE FORM 2.3.4.5.6.7.8.9.0.1 SUP ( 1 1234567890 5 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )" };
+        SchemaParserTestUtils.testMultiThreaded( parser, testValues );
+
+    }
+
+}



Mime
View raw message