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/12/03 21:21:37 UTC
svn commit: r1547566 - 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: Tue Dec 3 20:21:36 2013
New Revision: 1547566
URL: http://svn.apache.org/r1547566
Log:
* Moved utilities to render DitContentRule, DitStructureRule, and NameForm 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/DitContentRuleTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitStructureRuleTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/NameFormTest.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/DitContentRule.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitStructureRule.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/NameForm.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/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=1547566&r1=1547565&r2=1547566&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 Tue Dec 3 20:21:36 2013
@@ -81,263 +81,6 @@ public final class DescriptionUtils
/**
- * Generates the DITContentRuleDescription for a DitContentRule as defined
- * by the syntax: 1.3.6.1.4.1.1466.115.121.1.16. Only the right hand side of
- * the description starting at the opening parenthesis is generated: that
- * is 'DITContentRuleDescription = ' is not generated.
- *
- * <pre>
- * DITContentRuleDescription = "("
- * numericoid ; Structural ObjectClass identifier
- * [ "NAME" qdescrs ]
- * [ "DESC" qdstring ]
- * [ "OBSOLETE" ]
- * [ "AUX" oids ] ; Auxiliary ObjectClasses
- * [ "MUST" oids ] ; AttributeType identifiers
- * [ "MAY" oids ] ; AttributeType identifiers
- * [ "NOT" oids ] ; AttributeType identifiers
- * ")"
- * </pre>
- *
- * @param dITContentRule
- * the DIT content rule specification
- * @return the specification according to the DITContentRuleDescription
- * syntax
- */
- public static String getDescription( DitContentRule dITContentRule )
- {
- StringBuilder buf = new StringBuilder( "( " );
- buf.append( dITContentRule.getOid() );
- buf.append( '\n' );
-
- if ( dITContentRule.getNames() != null )
- {
- buf.append( " NAME " );
- getQDescrs( buf, dITContentRule.getNames() );
- buf.append( '\n' );
- }
-
- if ( dITContentRule.getDescription() != null )
- {
- buf.append( " DESC " );
- buf.append( dITContentRule.getDescription() );
- buf.append( '\n' );
- }
-
- if ( dITContentRule.isObsolete() )
- {
- buf.append( " OBSOLETE\n" );
- }
-
- // print out all the auxiliary object class oids
- List<ObjectClass> aux = dITContentRule.getAuxObjectClasses();
-
- if ( ( aux != null ) && ( aux.size() > 0 ) )
- {
- buf.append( " AUX " );
- getQDStrings( buf, aux );
- }
-
- List<AttributeType> must = dITContentRule.getMustAttributeTypes();
-
- if ( ( must != null ) && ( must.size() > 0 ) )
- {
- buf.append( " MUST " );
- getQDStrings( buf, must );
- }
-
- List<AttributeType> may = dITContentRule.getMayAttributeTypes();
-
- if ( ( may != null ) && ( may.size() > 0 ) )
- {
- buf.append( " MAY " );
- getQDStrings( buf, may );
- }
-
- List<AttributeType> not = dITContentRule.getNotAttributeTypes();
-
- if ( ( not != null ) && ( not.size() > 0 ) )
- {
- buf.append( " NOT " );
- getQDStrings( buf, not );
- }
-
- if ( dITContentRule.getExtensions() != null )
- {
- getExtensions( buf, dITContentRule.getExtensions() );
- }
-
- buf.append( " )\n" );
- return buf.toString();
- }
-
-
- /**
- * Generates the DITStructureRuleDescription for a DitStructureRule as
- * defined by the syntax: 1.3.6.1.4.1.1466.115.121.1.17. Only the right hand
- * side of the description starting at the opening parenthesis is
- * generated: that is 'DITStructureRuleDescription = ' is not generated.
- *
- * <pre>
- * DITStructureRuleDescription = "(" whsp
- * ruleid ; rule identifier
- * [ SP "NAME" SP qdescrs ] ; short names (descriptors)
- * [ SP "DESC" SP qdstring ] ; description
- * [ SP "OBSOLETE" ] ; not active
- * SP "FORM" SP oid ; NameForm
- * [ SP "SUP" ruleids ] ; superior rules
- * extensions WSP ; extensions
- * ")"
- * </pre>
- *
- * @param ditStructureRule
- * the DitStructureRule to generate the description for
- * @return the description in the DITStructureRuleDescription syntax
- */
- public static String getDescription( DitStructureRule ditStructureRule )
- {
- StringBuilder buf = new StringBuilder( "( " );
- buf.append( ditStructureRule.getOid() );
- buf.append( '\n' );
-
- if ( ditStructureRule.getNames() != null )
- {
- buf.append( " NAME " );
- getQDescrs( buf, ditStructureRule.getNames() );
- }
-
- if ( ditStructureRule.getDescription() != null )
- {
- buf.append( " DESC " );
- buf.append( ditStructureRule.getDescription() );
- buf.append( '\n' );
- }
-
- if ( ditStructureRule.isObsolete() )
- {
- buf.append( " OBSOLETE\n" );
- }
-
- buf.append( " FORM " );
- buf.append( ditStructureRule.getForm() );
- buf.append( '\n' );
-
- // TODO : Shouldn't we get the ruleId OID ?
- List<Integer> sups = ditStructureRule.getSuperRules();
-
- if ( ( sups != null ) && ( sups.size() > 0 ) )
- {
- buf.append( " SUP\n" );
-
- if ( sups.size() == 1 )
- {
- buf.append( sups.get( 0 ) );
- }
- else
- {
- boolean isFirst = true;
- buf.append( "( " );
-
- for ( int sup : sups )
- {
- if ( isFirst )
- {
- isFirst = false;
- }
- else
- {
- buf.append( " " );
- }
-
- buf.append( sup );
- }
-
- buf.append( " )" );
- }
-
- buf.append( '\n' );
- }
-
- 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
- * 'NameFormDescription = ' is not generated.
- *
- * <pre>
- * NameFormDescription = "(" whsp
- * numericoid whsp ; NameForm identifier
- * [ "NAME" qdescrs ]
- * [ "DESC" qdstring ]
- * [ "OBSOLETE" whsp ]
- * "OC" woid ; Structural ObjectClass
- * "MUST" oids ; AttributeTypes
- * [ "MAY" oids ] ; AttributeTypes
- * whsp ")"
- * </pre>
- *
- * @param nameForm
- * the NameForm to generate the description for
- * @return the NameFormDescription string
- */
- public static String getDescription( NameForm nameForm )
- {
- StringBuilder buf = new StringBuilder( "( " );
- buf.append( nameForm.getOid() );
- buf.append( '\n' );
-
- if ( nameForm.getNames() != null )
- {
- buf.append( " NAME " );
- getQDescrs( buf, nameForm.getNames() );
- }
-
- if ( nameForm.getDescription() != null )
- {
- buf.append( " DESC " );
- buf.append( nameForm.getDescription() );
- buf.append( '\n' );
- }
-
- if ( nameForm.isObsolete() )
- {
- buf.append( " OBSOLETE\n" );
- }
-
- buf.append( " OC " );
- buf.append( nameForm.getStructuralObjectClassOid() );
- buf.append( '\n' );
-
- buf.append( " MUST\n" );
- List<AttributeType> must = nameForm.getMustAttributeTypes();
-
- getQDStrings( buf, must );
-
- List<AttributeType> may = nameForm.getMayAttributeTypes();
-
- if ( ( may != null ) && ( may.size() > 0 ) )
- {
- buf.append( " MAY\n" );
- getQDStrings( buf, may );
- }
-
- if ( nameForm.getExtensions() != null )
- {
- getExtensions( buf, nameForm.getExtensions() );
- }
-
- buf.append( " )\n" );
- return buf.toString();
- }
-
-
- /**
* Generates the NormalizerDescription for a Normalizer. Only the right
* hand side of the description starting at the opening parenthesis is
* generated: that is 'NormalizerDescription = ' is not generated.
@@ -429,76 +172,6 @@ public final class DescriptionUtils
}
- private static void getQDStrings( StringBuilder sb, List<? extends SchemaObject> schemaObjects )
- {
- if ( ( schemaObjects != null ) && ( schemaObjects.size() != 0 ) )
- {
- if ( schemaObjects.size() == 1 )
- {
- sb.append( '\'' ).append( schemaObjects.get( 0 ).getName() ).append( '\'' );
- }
- else
- {
- boolean isFirst = true;
- sb.append( "( " );
-
- for ( SchemaObject schemaObject : schemaObjects )
- {
- if ( isFirst )
- {
- isFirst = false;
- }
- else
- {
- sb.append( " $ " );
- }
-
- sb.append( '\'' ).append( schemaObject.getName() ).append( '\'' );
- }
-
- sb.append( " )" );
- }
- }
-
- sb.append( '\n' );
- }
-
-
- private static void getQDescrs( StringBuilder sb, List<String> names )
- {
- if ( ( names != null ) && ( names.size() != 0 ) )
- {
- if ( names.size() == 1 )
- {
- sb.append( '\'' ).append( names.get( 0 ) ).append( '\'' );
- }
- else
- {
- boolean isFirst = true;
- sb.append( "( " );
-
- for ( String name : names )
- {
- if ( isFirst )
- {
- isFirst = false;
- }
- else
- {
- sb.append( " " );
- }
-
- sb.append( '\'' ).append( name ).append( '\'' );
- }
-
- sb.append( " )" );
- }
- }
-
- sb.append( '\n' );
- }
-
-
/**
* Generate the description for Comparators, Normalizers and SyntaxCheckers.
*/
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitContentRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitContentRule.java?rev=1547566&r1=1547565&r2=1547566&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitContentRule.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitContentRule.java Tue Dec 3 20:21:36 2013
@@ -569,7 +569,7 @@ public class DitContentRule extends Abst
*/
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/DitStructureRule.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitStructureRule.java?rev=1547566&r1=1547565&r2=1547566&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitStructureRule.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/DitStructureRule.java Tue Dec 3 20:21:36 2013
@@ -225,7 +225,7 @@ public class DitStructureRule extends Ab
@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/NameForm.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/NameForm.java?rev=1547566&r1=1547565&r2=1547566&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/NameForm.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/NameForm.java Tue Dec 3 20:21:36 2013
@@ -422,7 +422,7 @@ public class NameForm extends AbstractSc
*/
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/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=1547566&r1=1547565&r2=1547566&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 Tue Dec 3 20:21:36 2013
@@ -129,15 +129,7 @@ public class SchemaObjectRenderer
{
StringBuilder buf = renderStartOidNamesDescObsolete( oc, "objectclass" );
- List<String> superiorOids = oc.getSuperiorOids();
-
- if ( ( superiorOids != null ) && ( superiorOids.size() > 0 ) )
- {
- prettyPrintIndent( buf );
- buf.append( "SUP " );
- renderOids( buf, superiorOids );
- prettyPrintNewLine( buf );
- }
+ renderOids( buf, "SUP", oc.getSuperiorOids() );
if ( oc.getType() != null )
{
@@ -146,25 +138,9 @@ public class SchemaObjectRenderer
prettyPrintNewLine( buf );
}
- List<String> must = oc.getMustAttributeTypeOids();
+ renderOids( buf, "MUST", oc.getMustAttributeTypeOids() );
- if ( ( must != null ) && ( must.size() > 0 ) )
- {
- prettyPrintIndent( buf );
- buf.append( "MUST " );
- renderOids( buf, must );
- prettyPrintNewLine( buf );
- }
-
- List<String> may = oc.getMayAttributeTypeOids();
-
- if ( ( may != null ) && ( may.size() > 0 ) )
- {
- prettyPrintIndent( buf );
- buf.append( "MAY " );
- renderOids( buf, may );
- prettyPrintNewLine( buf );
- }
+ renderOids( buf, "MAY", oc.getMayAttributeTypeOids() );
renderXSchemaName( oc, buf );
@@ -445,13 +421,7 @@ public class SchemaObjectRenderer
buf.append( "( " ).append( syntax.getOid() );
prettyPrintNewLine( buf );
- if ( syntax.getDescription() != null )
- {
- prettyPrintIndent( buf );
- buf.append( "DESC " );
- renderQDString( buf, syntax.getDescription() );
- prettyPrintNewLine( buf );
- }
+ renderDescription( syntax, buf );
renderXSchemaName( syntax, buf );
@@ -503,6 +473,92 @@ public class SchemaObjectRenderer
}
+ /**
+ * NOT FULLY IMPLEMENTED!
+ */
+ public String render( DitContentRule dcr )
+ {
+ StringBuilder buf = renderStartOidNamesDescObsolete( dcr, "ditcontentrule" );
+
+ renderOids( buf, "AUX", dcr.getAuxObjectClassOids() );
+
+ renderOids( buf, "MUST", dcr.getMustAttributeTypeOids() );
+
+ renderOids( buf, "MAY", dcr.getMayAttributeTypeOids() );
+
+ renderOids( buf, "NOT", dcr.getNotAttributeTypeOids() );
+
+ renderXSchemaName( dcr, 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( DitStructureRule dsr )
+ {
+ StringBuilder buf = new StringBuilder();
+
+ if ( style.startWithSchemaType )
+ {
+ buf.append( "ditstructurerule " );
+ }
+
+ buf.append( "( " ).append( dsr.getRuleId() );
+
+ renderNames( dsr, buf );
+
+ renderDescription( dsr, buf );
+
+ renderObsolete( dsr, buf );
+
+ prettyPrintIndent( buf );
+ buf.append( "FORM " ).append( dsr.getForm() );
+ prettyPrintNewLine( buf );
+
+ renderRuleIds( buf, dsr.getSuperRules() );
+
+ renderXSchemaName( dsr, 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( NameForm nf )
+ {
+ StringBuilder buf = renderStartOidNamesDescObsolete( nf, "nameform" );
+
+ prettyPrintIndent( buf );
+ buf.append( "OC " ).append( nf.getStructuralObjectClassOid() );
+ prettyPrintNewLine( buf );
+
+ renderOids( buf, "MUST", nf.getMustAttributeTypeOids() );
+
+ renderOids( buf, "MAY", nf.getMayAttributeTypeOids() );
+
+ renderXSchemaName( nf, buf );
+
+ buf.append( ")" );
+
+ return buf.toString();
+ }
+
+
private StringBuilder renderStartOidNamesDescObsolete( SchemaObject so, String schemaObjectType )
{
StringBuilder buf = new StringBuilder();
@@ -514,6 +570,17 @@ public class SchemaObjectRenderer
buf.append( "( " ).append( so.getOid() );
+ renderNames( so, buf );
+
+ renderDescription( so, buf );
+
+ renderObsolete( so, buf );
+ return buf;
+ }
+
+
+ private void renderNames( SchemaObject so, StringBuilder buf )
+ {
List<String> names = so.getNames();
if ( ( names != null ) && ( names.size() > 0 ) )
@@ -526,7 +593,11 @@ public class SchemaObjectRenderer
{
prettyPrintNewLine( buf );
}
+ }
+
+ private void renderDescription( SchemaObject so, StringBuilder buf )
+ {
if ( so.getDescription() != null )
{
prettyPrintIndent( buf );
@@ -534,14 +605,17 @@ public class SchemaObjectRenderer
renderQDString( buf, so.getDescription() );
prettyPrintNewLine( buf );
}
+ }
+
+ private void renderObsolete( SchemaObject so, StringBuilder buf )
+ {
if ( so.isObsolete() )
{
prettyPrintIndent( buf );
buf.append( "OBSOLETE" );
prettyPrintNewLine( buf );
}
- return buf;
}
@@ -604,6 +678,18 @@ public class SchemaObjectRenderer
}
+ private void renderOids( StringBuilder buf, String prefix, List<String> oids )
+ {
+ if ( ( oids != null ) && ( oids.size() > 0 ) )
+ {
+ prettyPrintIndent( buf );
+ buf.append( prefix ).append( ' ' );
+ renderOids( buf, oids );
+ prettyPrintNewLine( buf );
+ }
+ }
+
+
/**
* Renders oids into a new buffer.<br>
* <pre>
@@ -681,6 +767,47 @@ public class SchemaObjectRenderer
}
+ private StringBuilder renderRuleIds( StringBuilder buf, List<Integer> ruleIds )
+ {
+ if ( ( ruleIds != null ) && ( ruleIds.size() > 0 ) )
+ {
+ prettyPrintIndent( buf );
+ buf.append( "SUP " );
+
+ if ( ruleIds.size() == 1 )
+ {
+ buf.append( ruleIds.get( 0 ) );
+ }
+ else
+ {
+ buf.append( "( " );
+
+ boolean isFirst = true;
+
+ for ( Integer ruleId : ruleIds )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ buf.append( " " );
+ }
+
+ buf.append( ruleId );
+ }
+
+ buf.append( " )" );
+ }
+
+ prettyPrintNewLine( buf );
+ }
+
+ return buf;
+ }
+
+
private void renderXSchemaName( SchemaObject oc, StringBuilder buf )
{
if ( style.printSchemaName )
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=1547566&r1=1547565&r2=1547566&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 Tue Dec 3 20:21:36 2013
@@ -204,49 +204,6 @@ public final class SchemaUtils
/**
- * Renders oids into a new buffer.<br>
- * <pre>
- * oids ::= oid | '(' WSP oidlist WSP ')'
- * oidlist ::= oid ( WSP '$' WSP oid )*
- * </pre>
- *
- * @param qdescrs the quoted description strings to render
- * @return the string buffer the qdescrs are rendered into
- */
- private static StringBuffer renderOids( StringBuffer buf, List<String> oids )
- {
- if ( oids.size() == 1 )
- {
- buf.append( oids.get( 0 ) );
- }
- else
- {
- buf.append( "( " );
-
- boolean isFirst = true;
-
- for ( String oid : oids )
- {
- if ( isFirst )
- {
- isFirst = false;
- }
- else
- {
- buf.append( " $ " );
- }
-
- buf.append( oid );
- }
-
- buf.append( " )" );
- }
-
- return buf;
- }
-
-
- /**
* Renders QDString into a new buffer.<br>
*
* @param qdescrs the quoted description strings to render
@@ -461,167 +418,7 @@ public final class SchemaUtils
}
- /**
- * NOT FULLY IMPLEMENTED!
- */
- public static StringBuffer render( DitContentRule dcr )
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "( " ).append( dcr.getOid() );
-
- List<String> names = dcr.getNames();
-
- if ( ( names != null ) && ( names.size() > 0 ) )
- {
- buf.append( " NAME " );
- renderQDescrs( buf, names );
- }
-
- if ( dcr.getDescription() != null )
- {
- buf.append( " DESC " );
- renderQDString( buf, dcr.getDescription() );
- }
-
- if ( dcr.isObsolete )
- {
- buf.append( " OBSOLETE" );
- }
-
- List<String> aux = dcr.getAuxObjectClassOids();
-
- if ( ( aux != null ) && ( aux.size() > 0 ) )
- {
- buf.append( " AUX " );
- renderOids( buf, aux );
- }
-
- List<String> must = dcr.getMustAttributeTypeOids();
-
- if ( ( must != null ) && ( must.size() > 0 ) )
- {
- buf.append( " MUST " );
- renderOids( buf, must );
- }
-
- List<String> may = dcr.getMayAttributeTypeOids();
-
- if ( ( may != null ) && ( may.size() > 0 ) )
- {
- buf.append( " MAY " );
- renderOids( buf, may );
- }
-
- List<String> not = dcr.getNotAttributeTypeOids();
-
- if ( ( not != null ) && ( not.size() > 0 ) )
- {
- buf.append( " AUX " );
- renderOids( buf, not );
- }
-
- buf.append( " X-SCHEMA '" );
- buf.append( dcr.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( DitStructureRule dsr )
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "( " ).append( dsr.getOid() );
-
- List<String> names = dsr.getNames();
-
- if ( ( names != null ) && ( names.size() > 0 ) )
- {
- buf.append( " NAME " );
- renderQDescrs( buf, names );
- }
-
- if ( dsr.getDescription() != null )
- {
- buf.append( " DESC " );
- renderQDString( buf, dsr.getDescription() );
- }
-
- if ( dsr.isObsolete )
- {
- buf.append( " OBSOLETE" );
- }
-
- buf.append( " FORM " ).append( dsr.getForm() );
-
- @SuppressWarnings("unused")
- List<Integer> ruleIds = dsr.getSuperRules();
- // TODO : Add the rendering
-
- buf.append( " X-SCHEMA '" );
- buf.append( dsr.getSchemaName() );
- buf.append( "' )" );
-
- return buf;
- }
-
-
- /**
- * NOT FULLY IMPLEMENTED!
- */
- public static StringBuffer render( NameForm nf )
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "( " ).append( nf.getOid() );
-
- List<String> names = nf.getNames();
-
- if ( ( names != null ) && ( names.size() > 0 ) )
- {
- buf.append( " NAME " );
- renderQDescrs( buf, names );
- }
-
- if ( nf.getDescription() != null )
- {
- buf.append( " DESC " );
- renderQDString( buf, nf.getDescription() );
- }
-
- if ( nf.isObsolete )
- {
- buf.append( " OBSOLETE" );
- }
-
- buf.append( " OC " );
- buf.append( nf.getStructuralObjectClass().getName() );
-
- buf.append( " MUST " );
- renderOids( buf, nf.getMustAttributeTypeOids() );
-
- List<String> may = nf.getMayAttributeTypeOids();
-
- if ( ( may != null ) && ( may.size() > 0 ) )
- {
- buf.append( " MAY " );
- renderOids( buf, may );
- }
-
- buf.append( " X-SCHEMA '" );
- buf.append( nf.getSchemaName() );
- buf.append( "' )" );
-
- return buf;
- }
-
+
/**
* Returns a String description of a schema. The resulting String format is :
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitContentRuleTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitContentRuleTest.java?rev=1547566&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitContentRuleTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitContentRuleTest.java Tue Dec 3 20:21:36 2013
@@ -0,0 +1,79 @@
+/*
+ * 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 DitContentRule.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class DitContentRuleTest
+{
+ private DitContentRule ditContentRule;
+
+
+ /**
+ * Initialize attribute type instances
+ */
+ @Before
+ public void initDitContentRules() throws Exception
+ {
+ ditContentRule = new DitContentRule( "1.2.3.4" );
+ ditContentRule.setNames( "name1", "name2" );
+ ditContentRule.setDescription( "description" );
+ ditContentRule.setObsolete( false );
+ ditContentRule.setAuxObjectClassOids( Arrays.asList( "oc1", "oc2" ) );
+ ditContentRule.setMustAttributeTypeOids( Arrays.asList( "must1", "must2" ) );
+ ditContentRule.setMayAttributeTypeOids( Arrays.asList( "may1", "may2" ) );
+ ditContentRule.setNotAttributeTypeOids( Arrays.asList( "not1", "not2" ) );
+ }
+
+
+ @Test
+ public void testToString() throws Exception
+ {
+ String string = ditContentRule.toString();
+
+ assertNotNull( string );
+ assertTrue( string.startsWith( "ditcontentrule (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tAUX " ) );
+ assertTrue( string.contains( "\n\tMUST" ) );
+ assertTrue( string.contains( "\n\tMAY" ) );
+ assertTrue( string.contains( "\n\tNOT" ) );
+ }
+}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitStructureRuleTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitStructureRuleTest.java?rev=1547566&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitStructureRuleTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/DitStructureRuleTest.java Tue Dec 3 20:21:36 2013
@@ -0,0 +1,75 @@
+/*
+ * 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 DitStructureRule.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class DitStructureRuleTest
+{
+ private DitStructureRule ditStructureRule;
+
+
+ /**
+ * Initialize attribute type instances
+ */
+ @Before
+ public void initDitStructureRules() throws Exception
+ {
+ ditStructureRule = new DitStructureRule( 1234 );
+ ditStructureRule.setNames( "name1", "name2" );
+ ditStructureRule.setDescription( "description" );
+ ditStructureRule.setObsolete( false );
+ ditStructureRule.setForm( "form1" );
+ ditStructureRule.setSuperRules( Arrays.asList( 111, 222, 333 ) );
+ }
+
+
+ @Test
+ public void testToString() throws Exception
+ {
+ String string = ditStructureRule.toString();
+
+ assertNotNull( string );
+ assertTrue( string.startsWith( "ditstructurerule (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tFORM " ) );
+ assertTrue( string.contains( "\n\tSUP" ) );
+ }
+}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/NameFormTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/NameFormTest.java?rev=1547566&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/NameFormTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/schema/NameFormTest.java Tue Dec 3 20:21:36 2013
@@ -0,0 +1,77 @@
+/*
+ * 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 NameForm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class NameFormTest
+{
+ private NameForm nameForm;
+
+
+ /**
+ * Initialize attribute type instances
+ */
+ @Before
+ public void initNameForms() throws Exception
+ {
+ nameForm = new NameForm( "1.2.3.4" );
+ nameForm.setNames( "name1", "name2" );
+ nameForm.setDescription( "description" );
+ nameForm.setObsolete( false );
+ nameForm.setStructuralObjectClassOid( "2.3.4.5" );
+ nameForm.setMustAttributeTypeOids( Arrays.asList( "must1", "must2" ) );
+ nameForm.setMayAttributeTypeOids( Arrays.asList( "may0" ) );
+ }
+
+
+ @Test
+ public void testToString() throws Exception
+ {
+ String string = nameForm.toString();
+
+ assertNotNull( string );
+ assertTrue( string.startsWith( "nameform (" ) );
+ assertTrue( string.contains( " NAME " ) );
+ assertTrue( string.contains( "\n\tDESC " ) );
+ assertTrue( string.contains( "\n\tOC" ) );
+ assertTrue( string.contains( "\n\tMUST" ) );
+ assertTrue( string.contains( "\n\tMAY" ) );
+ }
+}
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=1547566&r1=1547565&r2=1547566&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 Tue Dec 3 20:21:36 2013
@@ -23,13 +23,17 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertTrue;
import java.text.ParseException;
+import java.util.ArrayList;
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.DitContentRuleDescriptionSchemaParser;
+import org.apache.directory.api.ldap.model.schema.parsers.DitStructureRuleDescriptionSchemaParser;
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.NameFormDescriptionSchemaParser;
import org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser;
import org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser;
import org.junit.Before;
@@ -52,6 +56,9 @@ public class SchemaObjectRendererTest
private MutableMatchingRule matchingRule;
private MatchingRuleUse matchingRuleUse;
private LdapSyntax ldapSyntax;
+ private DitContentRule ditContentRule;
+ private DitStructureRule ditStructureRule;
+ private NameForm nameForm;
@Before
@@ -112,6 +119,32 @@ public class SchemaObjectRendererTest
ldapSyntax.setHumanReadable( false );
ldapSyntax.setSchemaName( "dummy" );
+ ditContentRule = new DitContentRule( "1.2.3.4" );
+ ditContentRule.setNames( "name1", "name2" );
+ ditContentRule.setDescription( "description with 'quotes'" );
+ ditContentRule.setObsolete( true );
+ ditContentRule.setAuxObjectClassOids( Arrays.asList( "oc1", "oc2" ) );
+ ditContentRule.setMustAttributeTypeOids( Arrays.asList( "must1", "must2" ) );
+ ditContentRule.setMayAttributeTypeOids( Arrays.asList( "may1", "may2" ) );
+ ditContentRule.setNotAttributeTypeOids( Arrays.asList( "not1", "not2" ) );
+ ditContentRule.setSchemaName( "dummy" );
+
+ ditStructureRule = new DitStructureRule( 1234 );
+ ditStructureRule.setNames( "name1", "name2" );
+ ditStructureRule.setDescription( "description with 'quotes'" );
+ ditStructureRule.setObsolete( true );
+ ditStructureRule.setForm( "form1" );
+ ditStructureRule.setSuperRules( Arrays.asList( 111, 222, 333 ) );
+ ditStructureRule.setSchemaName( "dummy" );
+
+ nameForm = new NameForm( "1.2.3.4" );
+ nameForm.setNames( "name1", "name2" );
+ nameForm.setDescription( "description with 'quotes'" );
+ nameForm.setObsolete( true );
+ nameForm.setStructuralObjectClassOid( "oc1" );
+ nameForm.setMustAttributeTypeOids( Arrays.asList( "must1", "must2" ) );
+ nameForm.setMayAttributeTypeOids( Arrays.asList( "may0" ) );
+ nameForm.setSchemaName( "dummy" );
}
@@ -417,4 +450,123 @@ public class SchemaObjectRendererTest
assertTrue( original.equals( parsed ) );
assertTrue( renderedOriginal.equals( renderedParsed ) );
}
+
+
+ @Test
+ public void testOpenLdapSchemaRendererDitContentRule()
+ {
+ String actual = SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( ditContentRule );
+ String expected = "ditcontentrule ( 1.2.3.4 NAME ( 'name1' 'name2' )\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tAUX ( oc1 $ oc2 )\n\tMUST ( must1 $ must2 )\n\tMAY ( may1 $ may2 )\n\tNOT ( not1 $ not2 )\n)";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererDitContentRule()
+ {
+ String actual = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( ditContentRule );
+ String expected = "( 1.2.3.4 NAME ( 'name1' 'name2' ) DESC 'description with \\27quotes\\27' OBSOLETE AUX ( oc1 $ oc2 ) MUST ( must1 $ must2 ) MAY ( may1 $ may2 ) NOT ( not1 $ not2 ) X-SCHEMA 'dummy' )";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererAndParserRoundtripDitContentRule() throws ParseException
+ {
+ testSubschemSubentryRendererAndParserRoundtrip( ditContentRule );
+ }
+
+
+ private void testSubschemSubentryRendererAndParserRoundtrip( DitContentRule original ) throws ParseException
+ {
+ String renderedOriginal = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( original );
+ DitContentRule parsed = new DitContentRuleDescriptionSchemaParser().parse( renderedOriginal );
+ String renderedParsed = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( parsed );
+
+ assertTrue( original.equals( parsed ) );
+ assertTrue( renderedOriginal.equals( renderedParsed ) );
+ }
+
+
+ @Test
+ public void testOpenLdapSchemaRendererDitStructureRule()
+ {
+ String actual = SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( ditStructureRule );
+ String expected = "ditstructurerule ( 1234 NAME ( 'name1' 'name2' )\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tFORM form1\n\tSUP ( 111 222 333 )\n)";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererDitStructureRule()
+ {
+ String actual = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( ditStructureRule );
+ String expected = "( 1234 NAME ( 'name1' 'name2' ) DESC 'description with \\27quotes\\27' OBSOLETE FORM form1 SUP ( 111 222 333 ) X-SCHEMA 'dummy' )";
+ assertEquals( expected, actual );
+
+ ditStructureRule.setSuperRules( null );
+ String actual2 = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( ditStructureRule );
+ String expected2 = "( 1234 NAME ( 'name1' 'name2' ) DESC 'description with \\27quotes\\27' OBSOLETE FORM form1 X-SCHEMA 'dummy' )";
+ assertEquals( expected2, actual2 );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererAndParserRoundtripDitStructureRule() throws ParseException
+ {
+ testSubschemSubentryRendererAndParserRoundtrip( ditStructureRule );
+ }
+
+
+ private void testSubschemSubentryRendererAndParserRoundtrip( DitStructureRule original ) throws ParseException
+ {
+ String renderedOriginal = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( original );
+ DitStructureRule parsed = new DitStructureRuleDescriptionSchemaParser().parse( renderedOriginal );
+ String renderedParsed = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( parsed );
+
+ assertTrue( original.equals( parsed ) );
+ assertTrue( renderedOriginal.equals( renderedParsed ) );
+ }
+
+
+ @Test
+ public void testOpenLdapSchemaRendererNameForm()
+ {
+ String actual = SchemaObjectRenderer.OPEN_LDAP_SCHEMA_RENDERER.render( nameForm );
+ System.out.println( actual );
+ String expected = "nameform ( 1.2.3.4 NAME ( 'name1' 'name2' )\n\tDESC 'description with \\27quotes\\27'\n\tOBSOLETE\n\tOC oc1\n\tMUST ( must1 $ must2 )\n\tMAY may0\n)";
+ assertEquals( expected, actual );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererNameForm()
+ {
+ String actual = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( nameForm );
+ String expected = "( 1.2.3.4 NAME ( 'name1' 'name2' ) DESC 'description with \\27quotes\\27' OBSOLETE OC oc1 MUST ( must1 $ must2 ) MAY may0 X-SCHEMA 'dummy' )";
+ assertEquals( expected, actual );
+
+ nameForm.setMayAttributeTypeOids( new ArrayList<String>() );
+ String actual2 = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( nameForm );
+ String expected2 = "( 1.2.3.4 NAME ( 'name1' 'name2' ) DESC 'description with \\27quotes\\27' OBSOLETE OC oc1 MUST ( must1 $ must2 ) X-SCHEMA 'dummy' )";
+ assertEquals( expected2, actual2 );
+ }
+
+
+ @Test
+ public void testSubschemSubentryRendererAndParserRoundtripNameForm() throws ParseException
+ {
+ testSubschemSubentryRendererAndParserRoundtrip( nameForm );
+ }
+
+
+ private void testSubschemSubentryRendererAndParserRoundtrip( NameForm original ) throws ParseException
+ {
+ String renderedOriginal = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( original );
+ NameForm parsed = new NameFormDescriptionSchemaParser().parse( renderedOriginal );
+ String renderedParsed = SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( parsed );
+
+ assertTrue( original.equals( parsed ) );
+ assertTrue( renderedOriginal.equals( renderedParsed ) );
+ }
}