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 2005/12/12 10:08:18 UTC
svn commit: r356220 -
/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapRDN.java
Author: elecharny
Date: Mon Dec 12 01:08:07 2005
New Revision: 356220
URL: http://svn.apache.org/viewcvs?rev=356220&view=rev
Log:
The RDN now stores the upName correctly.
Modified:
directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapRDN.java
Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapRDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapRDN.java?rev=356220&r1=356219&r2=356220&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapRDN.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapRDN.java Mon Dec 12 01:08:07 2005
@@ -87,6 +87,9 @@
*/
public class LdapRDN extends LdapString implements Cloneable, Comparable
{
+ /** The User Provided RDN */
+ private String upName = null;
+
/**
* Stores all couple type = value. We may have more than one type,
* if the '+' character appears in the AttributeTypeAndValue. The key is
@@ -94,6 +97,9 @@
*/
private MultiHashMap atavs;
+ /** Stores the lowest element of the RDN */
+ private transient String lowest = null;
+
/**
* A simple AttributeTypeAndValue is used to store the LdapRDN for the simple
* case where we only have a single type=value. This will be 99.99%
@@ -120,6 +126,7 @@
// name-components in a RDN... So we won't initialize the Map.
atavs = null;
atav = null;
+ upName = "";
nbAtavs = 0;
}
@@ -168,6 +175,7 @@
{
RDNParser.parse( new String( bytes, "UTF-8" ), this );
normalize();
+ upName = StringUtils.utf8ToString( bytes );
}
catch ( UnsupportedEncodingException uee )
{
@@ -191,6 +199,7 @@
atav = new AttributeTypeAndValue( type, value );
nbAtavs = 1;
normalize();
+ upName = type + '=' + value;
}
/**
@@ -266,11 +275,14 @@
String normalizedType = StringUtils.lowerCase( StringUtils.trim( type ) );
String normalizedValue = StringUtils.trim( value );
+ boolean isLowest = true;
+
switch ( nbAtavs )
{
case 0 :
// This is the first AttributeTypeAndValue. Just stores it.
atav = new AttributeTypeAndValue( normalizedType, normalizedValue );
+ lowest = normalizedType;
nbAtavs = 1;
break;
@@ -284,16 +296,26 @@
atavs.put( atav.getType(), atav );
atav = null;
- // add a new AttributeTypeAndValue
- atavs.put( normalizedType, new AttributeTypeAndValue( normalizedType, normalizedValue ) );
+ // Now, fall down to the commmon case
+ // NO BREAK !!!
- nbAtavs = 2;
- break;
-
default :
+ // Before adding the new AttributeTypeAndValue, we want to compare
+ // it to the first element : we must the first element to be the
+ // lowest of all the elements.
+
+ if ( normalizedType.compareTo( lowest ) < 0 )
+ {
+ lowest = normalizedType;
+ }
+ else
+ {
+ isLowest = false;
+ }
+
// add a new AttributeTypeAndValue
atavs.put( normalizedType, new AttributeTypeAndValue( normalizedType, normalizedValue ) );
-
+
nbAtavs++;
break;
@@ -305,7 +327,14 @@
}
else
{
- string = string + '+' + normalizedType + '=' + normalizedValue;
+ if ( isLowest )
+ {
+ string = normalizedType + '=' + normalizedValue + '+' + string;
+ }
+ else
+ {
+ string = string + '+' + normalizedType + '=' + normalizedValue;
+ }
}
}
@@ -370,6 +399,7 @@
atavs = null;
nbAtavs = 0;
string = "";
+ upName = "";
bytes = EMPTY_BYTES;
}
@@ -602,6 +632,22 @@
public String toString()
{
return string;
+ }
+
+ /**
+ * Returns a String representation of the RDN
+ */
+ public String getUpName()
+ {
+ return upName;
+ }
+
+ /**
+ * Set the User Provided Name
+ */
+ public void setUpName( String upName )
+ {
+ this.upName = upName;
}
/**