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/10/26 19:09:54 UTC
svn commit: r328683 - in
/directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message:
CompareRequestImpl.java DeleteRequestImpl.java ExtendedRequestImpl.java
ModifyDnRequestImpl.java ModifyRequestImpl.java
Author: elecharny
Date: Wed Oct 26 10:09:46 2005
New Revision: 328683
URL: http://svn.apache.org/viewcvs?rev=328683&view=rev
Log:
Added toString() methods for debugging purposes
Modified:
directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/CompareRequestImpl.java
directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java
directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java
directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyRequestImpl.java
Modified: directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/CompareRequestImpl.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/CompareRequestImpl.java?rev=328683&r1=328682&r2=328683&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/CompareRequestImpl.java (original)
+++ directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/CompareRequestImpl.java Wed Oct 26 10:09:46 2005
@@ -18,6 +18,8 @@
import java.io.UnsupportedEncodingException;
+import org.apache.asn1new.util.StringUtils;
+
/**
* Lockable comparison request implementation.
@@ -102,14 +104,7 @@
*/
public String getAssertionValue()
{
- try
- {
- return new String( attrVal, "UTF-8" );
- }
- catch (UnsupportedEncodingException uee)
- {
- return "";
- }
+ return StringUtils.toUtf8( attrVal );
}
/**
@@ -122,14 +117,7 @@
super.lockCheck(
"Attempt to alter attribute value of locked CompareRequest" );
- try
- {
- this.attrVal = attrVal.getBytes( "UTF-8" );
- }
- catch (UnsupportedEncodingException uee)
- {
- this.attrVal = new byte[]{};
- }
+ this.attrVal = StringUtils.getBytesUtf8( attrVal );
}
/**
@@ -267,5 +255,27 @@
}
return true;
+ }
+
+ /**
+ * Get a String representation of a Compare Request
+ *
+ * @return A Compare Request String
+ */
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( " Compare request\n" );
+ sb.append( " Entry : '" ).append( name.toString() ).append( "'\n" );
+ sb.append( " Attribute description : '" ).append( attrId ).append(
+ "'\n" );
+ sb.append( " Attribute value : '" ).
+ append( StringUtils.toUtf8( attrVal ) ).
+ append( '/' ).
+ append( StringUtils.dumpBytes( attrVal ) ).
+ append( "'\n" );
+
+ return sb.toString();
}
}
Modified: directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java?rev=328683&r1=328682&r2=328683&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java (original)
+++ directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java Wed Oct 26 10:09:46 2005
@@ -140,4 +140,20 @@
return true;
}
+
+ /**
+ * Return a String representing a DelRequest
+ *
+ * @return A DelRequest String
+ */
+ public String toString()
+ {
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( " Del request\n" );
+ sb.append( " Entry : '" ).append( name.toString() ).append( "'\n" );
+
+ return sb.toString();
+ }
}
Modified: directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java?rev=328683&r1=328682&r2=328683&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java (original)
+++ directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java Wed Oct 26 10:09:46 2005
@@ -17,6 +17,7 @@
package org.apache.ldap.common.message;
+import org.apache.asn1new.util.StringUtils;
import org.apache.ldap.common.util.ArrayUtils;
@@ -181,5 +182,29 @@
}
return true;
+ }
+
+ /**
+ * Get a String representation of an Extended Request
+ *
+ * @return an Extended Request String
+ */
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( " Extended request\n" );
+ sb.append( " Request name : '" ).append( oid.toString() ).append( "'\n" );
+
+ if ( oid != null )
+ {
+ sb.append( " Request value : '" ).
+ append( StringUtils.toUtf8( payload ) ).
+ append( '/' ).
+ append( StringUtils.dumpBytes( payload ) ).
+ append( "'\n" );
+ }
+
+ return sb.toString();
}
}
Modified: directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java?rev=328683&r1=328682&r2=328683&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java (original)
+++ directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java Wed Oct 26 10:09:46 2005
@@ -28,14 +28,18 @@
extends AbstractRequest implements ModifyDnRequest
{
static final long serialVersionUID = 1233507339633051696L;
+
/** PDU's modify Dn candidate <b>entry</b> distinguished name property */
- private String m_name ;
+ private String name ;
+
/** PDU's <b>newrdn</b> relative distinguished name property */
- private String m_newRdn ;
+ private String newRdn ;
+
/** PDU's <b>newSuperior</b> distinguished name property */
- private String m_newSuperior ;
+ private String newSuperior ;
+
/** PDU's <b>deleteOldRdn</b> flag */
- private boolean m_deleteOldRdn = false ;
+ private boolean deleteOldRdn = false ;
// -----------------------------------------------------------------------
@@ -69,7 +73,7 @@
*/
public boolean getDeleteOldRdn()
{
- return m_deleteOldRdn ;
+ return deleteOldRdn ;
}
@@ -85,7 +89,7 @@
{
lockCheck(
"Attempt to toggle deleteOldRdn flag of locked ModifyDnRequest!" ) ;
- m_deleteOldRdn = deleteOldRdn ;
+ this.deleteOldRdn = deleteOldRdn ;
}
@@ -99,7 +103,7 @@
*/
public boolean isMove()
{
- return m_newSuperior != null ;
+ return newSuperior != null ;
}
@@ -111,7 +115,7 @@
*/
public String getName()
{
- return m_name ;
+ return name ;
}
@@ -124,7 +128,7 @@
public void setName( String name )
{
lockCheck( "Attempt to alter entry name on locked ModifyDnRequest!" ) ;
- m_name = name ;
+ this.name = name ;
}
@@ -136,7 +140,7 @@
*/
public String getNewRdn()
{
- return m_newRdn ;
+ return newRdn ;
}
@@ -149,7 +153,7 @@
public void setNewRdn( String newRdn )
{
lockCheck( "Atttempt to alter the newRdn of locked ModifyDnRequest!" ) ;
- m_newRdn = newRdn ;
+ this.newRdn = newRdn ;
}
@@ -163,7 +167,7 @@
*/
public String getNewSuperior()
{
- return m_newSuperior ;
+ return newSuperior ;
}
@@ -179,7 +183,7 @@
*/
public void setNewSuperior( String newSuperior )
{
- m_newSuperior = newSuperior ;
+ this.newSuperior = newSuperior ;
}
@@ -221,65 +225,89 @@
ModifyDnRequest req = ( ModifyDnRequest ) obj;
- if ( m_name != null && req.getName() == null )
+ if ( name != null && req.getName() == null )
{
return false;
}
- if ( m_name == null && req.getName() != null )
+ if ( name == null && req.getName() != null )
{
return false;
}
- if ( m_name != null && req.getName() != null )
+ if ( name != null && req.getName() != null )
{
- if ( ! m_name.equals( req.getName() ) )
+ if ( ! name.equals( req.getName() ) )
{
return false;
}
}
- if ( m_deleteOldRdn != req.getDeleteOldRdn() )
+ if ( deleteOldRdn != req.getDeleteOldRdn() )
{
return false;
}
- if ( m_newRdn != null && req.getNewRdn() == null )
+ if ( newRdn != null && req.getNewRdn() == null )
{
return false;
}
- if ( m_newRdn == null && req.getNewRdn() != null )
+ if ( newRdn == null && req.getNewRdn() != null )
{
return false;
}
- if ( m_newRdn != null && req.getNewRdn() != null )
+ if ( newRdn != null && req.getNewRdn() != null )
{
- if ( ! m_newRdn.equals( req.getNewRdn() ) )
+ if ( ! newRdn.equals( req.getNewRdn() ) )
{
return false;
}
}
- if ( m_newSuperior != null && req.getNewSuperior() == null )
+ if ( newSuperior != null && req.getNewSuperior() == null )
{
return false;
}
- if ( m_newSuperior == null && req.getNewSuperior() != null )
+ if ( newSuperior == null && req.getNewSuperior() != null )
{
return false;
}
- if ( m_newSuperior != null && req.getNewSuperior() != null )
+ if ( newSuperior != null && req.getNewSuperior() != null )
{
- if ( ! m_newSuperior.equals( req.getNewSuperior() ) )
+ if ( ! newSuperior.equals( req.getNewSuperior() ) )
{
return false;
}
}
return true;
+ }
+
+ /**
+ * Get a String representation of a ModifyDNRequest
+ *
+ * @return A ModifyDNRequest String
+ */
+ public String toString()
+ {
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( " ModifyDN Response\n" );
+ sb.append( " Entry : '" ).append( name ).append( "'\n" );
+ sb.append( " New RDN : '" ).append( newRdn.toString() ).append( "'\n" );
+ sb.append( " Delete old RDN : " ).append( deleteOldRdn ).append( "\n" );
+
+ if ( newSuperior != null )
+ {
+ sb.append( " New superior : '" ).append( newSuperior.toString() ).append(
+ "'\n" );
+ }
+
+ return sb.toString();
}
}
Modified: directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyRequestImpl.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyRequestImpl.java?rev=328683&r1=328682&r2=328683&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyRequestImpl.java (original)
+++ directory/shared/ldap/branches/shared-ldap-utf8/common/src/java/org/apache/ldap/common/message/ModifyRequestImpl.java Wed Oct 26 10:09:46 2005
@@ -20,10 +20,21 @@
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Collections ;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem ;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Lockable ModifyRequest implementation.
@@ -36,6 +47,10 @@
extends AbstractRequest implements ModifyRequest
{
static final long serialVersionUID = -505803669028990304L;
+
+ /** The logger */
+ private static final transient Logger log = LoggerFactory.getLogger( ModifyRequestImpl.class );
+
/** Dn of the entry to modify or PDU's <b>object</b> field */
private String name ;
/** Sequence of modifications or PDU's <b>modification</b> seqence field */
@@ -230,14 +245,131 @@
return false;
}
- // looks like we have another ordering issue - this time the order of
- // attribute values does not match. Until this is resolved we'll
- // comment it out - NOT A GOOD PRACTICE AT ALL!!!!!
-// if ( ! item0.getAttribute().equals( item1.getAttribute() ) )
-// {
-// return false;
-// }
+ try
+ {
+ Attribute attr0 = item0.getAttribute();
+ Attribute attr1 = item1.getAttribute();
+
+ Set attrHash0 = new HashSet();
+
+ NamingEnumeration iter0 = attr0.getAll();
+
+ while ( iter0.hasMoreElements() )
+ {
+ attrHash0.add( iter0.next() );
+ }
+
+ NamingEnumeration iter1 = attr1.getAll();
+
+ while ( iter1.hasMoreElements() )
+ {
+ Object value = iter1.next();
+
+ if ( attrHash0.contains( value ) == false )
+ {
+ return false;
+ }
+ else
+ {
+ attrHash0.remove( value );
+ }
+ }
+
+ return ( attrHash0.size() != 0 );
+ }
+ catch ( NamingException ne )
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Get a String representation of a ModifyRequest
+ *
+ * @return A ModifyRequest String
+ */
+ public String toString()
+ {
- return true;
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( " Modify Request\n" );
+ sb.append( " Object : '" ).append( name ).append( "'\n" );
+
+ if ( mods != null )
+ {
+
+ for ( int i = 0; i < mods.size(); i++ )
+ {
+
+ ModificationItem modification = ( ModificationItem ) mods.get( i );
+
+ sb.append( " Modification[" ).append( i ).append( "]\n" );
+ sb.append( " Operation : " );
+
+ switch ( modification.getModificationOp() )
+ {
+
+ case DirContext.ADD_ATTRIBUTE :
+ sb.append( " add\n" );
+ break;
+
+ case DirContext.REPLACE_ATTRIBUTE :
+ sb.append( " replace\n" );
+ break;
+
+ case DirContext.REMOVE_ATTRIBUTE :
+ sb.append( " delete\n" );
+ break;
+ }
+
+ sb.append( " Modification\n" );
+
+ Attribute attribute = modification.getAttribute();
+
+ try
+ {
+ sb.append( " Type : '" ).append( attribute.getID() ).append(
+ "'\n" );
+ sb.append( " Vals\n" );
+
+ for ( int j = 0; j < attribute.size(); j++ )
+ {
+ sb.append( " Val[" ).append( j ).append( "] : '" );
+
+ Object attributeValue = attribute.get( j );
+
+ if ( attributeValue instanceof byte[] )
+ {
+ sb.append( StringUtils.toUtf8( (byte[])attributeValue ) ).
+ append( '/' ).append( StringUtils.dumpBytes( (byte[])attributeValue ) );
+ }
+ else if ( attributeValue instanceof String )
+ {
+ sb.append( attributeValue );
+ }
+ else if ( attributeValue instanceof OctetString )
+ {
+ sb.append( ( (OctetString)attributeValue).toString() ).
+ append( '/' ).append( StringUtils.dumpBytes( ( (OctetString)attributeValue ).getValue() ) );
+ }
+ else
+ {
+ sb.append( StringUtils.dumpBytes( StringUtils.getBytesUtf8( attributeValue.toString() ) ) );
+ }
+
+ sb.append( "' \n" );
+
+ }
+ }
+ catch ( NamingException ne )
+ {
+ log.error( "Naming exception while printing the '" + attribute.getID() +
+ "'" );
+ }
+ }
+ }
+
+ return sb.toString();
}
}