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/28 14:41:42 UTC
svn commit: r359515 -
/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
Author: elecharny
Date: Wed Dec 28 05:41:39 2005
New Revision: 359515
URL: http://svn.apache.org/viewcvs?rev=359515&view=rev
Log:
- Get rid of LdapString dependency
- Added a normName member which contains the normalized name
- Added a bytes member which contains the UTF-8 byte[] representation of the DN
- Added a toNormeName() method which normalize the DN
- The toString() method which returns the normalized name is modified to give more informations
- The getNormName does the same, but it's the one to be used.
- Added getBytes() and getNbBytes() methods for encoding purpose
Modified:
directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java?rev=359515&r1=359514&r2=359515&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java Wed Dec 28 05:41:39 2005
@@ -29,7 +29,6 @@
import javax.naming.Name;
import javax.naming.NamingException;
-import org.apache.ldap.common.LdapString;
import org.apache.ldap.common.schema.OidNormalizer;
import org.apache.ldap.common.util.StringTools;
import org.slf4j.Logger;
@@ -51,7 +50,7 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LdapDN extends LdapString implements Name
+public class LdapDN /*extends LdapString*/ implements Name
{
/** The LoggerFactory used by this class */
private static Logger log = LoggerFactory.getLogger( LdapDN.class );
@@ -76,8 +75,14 @@
/** The user provided name */
private String upName;
+ /** The normalized name */
+ private String normName;
+
+ /** The bytes representation of the normName */
+ private byte[] bytes;
+
/** A null LdapDN */
- public transient static final LdapDN EMPTY_LDAPDN = new LdapDN();
+ public static final LdapDN EMPTY_LDAPDN = new LdapDN();
//~ Methods ------------------------------------------------------------------------------------
@@ -88,6 +93,7 @@
{
super();
upName = "";
+ normName = "";
}
/**
@@ -146,17 +152,6 @@
{
if ( StringTools.isNotEmpty( upName ) )
{
- try
- {
- // Here, we just check that the user provided DN is an UTF-8 encoded String
- string.getBytes( "UTF-8" );
- }
- catch ( UnsupportedEncodingException uee )
- {
- log.error( "The byte array is not an UTF-8 encoded Unicode String : " + uee.getMessage() );
- throw new InvalidNameException( "The byte array is not an UTF-8 encoded Unicode String : " + uee.getMessage() );
- }
-
DnParser.parseInternal( upName, rdns );
}
@@ -181,8 +176,7 @@
{
upName = new String( bytes, "UTF-8" );
DnParser.parseInternal( upName, rdns );
- this.string = toString();
- this.bytes = bytes;
+ this.normName = toNormName();
}
catch ( UnsupportedEncodingException uee )
{
@@ -198,19 +192,19 @@
*/
private void normalize( String upName )
{
- string = toString();
- bytes = StringTools.getBytesUtf8( this.string );
+ normName = toNormName();
this.upName = upName == null ? "" : upName ;
}
/**
- * Return the normalized DN as a String,
+ * Build the normalized DN as a String,
* @return A String representing the normalized DN
*/
- public String toString()
+ public String toNormName()
{
if ( ( rdns == null ) || ( rdns.size() == 0 ) )
{
+ bytes = null;
return "";
}
else
@@ -232,11 +226,24 @@
sb.append( ( (Rdn)rdns.get( i ) ) );
}
- return sb.toString();
+ normName = sb.toString();
+ bytes = StringTools.getBytesUtf8( normName );
+
+ return normName;
}
}
/**
+ * Return the normalized DN as a String. It returns the same value as the
+ * getNormName method
+ * @return A String representing the normalized DN
+ */
+ public String toString()
+ {
+ return normName == null ? "" : normName;
+ }
+
+ /**
* Return the User Provided DN as a String,
* @return A String representing the User Provided DN
*/
@@ -388,6 +395,15 @@
}
/**
+ * Get the initial DN (without normalization)
+ * @return The DN as a String
+ */
+ public String getNormName()
+ {
+ return ( normName == null ? "" : normName );
+ }
+
+ /**
* Get the number of NameComponent conatained in this LdapDN
*
* @return The number of NameComponent conatained in this LdapDN
@@ -398,6 +414,24 @@
}
/**
+ * Get the number of bytes necessary to store this DN
+ * @return A integer, which is the size of the UTF-8 byte array
+ */
+ public int getNbBytes()
+ {
+ return bytes == null ? 0 : bytes.length;
+ }
+
+ /**
+ * Get an UTF-8 representation of the normalized form of the DN
+ * @return A byte[] representation of the DN
+ */
+ public byte[] getBytes()
+ {
+ return bytes;
+ }
+
+ /**
* Determines whether this name starts with a specified prefix.
* A name <tt>name</tt> is a prefix if it is equal to
* <tt>getPrefix(name.size())</tt>.
@@ -655,8 +689,7 @@
newLdapDN.rdns.add( ( (Rdn)rdns.get( i ) ).clone() );
}
- newLdapDN.string = newLdapDN.toString();
- newLdapDN.bytes = StringTools.getBytesUtf8( newLdapDN.string );
+ newLdapDN.normName = newLdapDN.toNormName();
newLdapDN.upName = getUpNamePrefix( posn );
return newLdapDN;
@@ -698,8 +731,7 @@
newLdapDN.rdns.add( ( (Rdn)rdns.get( i ) ).clone() );
}
- newLdapDN.string = newLdapDN.toString();
- newLdapDN.bytes = StringTools.getBytesUtf8( newLdapDN.string );
+ newLdapDN.normName = newLdapDN.toNormName();
newLdapDN.upName = getUpNameSuffix( posn );
return newLdapDN;
@@ -901,7 +933,7 @@
{
if ( obj instanceof String )
{
- return toString().equals( obj ) ;
+ return normName.equals( obj ) ;
}
else if ( obj instanceof LdapDN )
{
@@ -1108,6 +1140,8 @@
rdn.normalizeString();
rdn.setUpName( upName );
}
+
+ newDn.normalize( newDn.upName );
return newDn;
}