You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2003/12/24 02:08:04 UTC

svn commit: rev 1466 - in incubator/directory/ldap/trunk/eve/backend/schema/common/api: . src/java/org/apache/eve/schema

Author: akarasulu
Date: Tue Dec 23 17:08:04 2003
New Revision: 1466

Added:
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/BinarySyntaxChecker.java
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DefaultSyntax.java
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/RegexSyntaxChecker.java
Modified:
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/project.xml
   incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DescriptionUtils.java
Log:
These are things that should have been committed with 1465


Modified: incubator/directory/ldap/trunk/eve/backend/schema/common/api/project.xml
==============================================================================
--- incubator/directory/ldap/trunk/eve/backend/schema/common/api/project.xml	(original)
+++ incubator/directory/ldap/trunk/eve/backend/schema/common/api/project.xml	Tue Dec 23 17:08:04 2003
@@ -22,6 +22,13 @@
             <version>2.0</version>
             <url>http://jakarta.apache.org/commons/lang/api</url>
         </dependency>
+
+        <dependency>
+            <groupId>oro</groupId>
+            <artifactId>oro</artifactId>
+            <version>2.0.7</version>
+            <url>http://jakarta.apache.org/oro</url>
+        </dependency>
     </dependencies>
 </project>
 

Added: incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/BinarySyntaxChecker.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/BinarySyntaxChecker.java	Tue Dec 23 17:08:04 2003
@@ -0,0 +1,90 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+    and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema ;
+
+
+import javax.naming.NamingException ;
+
+
+/**
+ * The Binary (a.k.a. universal-acceptor) syntax checker.
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Rev$
+ */
+public class BinarySyntaxChecker implements SyntaxChecker
+{
+    /**
+     * @see org.apache.eve.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+     */
+    public void assertSyntax( Object a_value ) throws NamingException
+    {
+        // do nothing because everything is valid
+    }
+
+    
+    /**
+     * @see org.apache.eve.schema.SyntaxChecker#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return "1.3.6.1.4.1.1466.115.121.1.5" ;
+    }
+
+    
+    /**
+     * @see org.apache.eve.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object a_value )
+    {
+        return true ;
+    }
+}

Added: incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DefaultSyntax.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DefaultSyntax.java	Tue Dec 23 17:08:04 2003
@@ -0,0 +1,179 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+    and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema ;
+
+
+/**
+ * Default Syntax implementation.
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Rev$
+ */
+public class DefaultSyntax implements Syntax
+{
+    /** the oid of this Syntax */
+    private final String m_oid ;
+    /** the SyntaxChecker used to enforce this Syntax */
+    private final SyntaxChecker m_checker ;
+
+    /** the human readible flag */
+    private boolean m_isHumanReadible ;
+    /** a short description of this Syntax */
+    private String m_description ;
+    /** a human readible identifier for this Syntax */
+    private String m_name ;
+    
+    
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+    
+    /**
+     * Creates a Syntax object.
+     * 
+     * @param a_oid the OID for this Syntax
+     * @param a_checker the SyntaxChecker used to enforce this Syntax
+     */
+    public DefaultSyntax( String a_oid, SyntaxChecker a_checker )
+    {
+        m_oid = a_oid ;
+        m_checker = a_checker ;
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // Syntax interface methods
+    // ------------------------------------------------------------------------
+
+    
+    /**
+     * @see org.apache.eve.schema.Syntax#isHumanReadable()
+     */
+    public boolean isHumanReadable()
+    {
+        return m_isHumanReadible ;
+    }
+
+    
+    /**
+     * @see org.apache.eve.schema.Syntax#getDescription()
+     */
+    public String getDescription()
+    {
+        return m_description ;
+    }
+
+    
+    /**
+     * @see org.apache.eve.schema.Syntax#getName()
+     */
+    public String getName()
+    {
+        return m_name ;
+    }
+
+    
+    /**
+     * @see org.apache.eve.schema.Syntax#getOid()
+     */
+    public final String getOid()
+    {
+        return m_oid ;
+    }
+    
+
+    /**
+     * @see org.apache.eve.schema.Syntax#getSyntaxChecker()
+     */
+    public SyntaxChecker getSyntaxChecker()
+    {
+        return m_checker ;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Protected setters
+    // ------------------------------------------------------------------------
+
+    
+    /**
+     * Sets the description for this Syntax.
+     * 
+     * @param a_description the description to set
+     */
+    protected void setDescription( String a_description )
+    {
+        m_description = a_description ;
+    }
+
+    
+    /**
+     * Sets the human readible flag value.
+     * 
+     * @param a_isHumanReadible the human readible flag value to set
+     */
+    protected void setHumanReadible( boolean a_isHumanReadible )
+    {
+        m_isHumanReadible = a_isHumanReadible ;
+    }
+
+    
+    /**
+     * Sets the name of this Syntax.
+     * 
+     * @param a_name the name to set.
+     */
+    protected void setName( String a_name )
+    {
+        m_name = a_name ;
+    }
+}

Modified: incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DescriptionUtils.java
==============================================================================
--- incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DescriptionUtils.java	(original)
+++ incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/DescriptionUtils.java	Tue Dec 23 17:08:04 2003
@@ -83,7 +83,7 @@
      * @return the AttributeTypeDescription Syntax for the attributeType in a
      * pretty formated string
      */
-    public String getDescription( AttributeType a_type ) 
+    public static String getDescription( AttributeType a_type ) 
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_type.getOid() ).append( '\n' ) ;
@@ -167,7 +167,7 @@
      * @return the specification according to the DITContentRuleDescription
      * syntax 
      */
-    public String getDescription( ContentRule a_crule )
+    public static String getDescription( ContentRule a_crule )
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_crule.getOid() ).append( '\n' ) ;
@@ -251,7 +251,7 @@
      * @param a_mrule the MatchingRule to generate the description for
      * @return the MatchingRuleDescription string
      */
-    public String getDescription( MatchingRule a_mrule )
+    public static String getDescription( MatchingRule a_mrule )
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_mrule.getOid() ).append( '\n' ) ;
@@ -293,7 +293,7 @@
      * @param a_nameForm the NameForm to generate the description for
      * @return the NameFormDescription string
      */
-    public String getDescription( NameForm a_nameForm )
+    public static String getDescription( NameForm a_nameForm )
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_nameForm.getOid() ).append( '\n' ) ;
@@ -358,7 +358,7 @@
      * @param a_objectClass the ObjectClass to generate a description for
      * @return the description in the ObjectClassDescription syntax
      */
-    public String getDescription( ObjectClass a_objectClass )
+    public static String getDescription( ObjectClass a_objectClass )
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_objectClass.getOid() ).append( '\n' ) ;
@@ -436,7 +436,7 @@
      * @param a_srule the StructureRule to generate a description for
      * @return the description in the DITStructureRuleDescription syntax
      */
-    public String getDescription( StructureRule a_srule )
+    public static String getDescription( StructureRule a_srule )
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_srule.getOid() ).append( '\n' ) ;
@@ -486,7 +486,7 @@
      * @param a_syntax the Syntax to generate a description for
      * @return the description in the SyntaxDescription syntax
      */
-    public String getDescription( Syntax a_syntax )
+    public static String getDescription( Syntax a_syntax )
     {
         StringBuffer l_buf = new StringBuffer( "( " ) ;
         l_buf.append( a_syntax.getOid() ).append( '\n' ) ;

Added: incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/RegexSyntaxChecker.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/backend/schema/common/api/src/java/org/apache/eve/schema/RegexSyntaxChecker.java	Tue Dec 23 17:08:04 2003
@@ -0,0 +1,141 @@
+/*
+
+ ============================================================================
+                   The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of  source code must  retain the above copyright  notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+    include  the following  acknowledgment:  "This product includes  software
+    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
+    Alternately, this  acknowledgment may  appear in the software itself,  if
+    and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
+    and "Apache Software Foundation"  must not be used to endorse or promote
+    products derived  from this  software without  prior written
+    permission. For written permission, please contact apache@apache.org.
+
+ 5. Products  derived from this software may not  be called "Apache", nor may
+    "Apache" appear  in their name,  without prior written permission  of the
+    Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
+ APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
+ ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
+ (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software  consists of voluntary contributions made  by many individuals
+ on  behalf of the Apache Software  Foundation. For more  information on the
+ Apache Software Foundation, please see <http://www.apache.org/>.
+
+*/
+package org.apache.eve.schema ;
+
+
+import javax.naming.NamingException ;
+import javax.naming.directory.InvalidAttributeValueException ;
+
+import org.apache.oro.text.perl.Perl5Util ;
+
+
+/**
+ * A SyntaxChecker implemented using Perl5 regular expressions to constrain 
+ * values.
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Rev$
+ */
+public class RegexSyntaxChecker
+    implements SyntaxChecker
+{
+    /** the oid of the syntax checked */
+    private final String m_oid ;
+    /** the set of regular expressions */
+    private final String [] m_expressions ;
+    /** the Perl5 regex utilities */
+    private final Perl5Util m_perl = new Perl5Util() ;
+
+
+    /**
+     * Creates a Syntax validator for a specific Syntax using Perl5 matching
+     * rules for validation.
+     * 
+     * @param a_oid the oid of the Syntax values checked
+     * @param a_matchExprArray the array of matching expressions
+     */
+    public RegexSyntaxChecker( String a_oid, String [] a_matchExprArray )
+    {
+        m_expressions = a_matchExprArray ;
+        m_oid = a_oid ;
+    }
+
+
+    /**
+     * @see org.apache.eve.schema.SyntaxChecker#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return m_oid ;
+    }
+
+
+    /**
+     * @see org.apache.eve.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object a_value )
+    {
+        String l_str = null ;
+        boolean l_match = true ;
+        
+        if ( a_value instanceof String )
+        {
+            l_str = ( String ) a_value ;
+        }
+
+        for ( int ii = 0; ii < m_expressions.length; ii++ ) 
+        {
+            l_match = l_match && m_perl.match( m_expressions[ii], l_str ) ;
+            if ( ! l_match ) 
+            {
+                break ;
+            }
+        }
+
+        return l_match ;
+    }
+
+
+    /**
+     * @see org.apache.eve.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+     */
+    public void assertSyntax( Object a_value ) throws NamingException
+    {
+        if ( isValidSyntax( a_value ) )
+        {
+            return ;
+        }
+        
+        throw new InvalidAttributeValueException( a_value 
+                + " does not conform to the syntax specified by " 
+                + m_oid ) ;
+    }
+}