directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r485047 [1/2] - in /directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap: schema/ schema/syntax/ util/
Date Sat, 09 Dec 2006 19:28:28 GMT
Author: elecharny
Date: Sat Dec  9 11:28:26 2006
New Revision: 485047

URL: http://svn.apache.org/viewvc?view=rev&rev=485047
Log:
Created a a.o.d.shared/ldap/schema/syntax package
Move the SC from the previous package to the newly created one
Created 10 new SC
Modified the StringTools class by adding new methods to be used by SCs classes

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Syntax.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AcceptAllSyntaxChecker.java
      - copied, changed from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AcceptAllSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BinarySyntaxChecker.java
      - copied, changed from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BinarySyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BitStringSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BooleanSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/CountrySyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DeliveryMethodSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DirectoryStringSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/GeneralizedTimeSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/Ia5StringSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/IntegerSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/JpegSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericOidSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericStringSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassTypeSyntaxChecker.java
      - copied, changed from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClassTypeSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OctetStringSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OidSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PrintableStringSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/RegexSyntaxChecker.java
      - copied, changed from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/RegexSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/SyntaxChecker.java
      - copied, changed from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/UtcTimeSyntaxChecker.java
Removed:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AcceptAllSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BinarySyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NameOrNumericIdSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClassTypeSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/RegexSyntaxChecker.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java
Modified:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Syntax.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Syntax.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Syntax.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/Syntax.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,88 @@
+/*
+ *  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;
+
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+
+
+/**
+ * A syntax definition. Each attribute stored in a directory has a defined
+ * syntax (i.e. data type) which constrains the structure and format of its
+ * values. The description of each syntax specifies how attribute or assertion
+ * values conforming to the syntax are normally represented when transferred in
+ * LDAP operations. This representation is referred to as the LDAP-specific
+ * encoding to distinguish it from other methods of encoding attribute values.
+ * <p>
+ * According to ldapbis [MODELS]:
+ * </p>
+ * 
+ * <pre>
+ *  4.1.5. LDAP Syntaxes
+ *  
+ *    LDAP Syntaxes of (attribute and assertion) values are described in
+ *    terms of ASN.1 [X.680] and, optionally, have an octet string encoding
+ *    known as the LDAP-specific encoding.  Commonly, the LDAP-specific
+ *    encoding is constrained to string of Universal Character Set (UCS)
+ *    [ISO10646] characters in UTF-8 [UTF-8] form.
+ * 
+ *    Each LDAP syntax is identified by an object identifier (OID).
+ * 
+ *    LDAP syntax definitions are written according to the ABNF:
+ * 
+ *      SyntaxDescription = LPAREN WSP
+ *          numericoid                ; object identifier
+ *          [ SP &quot;DESC&quot; SP qdstring ] ; description
+ *          extensions WSP RPAREN     ; extensions
+ * 
+ *    where:
+ *      [numericoid] is object identifier assigned to this LDAP syntax;
+ *      DESC [qdstring] is a short descriptive string; and
+ *      [extensions] describe extensions.
+ * </pre>
+ * 
+ * @see <a href="http://www.faqs.org/rfcs/rfc2252.html"> RFC2252 Section 4.3.3</a>
+ * @see <a href=
+ *      "http://www.ietf.org/internet-drafts/draft-ietf-ldapbis-models-09.txt">
+ *      ldapbis [MODELS]</a>
+ * @see DescriptionUtils#getDescription(Syntax)
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437007 $
+ */
+public interface Syntax extends SchemaObject
+{
+    /**
+     * Gets whether or not the Syntax is human readible.
+     * 
+     * @return true if the syntax can be interpretted by humans, false otherwise
+     */
+    boolean isHumanReadible();
+
+
+    /**
+     * Gets the SyntaxChecker used to validate values in accordance with this
+     * Syntax.
+     * 
+     * @return the SyntaxChecker
+     */
+    SyntaxChecker getSyntaxChecker() throws NamingException;
+}

Copied: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AcceptAllSyntaxChecker.java (from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AcceptAllSyntaxChecker.java)
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AcceptAllSyntaxChecker.java?view=diff&rev=485047&p1=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AcceptAllSyntaxChecker.java&r1=482559&p2=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AcceptAllSyntaxChecker.java&r2=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AcceptAllSyntaxChecker.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/AcceptAllSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -17,10 +17,11 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.ldap.schema;
+package org.apache.directory.shared.ldap.schema.syntax;
 
 
 import javax.naming.NamingException;
+
 
 
 /**

Copied: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BinarySyntaxChecker.java (from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BinarySyntaxChecker.java)
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BinarySyntaxChecker.java?view=diff&rev=485047&p1=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BinarySyntaxChecker.java&r1=482559&p2=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BinarySyntaxChecker.java&r2=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/BinarySyntaxChecker.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BinarySyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -17,12 +17,13 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.ldap.schema;
+package org.apache.directory.shared.ldap.schema.syntax;
 
 
 import javax.naming.NamingException;
 
 
+
 /**
  * A binary value (universal value acceptor) syntax checker.
  * 
@@ -59,7 +60,7 @@
 
 
     /**
-     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(Object)
+     * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#assertSyntax(Object)
      */
     public void assertSyntax( Object value ) throws NamingException
     {
@@ -68,7 +69,7 @@
 
 
     /**
-     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+     * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#getSyntaxOid()
      */
     public String getSyntaxOid()
     {
@@ -77,7 +78,7 @@
 
 
     /**
-     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(Object)
+     * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#isValidSyntax(Object)
      */
     public boolean isValidSyntax( Object value )
     {

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BitStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BitStringSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BitStringSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BitStringSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,154 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Boolean according to RFC 4517.
+ * 
+ * From RFC 4512 & RFC 4517 :
+ * 
+ * BitString    = SQUOTE *binary-digit SQUOTE "B"
+ * binary-digit = "0" / "1"
+ * SQUOTE  = %x27                           ; hyphen ("'")
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BitStringSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.2 */
+    public static final String DEFAULT_OID = "1.3.6.1.4.1.1466.115.121.1.6";
+    
+    /** The Syntax OID */
+    private final String oid;
+    
+    
+    public BitStringSyntaxChecker( String oid )
+    {
+        this.oid = oid;
+    }
+    
+    /**
+     * 
+     * Creates a new instance of BitStringSyntaxChecker.
+     *
+     */
+    public BitStringSyntaxChecker()
+    {
+        this.oid = DEFAULT_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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return oid;
+    }
+
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        int pos = 0;
+        
+        // Check that the String respect the syntax : ' ([01]+) ' B
+        if ( ! StringTools.isCharASCII( strValue, pos++, '\'' ) )
+        {
+            return false;
+        }
+
+        // We must have at least one bit
+        if ( ! StringTools.isBit( strValue, pos++ ) )
+        {
+            return false;
+        }
+        
+        while ( StringTools.isBit( strValue, pos ) )
+        {
+            // Loop until we get a char which is not a 0 or a 1
+            pos++;
+        }
+
+        // Now, we must have a simple quote 
+        if ( ! StringTools.isCharASCII( strValue, pos++, '\'' ) )
+        {
+            return false;
+        }
+
+        // followed by a 'B'
+        if ( ! StringTools.isCharASCII( strValue, pos, 'B' ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BooleanSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BooleanSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BooleanSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/BooleanSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,110 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Boolean according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * 
+ * Boolean = "TRUE" / "FALSE"
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BooleanSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.3 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.7";
+    
+    /**
+     * 
+     * Creates a new instance of BooleanSyntaxChecker.
+     *
+     */
+    public BooleanSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        return ( ( "TRUE".equals( strValue ) ) || ( "FALSE".equals( strValue ) ) );
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/CountrySyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/CountrySyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/CountrySyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/CountrySyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,165 @@
+/*
+ *  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.HashSet;
+import java.util.Set;
+
+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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a country according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * 
+ * A value of the Country String syntax is one of the two-character
+ * codes from ISO 3166 [ISO3166] for representing a country.
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class CountrySyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.4 */
+    public static final String DEFAULT_OID = "1.3.6.1.4.1.1466.115.121.1.11";
+    
+    /** The Syntax OID */
+    private final String oid;
+    
+    /** The ISO 3166 list of countries, as of 2006 */
+    private static final String[] COUNTRY_ISO_3166 =
+        {
+        "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ",
+        "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ",
+        "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CX", "CY", "CZ",
+        "DE", "DJ", "DK", "DM", "DO", "DZ",
+        "EC", "EE", "EG", "EH", "ER", "ES", "ET",
+        "FI", "FJ", "FK", "FM", "FO", "FR",
+        "GA", "GB", "GD", "GE", "GG", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY",
+        "HK", "HM", "HN", "HR", "HT", "HU",
+        "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT",
+        "JE", "JM", "JO", "JP",
+        "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ",
+        "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY",
+        "MA", "MC", "MD", "ME", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ",
+        "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ",
+        "OM",
+        "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
+        "QA",
+        "RE", "RO", "RS", "RU", "RW", 
+        "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ",
+        "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ",
+        "UA", "UG", "UM", "US", "UY", "UZ",
+        "VA", "VC", "VE", "VG", "VI", "VN", "VU",
+        "WF", "WS",
+        "YE", "YT",
+        "ZA", "ZM", "ZW"
+        };
+    
+    /** The Set which contains the countries */
+    private final static Set<String> COUNTRIES = new HashSet<String>();
+    
+    /** Initialization of the country set */
+    static
+    {
+        for ( String country:COUNTRY_ISO_3166 )
+        {
+            COUNTRIES.add( country );
+        }
+    }
+    
+    public CountrySyntaxChecker( String oid )
+    {
+        this.oid = oid;
+    }
+    
+    /**
+     * 
+     * Creates a new instance of CountrySyntaxChecker.
+     *
+     */
+    public CountrySyntaxChecker()
+    {
+        this.oid = DEFAULT_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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return oid;
+    }
+
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        return COUNTRIES.contains( StringTools.toUpperCase( strValue ) );
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DeliveryMethodSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DeliveryMethodSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DeliveryMethodSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DeliveryMethodSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,234 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a delivery method 
+ * according to RFC 4517.
+ * 
+ * From RFC 4517 & RFC 4512:
+ * 
+ * DeliveryMethod = pdm *( WSP DOLLAR WSP pdm )
+ *
+ * pdm = "any" | "mhs" | "physical" | "telex" | "teletex" |
+ *       "g3fax" | "g4fax" | "ia5" | "videotex" | "telephone"
+ *           
+ * WSP     = 0*SPACE  ; zero or more " "
+ * DOLLAR  = %x24 ; dollar sign ("$")
+ * SPACE   = %x20 ; space (" ")
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DeliveryMethodSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.5 */
+    public static final String DEFAULT_OID = "1.3.6.1.4.1.1466.115.121.1.14";
+    
+    /** The Syntax OID */
+    private final String oid;
+
+    private static final String[] PDMS = 
+        {
+            "any", "mhs", "physical", "telex", "teletex",
+            "g3fax", "g4fax", "ia5", "videotex", "telephone"
+        };
+
+    /** The Set which contains the delivery methods */
+    private final static Set<String> DELIVERY_METHODS = new HashSet<String>();
+    
+    /** Initialization of the delivery methods set */
+    static
+    {
+        for ( String country:PDMS )
+        {
+            DELIVERY_METHODS.add( country );
+        }
+    }
+
+    
+    public DeliveryMethodSyntaxChecker( String oid )
+    {
+        this.oid = oid;
+    }
+    
+    /**
+     * 
+     * Creates a new instance of DeliveryMethodSyntaxChecker.
+     *
+     */
+    public DeliveryMethodSyntaxChecker()
+    {
+        this.oid = DEFAULT_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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return oid;
+    }
+
+    /**
+     * 
+     * Check if the string contains a delivery method which has 
+     * not already been found.
+     * 
+     */
+    private int isPdm( String strValue, int pos, Set<String> pmds )
+    {
+        int start = pos;
+        
+        while ( StringTools.isAlphaDigit( strValue, pos ) )
+        {
+            pos++;
+        }
+        
+        // No ascii string, this is not a delivery method
+        if ( pos == start )
+        {
+            return -1;
+        }
+        
+        String pmd = strValue.substring( start, pos );
+        
+        if ( ! DELIVERY_METHODS.contains( pmd ) )
+        {
+            // The delivery method is unknown
+            return -1;
+        }
+        else
+        {
+            if ( pmds.contains( pmd ) )
+            {
+                // The delivery method has already been found
+                return -1;
+            }
+            else
+            {
+                pmds.add( pmd );
+                return pos;
+            }
+        }
+    }
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // We will get the first delivery method
+        int length = strValue.length();
+        int pos = 0;
+        Set<String> pmds = new HashSet<String>();
+            
+        if ( ( pos = isPdm( strValue, pos, pmds ) ) == -1)
+        {
+            return false;
+        }
+        
+        // We have found at least the first pmd,
+        // now iterate through the other ones. We may have
+        // SP* '$' SP* before each pmd.
+        while ( pos < length )
+        {
+            // Skip spaces
+            while ( StringTools.isCharASCII( strValue, pos, ' ' ) )
+            {
+                pos++;
+            }
+            
+            if ( ! StringTools.isCharASCII( strValue, pos, '$' ) )
+            {
+                // A '$' was expected
+                return false;
+            }
+            else
+            {
+                pos++;
+            }
+            
+            // Skip spaces
+            while ( StringTools.isCharASCII( strValue, pos, ' ' ) )
+            {
+                pos++;
+            }
+
+            if ( ( pos = isPdm( strValue, pos, pmds ) ) == -1 )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DirectoryStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DirectoryStringSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DirectoryStringSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/DirectoryStringSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,119 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Directory String according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * DirectoryString = 1*UTF8
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437007 $
+ */
+public class DirectoryStringSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.6 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.15";
+    
+
+    /**
+     * 
+     * Creates a new instance of DirectoryStringSyntaxChecker.
+     *
+     */
+    public DirectoryStringSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+    
+    /* (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();
+        }
+
+        // If the value was an invalid UTF8 string, then it's length
+        // will be 0 as the StringTools.utf8ToString() call will
+        // return an empty string
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // In any other case, we have to check that the
+        // string does not contains the '0xFFFD' character
+        for ( char c:strValue.toCharArray() )
+        {
+            if ( c == 0xFFFD )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/GeneralizedTimeSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/GeneralizedTimeSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/GeneralizedTimeSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/GeneralizedTimeSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,158 @@
+/*
+ *  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.regex.Pattern;
+
+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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a generalized time
+ * according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * GeneralizedTime = century year month day hour
+ *                          [ minute [ second / leap-second ] ]
+ *                          [ fraction ]
+ *                          g-time-zone
+ *
+ * century = 2(%x30-39)            ; "00" to "99"
+ * year    = 2(%x30-39)            ; "00" to "99"
+ * month   = ( %x30 %x31-39 )      ; "01" (January) to "09"
+ *           | ( %x31 %x30-32 )    ; "10" to "12"
+ * day     = ( %x30 %x31-39 )      ; "01" to "09"
+ *           | ( %x31-32 %x30-39 ) ; "10" to "29"
+ *           | ( %x33 %x30-31 )    ; "30" to "31"
+ * hour    = ( %x30-31 %x30-39 ) 
+ *           | ( %x32 %x30-33 )    ; "00" to "23"
+ * minute  = %x30-35 %x30-39       ; "00" to "59"
+ *
+ * second  = ( %x30-35 %x30-39 )   ; "00" to "59"
+ * leap-second = ( %x36 %x30 )     ; "60"
+ *
+ * fraction = ( DOT / COMMA ) 1*(%x30-39)
+ * g-time-zone = %x5A              ; "Z"
+ *               | g-differential
+ * g-differential = ( MINUS / PLUS ) hour [ minute ]
+ * MINUS   = %x2D  ; minus sign ("-")
+ * 
+ * From RFC 4512 :
+ * PLUS    = %x2B ; plus sign ("+")
+ * DOT     = %x2E ; period (".")
+ * COMMA   = %x2C ; comma (",")
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class GeneralizedTimeSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.13 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.24";
+    
+    /** The GeneralizedDate pattern matching */
+    private static final String GENERALIZED_TIME_PATTERN = 
+                "^\\d{4}" +                                 // century + year : 0000 to 9999
+                "(0[1-9]|1[0-2])" +                         // month : 01 to 12
+                "(0[1-9]|[12]\\d|3[01])" +                  // day : 01 to 31
+                "([01]\\d|2[0-3])" +                        // hour : 00 to 23
+                "(" +
+                    "([0-5]\\d)" +                          // optionnal minute : 00 to 59
+                    "([0-5]\\d|60)?" +                      // optionnal second | leap second
+                ")?" +
+                "([.,]\\d+)?" +                             // fraction       
+                "(Z|[+-]([01]\\d|2[0-3])([0-5]\\d)?)$";     // time-zone
+    
+    // The regexp pattern matcher
+    private Pattern datePattern = Pattern.compile( GENERALIZED_TIME_PATTERN ); 
+
+    /**
+     * 
+     * Creates a new instance of GeneralizedTimeSyntaxChecker.
+     *
+     */
+    public GeneralizedTimeSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (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();
+        }
+
+        // A generalized time must have a minimal length of 11 
+        if ( strValue.length() < 11 )
+        {
+            return false;
+        }
+        
+        // Start the date parsing
+        return datePattern.matcher( strValue ).find();
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/Ia5StringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/Ia5StringSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/Ia5StringSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/Ia5StringSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,117 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a IA5 String according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * IA5String          = *(%x00-7F)
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437007 $
+ */
+public class Ia5StringSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.15 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.26";
+    
+
+    /**
+     * 
+     * Creates a new instance of Ia5StringSyntaxChecker.
+     *
+     */
+    public Ia5StringSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+    
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        //All the chars must be in [0x00, 0x7F]
+        for ( int i = 0; i < strValue.length(); i++ )
+        {
+            char c = strValue.charAt( i );
+            
+            if ( ( c < 0 ) || ( c > 0x7F ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/IntegerSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/IntegerSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/IntegerSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/IntegerSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,160 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is an Integer according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * 
+ * Integer = ( HYPHEN LDIGIT *DIGIT ) | number
+ * 
+ * From RFC 4512 :
+ * number  = DIGIT | ( LDIGIT 1*DIGIT )
+ * DIGIT   = %x30 | LDIGIT       ; "0"-"9"
+ * LDIGIT  = %x31-39             ; "1"-"9"
+ * HYPHEN  = %x2D                ; hyphen ("-")
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class IntegerSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.16 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.27";
+    
+    /**
+     * 
+     * Creates a new instance of IntegerSyntaxChecker.
+     *
+     */
+    public IntegerSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // The first char must be either a '-' or in [0..9].
+        // If it's a '0', then there should be any other char after
+        int pos = 0;
+        char c = strValue.charAt( pos );
+        
+        if ( c == '-' )
+        {
+            pos = 1;
+        }
+        else if ( !StringTools.isDigit( c ) )
+        {
+            return false;
+        }
+        else if ( c == '0' )
+        {
+            if ( strValue.length() > 1 )
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+            
+        // We must have at least a digit which is not '0'
+        if ( !StringTools.isDigit( strValue, pos ) )
+        {
+            return false;
+        }
+        else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+        {
+            return false;
+        }
+        else
+        {
+            pos++;
+        }
+        
+        while ( StringTools.isDigit( strValue, pos) )
+        {
+            pos++;
+        }
+        
+        return ( pos == strValue.length() );
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/JpegSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/JpegSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/JpegSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/JpegSyntaxChecker.java Sat Dec  9 11:28:26 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 javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Jpeg according to RFC 4517.
+ * 
+ * The JFIF (Jpeg File Interchange Format) specify that a jpeg image starts with
+ * the following bytes :
+ * 0xFF 0xD8 (SOI, Start Of Image)
+ * 0xFF 0xE0 (App0)
+ * 0xNN 0xNN (Header length)
+ * "JFIF\0" (JFIF string with an ending \0)
+ * some other bytes which are related to the image.
+ * 
+ * We will check for those 11 bytes, except the length.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437007 $
+ */
+public class JpegSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.25 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.28";
+    
+
+    /**
+     * 
+     * Creates a new instance of JpegSyntaxChecker.
+     *
+     */
+    public JpegSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        if ( value == null )
+        {
+            return false;
+        }
+        
+        // The value must be a byte array
+        if ( ! ( value instanceof byte[] ) )
+        {
+            return false;
+        }
+        
+        byte[] bytes = (byte[])value;
+
+        // The header must be at least 11 bytes long
+        if ( bytes.length < 11 )
+        {
+            return false;
+        }
+
+        if ( ( bytes[0] == (byte)0xFF ) && // SOI
+             ( bytes[1] == (byte)0xD8 ) &&
+             ( bytes[2] == (byte)0xFF ) && // APP0
+             ( bytes[3] == (byte)0xE0 ) &&
+             ( bytes[6] == 'J' ) && // JFIF
+             ( bytes[7] == 'F' ) && // JFIF
+             ( bytes[8] == 'I' ) && // JFIF
+             ( bytes[9] == 'F' ) &&
+             ( bytes[10] == '\0' ) ) // \0
+        {
+            // Note : this is not because the header is correct
+            // that the file is a jpeg file. There are much more
+            // elements to check, but we are not writing a jpeg
+            // file checker...
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericOidSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericOidSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericOidSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericOidSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,134 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a numeric oid 
+ * according to RFC 4512.
+ * 
+ * From RFC 4512 :
+ * 
+ * numericoid = number 1*( DOT number )
+ * number  = DIGIT | ( LDIGIT 1*DIGIT )
+ * DIGIT   = %x30 | LDIGIT                  ; "0"-"9"
+ * LDIGIT  = %x31-39                        ; "1"-"9"
+ * DOT     = %x2E                           ; period (".")
+
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NumericOidSyntaxChecker implements SyntaxChecker
+{
+    public static final String DEFAULT_OID = "1.3.6.1.4.1.18060.0.4.0.0.0";
+    private final String oid;
+    
+    
+    public NumericOidSyntaxChecker( String oid )
+    {
+        this.oid = oid;
+    }
+    
+    
+    public NumericOidSyntaxChecker()
+    {
+        this.oid = DEFAULT_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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return oid;
+    }
+
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // if the first character is a digit it's an attempt at an OID and must be
+        // checked to make sure there are no other chars except '.' and digits.
+        if ( Character.isDigit( strValue.charAt( 0 ) ) )
+        {
+            if ( ! org.apache.directory.shared.asn1.primitives.OID.isOID( strValue ) )
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+        else
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericStringSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericStringSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/NumericStringSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,140 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Numeric String according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * 
+ * NumericString = 1*(DIGIT / SPACE)
+ * 
+ * From RFC 4512 :
+ * number  = DIGIT | ( LDIGIT 1*DIGIT )
+ * DIGIT   = %x30 | LDIGIT       ; "0"-"9"
+ * LDIGIT  = %x31-39             ; "1"-"9"
+ * SPACE   = %x20                ; space (" ")
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NumericStringSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.23 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.36";
+    
+    /**
+     * 
+     * Creates a new instance of NumericStringSyntaxChecker.
+     *
+     */
+    public NumericStringSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+
+
+    /* (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();
+        }
+
+        // We should have at least one char
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // Check that each char is either a digit or a space
+        for ( int i = 0; i < strValue.length(); i++ )
+        {
+            switch ( strValue.charAt( i ) )
+            {
+                case '0': 
+                case '1' :
+                case '2' :
+                case '3' :
+                case '4' :
+                case '5' :
+                case '6' :
+                case '7' :
+                case '8' :
+                case '9' :
+                case ' ' :
+                    continue;
+                    
+                default : 
+                    return false;
+            }
+        }
+        
+        return true;
+    }
+}

Copied: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassTypeSyntaxChecker.java (from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClassTypeSyntaxChecker.java)
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassTypeSyntaxChecker.java?view=diff&rev=485047&p1=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClassTypeSyntaxChecker.java&r1=482559&p2=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassTypeSyntaxChecker.java&r2=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClassTypeSyntaxChecker.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/ObjectClassTypeSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -17,7 +17,7 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.ldap.schema;
+package org.apache.directory.shared.ldap.schema.syntax;
 
 
 import javax.naming.NamingException;
@@ -36,7 +36,10 @@
  */
 public class ObjectClassTypeSyntaxChecker implements SyntaxChecker
 {
+    /** The Apache OID for meta syntax checker */
     public static final String DEFAULT_OID = "1.3.6.1.4.1.18060.0.4.0.0.1";
+    
+    /** I don't really know if this member is usefull ... */
     private final String oid;
  
     
@@ -45,7 +48,11 @@
         this.oid = oid;
     }
     
-    
+    /**
+     * 
+     * Creates a new instance of ObjectClassTypeSyntaxChecker.
+     *
+     */
     public ObjectClassTypeSyntaxChecker()
     {
         this.oid = DEFAULT_OID;
@@ -98,21 +105,17 @@
             strValue = value.toString();
         }
 
-        if ( strValue.length() == 0 )
-        {
-            return false;
-        }
-
         if ( strValue.length() < 8 || strValue.length() > 10 )
         {
             return false;
         }
         
         char ch = strValue.charAt( 0 );
+
         switch( ch )
         {
             case( 'A' ):
-                if ( strValue.equals( "AUXILIARY" ) || strValue.equals( "ABSTRACT" ) )
+                if ( "AUXILIARY".equals( strValue ) || "ABSTRACT".equals( strValue ) )
                 {
                     return true;
                 }
@@ -120,8 +123,10 @@
                 {
                     return false;
                 }
+            
             case( 'S' ):
-                return strValue.equals( "STRUCTURAL" );
+                return "STRUCTURAL".equals( strValue );
+            
             default:
                 return false;
         }

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OctetStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OctetStringSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OctetStringSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OctetStringSyntaxChecker.java Sat Dec  9 11:28:26 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 javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Octet String according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * OctetString = *OCTET
+ * 
+ * From RFC 4512 :
+ * OCTET   = %x00-FF ; Any octet (8-bit data unit)
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437007 $
+ */
+public class OctetStringSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.25 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.40";
+    
+
+    /**
+     * 
+     * Creates a new instance of OctetStringSyntaxChecker.
+     *
+     */
+    public OctetStringSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        return ( value != null );
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OidSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OidSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OidSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/OidSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,163 @@
+/*
+ *  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 javax.naming.NamingException;
+
+
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is an oid according to RFC 4512.
+ * 
+ * From RFC 4512 :
+ * 
+ * oid = descr | numericoid
+ * descr = keystring
+ * keystring = leadkeychar *keychar
+ * leadkeychar = ALPHA
+ * keychar = ALPHA | DIGIT | HYPHEN
+ * number  = DIGIT | ( LDIGIT 1*DIGIT )
+ * ALPHA   = %x41-5A | %x61-7A              ; "A"-"Z" | "a"-"z"
+ * DIGIT   = %x30 | LDIGIT                  ; "0"-"9"
+ * LDIGIT  = %x31-39                        ; "1"-"9"
+ * HYPHEN  = %x2D                           ; hyphen ("-")
+ * numericoid = number 1*( DOT number )
+ * DOT     = %x2E                           ; period (".")
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class OidSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according RFC 4517, par. 3.3.26 */
+    public static final String DEFAULT_OID = "1.3.6.1.4.1.1466.115.121.1.38";
+    
+    /** The Syntax OID */
+    private final String oid;
+    
+    
+    public OidSyntaxChecker( String oid )
+    {
+        this.oid = oid;
+    }
+    
+    /**
+     * 
+     * Creates a new instance of OidSyntaxChecker.
+     *
+     */
+    public OidSyntaxChecker()
+    {
+        this.oid = DEFAULT_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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return oid;
+    }
+
+
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // if the first character is a digit it's an attempt at an OID and must be
+        // checked to make sure there are no other chars except '.' and digits.
+        if ( StringTools.isDigit( strValue.charAt( 0 ) ) )
+        {
+            if ( ! OID.isOID( strValue ) )
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+
+        // here we just need to make sure that we have the right characters in the 
+        // string and that it starts with a letter.
+        if ( StringTools.isAlphaASCII( strValue, 0 ) )
+        {
+            for ( int index = 0; index < strValue.length(); index++ )
+            {
+                if ( ! StringTools.isAlphaDigitMinus( strValue, index ))
+                {
+                    return false;
+                }
+            }
+            
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PrintableStringSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PrintableStringSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PrintableStringSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/PrintableStringSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -0,0 +1,166 @@
+/*
+ *  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 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.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Printable String according to RFC 4517.
+ * 
+ * From RFC 4517 :
+ * 
+ * PrintableString    = 1*PrintableCharacter
+ * PrintableCharacter = ALPHA | DIGIT | SQUOTE | LPAREN | RPAREN |
+ *                          PLUS | COMMA | HYPHEN | DOT | EQUALS |
+ *                          SLASH | COLON | QUESTION | SPACE
+ *                          
+ * SLASH   = %x2F                ; forward slash ("/")
+ * COLON   = %x3A                ; colon (":")
+ * QUESTION= %x3F                ; question mark ("?")
+ * 
+ * From RFC 4512 :
+ * ALPHA   = %x41-5A | %x61-7A   ; "A"-"Z" / "a"-"z"
+ * DIGIT   = %x30 | LDIGIT       ; "0"-"9"
+ * LDIGIT  = %x31-39             ; "1"-"9"
+ * SQUOTE  = %x27                ; single quote ("'")
+ * LPAREN  = %x28                ; left paren ("(")
+ * RPAREN  = %x29                ; right paren (")")
+ * PLUS    = %x2B                ; plus sign ("+")
+ * COMMA   = %x2C                ; comma (",")
+ * HYPHEN  = %x2D                ; hyphen ("-")
+ * DOT     = %x2E                ; period (".")
+ * EQUALS  = %x3D                ; equals sign ("=")
+ * SPACE   = %x20                ; space (" ")
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PrintableStringSyntaxChecker implements SyntaxChecker
+{
+    /** The Syntax OID, according to RFC 4517, par. 3.3.29 */
+    public static final String OID = "1.3.6.1.4.1.1466.115.121.1.44";
+    
+    /** A table containing booleans when the corresponding char is printable */
+    private static final boolean[] IS_PRINTABLE_CHAR =
+        {
+        false, false, false, false, false, false, false, false, // ---, ---, ---, ---, ---, ---, ---, ---
+        false, false, false, false, false, false, false, false, // ---, ---, ---, ---, ---, ---, ---, ---
+        false, false, false, false, false, false, false, false, // ---, ---, ---, ---, ---, ---, ---, ---
+        false, false, false, false, false, false, false, false, // ---, ---, ---, ---, ---, ---, ---, ---
+        true,  false, false, false, false, false, false, true,  // ' ', ---, ---, ---, ---, ---, ---, "'" 
+        true,  true,  false, true,  true,  true,  true,  true,  // '(', ')', ---, '+', ',', '-', '.', '/'
+        true,  true,  true,  true,  true,  true,  true,  true,  // '0', '1', '2', '3', '4', '5', '6', '7',  
+        true,  true,  true,  false, false, true,  false, true,  // '8', '9', ':', ---, ---, '=', ---, '?'
+        false, true,  true,  true,  true,  true,  true,  true,  // ---, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 
+        true,  true,  true,  true,  true,  true,  true,  true,  // 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'
+        true,  true,  true,  true,  true,  true,  true,  true,  // 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W'
+        true,  true,  true,  false, false, false, false, false, // 'X', 'Y', 'Z', ---, ---, ---, ---, ---
+        false, true,  true,  true,  true,  true,  true,  true,  // ---, 'a', 'b', 'c', 'd', 'e', 'f', 'g' 
+        true,  true,  true,  true,  true,  true,  true,  true,  // 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'
+        true,  true,  true,  true,  true,  true,  true,  true,  // 'p', 'q', 'r', 's', 't', 'u', 'v', 'w'
+        true,  true,  true,  false, false, false, false, false  // 'x', 'y', 'z', ---, ---, ---, ---, ---
+        };
+    
+    /**
+     * 
+     * Creates a new instance of PrintableStringSyntaxChecker.
+     *
+     */
+    public PrintableStringSyntaxChecker()
+    {
+    }
+    
+    
+    /* (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#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return OID;
+    }
+    
+    /* (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();
+        }
+
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        // We must have at least one char
+        if ( strValue.length() == 0 )
+        {
+            return false;
+        }
+        
+        for ( int i = 0; i < strValue.length(); i++ )
+        {
+            char c = strValue.charAt( i );
+            
+            if ( ( c > 127 ) || !IS_PRINTABLE_CHAR[ c ] )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+}

Copied: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/RegexSyntaxChecker.java (from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/RegexSyntaxChecker.java)
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/RegexSyntaxChecker.java?view=diff&rev=485047&p1=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/RegexSyntaxChecker.java&r1=482559&p2=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/RegexSyntaxChecker.java&r2=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/RegexSyntaxChecker.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/RegexSyntaxChecker.java Sat Dec  9 11:28:26 2006
@@ -17,13 +17,14 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.shared.ldap.schema;
+package org.apache.directory.shared.ldap.schema.syntax;
 
 
 import javax.naming.NamingException;
 import javax.naming.directory.InvalidAttributeValueException;
 
 
+
 /**
  * A SyntaxChecker implemented using Perl5 regular expressions to constrain
  * values.
@@ -57,7 +58,7 @@
 
 
     /**
-     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+     * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#getSyntaxOid()
      */
     public String getSyntaxOid()
     {
@@ -66,7 +67,7 @@
 
 
     /**
-     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#isValidSyntax(java.lang.Object)
      */
     public boolean isValidSyntax( Object value )
     {
@@ -93,7 +94,7 @@
 
 
     /**
-     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+     * @see org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker#assertSyntax(java.lang.Object)
      */
     public void assertSyntax( Object value ) throws NamingException
     {



Mime
View raw message