directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r109874 - in incubator/directory/ldap/trunk/common/src: java/org/apache/ldap/common/schema test/org/apache/ldap/common/schema
Date Sun, 05 Dec 2004 08:10:48 GMT
Author: akarasulu
Date: Sun Dec  5 00:10:46 2004
New Revision: 109874

URL: http://svn.apache.org/viewcvs?view=rev&rev=109874
Log:
added schema object rendering methods
Added:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SchemaUtils.java
   incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/schema/
   incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/schema/SchemaUtilsTest.java

Added: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SchemaUtils.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SchemaUtils.java?view=auto&rev=109874
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/SchemaUtils.java
Sun Dec  5 00:10:46 2004
@@ -0,0 +1,627 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.common.schema;
+
+
+import javax.naming.NamingException;
+
+
+/**
+ * Various utility methods for schema functions and objects.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SchemaUtils
+{
+    // ------------------------------------------------------------------------
+    // qdescrs rendering operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Renders qdescrs into an existing buffer.
+     *
+     * @param buf the string buffer to render the quoted description strs into
+     * @param qdescrs the quoted description strings to render
+     * @return the same string buffer that was given for call chaining
+     */
+    public static StringBuffer render( StringBuffer buf, String[] qdescrs )
+    {
+        if ( qdescrs == null || qdescrs.length == 0 )
+        {
+            return buf;
+        }
+        else if ( qdescrs.length == 1 )
+        {
+            buf.append( "'" ).append( qdescrs[0] ).append( "'" );
+        }
+        else
+        {
+            buf.append( "( " );
+            for ( int ii = 0; ii < qdescrs.length; ii++ )
+            {
+                buf.append( "'" ).append( qdescrs[ii] ).append( "' " );
+            }
+            buf.append( ")");
+        }
+
+        return buf;
+    }
+
+
+    /**
+     * Renders qdescrs into a new buffer.
+     *
+     * @param qdescrs the quoted description strings to render
+     * @return the string buffer the qdescrs are rendered into
+     */
+    public static StringBuffer render( String[] qdescrs )
+    {
+        StringBuffer buf = new StringBuffer();
+        return render( buf, qdescrs );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // objectClass list rendering operations
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Renders a list of object classes for things like a list of superior
+     * objectClasses using the ( oid $ oid ) format.
+     *
+     * @param ocs the objectClasses to list
+     * @return a buffer which contains the rendered list
+     */
+    public static StringBuffer render( ObjectClass[] ocs )
+    {
+        StringBuffer buf = new StringBuffer();
+        return render( buf, ocs );
+    }
+
+
+    /**
+     * Renders a list of object classes for things like a list of superior
+     * objectClasses using the ( oid $ oid ) format into an existing buffer.
+     *
+     * @param buf the string buffer to render the list of objectClasses into
+     * @param ocs the objectClasses to list
+     * @return a buffer which contains the rendered list
+     */
+    public static StringBuffer render( StringBuffer buf, ObjectClass[] ocs )
+    {
+        if ( ocs == null || ocs.length == 0 )
+        {
+            return buf;
+        }
+        else if ( ocs.length == 1 )
+        {
+            buf.append( ocs[0].getName() );
+        }
+        else
+        {
+            buf.append( "( " );
+            for ( int ii = 0; ii < ocs.length; ii++ )
+            {
+                if ( ii+1 < ocs.length )
+                {
+                    buf.append( ocs[ii].getName() ).append( " $ " );
+                }
+                else
+                {
+                    buf.append( ocs[ii].getName() );
+                }
+            }
+            buf.append( " )");
+        }
+
+        return buf;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // attributeType list rendering operations
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Renders a list of attributeTypes for things like the must or may list of
+     * objectClasses using the ( oid $ oid ) format.
+     *
+     * @param ats the attributeTypes to list
+     * @return a buffer which contains the rendered list
+     */
+    public static StringBuffer render( AttributeType[] ats )
+    {
+        StringBuffer buf = new StringBuffer();
+        return render( buf, ats );
+    }
+
+
+    /**
+     * Renders a list of attributeTypes for things like the must or may list of
+     * objectClasses using the ( oid $ oid ) format into an existing buffer.
+     *
+     * @param buf the string buffer to render the list of attributeTypes into
+     * @param ats the attributeTypes to list
+     * @return a buffer which contains the rendered list
+     */
+    public static StringBuffer render( StringBuffer buf, AttributeType[] ats )
+    {
+        if ( ats == null || ats.length == 0 )
+        {
+            return buf;
+        }
+        else if ( ats.length == 1 )
+        {
+            buf.append( ats[0].getName() );
+        }
+        else
+        {
+            buf.append( "( " );
+            for ( int ii = 0; ii < ats.length; ii++ )
+            {
+                if ( ii+1 < ats.length )
+                {
+                    buf.append( ats[ii].getName() ).append( " $ " );
+                }
+                else
+                {
+                    buf.append( ats[ii].getName() );
+                }
+            }
+            buf.append( " )");
+        }
+
+        return buf;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // schema object rendering operations
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Renders an objectClass into a new StringBuffer according to the Object
+     * Class Description Syntax 1.3.6.1.4.1.1466.115.121.1.37.  The syntax is
+     * described in detail within section 4.1.1. of LDAPBIS
+     * [<a href="http://ietf.org/internet-drafts/draft-ietf-ldapbis-models-12.txt">MODELS</a>]
+     * which is replicated here for convenience:
+     * <pre>
+     * 4.1.1. Object Class Definitions
+     *
+     *  Object Class definitions are written according to the ABNF:
+     *
+     *    ObjectClassDescription = LPAREN WSP
+     *        numericoid                 ; object identifier
+     *        [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+     *        [ SP "DESC" SP qdstring ]  ; description
+     *        [ SP "OBSOLETE" ]          ; not active
+     *        [ SP "SUP" SP oids ]       ; superior object classes
+     *        [ SP kind ]                ; kind of class
+     *        [ SP "MUST" SP oids ]      ; attribute types
+     *        [ SP "MAY" SP oids ]       ; attribute types
+     *        extensions WSP RPAREN
+     *
+     *    kind = "ABSTRACT" / "STRUCTURAL" / "AUXILIARY"
+     *
+     *  where:
+     *    <numericoid> is object identifier assigned to this object class;
+     *    NAME <qdescrs> are short names (descriptors) identifying this object
+     *        class;
+     *    DESC <qdstring> is a short descriptive string;
+     *    OBSOLETE indicates this object class is not active;
+     *    SUP <oids> specifies the direct superclasses of this object class;
+     *    the kind of object class is indicated by one of ABSTRACT,
+     *        STRUCTURAL, or AUXILIARY, default is STRUCTURAL;
+     *    MUST and MAY specify the sets of required and allowed attribute
+     *        types, respectively; and
+     *    <extensions> describe extensions.
+     * </pre>
+     * @param oc the objectClass to render the description of
+     * @return the buffer containing the objectClass description
+     * @throws NamingException if there are any problems accessing objectClass
+     * information
+     */
+    public static StringBuffer render( ObjectClass oc ) throws NamingException
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( oc.getOid() ).append( " NAME " );
+        render( buf, oc.getNames() ).append( " " );
+
+        if ( oc.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( oc.getDescription() ).append( "'
" );
+        }
+
+        if ( oc.isObsolete() )
+        {
+            buf.append( " OBSOLETE " );
+        }
+
+        if ( oc.getSuperClasses() != null && oc.getSuperClasses().length > 0 )
+        {
+            buf.append( "SUP " );
+            render( buf,  oc.getSuperClasses() );
+        }
+
+        if ( oc.getType() != null )
+        {
+            buf.append( " " ).append( oc.getType().getName() );
+        }
+
+        if ( oc.getMustList() != null )
+        {
+            buf.append( " MUST " );
+            render( buf, oc.getMustList() );
+        }
+
+        if ( oc.getMayList() != null )
+        {
+            buf.append( " MAY " );
+            render( buf, oc.getMayList() );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * Renders an attributeType into a new StringBuffer according to the
+     * Attribute Type Description Syntax 1.3.6.1.4.1.1466.115.121.1.3.  The
+     * syntax is described in detail within section 4.1.2. of LDAPBIS
+     * [<a href="http://ietf.org/internet-drafts/draft-ietf-ldapbis-models-12.txt">MODELS</a>]
+     * which is replicated here for convenience:
+     * <pre>
+     * 4.1.2. Attribute Types
+     *
+     *  Attribute Type definitions are written according to the ABNF:
+     *
+     *  AttributeTypeDescription = LPAREN WSP
+     *        numericoid                    ; object identifier
+     *        [ SP "NAME" SP qdescrs ]      ; short names (descriptors)
+     *        [ SP "DESC" SP qdstring ]     ; description
+     *        [ SP "OBSOLETE" ]             ; not active
+     *        [ SP "SUP" SP oid ]           ; supertype
+     *        [ SP "EQUALITY" SP oid ]      ; equality matching rule
+     *        [ SP "ORDERING" SP oid ]      ; ordering matching rule
+     *        [ SP "SUBSTR" SP oid ]        ; substrings matching rule
+     *        [ SP "SYNTAX" SP noidlen ]    ; value syntax
+     *        [ SP "SINGLE-VALUE" ]         ; single-value
+     *        [ SP "COLLECTIVE" ]           ; collective
+     *        [ SP "NO-USER-MODIFICATION" ] ; not user modifiable
+     *        [ SP "USAGE" SP usage ]       ; usage
+     *        extensions WSP RPAREN         ; extensions
+     *
+     *    usage = "userApplications"     /  ; user
+     *            "directoryOperation"   /  ; directory operational
+     *            "distributedOperation" /  ; DSA-shared operational
+     *            "dSAOperation"            ; DSA-specific operational
+     *
+     *  where:
+     *    <numericoid> is object identifier assigned to this attribute type;
+     *    NAME <qdescrs> are short names (descriptors) identifying this
+     *        attribute type;
+     *    DESC <qdstring> is a short descriptive string;
+     *    OBSOLETE indicates this attribute type is not active;
+     *    SUP oid specifies the direct supertype of this type;
+     *    EQUALITY, ORDERING, SUBSTR provide the oid of the equality,
+     *        ordering, and substrings matching rules, respectively;
+     *    SYNTAX identifies value syntax by object identifier and may suggest
+     *        a minimum upper bound;
+     *    SINGLE-VALUE indicates attributes of this type are restricted to a
+     *        single value;
+     *    COLLECTIVE indicates this attribute type is collective
+     *        [X.501][RFC3671];
+     *    NO-USER-MODIFICATION indicates this attribute type is not user
+     *        modifiable;
+     *    USAGE indicates the application of this attribute type; and
+     *    <extensions> describe extensions.
+     * </pre>
+     * @param at the AttributeType to render the description for
+     * @return the StringBuffer containing the rendered attributeType description
+     * @throws NamingException if there are problems accessing the objects
+     * associated with the attribute type.
+     */
+    public static StringBuffer render( AttributeType at ) throws NamingException
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( at.getOid() ).append( " NAME " );
+        render( buf, at.getNames() ).append( " " );
+
+        if ( at.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( at.getDescription() ).append( "'
" );
+        }
+
+        if ( at.isObsolete() )
+        {
+            buf.append( " OBSOLETE" );
+        }
+
+        if ( at.getSuperior() != null )
+        {
+            buf.append( " SUP " ).append( at.getSuperior().getName() );
+        }
+
+        if ( at.getEquality() != null )
+        {
+            buf.append( " EQUALITY " ).append( at.getEquality().getName() );
+        }
+
+        if ( at.getOrdering() != null )
+        {
+            buf.append( " ORDERING " ).append( at.getOrdering().getName() );
+        }
+
+        if ( at.getSubstr() != null )
+        {
+            buf.append( " SUBSTR " ).append( at.getSubstr().getName() );
+        }
+
+        if ( at.getSyntax() != null )
+        {
+            buf.append( " SYNTAX " ).append( at.getSyntax().getOid() );
+
+            if ( at.getLength() > 0 )
+            {
+                buf.append( "{" ).append( at.getLength() ).append( "}" );
+            }
+        }
+
+        if ( at.isSingleValue() )
+        {
+            buf.append( " SINGLE-VALUE" );
+        }
+
+        if ( at.isCollective() )
+        {
+            buf.append( " COLLECTIVE" );
+        }
+
+        if ( ! at.isCanUserModify() )
+        {
+            buf.append( " NO-USER-MODIFICATION" );
+        }
+
+        if ( at.getUsage() != null )
+        {
+            buf.append( " USAGE " ).append( at.getUsage().getName() );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * Renders an matchingRule into a new StringBuffer according to the
+     * MatchingRule Description Syntax 1.3.6.1.4.1.1466.115.121.1.30.  The
+     * syntax is described in detail within section 4.1.3. of LDAPBIS
+     * [<a href="http://ietf.org/internet-drafts/draft-ietf-ldapbis-models-12.txt">MODELS</a>]
+     * which is replicated here for convenience:
+     * <pre>
+     * 4.1.3. Matching Rules
+     *
+     *  Matching rules are used in performance of attribute value assertions,
+     *  such as in performance of a Compare operation.  They are also used in
+     *  evaluation of a Search filters, in determining which individual values
+     *  are be added or deleted during performance of a Modify operation, and
+     *  used in comparison of distinguished names.
+     *
+     *  Each matching rule is identified by an object identifier (OID) and,
+     *  optionally, one or more short names (descriptors).
+     *
+     *  Matching rule definitions are written according to the ABNF:
+     *
+     *  MatchingRuleDescription = LPAREN WSP
+     *       numericoid                 ; object identifier
+     *        [ SP "NAME" SP qdescrs ]   ; short names (descriptors)
+     *        [ SP "DESC" SP qdstring ]  ; description
+     *        [ SP "OBSOLETE" ]          ; not active
+     *        SP "SYNTAX" SP numericoid  ; assertion syntax
+     *        extensions WSP RPAREN      ; extensions
+     *
+     *  where:
+     *    <numericoid> is object identifier assigned to this matching rule;
+     *    NAME <qdescrs> are short names (descriptors) identifying this
+     *        matching rule;
+     *    DESC <qdstring> is a short descriptive string;
+     *    OBSOLETE indicates this matching rule is not active;
+     *    SYNTAX identifies the assertion syntax (the syntax of the assertion
+     *        value) by object identifier; and
+     *    <extensions> describe extensions.
+     * </pre>
+     * @param mr the MatchingRule to render the description for
+     * @return the StringBuffer containing the rendered matchingRule description
+     * @throws NamingException if there are problems accessing the objects
+     * associated with the MatchingRule.
+     */
+    public static StringBuffer render( MatchingRule mr ) throws NamingException
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( mr.getOid() ).append( " NAME " );
+        render( buf, mr.getNames() ).append( " " );
+
+        if ( mr.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( mr.getDescription() ).append( "'
" );
+        }
+
+        if ( mr.isObsolete() )
+        {
+            buf.append( " OBSOLETE" );
+        }
+
+        if ( mr.getSyntax() != null )
+        {
+            buf.append( " SYNTAX " ).append( mr.getSyntax().getOid() );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * Renders a Syntax into a new StringBuffer according to the LDAP Syntax
+     * Description Syntax 1.3.6.1.4.1.1466.115.121.1.54.  The syntax is
+     * described in detail within section 4.1.5. of LDAPBIS
+     * [<a href="http://ietf.org/internet-drafts/draft-ietf-ldapbis-models-12.txt">MODELS</a>]
+     * which is replicated here for convenience:
+     * <pre>
+     * LDAP syntax definitions are written according to the ABNF:
+     *
+     *  SyntaxDescription = LPAREN WSP
+     *      numericoid                 ; object identifier
+     *      [ SP "DESC" SP qdstring ]  ; description
+     *      extensions WSP RPAREN      ; extensions
+     *
+     * where:
+     *  <numericoid> is the object identifier assigned to this LDAP syntax;
+     *  DESC <qdstring> is a short descriptive string; and
+     *  <extensions> describe extensions.
+     * </pre>
+     * @param syntax the Syntax to render the description for
+     * @return the StringBuffer containing the rendered syntax description
+     */
+    public static StringBuffer render( Syntax syntax )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( syntax.getOid() ).append( " NAME " );
+        render( buf, syntax.getNames() ).append( " " );
+
+        if ( syntax.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( syntax.getDescription() ).append(
"' " );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * NOT FULLY IMPLEMENTED!
+     */
+    public static StringBuffer render( MatchingRuleUse mru )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( mru.getOid() ).append( " NAME " );
+        render( buf, mru.getNames() ).append( " " );
+
+        if ( mru.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( mru.getDescription() ).append( "'
" );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * NOT FULLY IMPLEMENTED!
+     */
+    public static StringBuffer render( DITContentRule dcr )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( dcr.getOid() ).append( " NAME " );
+        render( buf, dcr.getNames() ).append( " " );
+
+        if ( dcr.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( dcr.getDescription() ).append( "'
" );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * NOT FULLY IMPLEMENTED!
+     */
+    public static StringBuffer render( DITStructureRule dsr )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( dsr.getOid() ).append( " NAME " );
+        render( buf, dsr.getNames() ).append( " " );
+
+        if ( dsr.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( dsr.getDescription() ).append( "'
" );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+
+
+    /**
+     * NOT FULLY IMPLEMENTED!
+     */
+    public static StringBuffer render( NameForm nf )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "( " ).append( nf.getOid() ).append( " NAME " );
+        render( buf, nf.getNames() ).append( " " );
+
+        if ( nf.getDescription() != null )
+        {
+            buf.append( "DESC " ).append( "'" ).append( nf.getDescription() ).append( "'
" );
+        }
+
+        // @todo extensions are not presently supported and skipped
+        // the extensions would go here before closing off the description
+
+        buf.append( " )" );
+
+        return buf;
+    }
+}

Added: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/schema/SchemaUtilsTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/schema/SchemaUtilsTest.java?view=auto&rev=109874
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/schema/SchemaUtilsTest.java
Sun Dec  5 00:10:46 2004
@@ -0,0 +1,281 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.common.schema;
+
+
+import java.util.Comparator;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+import org.apache.ldap.common.NotImplementedException;
+
+
+/**
+ * The unit tests for methods on SchemaUtils.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SchemaUtilsTest extends TestCase
+{
+    public static Syntax[] getSyntaxes()
+    {
+        SyntaxImpl[] syntaxes = new SyntaxImpl[3];
+        syntaxes[0] = new SyntaxImpl( "1.3.6.1.4.1.1466.115.121.1.12",
+                "DN syntax", true );
+        syntaxes[1] = new SyntaxImpl( "1.3.6.1.4.1.1466.115.121.1.15",
+                "Directory String syntax", true );
+        syntaxes[2] = new SyntaxImpl( "1.3.6.1.4.1.1466.115.121.1.58",
+                "Substring assertion syntax", true );
+        return syntaxes;
+    }
+
+
+    public static MatchingRule[] getMatchingRules()
+    {
+        MatchingRuleImpl[] mrs = new MatchingRuleImpl[3];
+        mrs[0] = new MatchingRuleImpl( "2.5.13.2", getSyntaxes()[1] );
+        mrs[0].setNames( new String[] { "caseIgnoreMatch" } );
+        mrs[0].setDescription( "Ignores case in strings" );
+
+        mrs[1] = new MatchingRuleImpl( "2.5.13.4", getSyntaxes()[2] );
+        mrs[1].setNames( new String[] { "caseIgnoreSubstringsMatch" } );
+        mrs[1].setDescription( "Ignores case in substrings" );
+
+        mrs[2] = new MatchingRuleImpl( "2.5.13.1", getSyntaxes()[0] );
+        mrs[2].setNames( new String[] { "distinguishedNameMatch" } );
+        mrs[2].setDescription( "distinguishedNameMatch" );
+
+        return mrs;
+    }
+
+
+    public AttributeType[] getAttributeTypes()
+    {
+        AttributeTypeImpl[] ats = new AttributeTypeImpl[5];
+
+        ats[0] = new AttributeTypeImpl( "2.5.4.41" );
+        ats[0].setNames( new String[] { "name" } );
+        ats[0].syntax = getSyntaxes()[1];
+        ats[0].setLength( 32768 );
+        ats[0].equality = getMatchingRules()[0];
+        ats[0].substr = getMatchingRules()[1];
+
+        // ( 2.5.4.3 NAME 'cn' SUP name )
+        ats[1] = new AttributeTypeImpl( "2.5.4.3" );
+        ats[1].setNames( new String[] { "cn", "commonName" } );
+
+        ats[2] = new AttributeTypeImpl( "2.5.4.41" );
+        ats[2].setNames( new String[] { "name" } );
+        ats[2].syntax = getSyntaxes()[1];
+        ats[2].setLength( 32768 );
+        ats[2].equality = getMatchingRules()[0];
+        ats[2].substr = getMatchingRules()[1];
+
+        ats[3] = new AttributeTypeImpl( "2.5.4.41" );
+        ats[3].setNames( new String[] { "name" } );
+        ats[3].syntax = getSyntaxes()[1];
+        ats[3].setLength( 32768 );
+        ats[3].equality = getMatchingRules()[0];
+        ats[3].substr = getMatchingRules()[1];
+
+        ats[4] = new AttributeTypeImpl( "2.5.4.41" );
+        ats[4].setNames( new String[] { "name" } );
+        ats[4].syntax = getSyntaxes()[1];
+        ats[4].setLength( 32768 );
+        ats[4].equality = getMatchingRules()[0];
+        ats[4].substr = getMatchingRules()[1];
+
+        return ats;
+    }
+
+
+    public ObjectClass[] getObjectClasses()
+    {
+        /*
+            objectclass ( 2.5.6.2 NAME 'country'
+            DESC 'RFC2256: a country'
+            SUP top STRUCTURAL
+            MUST c
+            MAY ( searchGuide $ description ) )
+         */
+
+        DefaultObjectClass[] ocs = new DefaultObjectClass[2];
+        ocs[0] = new DefaultObjectClass( "1.1" );
+        ocs[0].setNames( new String[] { "oc1" } );
+        ocs[0].setDescription( "object class #1" );
+        ocs[0].setObsolete( false );
+        ocs[0].setType( ObjectClassTypeEnum.ABSTRACT );
+
+        /*
+            objectclass ( 2.5.6.6 NAME 'person'
+            DESC 'RFC2256: a person'
+            SUP top STRUCTURAL
+            MUST ( sn $ cn )
+            MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) )
+        */
+
+        return ocs;
+    }
+
+
+    /**
+     * Tests rendering operations on qdescrs render method.  Both overloaded
+     * operations {@link SchemaUtils#render(StringBuffer, String[])} and
+     * {@link SchemaUtils#render(String[])} are tested here.
+     */
+    public void testRenderQdescrs()
+    {
+        assertEquals( "", SchemaUtils.render( ( String[] ) null ).toString() ) ;
+        assertEquals( "", SchemaUtils.render( new String[] {} ).toString() ) ;
+        assertEquals( "'name1'", SchemaUtils.render( new String[] { "name1" } ).toString()
) ;
+        assertEquals( "( 'name1' 'name2' )", SchemaUtils.render( new String[] { "name1",
"name2" } ).toString() ) ;
+        assertEquals( "( 'name1' 'name2' 'name3' )", SchemaUtils.render( new String[] { "name1",
"name2", "name3" } ).toString() ) ;
+
+        StringBuffer buf = new StringBuffer();
+        assertEquals( "", SchemaUtils.render( buf, ( String[] ) null ).toString() ) ;
+
+        buf = new StringBuffer();
+        assertEquals( "", SchemaUtils.render( new String[] {} ).toString() ) ;
+
+        buf = new StringBuffer();
+        assertEquals( "'name1'", SchemaUtils.render( new String[] { "name1" } ).toString()
) ;
+
+        buf = new StringBuffer();
+        assertEquals( "( 'name1' 'name2' )", SchemaUtils.render( new String[] { "name1",
"name2" } ).toString() ) ;
+
+        buf = new StringBuffer();
+        assertEquals( "( 'name1' 'name2' 'name3' )", SchemaUtils.render( new String[] { "name1",
"name2", "name3" } ).toString() ) ;
+    }
+
+
+    public void testRenderObjectClassArray()
+    {
+    }
+
+
+    // --------------------
+
+
+    static class SyntaxImpl extends AbstractSyntax
+    {
+        protected SyntaxImpl( String oid )
+        {
+            super( oid );
+        }
+
+
+        protected SyntaxImpl( String oid, boolean isHumanReadible )
+        {
+            super( oid, isHumanReadible );
+        }
+
+
+        protected SyntaxImpl( String oid, String description )
+        {
+            super( oid, description );
+        }
+
+
+        protected SyntaxImpl( String oid, String description, boolean isHumanReadible )
+        {
+            super(oid,description,isHumanReadible);
+        }
+
+
+        public SyntaxChecker getSyntaxChecker() throws NamingException
+        {
+            return null;
+        }
+    }
+
+
+    static class AttributeTypeImpl extends AbstractAttributeType
+    {
+        Syntax syntax;
+        AttributeType sup;
+        MatchingRule equality;
+        MatchingRule ordering;
+        MatchingRule substr;
+
+
+        public AttributeTypeImpl( String oid )
+        {
+            super(oid);
+        }
+
+
+        public AttributeType getSuperior() throws NamingException
+        {
+            return sup;
+        }
+
+
+        public Syntax getSyntax() throws NamingException
+        {
+            return syntax;
+        }
+
+
+        public MatchingRule getEquality() throws NamingException
+        {
+            return equality;
+        }
+
+
+        public MatchingRule getOrdering() throws NamingException
+        {
+            return ordering;
+        }
+
+
+        public MatchingRule getSubstr() throws NamingException
+        {
+            return substr;
+        }
+    }
+
+
+    static class MatchingRuleImpl extends AbstractMatchingRule
+    {
+        Syntax syntax;
+
+        protected MatchingRuleImpl( String oid, Syntax syntax )
+        {
+            super(oid);
+            this.syntax = syntax;
+        }
+
+
+        public Syntax getSyntax() throws NamingException
+        {
+            return syntax;
+        }
+
+
+        public Comparator getComparator() throws NamingException
+        {
+            throw new NotImplementedException( "getComparator in org.apache.ldap.common.schema.SchemaUtilsTest.MatchingRuleImpl
not implemented!" );
+        }
+
+
+        public Normalizer getNormalizer() throws NamingException
+        {
+            throw new NotImplementedException( "getNormalizer in org.apache.ldap.common.schema.SchemaUtilsTest.MatchingRuleImpl
not implemented!" );
+        }
+    }
+}

Mime
View raw message