Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 61376 invoked from network); 28 Dec 2005 13:42:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Dec 2005 13:42:06 -0000 Received: (qmail 68826 invoked by uid 500); 28 Dec 2005 13:42:05 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 68798 invoked by uid 500); 28 Dec 2005 13:42:05 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 68786 invoked by uid 99); 28 Dec 2005 13:42:05 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Dec 2005 05:42:05 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 28 Dec 2005 05:42:03 -0800 Received: (qmail 61319 invoked by uid 65534); 28 Dec 2005 13:41:43 -0000 Message-ID: <20051228134143.61318.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r359515 - /directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java Date: Wed, 28 Dec 2005 13:41:42 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 Apache Directory Project */ -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 name is a prefix if it is equal to * getPrefix(name.size()). @@ -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; }