You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2013/11/27 23:04:35 UTC
svn commit: r1546208 - in /directory/shared/trunk/ldap/model/src:
main/java/org/apache/directory/api/ldap/model/schema/
test/java/org/apache/directory/api/ldap/model/schema/
Author: seelmann
Date: Wed Nov 27 22:04:34 2013
New Revision: 1546208
URL: http://svn.apache.org/r1546208
Log:
* Moved utilities to render MatchingRule and LdapSyntax to SchemaObjectRenderer class
* Removed redundant schema object render implementations
Added:
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/LdapSyntaxTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUseTest.java
Modified:
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DescriptionUtils.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapSyntax.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRule.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUse.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MutableMatchingRule.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRenderer.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaUtils.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/AttributeTypeTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/ObjectClassTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRendererTest.java
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DescriptionUtils.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DescriptionUtils.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DescriptionUtils.java Wed Nov 27 22:04:34 2013
@@ -265,158 +265,6 @@ public final class DescriptionUtils
/**
- * Generates the MatchingRuleDescription for a MatchingRule as defined by
- * the syntax: 1.3.6.1.4.1.1466.115.121.1.30. Only the right hand side of
- * the description starting at the opening parenthesis is generated: that
- * is 'MatchingRuleDescription = ' is not generated.
- *
- * <pre>
- * MatchingRuleDescription = "(" whsp
- * numericoid whsp ; MatchingRule object identifier
- * [ "NAME" qdescrs ]
- * [ "DESC" qdstring ]
- * [ "OBSOLETE" whsp ]
- * "SYNTAX" numericoid
- * whsp ")"
- * </pre>
- *
- * @param matchingRule
- * the MatchingRule to generate the description for
- * @return the MatchingRuleDescription string
- */
- public static String getDescription( MatchingRule matchingRule )
- {
- StringBuilder buf = new StringBuilder( "( " );
- buf.append( matchingRule.getOid() );
- buf.append( '\n' );
-
- if ( matchingRule.getNames() != null )
- {
- buf.append( " NAME " );
- getQDescrs( buf, matchingRule.getNames() );
- }
-
- if ( matchingRule.getDescription() != null )
- {
- buf.append( " DESC " );
- buf.append( matchingRule.getDescription() );
- buf.append( '\n' );
- }
-
- if ( matchingRule.isObsolete() )
- {
- buf.append( " OBSOLETE\n" );
- }
-
- buf.append( " SYNTAX " );
- buf.append( matchingRule.getSyntaxOid() );
- buf.append( '\n' );
-
- if ( matchingRule.getExtensions() != null )
- {
- getExtensions( buf, matchingRule.getExtensions() );
- }
-
- buf.append( " ) " );
- return buf.toString();
- }
-
-
- /**
- * Generates the MatchingRuleUseDescription for a MatchingRuleUse as defined
- * by the syntax: 1.3.6.1.4.1.1466.115.121.1.31. Only the right hand side of
- * the description starting at the opening parenthesis is generated: that
- * is 'MatchingRuleUseDescription = ' is not generated.
- *
- * <pre>
- * MatchingRuleUseDescription = LPAREN WSP
- * numericoid ; object identifier
- * [ SP "NAME" SP qdescrs ] ; short names (descriptors)
- * [ SP "DESC" SP qdstring ] ; description
- * [ SP "OBSOLETE" ] ; not active
- * SP "APPLIES" SP oids ; attribute types
- * extensions WSP RPAREN ; extensions
- *
- * where:
- * [numericoid] is the object identifier of the matching rule
- * associated with this matching rule use description;
- * NAME [qdescrs] are short names (descriptors) identifying this
- * matching rule use;
- * DESC [qdstring] is a short descriptive string;
- * OBSOLETE indicates this matching rule use is not active;
- * APPLIES provides a list of attribute types the matching rule applies
- * to; and
- * [extensions] describe extensions.
- * </pre>
- *
- * @param matchingRuleUse The matching rule from which we want to generate
- * a MatchingRuleUseDescription.
- * @return The generated MatchingRuleUseDescription
- */
- public static String getDescription( MatchingRuleUse matchingRuleUse )
- {
- StringBuilder buf = new StringBuilder( "( " );
- buf.append( matchingRuleUse.getOid() );
- buf.append( '\n' );
-
- buf.append( " NAME " );
- getQDescrs( buf, matchingRuleUse.getNames() );
-
- if ( matchingRuleUse.getDescription() != null )
- {
- buf.append( " DESC " );
- buf.append( matchingRuleUse.getDescription() );
- buf.append( '\n' );
- }
-
- if ( matchingRuleUse.isObsolete() )
- {
- buf.append( " OBSOLETE\n" );
- }
-
- buf.append( " APPLIES " );
- List<AttributeType> attributeTypes = matchingRuleUse.getApplicableAttributes();
-
- if ( attributeTypes.size() == 1 )
- {
- buf.append( attributeTypes.get( 0 ).getOid() );
- }
- else
- // for list of oids we need a parenthesis
- {
- buf.append( "( " );
-
- boolean isFirst = true;
-
- for ( AttributeType attributeType : attributeTypes )
- {
- if ( isFirst )
- {
- isFirst = false;
- }
- else
- {
- buf.append( " $ " );
- }
-
- buf.append( attributeType );
- }
-
- buf.append( " ) " );
- }
-
- if ( matchingRuleUse.getExtensions() != null )
- {
- getExtensions( buf, matchingRuleUse.getExtensions() );
- }
-
- buf.append( " )\n" );
-
- return buf.toString();
- }
-
-
- /**
* Generates the NameFormDescription for a NameForm as defined by the
* syntax: 1.3.6.1.4.1.1466.115.121.1.35. Only the right hand side of the
* description starting at the opening parenthesis is generated: that is
@@ -515,47 +363,6 @@ public final class DescriptionUtils
/**
- * Generates the SyntaxDescription for a Syntax as defined by the syntax:
- * 1.3.6.1.4.1.1466.115.121.1.54. Only the right hand side of the
- * description starting at the opening parenthesis is generated: that is
- * 'SyntaxDescription = ' is not generated.
- *
- * <pre>
- * SyntaxDescription = "(" whsp
- * numericoid whsp
- * [ "DESC" qdstring ]
- * [ extensions ]
- * whsp ")"
- * </pre>
- *
- * @param syntax
- * the Syntax to generate a description for
- * @return the description in the SyntaxDescription syntax
- */
- public static String getDescription( LdapSyntax syntax )
- {
- StringBuilder buf = new StringBuilder( "( " );
- buf.append( syntax.getOid() );
- buf.append( '\n' );
-
- if ( syntax.getDescription() != null )
- {
- buf.append( " DESC " );
- buf.append( syntax.getDescription() );
- buf.append( '\n' );
- }
-
- if ( syntax.getExtensions() != null )
- {
- getExtensions( buf, syntax.getExtensions() );
- }
-
- buf.append( " )" );
- return buf.toString();
- }
-
-
- /**
* Generates the SyntaxCheckerDescription for a SyntaxChecker. Only the right
* hand side of the description starting at the opening parenthesis is
* generated: that is 'SyntaxCheckerDescription = ' is not generated.
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapSyntax.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapSyntax.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapSyntax.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/LdapSyntax.java Wed Nov 27 22:04:34 2013
@@ -257,7 +257,7 @@ public class LdapSyntax extends Abstract
@Override
public String toString()
{
- return objectType + " " + DescriptionUtils.getDescription( this );
+ return SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( this );
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRule.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRule.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRule.java Wed Nov 27 22:04:34 2013
@@ -152,7 +152,7 @@ public class MatchingRule extends Abstra
*/
public String toString()
{
- return objectType + " " + DescriptionUtils.getDescription( this );
+ return SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( this );
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUse.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUse.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUse.java Wed Nov 27 22:04:34 2013
@@ -213,7 +213,7 @@ public class MatchingRuleUse extends Abs
*/
public String toString()
{
- return objectType + " " + DescriptionUtils.getDescription( this );
+ return SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( this );
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MutableMatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MutableMatchingRule.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MutableMatchingRule.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/MutableMatchingRule.java Wed Nov 27 22:04:34 2013
@@ -219,15 +219,6 @@ public class MutableMatchingRule extends
/**
- * @see Object#toString()
- */
- public String toString()
- {
- return objectType + " " + DescriptionUtils.getDescription( this );
- }
-
-
- /**
* {@inheritDoc}
*/
public void clear()
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRenderer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRenderer.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRenderer.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRenderer.java Wed Nov 27 22:04:34 2013
@@ -347,6 +347,162 @@ public class SchemaObjectRenderer
}
+ /**
+ * Renders an matchingRule 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.
+ * <a href="https://tools.ietf.org/rfc/rfc4512.txt">RFC 4512</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 LdapException if there are problems accessing the objects
+ * associated with the MatchingRule.
+ */
+ public String render( MatchingRule mr )
+ {
+ StringBuilder buf = renderStartOidNamesDescObsolete( mr, "matchingrule" );
+
+ prettyPrintIndent( buf );
+ buf.append( "SYNTAX " ).append( mr.getSyntaxOid() );
+ prettyPrintNewLine( buf );
+
+ renderXSchemaName( mr, buf );
+
+ // @todo extensions are not presently supported and skipped
+ // the extensions would go here before closing off the description
+
+ buf.append( ")" );
+
+ return buf.toString();
+ }
+
+
+ /**
+ * Renders a Syntax 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
+ * <a href="https://tools.ietf.org/rfc/rfc4512.txt">RFC 4512</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 String render( LdapSyntax syntax )
+ {
+ StringBuilder buf = new StringBuilder();
+
+ if ( style.startWithSchemaType )
+ {
+ buf.append( "ldapsyntax " );
+ }
+
+ buf.append( "( " ).append( syntax.getOid() );
+ prettyPrintNewLine( buf );
+
+ if ( syntax.getDescription() != null )
+ {
+ prettyPrintIndent( buf );
+ buf.append( "DESC " );
+ renderQDString( buf, syntax.getDescription() );
+ prettyPrintNewLine( buf );
+ }
+
+ renderXSchemaName( syntax, buf );
+
+ prettyPrintIndent( buf );
+ if ( syntax.isHumanReadable() )
+ {
+ buf.append( "X-NOT-HUMAN-READABLE 'false'" );
+ }
+ else
+ {
+ buf.append( "X-NOT-HUMAN-READABLE 'true'" );
+ }
+ prettyPrintNewLine( buf );
+
+ // @todo extensions are not presently supported and skipped
+ // the extensions would go here before closing off the description
+
+ buf.append( ")" );
+
+ return buf.toString();
+ }
+
+
+ /**
+ * NOT FULLY IMPLEMENTED!
+ */
+ public String render( MatchingRuleUse mru )
+ {
+ StringBuilder buf = renderStartOidNamesDescObsolete( mru, "matchingruleuse" );
+
+ List<String> applies = mru.getApplicableAttributeOids();
+
+ if ( ( applies != null ) && ( applies.size() > 0 ) )
+ {
+ prettyPrintIndent( buf );
+ buf.append( "APPLIES " );
+ renderOids( buf, applies );
+ prettyPrintNewLine( buf );
+ }
+
+ renderXSchemaName( mru, buf );
+
+ // @todo extensions are not presently supported and skipped
+ // the extensions would go here before closing off the description
+
+ buf.append( ")" );
+
+ return buf.toString();
+ }
+
+
private StringBuilder renderStartOidNamesDescObsolete( SchemaObject so, String schemaObjectType )
{
StringBuilder buf = new StringBuilder();
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaUtils.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaUtils.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/SchemaUtils.java Wed Nov 27 22:04:34 2013
@@ -462,192 +462,6 @@ public final class SchemaUtils
/**
- * 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 LdapException if there are problems accessing the objects
- * associated with the MatchingRule.
- */
- public static StringBuffer render( MatchingRule mr ) throws LdapException
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "( " ).append( mr.getOid() );
-
- List<String> names = mr.getNames();
-
- if ( ( names != null ) && ( names.size() > 0 ) )
- {
- buf.append( " NAME " );
- renderQDescrs( buf, names );
- }
-
- if ( mr.getDescription() != null )
- {
- buf.append( " DESC " );
- renderQDString( buf, mr.getDescription() );
- }
-
- if ( mr.isObsolete() )
- {
- buf.append( " OBSOLETE" );
- }
-
- buf.append( " SYNTAX " ).append( mr.getSyntax().getOid() );
-
- buf.append( " X-SCHEMA '" );
- buf.append( mr.getSchemaName() );
- buf.append( "'" );
-
- // @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( LdapSyntax syntax )
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "( " ).append( syntax.getOid() );
-
- if ( syntax.getDescription() != null )
- {
- buf.append( " DESC " );
- renderQDString( buf, syntax.getDescription() );
- }
-
- buf.append( " X-SCHEMA '" );
- buf.append( syntax.getSchemaName() );
-
- if ( syntax.isHumanReadable() )
- {
- buf.append( "' X-NOT-HUMAN-READABLE 'false'" );
- }
- else
- {
- buf.append( "' X-NOT-HUMAN-READABLE 'true'" );
- }
-
- // @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() );
-
- List<String> names = mru.getNames();
-
- if ( ( names != null ) && ( names.size() > 0 ) )
- {
- buf.append( " NAME " );
- renderQDescrs( buf, names );
- }
-
- if ( mru.getDescription() != null )
- {
- buf.append( " DESC " );
- renderQDString( buf, mru.getDescription() );
- }
-
- if ( mru.isObsolete )
- {
- buf.append( " OBSOLETE" );
- }
-
- List<String> applies = mru.getApplicableAttributeOids();
-
- if ( ( applies != null ) && ( applies.size() > 0 ) )
- {
- buf.append( " APPLIES " );
- renderOids( buf, applies );
- }
-
- buf.append( " X-SCHEMA '" );
- buf.append( mru.getSchemaName() );
- buf.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 )
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/AttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/AttributeTypeTest.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/AttributeTypeTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/AttributeTypeTest.java Wed Nov 27 22:04:34 2013
@@ -61,14 +61,13 @@ public class AttributeTypeTest
@Test
public void testToString() throws Exception
{
- String string1 = attributeType.toString();
- System.out.println( string1 );
+ String string = attributeType.toString();
- assertNotNull( string1 );
- assertTrue( string1.startsWith( "attributetype (" ) );
- assertTrue( string1.contains( " NAME " ) );
- assertTrue( string1.contains( "\n\tDESC " ) );
- assertTrue( string1.contains( "\n\tSUP " ) );
- assertTrue( string1.contains( "\n\tUSAGE" ) );
+ assertNotNull( string );
+ assertTrue( string.startsWith( "attributetype (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tSUP " ) );
+ assertTrue( string.contains( "\n\tUSAGE" ) );
}
}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/LdapSyntaxTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/LdapSyntaxTest.java?rev=1546208&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/LdapSyntaxTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/LdapSyntaxTest.java Wed Nov 27 22:04:34 2013
@@ -0,0 +1,68 @@
+/*
+ * 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.api.ldap.model.schema;
+
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Unit tests class LdapSyntax.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class LdapSyntaxTest
+{
+ private LdapSyntax ldapSyntax;
+
+
+ /**
+ * Initialize ldap syntax use instances
+ */
+ @Before
+ public void initMatchingRuleUses() throws Exception
+ {
+ ldapSyntax = new LdapSyntax( "1.2.3.4" );
+ ldapSyntax.setDescription( "description" );
+ ldapSyntax.setHumanReadable( true );
+ }
+
+
+ @Test
+ public void testToString() throws Exception
+ {
+ String string = ldapSyntax.toString();
+
+ assertNotNull( string );
+ assertTrue( string.startsWith( "ldapsyntax (" ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tX-NOT-HUMAN-READABLE " ) );
+ }
+}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleTest.java?rev=1546208&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleTest.java Wed Nov 27 22:04:34 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.api.ldap.model.schema;
+
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Unit tests class MatchingRule.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class MatchingRuleTest
+{
+ private MutableMatchingRule matchingRule;
+
+
+ /**
+ * Initialize matching rule instances
+ */
+ @Before
+ public void initMatchingRules() throws Exception
+ {
+ matchingRule = new MutableMatchingRule( "1.2.3.4" );
+ matchingRule.setNames( "name1", "name2" );
+ matchingRule.setDescription( "description" );
+ matchingRule.setObsolete( false );
+ matchingRule.setSyntaxOid( "2.3.4.5" );
+ }
+
+
+ @Test
+ public void testToString() throws Exception
+ {
+ String string = matchingRule.toString();
+
+ assertNotNull( string );
+ assertTrue( string.startsWith( "matchingrule (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tSYNTAX " ) );
+ }
+}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUseTest.java?rev=1546208&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUseTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/MatchingRuleUseTest.java Wed Nov 27 22:04:34 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.api.ldap.model.schema;
+
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Unit tests class MatchingRuleUse.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class MatchingRuleUseTest
+{
+ private MatchingRuleUse matchingRuleUse;
+
+
+ /**
+ * Initialize matching rule use instances
+ */
+ @Before
+ public void initMatchingRuleUses() throws Exception
+ {
+ matchingRuleUse = new MatchingRuleUse( "1.2.3.4" );
+ matchingRuleUse.setNames( "name1", "name2" );
+ matchingRuleUse.setDescription( "description" );
+ matchingRuleUse.setObsolete( false );
+ matchingRuleUse.setApplicableAttributeOids( Arrays.asList( "2.3.4.5" ) );
+ }
+
+
+ @Test
+ public void testToString() throws Exception
+ {
+ String string = matchingRuleUse.toString();
+
+ assertNotNull( string );
+ assertTrue( string.startsWith( "matchingruleuse (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tAPPLIES " ) );
+ }
+}
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/ObjectClassTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/ObjectClassTest.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/ObjectClassTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/ObjectClassTest.java Wed Nov 27 22:04:34 2013
@@ -141,16 +141,16 @@ public class ObjectClassTest
@Test
public void testToString() throws Exception
{
- String string1 = objectClass.toString();
+ String string = objectClass.toString();
- assertNotNull( string1 );
- assertTrue( string1.startsWith( "objectclass (" ) );
- assertTrue( string1.contains( " NAME " ) );
- assertTrue( string1.contains( "\n\tDESC " ) );
- assertTrue( string1.contains( "\n\tSUP " ) );
- assertTrue( string1.contains( "\n\tSTRUCTURAL" ) );
- assertTrue( string1.contains( "\n\tMUST" ) );
- assertTrue( string1.contains( "\n\tMAY" ) );
- assertTrue( string1.endsWith( "\n)" ) );
+ assertNotNull( string );
+ assertTrue( string.startsWith( "objectclass (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tSUP " ) );
+ assertTrue( string.contains( "\n\tSTRUCTURAL" ) );
+ assertTrue( string.contains( "\n\tMUST" ) );
+ assertTrue( string.contains( "\n\tMAY" ) );
+ assertTrue( string.endsWith( "\n)" ) );
}
}
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRendererTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRendererTest.java?rev=1546208&r1=1546207&r2=1546208&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRendererTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/SchemaObjectRendererTest.java Wed Nov 27 22:04:34 2013
@@ -27,11 +27,15 @@ import java.util.Arrays;
import java.util.Collections;
import org.apache.directory.api.ldap.model.schema.parsers.AttributeTypeDescriptionSchemaParser;
+import org.apache.directory.api.ldap.model.schema.parsers.LdapSyntaxDescriptionSchemaParser;
+import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleDescriptionSchemaParser;
+import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleUseDescriptionSchemaParser;
import org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser;
import org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser;
import org.junit.Before;
import org.junit.Test;
+
/**
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -45,6 +49,10 @@ public class SchemaObjectRendererTest
private MutableAttributeType attributeTypeSimple;
private MutableAttributeType attributeTypeComplex;
+ private MutableMatchingRule matchingRule;
+ private MatchingRuleUse matchingRuleUse;
+ private LdapSyntax ldapSyntax;
+
@Before
public void setUp()
@@ -84,6 +92,26 @@ public class SchemaObjectRendererTest
attributeTypeComplex.setUserModifiable( false );
attributeTypeComplex.setUsage( UsageEnum.DIRECTORY_OPERATION );
attributeTypeComplex.setSchemaName( "dummy" );
+
+ matchingRule = new MutableMatchingRule( "1.2.3.4" );
+ matchingRule.setNames( "name0" );
+ matchingRule.setDescription( "description with 'quotes'" );
+ matchingRule.setObsolete( true );
+ matchingRule.setSyntaxOid( "2.3.4.5" );
+ matchingRule.setSchemaName( "dummy" );
+
+ matchingRuleUse = new MatchingRuleUse( "1.2.3.4" );
+ matchingRuleUse.setNames( "name0" );
+ matchingRuleUse.setDescription( "description with 'quotes'" );
+ matchingRuleUse.setObsolete( true );
+ matchingRuleUse.setApplicableAttributeOids( Arrays.asList( "2.3.4.5", "3.4.5.6" ) );
+ matchingRuleUse.setSchemaName( "dummy" );
+
+ ldapSyntax = new LdapSyntax( "1.2.3.4" );
+ ldapSyntax.setDescription( "description with 'quotes'" );
+ ldapSyntax.setHumanReadable( false );
+ ldapSyntax.setSchemaName( "dummy" );
+
}
@@ -281,4 +309,112 @@ public class SchemaObjectRendererTest
assertTrue( original.equals( parsed ) );
assertTrue( renderedOriginal.equals( renderedParsed ) );
}
+
+
+ @Test
+ public void testOpenLdapSchemaRendererMatchingRule()
+ {
+ String actual = SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( matchingRule );
+ String expected = "matchingrule ( 1.2.3.4 NAME 'name0'\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tSYNTAX 2.3.4.5\n)";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererMatchingRule()
+ {
+ String actual = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( matchingRule );
+ String expected = "( 1.2.3.4 NAME 'name0' DESC 'description with \\27quotes\\27' OBSOLETE SYNTAX 2.3.4.5 X-SCHEMA 'dummy' )";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererAndParserRoundtripMatchingRule() throws ParseException
+ {
+ testSubschemSubentryRendererAndParserRoundtrip( matchingRule );
+ }
+
+
+ private void testSubschemSubentryRendererAndParserRoundtrip( MatchingRule original ) throws ParseException
+ {
+ String renderedOriginal = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( original );
+ MatchingRule parsed = new MatchingRuleDescriptionSchemaParser().parse( renderedOriginal );
+ String renderedParsed = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( parsed );
+
+ assertTrue( original.equals( parsed ) );
+ assertTrue( renderedOriginal.equals( renderedParsed ) );
+ }
+
+
+ @Test
+ public void testOpenLdapSchemaRendererLdapSyntax()
+ {
+ String actual = SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( ldapSyntax );
+ String expected = "ldapsyntax ( 1.2.3.4\n\tDESC 'description with \\27quotes\\27'\n\tX-NOT-HUMAN-READABLE 'true'\n)";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererLdapSyntax()
+ {
+ String actual = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( ldapSyntax );
+ String expected = "( 1.2.3.4 DESC 'description with \\27quotes\\27' X-SCHEMA 'dummy' X-NOT-HUMAN-READABLE 'true' )";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererAndParserRoundtripLdapSyntax() throws ParseException
+ {
+ testSubschemSubentryRendererAndParserRoundtrip( ldapSyntax );
+ }
+
+
+ private void testSubschemSubentryRendererAndParserRoundtrip( LdapSyntax original ) throws ParseException
+ {
+ String renderedOriginal = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( original );
+ LdapSyntax parsed = new LdapSyntaxDescriptionSchemaParser().parse( renderedOriginal );
+ String renderedParsed = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( parsed );
+
+ assertTrue( original.equals( parsed ) );
+ assertTrue( renderedOriginal.equals( renderedParsed ) );
+ }
+
+
+ @Test
+ public void testOpenLdapSchemaRendererMatchingRuleUse()
+ {
+ String actual = SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( matchingRuleUse );
+ String expected = "matchingruleuse ( 1.2.3.4 NAME 'name0'\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tAPPLIES ( 2.3.4.5 $ 3.4.5.6 )\n)";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererMatchingRuleUse()
+ {
+ String actual = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( matchingRuleUse );
+ String expected = "( 1.2.3.4 NAME 'name0' DESC 'description with \\27quotes\\27' OBSOLETE APPLIES ( 2.3.4.5 $ 3.4.5.6 ) X-SCHEMA 'dummy' )";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererAndParserRoundtripMatchingRuleUse() throws ParseException
+ {
+ testSubschemSubentryRendererAndParserRoundtrip( matchingRuleUse );
+ }
+
+
+ private void testSubschemSubentryRendererAndParserRoundtrip( MatchingRuleUse original ) throws ParseException
+ {
+ String renderedOriginal = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( original );
+ MatchingRuleUse parsed = new MatchingRuleUseDescriptionSchemaParser().parse( renderedOriginal );
+ String renderedParsed = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( parsed );
+
+ assertTrue( original.equals( parsed ) );
+ assertTrue( renderedOriginal.equals( renderedParsed ) );
+ }
}