You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/01/06 18:52:31 UTC
svn commit: r896579 [2/14] - in /directory/shared/trunk: ./ ldap/
ldap/src/main/antlr/ ldap/src/main/java/org/apache/directory/shared/ldap/
ldap/src/main/java/org/apache/directory/shared/ldap/codec/
ldap/src/main/java/org/apache/directory/shared/ldap/c...
Modified: directory/shared/trunk/ldap/src/main/antlr/schema.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/schema.g?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/schema.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/schema.g Wed Jan 6 17:52:15 2010
@@ -26,19 +26,19 @@
import java.util.List;
import java.util.Map;
-import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescription;
-import org.apache.directory.shared.ldap.schema.parsers.DITContentRuleDescription;
-import org.apache.directory.shared.ldap.schema.parsers.DITStructureRuleDescription;
-import org.apache.directory.shared.ldap.schema.parsers.LdapSyntaxDescription;
-import org.apache.directory.shared.ldap.schema.parsers.MatchingRuleDescription;
-import org.apache.directory.shared.ldap.schema.parsers.MatchingRuleUseDescription;
-import org.apache.directory.shared.ldap.schema.parsers.NameFormDescription;
+import org.apache.directory.shared.ldap.schema.parsers.LdapComparatorDescription;
+import org.apache.directory.shared.ldap.schema.DITContentRule;
+import org.apache.directory.shared.ldap.schema.DITStructureRule;
+import org.apache.directory.shared.ldap.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
+import org.apache.directory.shared.ldap.schema.NameForm;
import org.apache.directory.shared.ldap.schema.parsers.NormalizerDescription;
import org.apache.directory.shared.ldap.schema.parsers.ParserMonitor;
-import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescription;
-import org.apache.directory.shared.ldap.schema.parsers.ObjectClassDescription;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
import org.apache.directory.shared.ldap.schema.parsers.SyntaxCheckerDescription;
-import org.apache.directory.shared.ldap.schema.syntaxes.OpenLdapObjectIdentifierMacro;
+import org.apache.directory.shared.ldap.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro;
import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
import org.apache.directory.shared.ldap.schema.UsageEnum;
@@ -119,7 +119,7 @@
OC : ( "oc" (options {greedy=true;} : WHSP)? oc:VALUES ) { setText(oc.getText()); } ;
EQUALITY : ( "equality" (options {greedy=true;} : WHSP)? equality:VALUES ) { setText(equality.getText().trim()); } ;
ORDERING : ( "ordering" (options {greedy=true;} : WHSP)? ordering:VALUES ) { setText(ordering.getText().trim()); } ;
-SUBSTR : ( "substr" (options {greedy=true;} : WHSP)? substr:VALUES ) { setText(substr.getText().trim()); } ;
+SUBSTR : ( "substr" (options {greedy=true;} : WHSP)? substring:VALUES ) { setText(substring.getText().trim()); } ;
SYNTAX : ( "syntax" (options {greedy=true;} : WHSP)? syntax:VALUES (len:LEN)? ) { setText(syntax.getText().trim() + (len!=null?len.getText().trim():"")); } ;
APPLIES : ( "applies" (options {greedy=true;} : WHSP)? applies:VALUES ) { setText(applies.getText().trim()); } ;
EXTENSION : x:( "x-" ( options {greedy=true;} : 'a'..'z' | '-' | '_' )+ (options {greedy=true;} : WHSP)? VALUES ) ;
@@ -245,17 +245,17 @@
openLdapSchema returns [List<Object> list = new ArrayList<Object>()]
{
- AttributeTypeDescription atd = null;
- ObjectClassDescription ocd = null;
+ AttributeType attributeType = null;
+ ObjectClass objectClass = null;
OpenLdapObjectIdentifierMacro oloid = null;
}
:
(
oloid = openLdapObjectIdentifier { list.add( oloid ); }
|
- atd = openLdapAttributeType { list.add( atd ); }
+ attributeType = openLdapAttributeType { list.add( attributeType ); }
|
- ocd = openLdapObjectClass { list.add( ocd ); }
+ objectClass = openLdapObjectClass { list.add( objectClass ); }
)*
;
@@ -276,26 +276,26 @@
;
-openLdapObjectClass returns [ObjectClassDescription ocd]
+openLdapObjectClass returns [ObjectClass objectClass]
{
matchedProduction( "openLdapObjectClass()" );
}
:
(
OBJECTCLASS
- ( ocd=objectClassDescription )
+ ( objectClass=objectClassDescription )
)
;
-openLdapAttributeType returns [AttributeTypeDescription atd]
+openLdapAttributeType returns [AttributeType attributeType]
{
matchedProduction( "openLdapAttributeType()" );
}
:
(
ATTRIBUTETYPE
- ( atd=attributeTypeDescription )
+ ( attributeType=attributeTypeDescription )
)
;
@@ -322,37 +322,37 @@
* xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE )
* </pre>
*/
-objectClassDescription returns [ObjectClassDescription ocd = new ObjectClassDescription()]
+objectClassDescription returns [ObjectClass objectClass]
{
matchedProduction( "objectClassDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { ocd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { objectClass = new ObjectClass(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); ocd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); objectClass.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); ocd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); objectClass.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); ocd.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); objectClass.setObsolete( true ); } )
|
- ( sup:SUP { et.track("SUP", sup); ocd.setSuperiorObjectClasses(oids(sup.getText())); } )
+ ( sup:SUP { et.track("SUP", sup); objectClass.setSuperiorOids(oids(sup.getText())); } )
|
- ( kind1:ABSTRACT { et.track("KIND", kind1); ocd.setKind( ObjectClassTypeEnum.ABSTRACT ); }
+ ( kind1:ABSTRACT { et.track("KIND", kind1); objectClass.setType( ObjectClassTypeEnum.ABSTRACT ); }
|
- kind2:STRUCTURAL { et.track("KIND", kind2); ocd.setKind( ObjectClassTypeEnum.STRUCTURAL ); }
+ kind2:STRUCTURAL { et.track("KIND", kind2); objectClass.setType( ObjectClassTypeEnum.STRUCTURAL ); }
|
- kind3:AUXILIARY { et.track("KIND", kind3); ocd.setKind( ObjectClassTypeEnum.AUXILIARY ); }
+ kind3:AUXILIARY { et.track("KIND", kind3); objectClass.setType( ObjectClassTypeEnum.AUXILIARY ); }
)
|
- ( must:MUST { et.track("MUST", must); ocd.setMustAttributeTypes(oids(must.getText())); } )
+ ( must:MUST { et.track("MUST", must); objectClass.setMustAttributeTypeOids(oids(must.getText())); } )
|
- ( may:MAY { et.track("MAY", may); ocd.setMayAttributeTypes(oids(may.getText())); } )
+ ( may:MAY { et.track("MAY", may); objectClass.setMayAttributeTypeOids(oids(may.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- ocd.addExtension(ex.key, ex.values);
+ objectClass.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -389,54 +389,54 @@
* xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE )
* </pre>
*/
-attributeTypeDescription returns [AttributeTypeDescription atd = new AttributeTypeDescription()]
+attributeTypeDescription returns [AttributeType attributeType]
{
matchedProduction( "attributeTypeDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { atd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { attributeType = new AttributeType(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); atd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); attributeType.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); atd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); attributeType.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); atd.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); attributeType.setObsolete( true ); } )
|
- ( sup:SUP { et.track("SUP", sup); atd.setSuperType(oid(sup.getText())); } )
+ ( superior:SUP { et.track("SUP", superior); attributeType.setSuperiorOid(oid(superior.getText())); } )
|
- ( equality:EQUALITY { et.track("EQUALITY", equality); atd.setEqualityMatchingRule(oid(equality.getText())); } )
+ ( equality:EQUALITY { et.track("EQUALITY", equality); attributeType.setEqualityOid(oid(equality.getText())); } )
|
- ( ordering:ORDERING { et.track("ORDERING", ordering); atd.setOrderingMatchingRule(oid(ordering.getText())); } )
+ ( ordering:ORDERING { et.track("ORDERING", ordering); attributeType.setOrderingOid(oid(ordering.getText())); } )
|
- ( substr:SUBSTR { et.track("SUBSTR", substr); atd.setSubstringsMatchingRule(oid(substr.getText())); } )
+ ( substring:SUBSTR { et.track("SUBSTR", substring); attributeType.setSubstringOid(oid(substring.getText())); } )
|
( syntax:SYNTAX {
et.track("SYNTAX", syntax);
NoidLen noidlen = noidlen(syntax.getText());
- atd.setSyntax(noidlen.noid);
- atd.setSyntaxLength(noidlen.len);
+ attributeType.setSyntaxOid(noidlen.noid);
+ attributeType.setSyntaxLength(noidlen.len);
} )
|
- ( singleValue:SINGLE_VALUE { et.track("SINGLE_VALUE", singleValue); atd.setSingleValued( true ); } )
+ ( singleValued:SINGLE_VALUE { et.track("SINGLE_VALUE", singleValued); attributeType.setSingleValued( true ); } )
|
- ( collective:COLLECTIVE { et.track("COLLECTIVE", collective); atd.setCollective( true ); } )
+ ( collective:COLLECTIVE { et.track("COLLECTIVE", collective); attributeType.setCollective( true ); } )
|
- ( noUserModification:NO_USER_MODIFICATION { et.track("NO_USER_MODIFICATION", noUserModification); atd.setUserModifiable( false ); } )
+ ( noUserModification:NO_USER_MODIFICATION { et.track("NO_USER_MODIFICATION", noUserModification); attributeType.setUserModifiable( false ); } )
|
- ( usage1:USAGE (WHSP)* USER_APPLICATIONS { et.track("USAGE", usage1); atd.setUsage( UsageEnum.USER_APPLICATIONS ); }
+ ( usage1:USAGE (WHSP)* USER_APPLICATIONS { et.track("USAGE", usage1); attributeType.setUsage( UsageEnum.USER_APPLICATIONS ); }
|
- usage2:USAGE DIRECTORY_OPERATION { et.track("USAGE", usage2); atd.setUsage( UsageEnum.DIRECTORY_OPERATION ); }
+ usage2:USAGE DIRECTORY_OPERATION { et.track("USAGE", usage2); attributeType.setUsage( UsageEnum.DIRECTORY_OPERATION ); }
|
- usage3:USAGE DISTRIBUTED_OPERATION { et.track("USAGE", usage3); atd.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); }
+ usage3:USAGE DISTRIBUTED_OPERATION { et.track("USAGE", usage3); attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); }
|
- usage4:USAGE DSA_OPERATION { et.track("USAGE", usage4); atd.setUsage( UsageEnum.DSA_OPERATION ); }
+ usage4:USAGE DSA_OPERATION { et.track("USAGE", usage4); attributeType.setUsage( UsageEnum.DSA_OPERATION ); }
)
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- atd.addExtension(ex.key, ex.values);
+ attributeType.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -450,13 +450,13 @@
}
// COLLECTIVE requires USAGE userApplications
- if ( atd.isCollective() && ( atd.getUsage() != UsageEnum.USER_APPLICATIONS ) )
+ if ( attributeType.isCollective() && ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) )
{
throw new SemanticException( "COLLECTIVE requires USAGE userApplications", null, 0, 0 );
}
// NO-USER-MODIFICATION requires an operational USAGE.
- if ( !atd.isUserModifiable() && ( atd.getUsage() == UsageEnum.USER_APPLICATIONS ) )
+ if ( !attributeType.isUserModifiable() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) )
{
throw new SemanticException( "NO-USER-MODIFICATION requires an operational USAGE", null, 0, 0 );
}
@@ -476,22 +476,22 @@
* extensions WSP RPAREN ; extensions
* </pre>
*/
-ldapSyntaxDescription returns [LdapSyntaxDescription lsd = new LdapSyntaxDescription()]
+ldapSyntaxDescription returns [LdapSyntax ldapSyntax]
{
matchedProduction( "ldapSyntaxDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { lsd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { ldapSyntax = new LdapSyntax(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); lsd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); ldapSyntax.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); lsd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); ldapSyntax.setDescription(qdstring(desc.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- lsd.addExtension(ex.key, ex.values);
+ ldapSyntax.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -513,26 +513,26 @@
* extensions WSP RPAREN ; extensions
* </pre>
*/
-matchingRuleDescription returns [MatchingRuleDescription mrd = new MatchingRuleDescription()]
+matchingRuleDescription returns [MatchingRule matchingRule]
{
matchedProduction( "matchingRuleDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { mrd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { matchingRule = new MatchingRule(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); mrd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); matchingRule.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); mrd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); matchingRule.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); mrd.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); matchingRule.setObsolete( true ); } )
|
- ( syntax:SYNTAX { et.track("SYNTAX", syntax); mrd.setSyntax(numericoid(syntax.getText())); } )
+ ( syntax:SYNTAX { et.track("SYNTAX", syntax); matchingRule.setSyntaxOid(numericoid(syntax.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- mrd.addExtension(ex.key, ex.values);
+ matchingRule.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -562,26 +562,26 @@
* extensions WSP RPAREN ; extensions
* </pre>
*/
-matchingRuleUseDescription returns [MatchingRuleUseDescription mrud = new MatchingRuleUseDescription()]
+matchingRuleUseDescription returns [MatchingRuleUse matchingRuleUse]
{
matchedProduction( "matchingRuleUseDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { mrud.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { matchingRuleUse = new MatchingRuleUse(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); mrud.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); matchingRuleUse.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); mrud.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); matchingRuleUse.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); mrud.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); matchingRuleUse.setObsolete( true ); } )
|
- ( applies:APPLIES { et.track("APPLIES", applies); mrud.setApplicableAttributes(oids(applies.getText())); } )
+ ( applies:APPLIES { et.track("APPLIES", applies); matchingRuleUse.setApplicableAttributeOids(oids(applies.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- mrud.addExtension(ex.key, ex.values);
+ matchingRuleUse.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -614,32 +614,32 @@
* extensions WSP RPAREN ; extensions
* </pre>
*/
-ditContentRuleDescription returns [DITContentRuleDescription dcrd = new DITContentRuleDescription()]
+ditContentRuleDescription returns [DITContentRule ditContentRule]
{
matchedProduction( "ditContentRuleDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { dcrd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { ditContentRule = new DITContentRule(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); dcrd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); ditContentRule.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); dcrd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); ditContentRule.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); dcrd.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); ditContentRule.setObsolete( true ); } )
|
- ( aux:AUX { et.track("AUX", aux); dcrd.setAuxiliaryObjectClasses(oids(aux.getText())); } )
+ ( aux:AUX { et.track("AUX", aux); ditContentRule.setAuxObjectClassOids(oids(aux.getText())); } )
|
- ( must:MUST { et.track("MUST", must); dcrd.setMustAttributeTypes(oids(must.getText())); } )
+ ( must:MUST { et.track("MUST", must); ditContentRule.setMustAttributeTypeOids(oids(must.getText())); } )
|
- ( may:MAY { et.track("MAY", may); dcrd.setMayAttributeTypes(oids(may.getText())); } )
+ ( may:MAY { et.track("MAY", may); ditContentRule.setMayAttributeTypeOids(oids(may.getText())); } )
|
- ( not:NOT { et.track("NOT", not); dcrd.setNotAttributeTypes(oids(not.getText())); } )
+ ( not:NOT { et.track("NOT", not); ditContentRule.setNotAttributeTypeOids(oids(not.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- dcrd.addExtension(ex.key, ex.values);
+ ditContentRule.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -665,28 +665,28 @@
* ruleid = number
* </pre>
*/
-ditStructureRuleDescription returns [DITStructureRuleDescription dsrd = new DITStructureRuleDescription()]
+ditStructureRuleDescription returns [DITStructureRule ditStructureRule]
{
matchedProduction( "ditStructureRuleDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( ruleid:STARTNUMERICOID { dsrd.setRuleId(ruleid(ruleid.getText())); } )
+ ( ruleid:STARTNUMERICOID { ditStructureRule = new DITStructureRule(ruleid(ruleid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); dsrd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); ditStructureRule.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); dsrd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); ditStructureRule.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); dsrd.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); ditStructureRule.setObsolete( true ); } )
|
- ( form:FORM { et.track("FORM", form); dsrd.setForm(oid(form.getText())); } )
+ ( form:FORM { et.track("FORM", form); ditStructureRule.setForm(oid(form.getText())); } )
|
- ( sup:SUP { et.track("SUP", sup); dsrd.setSuperRules(ruleids(sup.getText())); } )
+ ( sup:SUP { et.track("SUP", sup); ditStructureRule.setSuperRules(ruleids(sup.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- dsrd.addExtension(ex.key, ex.values);
+ ditStructureRule.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -718,30 +718,30 @@
* extensions WSP RPAREN ; extensions
* </pre>
*/
-nameFormDescription returns [NameFormDescription nfd = new NameFormDescription()]
+nameFormDescription returns [NameForm nameForm]
{
matchedProduction( "nameFormDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { nfd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { nameForm = new NameForm(numericoid(oid.getText())); } )
(
- ( name:NAME { et.track("NAME", name); nfd.setNames(qdescrs(name.getText())); } )
+ ( name:NAME { et.track("NAME", name); nameForm.setNames(qdescrs(name.getText())); } )
|
- ( desc:DESC { et.track("DESC", desc); nfd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); nameForm.setDescription(qdstring(desc.getText())); } )
|
- ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); nfd.setObsolete( true ); } )
+ ( obsolete:OBSOLETE { et.track("OBSOLETE", obsolete); nameForm.setObsolete( true ); } )
|
- ( oc:OC { et.track("OC", oc); nfd.setStructuralObjectClass(oid(oc.getText())); } )
+ ( oc:OC { et.track("OC", oc); nameForm.setStructuralObjectClassOid(oid(oc.getText())); } )
|
- ( must:MUST { et.track("MUST", must); nfd.setMustAttributeTypes(oids(must.getText())); } )
+ ( must:MUST { et.track("MUST", must); nameForm.setMustAttributeTypeOids(oids(must.getText())); } )
|
- ( may:MAY { et.track("MAY", may); nfd.setMayAttributeTypes(oids(may.getText())); } )
+ ( may:MAY { et.track("MAY", may); nameForm.setMayAttributeTypeOids(oids(may.getText())); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- nfd.addExtension(ex.key, ex.values);
+ nameForm.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -773,7 +773,7 @@
* against element ordering.
*
* <pre>
- * ComparatorDescription = LPAREN WSP
+ * LdapComparator = LPAREN WSP
* numericoid ; object identifier
* [ SP "DESC" SP qdstring ] ; description
* SP "FQCN" SP fqcn ; fully qualified class name
@@ -786,24 +786,24 @@
* fqcnComponent = ???
* </pre>
*/
-comparatorDescription returns [ComparatorDescription cd = new ComparatorDescription()]
+ldapComparator returns [LdapComparatorDescription lcd]
{
- matchedProduction( "comparatorDescription()" );
+ matchedProduction( "ldapComparator()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { cd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { lcd = new LdapComparatorDescription(numericoid(oid.getText())); } )
(
- ( desc:DESC { et.track("DESC", desc); cd.setDescription(qdstring(desc.getText())); } )
+ ( desc:DESC { et.track("DESC", desc); lcd.setDescription(qdstring(desc.getText())); } )
|
- ( fqcn:FQCN { et.track("FQCN", fqcn); cd.setFqcn(fqcn.getText()); } )
+ ( fqcn:FQCN { et.track("FQCN", fqcn); lcd.setFqcn(fqcn.getText()); } )
|
- ( bytecode:BYTECODE { et.track("BYTECODE", bytecode); cd.setBytecode(bytecode.getText()); } )
+ ( bytecode:BYTECODE { et.track("BYTECODE", bytecode); lcd.setBytecode(bytecode.getText()); } )
|
( extension:EXTENSION {
Extension ex = extension(extension.getText());
et.track(ex.key, extension);
- cd.addExtension(ex.key, ex.values);
+ lcd.addExtension(ex.key, ex.values);
} )
)*
RPAR
@@ -816,7 +816,7 @@
}
// semantic check: length should be divisible by 4
- if( cd.getBytecode() != null && ( cd.getBytecode().length() % 4 != 0 ) ) {
+ if( ( lcd.getBytecode() != null ) && ( lcd.getBytecode().length() % 4 != 0 ) ) {
throw new SemanticException( "BYTECODE must be divisible by 4", null, 0, 0 );
}
}
@@ -842,13 +842,13 @@
* fqcnComponent = ???
* </pre>
*/
-normalizerDescription returns [NormalizerDescription nd = new NormalizerDescription()]
+normalizerDescription returns [NormalizerDescription nd]
{
matchedProduction( "normalizerDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { nd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { nd = new NormalizerDescription(numericoid(oid.getText())); } )
(
( desc:DESC { et.track("DESC", desc); nd.setDescription(qdstring(desc.getText())); } )
|
@@ -898,13 +898,13 @@
* fqcnComponent = ???
* </pre>
*/
-syntaxCheckerDescription returns [SyntaxCheckerDescription scd = new SyntaxCheckerDescription()]
+syntaxCheckerDescription returns [SyntaxCheckerDescription scd]
{
matchedProduction( "syntaxCheckerDescription()" );
ElementTracker et = new ElementTracker();
}
:
- ( oid:STARTNUMERICOID { scd.setNumericOid(numericoid(oid.getText())); } )
+ ( oid:STARTNUMERICOID { scd = new SyntaxCheckerDescription(numericoid(oid.getText())); } )
(
( desc:DESC { et.track("DESC", desc); scd.setDescription(qdstring(desc.getText())); } )
|
@@ -1081,4 +1081,4 @@
;
-
\ No newline at end of file
+
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultCodec.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultCodec.java Wed Jan 6 17:52:15 2010
@@ -269,7 +269,7 @@
}
else
{
- matchedDNBytes = StringTools.getBytesUtf8( StringTools.trimLeft( matchedDN.getUpName() ) );
+ matchedDNBytes = StringTools.getBytesUtf8( StringTools.trimLeft( matchedDN.getName() ) );
ldapResultLength += 1 + TLV.getNbBytes( matchedDNBytes.length ) + matchedDNBytes.length;
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncStateValue/SyncStateValueControlGrammar.java Wed Jan 6 17:52:15 2010
@@ -29,12 +29,9 @@
import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
import org.apache.directory.shared.asn1.ber.tlv.Value;
import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.util.BooleanDecoder;
-import org.apache.directory.shared.asn1.util.BooleanDecoderException;
import org.apache.directory.shared.asn1.util.IntegerDecoder;
import org.apache.directory.shared.asn1.util.IntegerDecoderException;
import org.apache.directory.shared.ldap.message.control.replication.SyncStateTypeEnum;
-import org.apache.directory.shared.ldap.message.control.replication.SynchronizationModeEnum;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestCodec.java Wed Jan 6 17:52:15 2010
@@ -36,10 +36,8 @@
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.client.ClientModification;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryCodec.java Wed Jan 6 17:52:15 2010
@@ -36,7 +36,6 @@
import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.name.LdapDN;
@@ -242,7 +241,7 @@
*/
public int computeLength()
{
- objectNameBytes = StringTools.getBytesUtf8( entry.getDn().getUpName() );
+ objectNameBytes = StringTools.getBytesUtf8( entry.getDn().getName() );
// The entry
searchResultEntryLength = 1 + TLV.getNbBytes( objectNameBytes.length ) + objectNameBytes.length;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/entryChange/EntryChangeControlCodec.java Wed Jan 6 17:52:15 2010
@@ -125,7 +125,7 @@
if ( previousDn != null )
{
- previousDnBytes = StringTools.getBytesUtf8( previousDn.getUpName() );
+ previousDnBytes = StringTools.getBytesUtf8( previousDn.getName() );
previousDnLength = 1 + TLV.getNbBytes( previousDnBytes.length ) + previousDnBytes.length;
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValue.java Wed Jan 6 17:52:15 2010
@@ -233,7 +233,7 @@
{
ClientBinaryValue binaryValue = ( ClientBinaryValue ) value;
- return ByteArrayComparator.INSTANCE.compare( getNormalizedValue(), binaryValue.getNormalizedValue() );
+ return new ByteArrayComparator( null ).compare( getNormalizedValue(), binaryValue.getNormalizedValue() );
}
String message = "I don't really know how to compare anything other " +
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java Wed Jan 6 17:52:15 2010
@@ -1102,7 +1102,7 @@
StringBuilder sb = new StringBuilder();
sb.append( "ClientEntry\n" );
- sb.append( " dn: " ).append( dn.getUpName() ).append( '\n' );
+ sb.append( " dn: " ).append( dn.getName() ).append( '\n' );
// First dump the ObjectClass attribute
if ( containsAttribute( "objectClass" ) )
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java Wed Jan 6 17:52:15 2010
@@ -26,7 +26,6 @@
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
-import org.apache.directory.shared.ldap.util.StringTools;
/**
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java Wed Jan 6 17:52:15 2010
@@ -20,12 +20,7 @@
package org.apache.directory.shared.ldap.filter;
-import java.util.Arrays;
-
import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
-import org.apache.directory.shared.ldap.util.StringTools;
/**
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java Wed Jan 6 17:52:15 2010
@@ -22,8 +22,6 @@
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
/**
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java Wed Jan 6 17:52:15 2010
@@ -26,7 +26,6 @@
import javax.naming.NamingException;
-import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.util.StringTools;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java Wed Jan 6 17:52:15 2010
@@ -20,6 +20,7 @@
package org.apache.directory.shared.ldap.ldif;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
@@ -274,7 +275,7 @@
}
StringReader strIn = new StringReader( ldif );
- in = new BufferedReader( strIn );
+ reader = new BufferedReader( strIn );
try
{
@@ -294,5 +295,16 @@
LOG.error( "Cannot parse the ldif buffer : {}", ne.getMessage() );
throw new NamingException( "Error while parsing the ldif buffer" );
}
+ finally
+ {
+ try
+ {
+ reader.close();
+ }
+ catch ( IOException ioe )
+ {
+ // Do nothing
+ }
+ }
}
}
\ No newline at end of file
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java Wed Jan 6 17:52:15 2010
@@ -355,7 +355,7 @@
{
if ( "dn".equalsIgnoreCase( attributeId ) )
{
- return new DefaultClientAttribute( "dn", entry.getDn().getUpName() );
+ return new DefaultClientAttribute( "dn", entry.getDn().getName() );
}
return entry.get( attributeId );
@@ -632,65 +632,18 @@
/**
- * @return a String representing the Entry
+ * @return a String representing the Entry, as a LDIF
*/
public String toString()
{
- StringBuffer sb = new StringBuffer();
- sb.append( "Entry : " );
-
- if ( entry.getDn() == null )
+ try
{
- sb.append( "" );
+ return LdifUtils.convertToLdif( this );
}
- else
+ catch ( NamingException ne )
{
- sb.append( entry.getDn().getUpName() ).append( '\n' );
- }
-
- sb.append( '\n' );
-
- if ( control != null )
- {
- sb.append( " Control : " ).append( control ).append( '\n' );
- }
-
- switch ( changeType )
- {
- case Add :
- sb.append( " Change type is ADD\n" );
- sb.append( " Attributes : \n" );
- sb.append( dumpAttributes() );
- break;
-
- case Modify :
- sb.append( " Change type is MODIFY\n" );
- sb.append( " Modifications : \n" );
- sb.append( dumpModificationItems() );
- break;
-
- case Delete :
- sb.append( " Change type is DELETE\n" );
- break;
-
- case ModDn :
- case ModRdn :
- sb.append( " Change type is ").append( changeType == ChangeType.ModDn ? "MODDN\n" : "MODRDN\n" );
- sb.append( " Delete old RDN : " ).append( deleteOldRdn ? "true\n" : "false\n" );
- sb.append( " New RDN : " ).append( newRdn ).append( '\n' );
-
- if ( !StringTools.isEmpty( newSuperior ) )
- {
- sb.append( " New superior : " ).append( newSuperior ).append( '\n' );
- }
-
- break;
-
- default :
- break; // Do nothing
+ return null;
}
-
- return sb.toString();
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Wed Jan 6 17:52:15 2010
@@ -19,7 +19,9 @@
*/
package org.apache.directory.shared.ldap.ldif;
+
import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -58,6 +60,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
* <pre>
* <ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep>
@@ -165,7 +168,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class LdifReader implements Iterable<LdifEntry>
+public class LdifReader implements Iterable<LdifEntry>, Closeable
{
/** A logger */
private static final Logger LOG = LoggerFactory.getLogger( LdifReader.class );
@@ -180,6 +183,7 @@
/** The current position */
private int pos;
+
/**
* Creates a new instance of Position.
*/
@@ -188,6 +192,7 @@
pos = 0;
}
+
/**
* Increment the current position by one
*
@@ -197,6 +202,7 @@
pos++;
}
+
/**
* Increment the current position by the given value
*
@@ -244,7 +250,7 @@
protected LdifEntry prefetched;
/** The ldif Reader */
- protected Reader in;
+ protected Reader reader;
/** A flag set if the ldif contains entries */
protected boolean containsEntries;
@@ -258,6 +264,7 @@
*/
protected Exception error;
+
/**
* Constructors
*/
@@ -268,9 +275,10 @@
version = DEFAULT_VERSION;
}
- private void init( BufferedReader inf ) throws NamingException
+
+ private void init( BufferedReader reader ) throws NamingException
{
- this.in = inf;
+ this.reader = reader;
lines = new ArrayList<String>();
position = new Position();
version = DEFAULT_VERSION;
@@ -282,6 +290,7 @@
prefetched = parseEntry();
}
+
/**
* A constructor which takes a file name
*
@@ -291,43 +300,31 @@
*/
public LdifReader( String ldifFileName ) throws NamingException
{
- File inf = new File( ldifFileName );
+ File file = new File( ldifFileName );
- if ( !inf.exists() )
+ if ( !file.exists() )
{
- LOG.error( "File {} cannot be found", inf.getAbsoluteFile() );
- throw new NamingException( "Cannot find file " + inf.getAbsoluteFile() );
+ LOG.error( "File {} cannot be found", file.getAbsoluteFile() );
+ throw new NamingException( "Cannot find file " + file.getAbsoluteFile() );
}
- if ( !inf.canRead() )
+ if ( !file.canRead() )
{
- LOG.error( "File {} cannot be read", inf.getName() );
- throw new NamingException( "Cannot read file " + inf.getName() );
+ LOG.error( "File {} cannot be read", file.getName() );
+ throw new NamingException( "Cannot read file " + file.getName() );
}
try
{
- init( new BufferedReader( new FileReader( inf ) ) );
+ init( new BufferedReader( new FileReader( file ) ) );
}
- catch (FileNotFoundException fnfe)
+ catch ( FileNotFoundException fnfe )
{
- LOG.error( "File {} cannot be found", inf.getAbsoluteFile() );
- throw new NamingException( "Cannot find file " + inf.getAbsoluteFile() );
+ LOG.error( "File {} cannot be found", file.getAbsoluteFile() );
+ throw new NamingException( "Cannot find file " + file.getAbsoluteFile() );
}
}
- /**
- * A constructor which takes a BufferedReader
- *
- * @param in
- * A BufferedReader containing ldif formated input
- * @throws NamingException
- * If the file cannot be processed or if the format is incorrect
- */
- public LdifReader( BufferedReader in ) throws NamingException
- {
- init( in );
- }
/**
* A constructor which takes a Reader
@@ -342,6 +339,7 @@
init( new BufferedReader( in ) );
}
+
/**
* A constructor which takes an InputStream
*
@@ -355,6 +353,7 @@
init( new BufferedReader( new InputStreamReader( in ) ) );
}
+
/**
* A constructor which takes a File
*
@@ -363,31 +362,32 @@
* @throws NamingException
* If the file cannot be processed or if the format is incorrect
*/
- public LdifReader( File in ) throws NamingException
+ public LdifReader( File file ) throws NamingException
{
- if ( !in.exists() )
+ if ( !file.exists() )
{
- LOG.error( "File {} cannot be found", in.getAbsoluteFile() );
- throw new NamingException( "Cannot find file " + in.getAbsoluteFile() );
+ LOG.error( "File {} cannot be found", file.getAbsoluteFile() );
+ throw new NamingException( "Cannot find file " + file.getAbsoluteFile() );
}
- if ( !in.canRead() )
+ if ( !file.canRead() )
{
- LOG.error( "File {} cannot be read", in.getName() );
- throw new NamingException( "Cannot read file " + in.getName() );
+ LOG.error( "File {} cannot be read", file.getName() );
+ throw new NamingException( "Cannot read file " + file.getName() );
}
try
{
- init( new BufferedReader( new FileReader( in ) ) );
+ init( new BufferedReader( new FileReader( file ) ) );
}
- catch (FileNotFoundException fnfe)
+ catch ( FileNotFoundException fnfe )
{
- LOG.error( "File {} cannot be found", in.getAbsoluteFile() );
- throw new NamingException( "Cannot find file " + in.getAbsoluteFile() );
+ LOG.error( "File {} cannot be found", file.getAbsoluteFile() );
+ throw new NamingException( "Cannot find file " + file.getAbsoluteFile() );
}
}
+
/**
* @return The ldif file version
*/
@@ -396,6 +396,7 @@
return version;
}
+
/**
* @return The maximum size of a file which is used into an attribute value.
*/
@@ -404,6 +405,7 @@
return sizeLimit;
}
+
/**
* Set the maximum file size that can be accepted for an attribute value
*
@@ -415,6 +417,7 @@
this.sizeLimit = sizeLimit;
}
+
// <fill> ::= ' ' <fill> | �
private static void parseFill( char[] document, Position position )
{
@@ -425,6 +428,7 @@
}
}
+
/**
* Parse a number following the rules :
*
@@ -463,6 +467,7 @@
}
}
+
/**
* Parse the changeType
*
@@ -500,6 +505,7 @@
return operation;
}
+
/**
* Parse the DN of an entry
*
@@ -537,7 +543,7 @@
{
dn = new String( Base64.decode( trimmedLine.toCharArray() ), "UTF-8" );
}
- catch (UnsupportedEncodingException uee)
+ catch ( UnsupportedEncodingException uee )
{
// The DN is not base 64 encoded
LOG.error( "The ldif entry is supposed to have a base 64 encoded DN" );
@@ -567,7 +573,7 @@
{
LdapDnParser.parseInternal( dn, new ArrayList<Rdn>() );
}
- catch (InvalidNameException ine)
+ catch ( InvalidNameException ine )
{
LOG.error( "The DN {} is not valid" );
throw ine;
@@ -576,6 +582,7 @@
return dn;
}
+
/**
* Parse the value part.
*
@@ -608,6 +615,7 @@
}
}
+
/**
* Parse the value part.
*
@@ -661,7 +669,7 @@
}
else
{
- byte[] data = new byte[(int) length];
+ byte[] data = new byte[( int ) length];
DataInputStream inf = null;
try
@@ -671,7 +679,7 @@
return data;
}
- catch (FileNotFoundException fnfe)
+ catch ( FileNotFoundException fnfe )
{
// We can't reach this point, the file
// existence has already been
@@ -679,7 +687,7 @@
LOG.error( "File {} not found", fileName );
throw new NamingException( "Bad URL, file not found" );
}
- catch (IOException ioe)
+ catch ( IOException ioe )
{
LOG.error( "File {} error reading", fileName );
throw new NamingException( "Bad URL, file can't be read" );
@@ -705,7 +713,7 @@
throw new NamingException( "Unsupported URL protocol" );
}
}
- catch (MalformedURLException mue)
+ catch ( MalformedURLException mue )
{
LOG.error( "Bad URL {}", urlName );
throw new NamingException( "Bad URL" );
@@ -722,6 +730,7 @@
}
}
+
/**
* Parse a control. The grammar is : <control> ::= "control:" <fill>
* <ldap-oid> <critical-e> <value-spec-e> <sep> <critical-e> ::= <spaces>
@@ -776,7 +785,7 @@
{
oid = new OID( oidString );
}
- catch (DecoderException de)
+ catch ( DecoderException de )
{
LOG.error( "The OID {} is not valid", oidString );
throw new NamingException( "Bad control oid" );
@@ -842,7 +851,7 @@
for ( int i = 0; i < length - criticalPos - 1; i++ )
{
- value[i] = (byte) controlValue[i + criticalPos + 1];
+ value[i] = ( byte ) controlValue[i + criticalPos + 1];
}
control.setValue( value );
@@ -852,6 +861,7 @@
return control;
}
+
/**
* Parse an AttributeType/AttributeValue
*
@@ -876,6 +886,7 @@
}
}
+
/**
* Parse an AttributeType/AttributeValue
*
@@ -903,6 +914,7 @@
entry.addAttribute( attributeType, attributeValue );
}
+
/**
* Parse a ModRDN operation
*
@@ -926,8 +938,8 @@
{
int colonIndex = line.indexOf( ':' );
Object attributeValue = parseValue( line, colonIndex );
- entry.setNewRdn( attributeValue instanceof String ? (String) attributeValue : StringTools
- .utf8ToString( (byte[]) attributeValue ) );
+ entry.setNewRdn( attributeValue instanceof String ? ( String ) attributeValue : StringTools
+ .utf8ToString( ( byte[] ) attributeValue ) );
}
else
{
@@ -968,6 +980,7 @@
return;
}
+
/**
* Parse a modify change type.
*
@@ -1095,13 +1108,13 @@
if ( attributeValue instanceof String )
{
- attribute.add( (String)attributeValue );
+ attribute.add( ( String ) attributeValue );
}
else
{
- attribute.add( (byte[])attributeValue );
+ attribute.add( ( byte[] ) attributeValue );
}
-
+
isEmptyValue = false;
state = ATTRVAL_SPEC_OR_SEP;
@@ -1109,6 +1122,7 @@
}
}
+
/**
* Parse a change operation. We have to handle different cases depending on
* the operation. 1) Delete : there should *not* be any line after the
@@ -1177,8 +1191,8 @@
{
int colonIndex = line.indexOf( ':' );
Object attributeValue = parseValue( line, colonIndex );
- entry.setNewSuperior( attributeValue instanceof String ? (String) attributeValue : StringTools
- .utf8ToString( (byte[]) attributeValue ) );
+ entry.setNewSuperior( attributeValue instanceof String ? ( String ) attributeValue
+ : StringTools.utf8ToString( ( byte[] ) attributeValue ) );
}
else
{
@@ -1207,6 +1221,7 @@
}
}
+
/**
* Parse a ldif file. The following rules are processed :
*
@@ -1232,7 +1247,7 @@
String line = lines.get( 0 );
String name = parseDn( line );
-
+
LdapDN dn = new LdapDN( name );
// Ok, we have found a DN
@@ -1362,6 +1377,7 @@
return entry;
}
+
/**
* Parse the version from the ldif input.
*
@@ -1410,7 +1426,7 @@
{
ver = Integer.parseInt( versionNumber );
}
- catch (NumberFormatException nfe)
+ catch ( NumberFormatException nfe )
{
LOG.error( "The version is not a number" );
throw new NamingException( "Ldif parsing error" );
@@ -1420,7 +1436,7 @@
// We have found the version, just discard the line from the list
lines.remove( 0 );
-
+
// and read the next lines if the current buffer is empty
if ( lines.size() == 0 )
{
@@ -1435,6 +1451,7 @@
return ver;
}
+
/**
* Reads an entry in a ldif buffer, and returns the resulting lines, without
* comments, and unfolded.
@@ -1454,7 +1471,7 @@
try
{
- while ( ( line = ( (BufferedReader) in ).readLine() ) != null )
+ while ( ( line = ( ( BufferedReader ) reader ).readLine() ) != null )
{
if ( line.length() == 0 )
{
@@ -1513,7 +1530,7 @@
}
}
}
- catch (IOException ioe)
+ catch ( IOException ioe )
{
throw new NamingException( "Error while reading ldif lines" );
}
@@ -1527,6 +1544,7 @@
return;
}
+
/**
* Parse a ldif file (using the default encoding).
*
@@ -1541,6 +1559,7 @@
return parseLdifFile( fileName, Charset.forName( StringTools.getDefaultCharsetName() ).toString() );
}
+
/**
* Parse a ldif file, decoding it using the given charset encoding
*
@@ -1568,21 +1587,40 @@
throw new NamingException( "Filename " + fileName + " not found." );
}
+ BufferedReader reader = null;
+
// Open the file and then get a channel from the stream
try
{
- BufferedReader inf = new BufferedReader( new InputStreamReader( new FileInputStream( file ),
- Charset.forName( encoding ) ) );
+ reader = new BufferedReader(
+ new InputStreamReader(
+ new FileInputStream( file ), Charset.forName( encoding ) ) );
- return parseLdif( inf );
+ return parseLdif( reader );
}
- catch (FileNotFoundException fnfe)
+ catch ( FileNotFoundException fnfe )
{
LOG.error( "Cannot find file {}", fileName );
throw new NamingException( "Filename " + fileName + " not found." );
}
+ finally
+ {
+ // close the reader
+ try
+ {
+ if ( reader != null )
+ {
+ reader.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ // Nothing to do
+ }
+ }
}
+
/**
* A method which parses a ldif string and returns a list of entries.
*
@@ -1601,27 +1639,45 @@
return new ArrayList<LdifEntry>();
}
- StringReader strIn = new StringReader( ldif );
- BufferedReader inf = new BufferedReader( strIn );
+ BufferedReader reader = new BufferedReader(
+ new StringReader( ldif ) );
try
{
- List<LdifEntry> entries = parseLdif( inf );
+ List<LdifEntry> entries = parseLdif( reader );
if ( LOG.isDebugEnabled() )
{
- LOG.debug( "Parsed {} entries.", ( entries == null ? Integer.valueOf( 0 ) : Integer.valueOf( entries.size() ) ) );
+ LOG.debug( "Parsed {} entries.", ( entries == null ? Integer.valueOf( 0 ) : Integer.valueOf( entries
+ .size() ) ) );
}
return entries;
}
- catch (NamingException ne)
+ catch ( NamingException ne )
{
LOG.error( "Cannot parse the ldif buffer : {}", ne.getMessage() );
throw new NamingException( "Error while parsing the ldif buffer" );
}
+ finally
+ {
+ // Close the reader
+ try
+ {
+ if ( reader != null )
+ {
+ reader.close();
+ }
+ }
+ catch ( IOException ioe )
+ {
+ // Nothing to do
+ }
+
+ }
}
+
// ------------------------------------------------------------------------
// Iterator Methods
// ------------------------------------------------------------------------
@@ -1645,7 +1701,7 @@
{
prefetched = parseEntry();
}
- catch (NamingException ne)
+ catch ( NamingException ne )
{
error = ne;
throw new NoSuchElementException( ne.getMessage() );
@@ -1655,7 +1711,7 @@
return entry;
}
- catch (NamingException ne)
+ catch ( NamingException ne )
{
LOG.error( "Premature termination of LDIF iterator" );
error = ne;
@@ -1663,7 +1719,7 @@
}
}
-
+
/**
* Gets the next LDIF on the channel.
*
@@ -1686,7 +1742,7 @@
return null != prefetched;
}
-
+
/**
* Tests to see if another LDIF is on the input channel.
*
@@ -1710,7 +1766,7 @@
throw new UnsupportedOperationException();
}
-
+
/**
* Always throws UnsupportedOperationException!
*
@@ -1721,30 +1777,34 @@
removeInternal();
}
+
/**
* @return An iterator on the file
*/
public Iterator<LdifEntry> iterator()
{
- return new Iterator<LdifEntry>()
+ return new Iterator<LdifEntry>()
{
- public boolean hasNext()
+ public boolean hasNext()
{
return hasNextInternal();
}
-
- public LdifEntry next()
+
+
+ public LdifEntry next()
{
return nextInternal();
}
-
- public void remove()
+
+
+ public void remove()
{
throw new UnsupportedOperationException();
}
};
}
+
/**
* @return True if an error occured during parsing
*/
@@ -1753,6 +1813,7 @@
return error != null;
}
+
/**
* @return The exception that occurs during an entry parsing
*/
@@ -1761,6 +1822,7 @@
return error;
}
+
/**
* The main entry point of the LdifParser. It reads a buffer and returns a
* List of entries.
@@ -1771,12 +1833,12 @@
* @throws NamingException
* If something went wrong
*/
- public List<LdifEntry> parseLdif( BufferedReader inf ) throws NamingException
+ public List<LdifEntry> parseLdif( BufferedReader reader ) throws NamingException
{
// Create a list that will contain the read entries
List<LdifEntry> entries = new ArrayList<LdifEntry>();
- this.in = inf;
+ this.reader = reader;
// First get the version - if any -
version = parseVersion();
@@ -1785,7 +1847,7 @@
// When done, get the entries one by one.
try
{
- for ( LdifEntry entry:this )
+ for ( LdifEntry entry : this )
{
if ( entry != null )
{
@@ -1801,6 +1863,7 @@
return entries;
}
+
/**
* @return True if the ldif file contains entries, fals if it contains
* changes
@@ -1809,4 +1872,16 @@
{
return containsEntries;
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException
+ {
+ if ( reader != null )
+ {
+ reader.close();
+ }
+ }
}
\ No newline at end of file
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java Wed Jan 6 17:52:15 2010
@@ -34,7 +34,7 @@
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.client.ClientModification;
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
-import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
+import org.apache.directory.shared.ldap.name.AVA;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.AttributeUtils;
@@ -280,7 +280,7 @@
entry.setChangeType( ChangeType.ModDn );
entry.setDn( newDn );
entry.setNewRdn( currentRdn.getUpName() );
- entry.setNewSuperior( currentParent.getUpName() );
+ entry.setNewSuperior( currentParent.getName() );
entry.setDeleteOldRdn( false );
return entry;
}
@@ -322,7 +322,7 @@
LdapDN oldSuperior = ( LdapDN ) entry.getDn().clone();
oldSuperior.remove( oldSuperior.size() - 1 );
- reverted.setNewSuperior( oldSuperior.getUpName() );
+ reverted.setNewSuperior( oldSuperior.getName() );
}
return reverted;
@@ -341,7 +341,7 @@
// been renamed
restored.setDn( parentDn );
- for ( AttributeTypeAndValue ava:newRdn )
+ for ( AVA ava:newRdn )
{
// No need to add something which has already been added
// in the previous modification
@@ -388,7 +388,7 @@
LdapDN oldSuperior = ( LdapDN ) newDn.clone();
oldSuperior.remove( oldSuperior.size() - 1 );
- reverted.setNewSuperior( oldSuperior.getUpName() );
+ reverted.setNewSuperior( oldSuperior.getName() );
}
// Delete the newRDN values
@@ -485,7 +485,7 @@
// Does it overlap ?
// Is the new RDN AVAs contained into the entry?
- for ( AttributeTypeAndValue atav:newRdn )
+ for ( AVA atav:newRdn )
{
if ( atav.equals( oldRdn.getAtav() ) )
{
@@ -558,17 +558,17 @@
boolean overlapping = false;
boolean existInEntry = false;
- Set<AttributeTypeAndValue> oldAtavs = new HashSet<AttributeTypeAndValue>();
+ Set<AVA> oldAtavs = new HashSet<AVA>();
// We first build a set with all the oldRDN ATAVs
- for ( AttributeTypeAndValue atav:oldRdn )
+ for ( AVA atav:oldRdn )
{
oldAtavs.add( atav );
}
// Now we loop on the newRDN ATAVs to evaluate if the Rdns are overlaping
// and if the newRdn ATAVs are present in the entry
- for ( AttributeTypeAndValue atav:newRdn )
+ for ( AVA atav:newRdn )
{
if ( oldAtavs.contains( atav ) )
{
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Wed Jan 6 17:52:15 2010
@@ -239,13 +239,13 @@
if ( entry.getDn() != null )
{
// First, dump the DN
- if ( isLDIFSafe( entry.getDn().getUpName() ) )
+ if ( isLDIFSafe( entry.getDn().getName() ) )
{
- sb.append( stripLineToNChars( "dn: " + entry.getDn().getUpName(), length ) );
+ sb.append( stripLineToNChars( "dn: " + entry.getDn().getName(), length ) );
}
else
{
- sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getUpName() ), length ) );
+ sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getName() ), length ) );
}
sb.append( '\n' );
@@ -306,13 +306,13 @@
StringBuilder sb = new StringBuilder();
// First, dump the DN
- if ( isLDIFSafe( entry.getDn().getUpName() ) )
+ if ( isLDIFSafe( entry.getDn().getName() ) )
{
sb.append( stripLineToNChars( "dn: " + entry.getDn(), length ) );
}
else
{
- sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getUpName() ), length ) );
+ sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getName() ), length ) );
}
sb.append( '\n' );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/ComplexLdapDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/ComplexLdapDnParser.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/ComplexLdapDnParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/ComplexLdapDnParser.java Wed Jan 6 17:52:15 2010
@@ -46,6 +46,7 @@
public void parseDn( String name, List<Rdn> rdns ) throws InvalidNameException
{
AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) );
+
try
{
dnParser.relativeDistinguishedNames( rdns );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/FastLdapDnParser.java Wed Jan 6 17:52:15 2010
@@ -82,7 +82,7 @@
void parseDn( String name, List<Rdn> rdns ) throws InvalidNameException
{
- if ( name == null || name.trim().length() == 0 )
+ if ( ( name == null ) || ( name.trim().length() == 0 ) )
{
// We have an empty DN, just get out of the function.
return;
@@ -133,17 +133,16 @@
{
throw new InvalidNameException( "RDN must not be empty" );
}
+ if( rdn == null )
+ {
+ throw new InvalidNameException( "RDN must not be null" );
+ }
Position pos = new Position();
pos.start = 0;
pos.length = name.length();
parseRdnInternal( name, pos, rdn );
-
- if ( !hasMoreChars( pos ) )
- {
- throw new InvalidNameException( "Expected no more characters at position " + pos.start );
- }
}
@@ -175,13 +174,14 @@
// SPACE*
matchSpaces( name, pos );
- rdn.addAttributeTypeAndValue( type, type,
- new ClientStringValue( upValue ),
- new ClientStringValue( value ) );
+ String upName = name.substring( rdnStart, pos.start );
- rdn.setUpName( name.substring( rdnStart, pos.start ) );
- rdn.normalize();
+ AVA ava = new AVA( type, type, new ClientStringValue( upValue ),
+ new ClientStringValue( value ), upName );
+ rdn.addAttributeTypeAndValue( ava );
+ rdn.setUpName( upName );
+ rdn.normalize();
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Wed Jan 6 17:52:15 2010
@@ -36,7 +36,6 @@
import javax.naming.Name;
import javax.naming.NamingException;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
@@ -215,6 +214,73 @@
/**
+ * Creates a new instance of LdapDN, using varargs to declare the RDNs. Each
+ * String is either a full RDN, or a couple of AttributeType DI and a value.
+ * If the String contains a '=' symbol, the the constructor will assume that
+ * the String arg contains afull RDN, otherwise, it will consider that the
+ * following arg is the value.
+ * An example of usage would be :
+ * <pre>
+ * String exampleName = "example";
+ * String baseDn = "dc=apache,dc=org";
+ *
+ * LdapDN dn = new LdapDN(
+ * "cn=Test",
+ * "ou", exampleName,
+ * baseDn);
+ * </pre>
+ *
+ * @param upNames
+ * @throws InvalidNameException
+ */
+ public LdapDN( String... upNames ) throws InvalidNameException
+ {
+ StringBuilder sb = new StringBuilder();
+ boolean valueExpected = false;
+ boolean isFirst = true;
+
+ for ( String upName : upNames )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else if ( !valueExpected )
+ {
+ sb.append( ',' );
+ }
+
+ if ( !valueExpected )
+ {
+ sb.append( upName );
+
+ if ( upName.indexOf( '=' ) == -1 )
+ {
+ valueExpected = true;
+ }
+ }
+ else
+ {
+ sb.append( "=" ).append( upName );
+
+ valueExpected = false;
+ }
+ }
+
+ if ( valueExpected )
+ {
+ throw new InvalidNameException( "A value is missing on some RDN" );
+ }
+
+ // Stores the representations of a DN : internal (as a string and as a
+ // byte[]) and external.
+ upName = sb.toString();
+ LdapDnParser.parseInternal( upName, rdns );
+ normalizeInternal();
+ normalized = false;
+ }
+
+ /**
* Create a DN when deserializing it.
*
* Note : this constructor is used only by the deserialization method.
@@ -334,7 +400,7 @@
sb.append( ',' );
}
- sb.append( rdn );
+ sb.append( rdn.getNormName() );
}
String newNormName = sb.toString();
@@ -355,10 +421,11 @@
* getNormName method
*
* @return A String representing the normalized DN
+ * @TODO : use the getName() method instead
*/
public String toString()
{
- return normName == null ? "" : normName;
+ return getNormName();
}
@@ -520,9 +587,21 @@
/**
+ * Get the initial DN
+ *
+ * @return The DN as a String
+ */
+ public String getName()
+ {
+ return ( upName == null ? "" : upName );
+ }
+
+
+ /**
* Get the initial DN (without normalization)
*
* @return The DN as a String
+ * @deprecated
*/
public String getUpName()
{
@@ -1097,7 +1176,7 @@
{
normName = dn.getNormName() + "," + normName;
bytes = StringTools.getBytesUtf8( normName );
- upName = dn.getUpName() + "," + upName;
+ upName = dn.getName() + "," + upName;
}
}
else
@@ -1363,7 +1442,7 @@
}
- private static AttributeTypeAndValue atavOidToName( AttributeTypeAndValue atav, Map<String, OidNormalizer> oidsMap )
+ private static AVA atavOidToName( AVA atav, Map<String, OidNormalizer> oidsMap )
throws InvalidNameException, NamingException
{
String type = StringTools.trim( atav.getNormType() );
@@ -1381,14 +1460,16 @@
}
else
{
- OidNormalizer oidNormalizer = oidsMap.get( type );
+ OidNormalizer oidNormalizer = oidsMap.get( type.toLowerCase() );
if ( oidNormalizer != null )
{
- return new AttributeTypeAndValue( atav.getUpType(), oidNormalizer.getAttributeTypeOid(),
- atav.getUpValue(),
- oidNormalizer.getNormalizer().normalize( atav.getNormValue() ) );
-
+ return new AVA(
+ atav.getUpType(),
+ oidNormalizer.getAttributeTypeOid(),
+ atav.getUpValue(),
+ oidNormalizer.getNormalizer().normalize( atav.getNormValue() ),
+ atav.getUpName() );
}
else
{
@@ -1403,29 +1484,8 @@
LOG.error( "Empty type not allowed in a DN" );
throw new InvalidNameException( "Empty type not allowed in a DN" );
}
-
}
- /**
- * This private method is used to normalize the value, when we have found a normalizer.
- * This method deals with RDN having one single ATAV.
- *
- * @param rdn the RDN we want to normalize. It will contain the resulting normalized RDN
- * @param oidNormalizer the normalizer to use for the RDN
- * @throws NamingException If something went wrong.
- */
- private static void oidNormalize( Rdn rdn, OidNormalizer oidNormalizer ) throws NamingException
- {
- String upValue = rdn.getUpValue();
- String upType = rdn.getUpType();
- rdn.clear();
- String normStringValue = DefaultStringNormalizer.normalizeString( ( String ) upValue );
- String normValue = oidNormalizer.getNormalizer().normalize( normStringValue );
-
- rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(),
- new ClientStringValue( upValue ),
- new ClientStringValue( normValue ) );
- }
/**
* Transform a RDN by changing the value to its OID counterpart and
@@ -1436,7 +1496,7 @@
* @throws InvalidNameException If the RDN is invalid.
* @throws NamingException If something went wrong.
*/
- private static void rdnOidToName( Rdn rdn, Map<String, OidNormalizer> oidsMap ) throws InvalidNameException,
+ /** No qualifier */ static void rdnOidToName( Rdn rdn, Map<String, OidNormalizer> oidsMap ) throws InvalidNameException,
NamingException
{
if ( rdn.getNbAtavs() > 1 )
@@ -1446,66 +1506,18 @@
Rdn rdnCopy = ( Rdn ) rdn.clone();
rdn.clear();
- for ( AttributeTypeAndValue val:rdnCopy )
+ for ( AVA val:rdnCopy )
{
- AttributeTypeAndValue newAtav = atavOidToName( val, oidsMap );
- rdn.addAttributeTypeAndValue( val.getUpType(), newAtav.getNormType(), val.getUpValue(), newAtav.getNormValue() );
+ AVA newAtav = atavOidToName( val, oidsMap );
+ rdn.addAttributeTypeAndValue( newAtav );
}
-
}
else
{
- String type = rdn.getNormType();
-
- if ( StringTools.isNotEmpty( type ) )
- {
- if ( oidsMap == null )
- {
- return;
- }
- else
- {
- OidNormalizer oidNormalizer = oidsMap.get( type );
-
- if ( oidNormalizer != null )
- {
- oidNormalize( rdn, oidNormalizer );
- }
- else
- {
- // May be the oidNormalizer was null because the type starts with OID
- if ( ( type.startsWith( "oid." ) ) || ( type.startsWith( "OID." ) ) )
- {
- type = type.substring( 4 );
- oidNormalizer = oidsMap.get( type );
-
- if ( oidNormalizer != null )
- {
- // Ok, just normalize after having removed the 4 first chars
- oidNormalize( rdn, oidNormalizer );
- }
- else
- {
- // We don't have a normalizer for this OID : just do
- // nothing.
- return;
- }
- }
- else
- {
- // We don't have a normalizer for this OID : just do
- // nothing.
- return;
- }
- }
- }
- }
- else
- {
- // The type is empty : this is not possible...
- LOG.error( "We should not have an empty DN" );
- throw new InvalidNameException( "Empty type not allowed in a DN" );
- }
+ AVA val = rdn.getAtav();
+ rdn.clear();
+ AVA newAtav = atavOidToName( val, oidsMap );
+ rdn.addAttributeTypeAndValue( newAtav );
}
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDNSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDNSerializer.java?rev=896579&r1=896578&r2=896579&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDNSerializer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDNSerializer.java Wed Jan 6 17:52:15 2010
@@ -57,7 +57,7 @@
*/
public static void serialize( LdapDN dn, ObjectOutput out ) throws IOException
{
- if ( dn.getUpName() == null )
+ if ( dn.getName() == null )
{
String message = "Cannot serialize a NULL DN";
LOG.error( message );
@@ -65,12 +65,12 @@
}
// Write the UPName
- out.writeUTF( dn.getUpName() );
+ out.writeUTF( dn.getName() );
// Write the NormName if different
if ( dn.isNormalized() )
{
- if ( dn.getUpName().equals( dn.getNormName() ) )
+ if ( dn.getName().equals( dn.getNormName() ) )
{
out.writeUTF( "" );
}