Author: elecharny
Date: Thu Jan 5 01:02:51 2006
New Revision: 366127
URL: http://svn.apache.org/viewcvs?rev=366127&view=rev
Log:
Backporting DN-refactoring to this branch
Added:
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnOidContainer.java (with props)
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapDN.java (with props)
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/Rdn.java (with props)
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/RdnParser.java (with props)
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/schema/OidNormalizer.java (with props)
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/util/DnUtils.java (with props)
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/name/LdapDNTest.java (with props)
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/name/RdnTest.java (with props)
Removed:
directory/branches/DN-refactoring/ldap-common/src/main/antlr/DnCommonTokenTypes.txt
directory/branches/DN-refactoring/ldap-common/src/main/antlr/dnparser.g
directory/branches/DN-refactoring/ldap-common/src/main/antlr/typelexer.g
directory/branches/DN-refactoring/ldap-common/src/main/antlr/valuelexer.g
directory/branches/DN-refactoring/ldap-common/src/main/antlr/valueparser.g
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/aci/ACIItemParser.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/AttributeTypeAndValue.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/DNParser.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapDN.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapRDN.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/RDNParser.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnParser.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapName.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/NameComponentNormalizer.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/ReusableAntlrNameParser.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/ReusableAntlrTypeLexer.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/ReusableAntlrValueLexer.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/SimpleNameComponentNormalizer.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/schema/DnComparator.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/schema/DnNormalizer.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/schema/DnSyntaxChecker.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/subtree/BaseSubtreeSpecification.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/subtree/SubtreeSpecificationModifier.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/util/NamespaceTools.java
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/codec/util/DNParserTest.java
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/codec/util/LdapDNTest.java
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/codec/util/LdapRDNTest.java
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/name/DnParserTest.java
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/name/LdapNameTest.java
directory/branches/DN-refactoring/ldap-common/src/test/java/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
Modified:
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResult.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequest.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequestGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntry.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntryGrammar.java
directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapURL.java
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResult.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResult.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResult.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResult.java Thu Jan 5 01:02:51 2006
@@ -21,10 +21,10 @@
import org.apache.asn1.ber.tlv.Length;
import org.apache.asn1.ber.tlv.Value;
import org.apache.asn1.ber.tlv.UniversalTag;
-import org.apache.ldap.common.codec.util.LdapDN;
import org.apache.ldap.common.codec.util.LdapResultEnum;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapURL;
+import org.apache.ldap.common.name.LdapDN;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java Thu Jan 5 01:02:51 2006
@@ -31,7 +31,7 @@
import org.apache.asn1.ber.IAsn1Container;
import org.apache.asn1.util.IntegerDecoder;
import org.apache.asn1.util.IntegerDecoderException;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapResultEnum;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/TwixTransformer.java Thu Jan 5 01:02:51 2006
@@ -61,7 +61,7 @@
import org.apache.ldap.common.codec.search.SearchResultReference;
import org.apache.ldap.common.codec.search.SubstringFilter;
import org.apache.ldap.common.codec.search.controls.PSearchControl;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.codec.util.LdapURL;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequest.java Thu Jan 5 01:02:51 2006
@@ -22,7 +22,7 @@
import org.apache.asn1.ber.tlv.UniversalTag;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.util.AttributeUtils;
import org.apache.ldap.common.util.StringTools;
@@ -155,7 +155,7 @@
*/
public String getEntry()
{
- return ( ( entry == null ) ? "" : entry.getString() );
+ return ( ( entry == null ) ? "" : entry.getNormName() );
}
/**
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -30,7 +30,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequest.java Thu Jan 5 01:02:51 2006
@@ -24,7 +24,7 @@
import org.apache.asn1.ber.tlv.Value;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/bind/BindRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -33,7 +33,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequest.java Thu Jan 5 01:02:51 2006
@@ -25,7 +25,7 @@
import org.apache.asn1.ber.tlv.Value;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.util.StringTools;
@@ -94,7 +94,7 @@
*/
public String getEntry()
{
- return ( ( entry == null ) ? "" : entry.getString() );
+ return ( ( entry == null ) ? "" : entry.getNormName() );
}
/**
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -30,7 +30,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequest.java Thu Jan 5 01:02:51 2006
@@ -23,7 +23,7 @@
import org.apache.asn1.ber.tlv.Length;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
/**
@@ -68,7 +68,7 @@
*/
public String getEntry()
{
- return ( ( entry == null ) ? "" : entry.getString() );
+ return ( ( entry == null ) ? "" : entry.getNormName() );
}
/**
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/del/DelRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -29,7 +29,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequest.java Thu Jan 5 01:02:51 2006
@@ -22,7 +22,7 @@
import org.apache.asn1.ber.tlv.Value;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.util.StringTools;
import org.slf4j.Logger;
@@ -209,7 +209,7 @@
*/
public String getObject()
{
- return ( ( object == null ) ? "" : object.getString() );
+ return ( ( object == null ) ? "" : object.getNormName() );
}
/**
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modify/ModifyRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -32,7 +32,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequest.java Thu Jan 5 01:02:51 2006
@@ -24,8 +24,9 @@
import org.apache.asn1.ber.tlv.Value;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
-import org.apache.ldap.common.codec.util.LdapRDN;
+import org.apache.ldap.common.name.LdapDN;
+import org.apache.ldap.common.name.Rdn;
+import org.apache.ldap.common.util.StringTools;
/**
@@ -46,7 +47,7 @@
private LdapDN entry;
/** The new RDN to be added to the RDN or to the new superior, if present */
- private LdapRDN newRDN;
+ private Rdn newRDN;
/** If the previous RDN is to be deleted, this flag will be set to true */
private boolean deleteOldRDN;
@@ -85,7 +86,7 @@
*/
public String getEntry()
{
- return ( ( entry == null ) ? "" : entry.getString() );
+ return ( ( entry == null ) ? "" : entry.getNormName() );
}
/**
@@ -124,7 +125,7 @@
*/
public String getNewRDN()
{
- return ( ( newRDN == null ) ? "" : newRDN.getString() );
+ return ( ( newRDN == null ) ? "" : newRDN.toString() );
}
/**
@@ -132,7 +133,7 @@
*
* @param newRDN The newRDN to set.
*/
- public void setNewRDN( LdapRDN newRDN )
+ public void setNewRDN( Rdn newRDN )
{
this.newRDN = newRDN;
}
@@ -144,7 +145,7 @@
*/
public String getNewSuperior()
{
- return ( ( newSuperior == null ) ? "" : newSuperior.getString() );
+ return ( ( newSuperior == null ) ? "" : newSuperior.getNormName() );
}
/**
@@ -180,9 +181,10 @@
public int computeLength()
{
+ int newRdnlength = StringTools.getBytesUtf8( newRDN.toString() ).length;
modifyDNRequestLength =
1 + Length.getNbBytes( entry.getNbBytes() ) + entry.getNbBytes() +
- 1 + Length.getNbBytes( newRDN.getNbBytes() ) + newRDN.getNbBytes() +
+ 1 + Length.getNbBytes( newRdnlength ) + newRdnlength +
1 + 1 + 1; // deleteOldRDN
if ( newSuperior != null )
@@ -215,7 +217,7 @@
throw new EncoderException( "Cannot put a PDU in a null buffer !" );
}
- try
+ try
{
// The ModifyDNRequest Tag
buffer.put( LdapConstants.MODIFY_DN_REQUEST_TAG );
@@ -223,20 +225,20 @@
// The entry
Value.encode( buffer, entry.getBytes() );
-
+
// The newRDN
- Value.encode( buffer, newRDN.getBytes() );
-
+ Value.encode( buffer, newRDN.toString() );
+
// The flag deleteOldRdn
Value.encode( buffer, deleteOldRDN );
-
+
// The new superior, if any
if ( newSuperior != null )
{
// Encode the reference
- buffer.put( (byte) LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG );
+ buffer.put( (byte)LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG );
buffer.put( Length.getBytes( newSuperior.getNbBytes() ) );
-
+
if ( newSuperior.getNbBytes() != 0 )
{
buffer.put( newSuperior.getBytes() );
@@ -245,7 +247,7 @@
}
catch ( BufferOverflowException boe )
{
- throw new EncoderException("The PDU buffer size is too small !");
+ throw new EncoderException("The PDU buffer size is too small !");
}
return buffer;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -33,8 +33,8 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
-import org.apache.ldap.common.codec.util.LdapRDN;
+import org.apache.ldap.common.name.LdapDN;
+import org.apache.ldap.common.name.Rdn;
import org.apache.ldap.common.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -199,7 +199,7 @@
TLV tlv = ldapMessageContainer.getCurrentTLV();
// We have to handle the special case of a 0 length matched newDN
- LdapRDN newRdn = null;
+ Rdn newRdn = null;
if ( tlv.getLength().getLength() == 0 )
{
@@ -209,7 +209,7 @@
{
try
{
- newRdn = new LdapRDN( tlv.getValue().getData() );
+ newRdn = new Rdn( tlv.getValue().getData() );
modifyDNRequest.setNewRDN( newRdn );
}
catch ( InvalidNameException ine )
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequest.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequest.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequest.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequest.java Thu Jan 5 01:02:51 2006
@@ -22,7 +22,7 @@
import org.apache.asn1.ber.tlv.UniversalTag;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.util.StringTools;
@@ -144,7 +144,7 @@
*/
public String getBaseObject()
{
- return ( ( baseObject == null ) ? null : baseObject.getString() );
+ return ( ( baseObject == null ) ? null : baseObject.getNormName() );
}
/**
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequestGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequestGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchRequestGrammar.java Thu Jan 5 01:02:51 2006
@@ -35,7 +35,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntry.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntry.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntry.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntry.java Thu Jan 5 01:02:51 2006
@@ -22,7 +22,7 @@
import org.apache.asn1.ber.tlv.UniversalTag;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.util.AttributeUtils;
import org.apache.ldap.common.util.StringTools;
@@ -114,7 +114,7 @@
*/
public String getObjectName()
{
- return ( ( objectName == null ) ? null : objectName.getString() );
+ return ( ( objectName == null ) ? null : objectName.getNormName() );
}
/**
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntryGrammar.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntryGrammar.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntryGrammar.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/search/SearchResultEntryGrammar.java Thu Jan 5 01:02:51 2006
@@ -30,7 +30,7 @@
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
import org.apache.ldap.common.codec.LdapStatesEnum;
-import org.apache.ldap.common.codec.util.LdapDN;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import org.apache.ldap.common.codec.util.LdapStringEncodingException;
import org.apache.ldap.common.util.StringTools;
Modified: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapURL.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapURL.java?rev=366127&r1=366126&r2=366127&view=diff
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapURL.java (original)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/codec/util/LdapURL.java Thu Jan 5 01:02:51 2006
@@ -22,8 +22,8 @@
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.ldap.common.filter.FilterParserImpl;
+import org.apache.ldap.common.name.LdapDN;
import org.apache.ldap.common.util.StringTools;
-import org.apache.ldap.common.codec.util.LdapDN;
import org.apache.ldap.common.codec.util.LdapString;
import java.io.IOException;
Added: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnOidContainer.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnOidContainer.java?rev=366127&view=auto
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnOidContainer.java (added)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnOidContainer.java Thu Jan 5 01:02:51 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ldap.common.name;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The DnOidContainer is a class which ill contain a global Map associating
+ * names to thier OIDs and Normalizer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ *
+ */
+public class DnOidContainer
+{
+ /** The internaml map containing the name, Oid, Normalizer */
+ private static Map oidByName = new HashMap();
+
+ private static DnOidContainer instance;
+
+ static
+ {
+ instance = new DnOidContainer();
+ }
+ /**
+ * Private constructor. This class cannot be constructed
+ *
+ */
+ private DnOidContainer()
+ {
+ // Empty private constructor
+ }
+
+ public static DnOidContainer getInstance()
+ {
+ return instance;
+ }
+
+ /**
+ * Get the OID/Normalizer associated with the given name
+ * @param name The type which OID is asked for
+ * @return The couple OID/Normalizer correspondning to the given name
+ */
+ public static Object getOidByName( String name )
+ {
+ return oidByName.get( name );
+ }
+
+ /**
+ * Get the Map
+ * @return The Oid Map
+ */
+ public static Map getOids()
+ {
+ return oidByName;
+ }
+
+ /**
+ * Set the Map
+ * @param oids The Map to store
+ */
+ public static void setOids(Map oids)
+ {
+ DnOidContainer.oidByName = oids;
+ }
+}
Propchange: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/DnOidContainer.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapDN.java
URL: http://svn.apache.org/viewcvs/directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapDN.java?rev=366127&view=auto
==============================================================================
--- directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapDN.java (added)
+++ directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapDN.java Thu Jan 5 01:02:51 2006
@@ -0,0 +1,1149 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ldap.common.name;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+import org.apache.ldap.common.codec.AttributeTypeAndValue;
+import org.apache.ldap.common.schema.OidNormalizer;
+import org.apache.ldap.common.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The LdapDN class contains a DN (Distinguished Name). Its specification can be found in RFC 2253,
+ * "UTF-8 String Representation of Distinguished Names".
+ *
+ * We will store two representation of a DN :
+ * - a user Provider represeentation, which is the parsed String given by a user
+ * - an internal representation.
+ *
+ * A DN is formed of RDNs, in a specific order :
+ * RDN[n], RDN[n-1], ... RDN[1], RDN[0]
+ *
+ * It represents a tree, in which the root is the last RDN (RDN[0]) and the leaf is the
+ * first RDN (RDN[n]).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapDN /*extends LdapString*/ implements Name
+{
+ /** The LoggerFactory used by this class */
+ private static Logger log = LoggerFactory.getLogger( LdapDN.class );
+
+ /**
+ * Declares the Serial Version Uid.
+ *
+ * @see <a href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always Declare Serial Version Uid</a>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Value returned by the compareTo method if values are not equals */
+ public final static int NOT_EQUALS = -1;
+
+ /** Value returned by the compareTo method if values are equals */
+ public final static int EQUALS = 0;
+
+ //~ Static fields/initializers -----------------------------------------------------------------
+ /** The RDNs that are elements of the DN */
+ private List rdns = new ArrayList(5);
+
+ /** 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 static final LdapDN EMPTY_LDAPDN = new LdapDN();
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Construct an empty LdapDN object
+ */
+ public LdapDN()
+ {
+ super();
+ upName = "";
+ normName = "";
+ }
+
+ /**
+ * Creates an ldap name using a list of NameComponents. Each NameComponent
+ * is a String
+ *
+ * @param a_list of String name components.
+ */
+ LdapDN( List list ) throws InvalidNameException
+ {
+ super();
+
+ if ( ( list != null ) && ( list.size() != 0 ) )
+ {
+ Iterator nameComponents = list.iterator();
+
+ while ( nameComponents.hasNext() )
+ {
+ String nameComponent = (String)nameComponents.next();
+ add( 0, nameComponent );
+ }
+ }
+ }
+
+ /**
+ * Creates an ldap name using a list of name components.
+ *
+ * @param nameComponents List of String name components.
+ */
+ LdapDN( Iterator nameComponents ) throws InvalidNameException
+ {
+ super();
+
+ if ( nameComponents != null )
+ {
+ while ( nameComponents.hasNext() )
+ {
+ String nameComponent = (String)nameComponents.next();
+ add( 0, nameComponent );
+ }
+ }
+ }
+
+ /**
+ * Parse a String and checks that it is a valid DN <br>
+ * <p>
+ * <distinguishedName> ::= <name> | e <br>
+ * <name> ::= <name-component> <name-components> <br>
+ * <name-components> ::= <spaces> <separator> <spaces> <name-component> <name-components> | e <br>
+ * </p>
+ *
+ * @param bytes The byte buffer that contains the DN
+ * @exception A InvalidNameException is thrown if the buffer does not contains a valid DN.
+ */
+ public LdapDN( String upName ) throws InvalidNameException
+ {
+ if ( StringTools.isNotEmpty( upName ) )
+ {
+ DnParser.parseInternal( upName, rdns );
+ }
+
+ // Stores the representations of a DN : internal (as a string and as a byte[]) and external.
+ normalize( upName );
+ }
+
+ /**
+ * Parse a buffer and checks that it is a valid DN <br>
+ * <p>
+ * <distinguishedName> ::= <name> | e <br>
+ * <name> ::= <name-component> <name-components> <br>
+ * <name-components> ::= <spaces> <separator> <spaces> <name-component> <name-components> | e <br>
+ * </p>
+ *
+ * @param bytes The byte buffer that contains the DN
+ * @exception A InvalidNameException is thrown if the buffer does not contains a valid DN.
+ */
+ public LdapDN( byte[] bytes ) throws InvalidNameException
+ {
+ try
+ {
+ upName = new String( bytes, "UTF-8" );
+ DnParser.parseInternal( upName, rdns );
+ this.normName = toNormName();
+ }
+ 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() );
+ }
+ }
+
+
+ /**
+ * Normalize the DN by triming useless spaces and lowercasing names.
+ * @return a normalized form of the DN
+ */
+ private void normalize( String upName )
+ {
+ normName = toNormName();
+ this.upName = upName == null ? "" : upName ;
+ }
+
+ /**
+ * Build the normalized DN as a String,
+ * @return A String representing the normalized DN
+ */
+ public String toNormName()
+ {
+ if ( ( rdns == null ) || ( rdns.size() == 0 ) )
+ {
+ bytes = null;
+ return "";
+ }
+ else
+ {
+ StringBuffer sb = new StringBuffer();
+ boolean isFirst = true;
+
+ for ( int i = 0; i < rdns.size(); i++ )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
+
+ sb.append( ( (Rdn)rdns.get( i ) ) );
+ }
+
+ 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
+ */
+ public String toUpName()
+ {
+ if ( ( rdns == null ) || ( rdns.size() == 0 ) )
+ {
+ return "";
+ }
+ else
+ {
+ StringBuffer sb = new StringBuffer();
+ boolean isFirst = true;
+
+ for ( int i = 0; i < rdns.size(); i++ )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
+
+ sb.append(( (Rdn)rdns.get( i ) ).getUpName() );
+ }
+
+ return sb.toString();
+ }
+ }
+
+ /**
+ * Return the User Provided prefix representation of the DN starting at the posn position.
+ *
+ * If posn = 0, return an empty string.
+ *
+ * for DN : sn=smith, dc=apache, dc=org
+ *
+ * getUpname(0) -> ""
+ * getUpName(1) -> "dc=org"
+ * getUpname(3) -> "sn=smith, dc=apache, dc=org"
+ * getUpName(4) -> ArrayOutOfBoundException
+ *
+ * Warning ! The returned String is not exactly the user provided DN, as spaces
+ * before and after each RDNs have been trimmed.
+ *
+ * @param posn The starting position
+ * @return The truncated DN
+ */
+ private String getUpNamePrefix( int posn )
+ {
+ if ( posn == 0 )
+ {
+ return "";
+ }
+
+ if ( posn > rdns.size() )
+ {
+ String message = "Impossible to get the position " + posn + ", the DN only has " + rdns.size() + " RDNs";
+ log.error( message );
+ throw new ArrayIndexOutOfBoundsException( message );
+ }
+
+ int start = rdns.size() - posn;
+ StringBuffer sb = new StringBuffer();
+ boolean isFirst = true;
+
+ for ( int i = start; i < rdns.size(); i++ )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
+
+ sb.append( ( (Rdn)rdns.get( i ) ).getUpName() );
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Return the User Provided suffix representation of the DN starting at the posn position.
+ *
+ * If posn = 0, return an empty string.
+ *
+ * for DN : sn=smith, dc=apache, dc=org
+ *
+ * getUpname(0) -> "sn=smith, dc=apache, dc=org"
+ * getUpName(1) -> "sn=smith, dc=apache"
+ * getUpname(3) -> "sn=smith"
+ * getUpName(4) -> ""
+ *
+ * Warning ! The returned String is not exactly the user provided DN, as spaces
+ * before and after each RDNs have been trimmed.
+ *
+ * @param posn The starting position
+ * @return The truncated DN
+ */
+ private String getUpNameSuffix( int posn )
+ {
+ if ( posn > rdns.size() )
+ {
+ return "";
+ }
+
+ int end = rdns.size() - posn;
+ StringBuffer sb = new StringBuffer();
+ boolean isFirst = true;
+
+ for ( int i = 0; i < end; i++ )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
+
+ sb.append( ( (Rdn)rdns.get( i ) ).getUpName() );
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Gets the hashcode of the string representation of this name.
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return upName.hashCode() ;
+ }
+
+
+ /**
+ * Get the initial DN (without normalization)
+ * @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
+ */
+ 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
+ */
+ public int size()
+ {
+ return rdns.size();
+ }
+
+ /**
+ * 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>.
+ *
+ * Be aware that for a specific DN like :
+ *
+ * cn=xxx, ou=yyy
+ *
+ * the startsWith method will retourn true with ou=yyy, and
+ * false with cn=xxx
+ *
+ * @param name the name to check
+ * @return true if <tt>name</tt> is a prefix of this name, false otherwise
+ */
+ public boolean startsWith ( Name name )
+ {
+ if ( name instanceof LdapDN )
+ {
+ LdapDN nameDN = (LdapDN)name;
+
+ if ( nameDN.size() == 0 )
+ {
+ return true;
+ }
+
+ if ( nameDN.size() > size() )
+ {
+ // The name is longer than the current LdapDN.
+ return false;
+ }
+
+ // Ok, iterate through all the RDN of the name,
+ // starting a the end of the current list.
+
+ for ( int i = nameDN.size() - 1; i >= 0; i-- )
+ {
+ Rdn nameRdn = (Rdn)(nameDN.rdns.get( nameDN.rdns.size() - i - 1 ));
+ Rdn ldapRdn = (Rdn)rdns.get( rdns.size() - i - 1 );
+
+ if ( nameRdn.compareTo(ldapRdn) != 0 )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ else
+ {
+ // We don't accept a Name which is not a LdapName
+ return name == null;
+ }
+ }
+
+ /**
+ * Determines whether this name ends with a specified suffix.
+ * A name <tt>name</tt> is a suffix if it is equal to
+ * <tt>getSuffix(size()-name.size())</tt>.
+ *
+ * Be aware that for a specific DN like :
+ *
+ * cn=xxx, ou=yyy
+ *
+ * the endsWith method will retourn true with cn=xxx, and
+ * false with ou=yyy
+ *
+ * @param name the name to check
+ * @return true if <tt>name</tt> is a suffix of this name, false otherwise
+ */
+ public boolean endsWith ( Name name )
+ {
+ if ( name instanceof LdapDN )
+ {
+ LdapDN nameDN = (LdapDN)name;
+
+ if ( nameDN.size() == 0 )
+ {
+ return true;
+ }
+
+ if ( nameDN.size() > size() )
+ {
+ // The name is longer than the current LdapDN.
+ return false;
+ }
+
+ // Ok, iterate through all the RDN of the name
+ for ( int i = 0; i < nameDN.size(); i++ )
+ {
+ Rdn nameRdn = (Rdn)(nameDN.rdns.get( i ));
+ Rdn ldapRdn = (Rdn)rdns.get( i );
+
+ if ( nameRdn.compareTo(ldapRdn) != 0 )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ else
+ {
+ // We don't accept a Name which is not a LdapName
+ return name == null;
+ }
+ }
+
+ /**
+ * Determines whether this name is empty.
+ * An empty name is one with zero components.
+ *
+ * @return true if this name is empty, false otherwise
+ */
+ public boolean isEmpty()
+ {
+ return ( rdns.size() == 0 );
+ }
+
+ /**
+ * Retrieves a component of this name.
+ *
+ * @param posn
+ * the 0-based index of the component to retrieve.
+ * Must be in the range [0,size()).
+ * @return the component at index posn
+ * @throws ArrayIndexOutOfBoundsException
+ * if posn is outside the specified range
+ */
+ public String get( int posn )
+ {
+ if ( rdns.size() == 0 )
+ {
+ return "";
+ }
+ else
+ {
+ Rdn rdn = (Rdn)rdns.get( rdns.size() - posn - 1 );
+
+ return rdn.toString();
+ }
+ }
+
+ /**
+ * Retrieves the components of this name as an enumeration
+ * of strings. The effect on the enumeration of updates to
+ * this name is undefined. If the name has zero components,
+ * an empty (non-null) enumeration is returned.
+ *
+ * @return an enumeration of the components of this name, each as string
+ */
+ public Enumeration getAll()
+ {
+ /*
+ * Note that by accessing the name component using the get() method on
+ * the name rather than get() on the list we are reading components from
+ * right to left with increasing index values. LdapName.get() does the
+ * index translation on m_list for us.
+ */
+ return new Enumeration()
+ {
+ private int pos ;
+
+ public boolean hasMoreElements()
+ {
+ return pos < rdns.size() ;
+ }
+
+ public Object nextElement()
+ {
+ if ( pos >= rdns.size() )
+ {
+ log.error( "Exceeded number of elements in the current object" );
+ throw new NoSuchElementException() ;
+ }
+
+ Object obj = rdns.get( rdns.size() - pos - 1 );
+ pos++ ;
+ return obj.toString();
+ }
+ };
+ }
+
+ /**
+ * Retrieves the components of this name as an enumeration
+ * of strings. The effect on the enumeration of updates to
+ * this name is undefined. If the name has zero components,
+ * an empty (non-null) enumeration is returned.
+ *
+ * @return an enumeration of the components of this name, as Rdn
+ */
+ public Enumeration getAllRdn()
+ {
+ /*
+ * Note that by accessing the name component using the get() method on
+ * the name rather than get() on the list we are reading components from
+ * right to left with increasing index values. LdapName.get() does the
+ * index translation on m_list for us.
+ */
+ return new Enumeration()
+ {
+ private int pos ;
+
+ public boolean hasMoreElements()
+ {
+ return pos < rdns.size() ;
+ }
+
+ public Object nextElement()
+ {
+ if ( pos >= rdns.size() )
+ {
+ log.error( "Exceeded number of elements in the current object" );
+ throw new NoSuchElementException() ;
+ }
+
+ Object obj = rdns.get( rdns.size() - pos - 1 );
+ pos++ ;
+ return obj ;
+ }
+ };
+ }
+
+ /**
+ * Creates a name whose components consist of a prefix of the
+ * components of this name. Subsequent changes to
+ * this name will not affect the name that is returned and vice versa.
+ *
+ * @param posn
+ * the 0-based index of the component at which to stop.
+ * Must be in the range [0,size()].
+ * @return a name consisting of the components at indexes in
+ * the range [0,posn].
+ * @throws ArrayIndexOutOfBoundsException
+ * if posn is outside the specified range
+ */
+ public Name getPrefix( int posn )
+ {
+ if ( rdns.size() == 0 )
+ {
+ return EMPTY_LDAPDN;
+ }
+
+ if ( ( posn < 0 ) || ( posn > rdns.size() ) )
+ {
+ String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
+ log.error( message );
+ throw new ArrayIndexOutOfBoundsException( message );
+ }
+
+ LdapDN newLdapDN = new LdapDN();
+
+ for (int i = rdns.size() - posn; i < rdns.size(); i++ )
+ {
+ // Don't forget to clone the rdns !
+ newLdapDN.rdns.add( ( (Rdn)rdns.get( i ) ).clone() );
+ }
+
+ newLdapDN.normName = newLdapDN.toNormName();
+ newLdapDN.upName = getUpNamePrefix( posn );
+
+ return newLdapDN;
+ }
+
+ /**
+ * Creates a name whose components consist of a suffix of the
+ * components in this name. Subsequent changes to
+ * this name do not affect the name that is returned and vice versa.
+ *
+ * @param posn
+ * the 0-based index of the component at which to start.
+ * Must be in the range [0,size()].
+ * @return a name consisting of the components at indexes in
+ * the range [posn,size()]. If posn is equal to
+ * size(), an empty name is returned.
+ * @throws ArrayIndexOutOfBoundsException
+ * if posn is outside the specified range
+ */
+ public Name getSuffix( int posn )
+ {
+ if ( rdns.size() == 0 )
+ {
+ return EMPTY_LDAPDN;
+ }
+
+ if ( ( posn < 0 ) || ( posn > rdns.size() ) )
+ {
+ String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
+ log.error( message );
+ throw new ArrayIndexOutOfBoundsException( message );
+ }
+
+ LdapDN newLdapDN = new LdapDN();
+
+ for (int i = 0; i < size() - posn; i++ )
+ {
+ // Don't forget to clone the rdns !
+ newLdapDN.rdns.add( ( (Rdn)rdns.get( i ) ).clone() );
+ }
+
+ newLdapDN.normName = newLdapDN.toNormName();
+ newLdapDN.upName = getUpNameSuffix( posn );
+
+ return newLdapDN;
+ }
+
+ /**
+ * Adds the components of a name -- in order -- to the end of this name.
+ *
+ * @param suffix
+ * the components to add
+ * @return the updated name (not a new one)
+ *
+ * @throws InvalidNameException if <tt>suffix</tt> is not a valid name,
+ * or if the addition of the components would violate the syntax
+ * rules of this name
+ */
+ public Name addAll( Name suffix ) throws InvalidNameException
+ {
+ addAll( rdns.size(), suffix );
+
+ return this;
+ }
+
+ /**
+ * Adds the components of a name -- in order -- at a specified position
+ * within this name.
+ * Components of this name at or after the index of the first new
+ * component are shifted up (away from 0) to accommodate the new
+ * components.
+ *
+ * @param name
+ * the components to add
+ * @param posn
+ * the index in this name at which to add the new
+ * components. Must be in the range [0,size()].
+ * @return the updated name (not a new one)
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ * if posn is outside the specified range
+ * @throws InvalidNameException if <tt>n</tt> is not a valid name,
+ * or if the addition of the components would violate the syntax
+ * rules of this name
+ */
+ public Name addAll(int posn, Name name) throws InvalidNameException
+ {
+ if (name instanceof LdapDN )
+ {
+ if ( ( name == null ) || ( name.size() == 0 ) )
+ {
+ return this;
+ }
+
+ // Concatenate the rdns
+ rdns.addAll( size() - posn, ((LdapDN)name).rdns );
+
+ // Regenerate the normalized name and the original string
+ normalize( toUpName() );
+
+ return this;
+ }
+ else
+ {
+ log.error( "Not a valid LdapDN suffix : " + name );
+ throw new InvalidNameException( "The suffix is not a LdapDN" );
+ }
+ }
+
+ /**
+ * Adds a single component to the end of this name.
+ *
+ * @param comp
+ * the component to add
+ * @return the updated name (not a new one)
+ *
+ * @throws InvalidNameException if adding <tt>comp</tt> would violate
+ * the syntax rules of this name
+ */
+ public Name add(String comp) throws InvalidNameException
+ {
+ // We have to parse the nameComponent which is given as an argument
+ Rdn newRdn = new Rdn( comp );
+
+ rdns.add( 0, newRdn );
+ normalize( toUpName() );
+
+ return this;
+ }
+
+ /**
+ * Adds a single component at a specified position within this name.
+ * Components of this name at or after the index of the new component
+ * are shifted up by one (away from index 0) to accommodate the new
+ * component.
+ *
+ * @param comp
+ * the component to add
+ * @param posn
+ * the index at which to add the new component.
+ * Must be in the range [0,size()].
+ * @return the updated name (not a new one)
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ * if posn is outside the specified range
+ * @throws InvalidNameException if adding <tt>comp</tt> would violate
+ * the syntax rules of this name
+ */
+ public Name add(int posn, String comp) throws InvalidNameException
+ {
+ if ( ( posn < 0 ) || ( posn > size() ) )
+ {
+ String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
+ log.error( message );
+ throw new ArrayIndexOutOfBoundsException( message );
+ }
+
+ // We have to parse the nameComponent which is given as an argument
+ Rdn newRdn = new Rdn( comp );
+
+ int realPos = size() - posn;
+ rdns.add( realPos, newRdn );
+
+ normalize( toUpName() );
+
+ return this;
+ }
+
+ /**
+ * Removes a component from this name.
+ * The component of this name at the specified position is removed.
+ * Components with indexes greater than this position
+ * are shifted down (toward index 0) by one.
+ *
+ * @param posn
+ * the index of the component to remove.
+ * Must be in the range [0,size()).
+ * @return the component removed (a String)
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ * if posn is outside the specified range
+ * @throws InvalidNameException if deleting the component
+ * would violate the syntax rules of the name
+ */
+ public Object remove(int posn) throws InvalidNameException
+ {
+ if ( rdns.size() == 0 )
+ {
+ return EMPTY_LDAPDN;
+ }
+
+ if ( ( posn < 0 ) || ( posn >= rdns.size() ) )
+ {
+ String message = "The posn(" + posn + ") should be in the range [0, " + rdns.size() + "]";
+ log.error ( message );
+ throw new ArrayIndexOutOfBoundsException( message );
+ }
+
+ int realPos = size() - posn - 1;
+ Rdn rdn = (Rdn)rdns.remove( realPos );
+
+ normalize( toUpName() );
+
+ return rdn;
+ }
+
+ /**
+ * Generates a new copy of this name.
+ * Subsequent changes to the components of this name will not
+ * affect the new copy, and vice versa.
+ *
+ * @return a copy of this name
+ *
+ * @see Object#clone()
+ */
+ public Object clone()
+ {
+ try
+ {
+ LdapDN dn = (LdapDN)super.clone();
+ dn.rdns = new ArrayList();
+
+ for ( int i = 0; i < rdns.size(); i++ )
+ {
+ dn.rdns.add( i, ((Rdn)rdns.get( i ) ).clone() );
+ }
+
+ return dn;
+ }
+ catch ( CloneNotSupportedException cnse )
+ {
+ log.error( "The clone operation has failed" );
+ throw new Error( "Assertion failure : cannot clone the object" );
+ }
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj )
+ {
+ if ( obj instanceof String )
+ {
+ return normName.equals( obj ) ;
+ }
+ else if ( obj instanceof LdapDN )
+ {
+ LdapDN name = ( LdapDN ) obj ;
+
+ if ( name.size() != this.size() )
+ {
+ return false ;
+ }
+
+ for ( int i = 0; i < size(); i++ )
+ {
+ if ( ( (Rdn)name.rdns.get( i ) ).compareTo( rdns.get( i ) ) != 0)
+ {
+ return false;
+ }
+ }
+
+ // All components matched so we return true
+ return true ;
+ }
+ else
+ {
+ return false ;
+ }
+ }
+
+ /**
+ * Compares this name with another name for order.
+ * Returns a negative integer, zero, or a positive integer as this
+ * name is less than, equal to, or greater than the given name.
+ *
+ * <p> As with <tt>Object.equals()</tt>, the notion of ordering for names
+ * depends on the class that implements this interface.
+ * For example, the ordering may be
+ * based on lexicographical ordering of the name components.
+ * Specific attributes of the name, such as how it treats case,
+ * may affect the ordering. In general, two names of different
+ * classes may not be compared.
+ *
+ * @param obj the non-null object to compare against.
+ * @return a negative integer, zero, or a positive integer as this name
+ * is less than, equal to, or greater than the given name
+ * @throws ClassCastException if obj is not a <tt>Name</tt> of a
+ * type that may be compared with this name
+ *
+ * @see Comparable#compareTo(Object)
+ */
+ public int compareTo(Object obj)
+ {
+ if ( obj instanceof LdapDN )
+ {
+ LdapDN ldapDN = (LdapDN)obj;
+
+ if ( ldapDN.size() != size() )
+ {
+ return size() - ldapDN.size();
+ }
+
+ for ( int i = rdns.size(); i > 0; i-- )
+ {
+ Rdn rdn1 = (Rdn) rdns.get( i - 1 );
+ Rdn rdn2 = (Rdn) ldapDN.rdns.get( i - 1 );
+ int res = rdn1.compareTo( rdn2 );
+
+ if ( res != 0 )
+ {
+ return res;
+ }
+ }
+
+ return EQUALS;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ private static AttributeTypeAndValue atavToOid( AttributeTypeAndValue atav, Map oids ) throws InvalidNameException, NamingException
+ {
+ String type = StringTools.trim( atav.getType() );
+
+ if ( StringTools.isNotEmpty( StringTools.lowerCase( type ) ) )
+ {
+ OidNormalizer oidNormalizer = (OidNormalizer)oids.get( type );
+
+ if ( oidNormalizer != null )
+ {
+ return new AttributeTypeAndValue( oidNormalizer.getOid(),
+ (String)oidNormalizer.getNormalizer().normalize( atav.getValue() ) );
+
+ }
+ else
+ {
+ // We don't have a normalizer for this OID : just do nothing.
+ return atav;
+ }
+ }
+ else
+ {
+ // The type is empty : this is not possible...
+ log.error( "Empty type not allowed in a DN" );
+ throw new InvalidNameException( "Empty type not allowed in a DN" );
+ }
+
+ }
+
+ /**
+ * Transform a RDN by changing the value to its OID counterpart and normalizing
+ * the value accordingly to its type.
+ * @param rdn The RDN to modify
+ * @param oids The map of all existing oids and normalizer
+ * @throws InvalidNameException If
+ * @throws NamingException
+ */
+ private static void rdnToOid( Rdn rdn, Map oids ) throws InvalidNameException, NamingException
+ {
+ if ( rdn.getNbAtavs() > 1 )
+ {
+ // We have more than one ATAV for this RDN. We will loop on all ATAVs
+ Rdn rdnCopy = (Rdn)rdn.clone();
+ rdn.clear();
+
+ Iterator atavs = rdnCopy.iterator();
+
+ while ( atavs.hasNext() )
+ {
+ AttributeTypeAndValue newAtav = atavToOid( (AttributeTypeAndValue)atavs.next(), oids );
+ rdn.addAttributeTypeAndValue( newAtav.getType(), newAtav.getValue() );
+ }
+
+
+ }
+ else
+ {
+ String type = StringTools.trim( rdn.getType() );
+
+ if ( StringTools.isNotEmpty( StringTools.lowerCase( type ) ) )
+ {
+ OidNormalizer oidNormalizer = (OidNormalizer)oids.get( type );
+
+ if ( oidNormalizer != null )
+ {
+ Rdn rdnCopy = (Rdn)rdn.clone();
+ rdn.clear();
+
+ rdn.addAttributeTypeAndValue( oidNormalizer.getOid(),
+ (String)oidNormalizer.getNormalizer().normalize( rdnCopy.getValue() ) );
+
+ }
+ 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" );
+ }
+ }
+ }
+
+ /**
+ * Change the internal DN, using OID instead of names. As we still have the UP name
+ * of each RDN, we will be able to provide both representation of the DN.
+ *
+ * example :
+ *
+ * dn: cn=People, dc=example, dc=com
+ *
+ * will be transformed to :
+ *
+ * 2.5.4.3=People, 0.9.2342.19200300.100.1.25=example, 0.9.2342.19200300.100.1.25=com
+ *
+ * This is really important do have such a representation, as 'cn' and 'commonname'
+ * share the same OID. To find a DN into the backend, we will use the OID as a key.
+ *
+ * @param dn The DN to transform
+ * @param oids The mapping between names and oids.
+ * @return A OID form of the DN
+ * @throws InvalidNameException If the DN is invalid
+ */
+ public static Name toOidName( Name dn, Map oids ) throws InvalidNameException, NamingException
+ {
+ if ( ( dn == null ) || ( dn.size() == 0 ) || ( oids== null ) || ( oids.size() == 0 ) )
+ {
+ return dn;
+ }
+
+ LdapDN newDn = (LdapDN)dn.clone();
+
+ Enumeration rdns = newDn.getAllRdn();
+
+ // Loop on all RDNs
+ while ( rdns.hasMoreElements() )
+ {
+ Rdn rdn = (Rdn)rdns.nextElement();
+ String upName = rdn.getUpName();
+ rdnToOid( rdn, oids );
+ rdn.normalizeString();
+ rdn.setUpName( upName );
+ }
+
+ newDn.normalize( newDn.upName );
+
+ return newDn;
+ }
+}
Propchange: directory/branches/DN-refactoring/ldap-common/src/main/java/org/apache/ldap/common/name/LdapDN.java
------------------------------------------------------------------------------
svn:executable = *
|