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/26 02:15:59 UTC
svn commit: r359033 -
/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DNNormalizer.java
Author: elecharny
Date: Sun Dec 25 17:15:54 2005
New Revision: 359033
URL: http://svn.apache.org/viewcvs?rev=359033&view=rev
Log:
Finished the internalNormalize() method
Modified:
directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DNNormalizer.java
Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DNNormalizer.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DNNormalizer.java?rev=359033&r1=359032&r2=359033&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DNNormalizer.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/schema/DNNormalizer.java Sun Dec 25 17:15:54 2005
@@ -17,14 +17,14 @@
package org.apache.ldap.common.schema;
-import java.util.Enumeration;
-
+import javax.naming.InvalidNameException;
import javax.naming.Name ;
import javax.naming.NamingException ;
-import org.apache.ldap.common.name.DNParser;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ldap.common.name.DnParser;
import org.apache.ldap.common.name.DnOidContainer;
-import org.apache.ldap.common.name.LdapRDN;
+import org.apache.ldap.common.name.LdapDN;
/**
@@ -33,7 +33,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class DNNormalizer
+public class DNNormalizer implements Normalizer
{
private static DnOidContainer oidContainer;
@@ -43,53 +43,77 @@
}
/**
+ * @see org.apache.ldap.common.schema.Normalizer#normalize(java.lang.Object)
+ */
+ public Object normalize( Object value ) throws NamingException
+ {
+ if ( value instanceof String )
+ {
+ return DNNormalizer.normalize( (String)value );
+ }
+ else
+ {
+ return DNNormalizer.normalize( (Name)value );
+ }
+ }
+
+ private static Name internalNormalize( Name name ) throws InvalidNameException, NamingException
+ {
+ // First, check that the mapping table is filled with
+ // values, else we can return the name as is.
+ if ( oidContainer == null )
+ {
+ return name;
+ }
+
+ // Loop on every NameComponent
+ if ( name.size() != 0 )
+ {
+ name = LdapDN.toOidName( name, DnOidContainer.getOids() );
+ }
+
+ return name;
+ }
+
+ /**
* Normalizes the value if it is a Name or a String returning the String
* representation always. If the value is not a String or a Name the object
* is returned as is.
*
* @see org.apache.ldap.common.schema.Normalizer#normalize(java.lang.Object)
*/
- public static Object normalize( Object value ) throws NamingException
+ public static Object normalize( Name value ) throws NamingException
{
if ( value == null )
{
return null;
}
- Name name = null;
-
- if ( value instanceof Name )
- {
- name = (Name)value;
- }
- else if ( value instanceof String )
- {
- name = DNParser.getNameParser().parse( ( String ) value ) ;
- }
+ return internalNormalize( (Name)value );
+ }
- // Loop on every NameComponent
-
- if ( name.size() != 0 )
+ /**
+ * Normalizes the value if it is a Name or a String returning the String
+ * representation always. If the value is not a String or a Name the object
+ * is returned as is.
+ *
+ * @see org.apache.ldap.common.schema.Normalizer#normalize(java.lang.Object)
+ */
+ public static Object normalize( String value ) throws NamingException
+ {
+ if ( StringUtils.isEmpty( value ) )
{
- Enumeration rdns = name.getAll();
-
- while ( rdns.hasMoreElements() )
- {
- // loop on all AttributeTypeAndValue
-
- LdapRDN rdn = (LdapRDN)rdns.nextElement();
-
- if ( rdn.getNbAtavs() > 1 )
- {
-
- }
- else
- {
-
- }
- }
+ return null;
}
- return name;
+ return internalNormalize( DnParser.getNameParser().parse( value ) );
+ }
+
+ /**
+ * A String representation of this normalizer
+ */
+ public String toString()
+ {
+ return "DNNormalizer";
}
}