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 2012/09/20 17:30:51 UTC
svn commit: r1388074 -
/directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
Author: elecharny
Date: Thu Sep 20 15:30:51 2012
New Revision: 1388074
URL: http://svn.apache.org/viewvc?rev=1388074&view=rev
Log:
o The Dn.apply( SchemaManager ) methods now does not apply the SchemaManager if the Dn already has a schema manager
o Added a Dn.apply( SchemaManager, boolean) method to be used when one want to force the SchemaManager to be replaced, if the Dn is already schema aware
Modified:
directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
Modified: directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1388074&r1=1388073&r2=1388074&view=diff
==============================================================================
--- directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java (original)
+++ directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java Thu Sep 20 15:30:51 2012
@@ -782,7 +782,7 @@ public class Dn implements Iterable<Rdn>
}
newDn.toUpName();
- newDn.apply( schemaManager );
+ newDn.apply( schemaManager, true );
return newDn;
}
@@ -864,7 +864,7 @@ public class Dn implements Iterable<Rdn>
}
newDn.toUpName();
- newDn.apply( schemaManager );
+ newDn.apply( schemaManager, true );
return newDn;
}
@@ -897,7 +897,7 @@ public class Dn implements Iterable<Rdn>
}
else
{
- clonedDn.apply( schemaManager );
+ clonedDn.apply( schemaManager, true );
clonedDn.toUpName();
}
@@ -922,7 +922,7 @@ public class Dn implements Iterable<Rdn>
clonedDn.rdns.add( 0, newRdn );
- clonedDn.apply( schemaManager );
+ clonedDn.apply( schemaManager, true );
clonedDn.toUpName();
return clonedDn;
@@ -945,7 +945,7 @@ public class Dn implements Iterable<Rdn>
Dn clonedDn = copy();
clonedDn.rdns.add( 0, newRdn.clone() );
- clonedDn.apply( schemaManager );
+ clonedDn.apply( schemaManager, true );
clonedDn.toUpName();
return clonedDn;
@@ -978,7 +978,7 @@ public class Dn implements Iterable<Rdn>
try
{
- newDn.apply( schemaManager );
+ newDn.apply( schemaManager, true );
}
catch ( LdapInvalidDnException e )
{
@@ -1029,7 +1029,7 @@ public class Dn implements Iterable<Rdn>
{
return true;
}
-
+
if ( name.size() != this.size() )
{
return false;
@@ -1137,7 +1137,7 @@ public class Dn implements Iterable<Rdn>
// ATAVs
Rdn rdnCopy = rdn.clone();
rdn.clear();
-
+
if ( rdnCopy.size() < 2 )
{
Ava newAtav = atavOidToName( rdnCopy.getAva(), schemaManager );
@@ -1156,7 +1156,7 @@ public class Dn implements Iterable<Rdn>
sortedOids.add( oid );
avas.put( oid, newAtav );
}
-
+
// And create the Rdn
for ( String oid : sortedOids )
{
@@ -1167,90 +1167,94 @@ public class Dn implements Iterable<Rdn>
/**
- * Normalizes the Dn using the given the schema manager
+ * Normalizes the Dn using the given the schema manager. If the flag is set to true,
+ * we will replace the inner SchemaManager by the provided one.
*
* @param schemaManager The schemaManagerto use to normalize the Dn
+ * @param force Tells if we should replace an existing SchemaManager by a new one
* @return The normalized Dn
* @throws LdapInvalidDnException If the Dn is invalid.
*/
- public Dn apply( SchemaManager schemaManager ) throws LdapInvalidDnException
+ public Dn apply( SchemaManager schemaManager, boolean force ) throws LdapInvalidDnException
{
- this.schemaManager = schemaManager;
-
- if ( this.schemaManager != null )
+ if ( ( this.schemaManager == null ) || force )
{
- synchronized ( this )
- {
- if ( size() == 0 )
- {
- bytes = null;
- normName = "";
-
- return this;
- }
- StringBuilder sb = new StringBuilder();
- boolean isFirst = true;
+ this.schemaManager = schemaManager;
- for ( Rdn rdn : rdns )
+ if ( this.schemaManager != null )
+ {
+ synchronized ( this )
{
- rdn.apply( schemaManager );
-
- if ( isFirst )
+ if ( size() == 0 )
{
- isFirst = false;
+ bytes = null;
+ normName = "";
+
+ return this;
}
- else
+
+ StringBuilder sb = new StringBuilder();
+ boolean isFirst = true;
+
+ for ( Rdn rdn : rdns )
{
- sb.append( ',' );
- }
+ rdn.apply( schemaManager );
- sb.append( rdn.getNormName() );
- }
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
- String newNormName = sb.toString();
+ sb.append( rdn.getNormName() );
+ }
- if ( ( normName == null ) || !normName.equals( newNormName ) )
- {
- bytes = Strings.getBytesUtf8( newNormName );
- normName = newNormName;
- }
+ String newNormName = sb.toString();
- return this;
- }
- }
- else
- {
- if ( rdns.size() == 0 )
- {
- bytes = null;
- normName = "";
+ if ( ( normName == null ) || !normName.equals( newNormName ) )
+ {
+ bytes = Strings.getBytesUtf8( newNormName );
+ normName = newNormName;
+ }
+ }
}
else
{
- StringBuffer sb = new StringBuffer();
- boolean isFirst = true;
-
- for ( Rdn rdn : rdns )
+ if ( rdns.size() == 0 )
{
- if ( isFirst )
- {
- isFirst = false;
- }
- else
+ bytes = null;
+ normName = "";
+ }
+ else
+ {
+ StringBuffer sb = new StringBuffer();
+ boolean isFirst = true;
+
+ for ( Rdn rdn : rdns )
{
- sb.append( ',' );
- }
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
- sb.append( rdn.getNormName() );
- }
+ sb.append( rdn.getNormName() );
+ }
- String newNormName = sb.toString();
+ String newNormName = sb.toString();
- if ( ( normName == null ) || !normName.equals( newNormName ) )
- {
- bytes = Strings.getBytesUtf8( newNormName );
- normName = newNormName;
+ if ( ( normName == null ) || !normName.equals( newNormName ) )
+ {
+ bytes = Strings.getBytesUtf8( newNormName );
+ normName = newNormName;
+ }
}
}
}
@@ -1260,6 +1264,26 @@ public class Dn implements Iterable<Rdn>
/**
+ * Normalizes the Dn using the given the schema manager, unless the Dn is already normalized
+ *
+ * @param schemaManager The schemaManagerto use to normalize the Dn
+ * @return The normalized Dn
+ * @throws LdapInvalidDnException If the Dn is invalid.
+ */
+ public Dn apply( SchemaManager schemaManager ) throws LdapInvalidDnException
+ {
+ if ( this.schemaManager != null )
+ {
+ return this;
+ }
+ else
+ {
+ return apply( schemaManager, true );
+ }
+ }
+
+
+ /**
* Tells if the Dn is schema aware
*
* @return <code>true</code> if the Dn is schema aware.