Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 23183 invoked from network); 25 Jul 2007 02:44:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Jul 2007 02:44:41 -0000 Received: (qmail 66452 invoked by uid 500); 25 Jul 2007 02:44:42 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66424 invoked by uid 500); 25 Jul 2007 02:44:42 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 66413 invoked by uid 99); 25 Jul 2007 02:44:41 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jul 2007 19:44:41 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jul 2007 19:44:40 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CE6881A981D; Tue, 24 Jul 2007 19:44:19 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r559290 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java Date: Wed, 25 Jul 2007 02:44:19 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070725024419.CE6881A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Tue Jul 24 19:44:18 2007 New Revision: 559290 URL: http://svn.apache.org/viewvc?view=rev&rev=559290 Log: adding similar code to render(AttributeType) which converts a AttributeTypeDescription into the text for such a description according to the syntax defined for atds Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java?view=diff&rev=559290&r1=559289&r2=559290 ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java Tue Jul 24 19:44:18 2007 @@ -21,6 +21,7 @@ import java.util.List; +import java.util.Map; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -32,6 +33,7 @@ import org.apache.directory.shared.ldap.message.ModificationItemImpl; import org.apache.directory.shared.ldap.schema.syntax.AbstractAdsSchemaDescription; import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription; +import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription; /** @@ -609,6 +611,197 @@ // the extensions would go here before closing off the description buf.append( " )" ); + + return buf; + } + + + /** + * Renders an attributeType description object into a new StringBuffer + * according to the Attribute Type Description Syntax defined in MODELS + * 1.3.6.1.4.1.1466.115.121.1.3. The syntax is described in detail within + * section 4.1.2. of (@TODO NEEDS TO CHANGE SINCE THIS IS NOW AN RFC) LDAPBIS [MODELS] + * which is replicated here for convenience: + * + *
+     *  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.
+     * 
+ * @param atd the AttributeTypeDescription 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( AttributeTypeDescription atd ) throws NamingException + { + StringBuffer buf = new StringBuffer(); + buf.append( "( " ).append( atd.getNumericOid() ); + + if ( atd.getNames() != null && atd.getNames().size() > 0 ) + { + buf.append( " NAME " ); + render( buf, atd.getNames().toArray( new String[ atd.getNames().size() ]) ).append( " " ); + } + else + { + buf.append( " " ); + } + + if ( atd.getDescription() != null ) + { + buf.append( "DESC " ).append( "'" ).append( atd.getDescription() ).append( "' " ); + } + + if ( atd.isObsolete() ) + { + buf.append( " OBSOLETE" ); + } + + if ( atd.getSuperType() != null ) + { + buf.append( " SUP " ).append( atd.getSuperType() ); + } + + if ( atd.getEqualityMatchingRule() != null ) + { + buf.append( " EQUALITY " ).append( atd.getEqualityMatchingRule() ); + } + + if ( atd.getOrderingMatchingRule() != null ) + { + buf.append( " ORDERING " ).append( atd.getOrderingMatchingRule() ); + } + + if ( atd.getSubstringsMatchingRule() != null ) + { + buf.append( " SUBSTR " ).append( atd.getSubstringsMatchingRule() ); + } + + if ( atd.getSyntax() != null ) + { + buf.append( " SYNTAX " ).append( atd.getSyntax() ); + + if ( atd.getSyntaxLength() > 0 ) + { + buf.append( "{" ).append( atd.getSyntaxLength() ).append( "}" ); + } + } + + if ( atd.isSingleValued() ) + { + buf.append( " SINGLE-VALUE" ); + } + + if ( atd.isCollective() ) + { + buf.append( " COLLECTIVE" ); + } + + if ( !atd.isUserModifiable() ) + { + buf.append( " NO-USER-MODIFICATION" ); + } + + if ( atd.getUsage() != null ) + { + buf.append( " USAGE " ).append( UsageEnum.render( atd.getUsage() ) ); + } + + return buf.append( render( atd.getExtensions() ) ).append( ")" ); + } + + + /** + * Renders the schema extensions into a new StringBuffer. + * + * @param extensions the schema extensions map with key and values + * @return a StringBuffer with the extensions component of a syntax description + */ + public static StringBuffer render( Map> extensions ) + { + StringBuffer buf = new StringBuffer(); + + if ( extensions.isEmpty() ) + { + return buf; + } + + for ( String key : extensions.keySet() ) + { + buf.append( " " ).append( key ).append( " " ); + + List values = extensions.get( key ); + + // For extensions without values like X-IS-HUMAN-READIBLE + if ( values == null || values.isEmpty() ) + { + continue; + } + + // For extensions with a single value we can use one qdstring like 'value' + if ( values.size() == 1 ) + { + buf.append( "'" ).append( values.get( 0 ) ).append( "' " ); + continue; + } + + // For extensions with several values we have to surround whitespace + // separated list of qdstrings like ( 'value0' 'value1' 'value2' ) + buf.append( "( " ); + for ( String value : values ) + { + buf.append( "'" ).append( value ).append( "' " ); + } + buf.append( ")" ); + } + + if ( buf.charAt( buf.length() - 1 ) != ' ' ) + { + buf.append( " " ); + } return buf; }