directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r409468 [1/3] - in /directory/releases/shared/0.9.5.1/ldap/src: main/java/org/apache/directory/shared/ldap/codec/ main/java/org/apache/directory/shared/ldap/codec/add/ main/java/org/apache/directory/shared/ldap/codec/modify/ main/java/org/a...
Date Thu, 25 May 2006 21:01:10 GMT
Author: elecharny
Date: Thu May 25 14:01:09 2006
New Revision: 409468

URL: http://svn.apache.org/viewvc?rev=409468&view=rev
Log:
merging ldif modification into 1.0-trunks

Added:
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
    directory/releases/shared/0.9.5.1/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
Removed:
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifIterator.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifIteratorMonitor.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifIteratorMonitorAdapter.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParser.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifParserImpl.java
    directory/releases/shared/0.9.5.1/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifParserImplTest.java
Modified:
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/util/PropertiesUtils.java
    directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java

Modified: directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java
URL: http://svn.apache.org/viewvc/directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java?rev=409468&r1=409467&r2=409468&view=diff
==============================================================================
--- directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java
(original)
+++ directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixDecoder.java
Thu May 25 14:01:09 2006
@@ -62,6 +62,7 @@
     public void decode( Object encoded ) throws DecoderException
     {
         ByteBuffer buf;
+        int position = 0;
 
         if ( encoded instanceof ByteBuffer )
         {
@@ -77,42 +78,47 @@
                 + encoded.getClass() );
         }
 
-        if ( log.isDebugEnabled() )
+        while ( buf.hasRemaining() )
         {
-            log.debug( "Decoding the PDU : " );
 
-            if ( buf.hasArray() )
-            {
-                log.debug( StringTools.dumpBytes( buf.array() ) );
-            }
-            else
-            {
-                byte[] array = new byte[buf.capacity()];
-                int i = 0;
+            ldapDecoder.decode( buf, ldapMessageContainer );
 
-                while ( buf.hasRemaining() )
-                {
-                    array[i++] = buf.get();
-                }
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Decoding the PDU : " );
 
+                int size = buf.position();
                 buf.flip();
+                
+            	byte[] array = new byte[ size - position ];
+            	
+            	for ( int i = position; i < size; i++ )
+            	{
+            		array[ i ] = buf.get();
+            	}
+
+                position = size;
+                
                 log.debug( StringTools.dumpBytes( array ) );
             }
-        }
-
-        while ( buf.hasRemaining() )
-        {
-            ldapDecoder.decode( buf, ldapMessageContainer );
-
+            
             if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
             {
                 if ( log.isDebugEnabled() )
                 {
                     log.debug( "Decoded LdapMessage : " + ldapMessageContainer.getLdapMessage()
);
+                    buf.mark();
                 }
 
                 decoderCallback.decodeOccurred( null, ldapMessageContainer.getLdapMessage()
);
                 ldapMessageContainer.clean();
+            }
+            else
+            {
+            	if ( log.isDebugEnabled() )
+            	{
+            		
+            	}
             }
         }
     }

Modified: directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java
URL: http://svn.apache.org/viewvc/directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java?rev=409468&r1=409467&r2=409468&view=diff
==============================================================================
--- directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java
(original)
+++ directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequest.java
Thu May 25 14:01:09 2006
@@ -144,6 +144,18 @@
         attributes.put( currentAttribute );
     }
 
+    /**
+     * Create a new attributeValue
+     * 
+     * @param type
+     *            The attribute's name (called 'type' in the grammar)
+     */
+    public void addAttributeType( String type )
+    {
+        currentAttribute = new BasicAttribute( type.toLowerCase() );
+        attributes.put( currentAttribute );
+    }
+
 
     /**
      * Add a new value to the current attribute

Modified: directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java?rev=409468&r1=409467&r2=409468&view=diff
==============================================================================
--- directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java
(original)
+++ directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequest.java
Thu May 25 14:01:09 2006
@@ -165,7 +165,18 @@
      */
     public void addAttributeTypeAndValues( LdapString type )
     {
-        currentAttribute = new BasicAttribute( StringTools.lowerCase( type.getString() )
);
+        addAttributeTypeAndValues( type.getString() );
+    }
+
+    /**
+     * Add a new attributeTypeAndValue
+     * 
+     * @param type
+     *            The attribute's name
+     */
+    public void addAttributeTypeAndValues( String type )
+    {
+        currentAttribute = new BasicAttribute( StringTools.lowerCase( type ) );
 
         int operation = 0;
 

Added: directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java
URL: http://svn.apache.org/viewvc/directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java?rev=409468&view=auto
==============================================================================
--- directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java
(added)
+++ directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java
Thu May 25 14:01:09 2006
@@ -0,0 +1,710 @@
+/*
+ *   Copyright 2004 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.directory.shared.ldap.ldif;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * A entry to be populated by an ldif parser.
+ * 
+ * We will have different kind of entries : - added entries - deleted entries -
+ * modified entries - RDN modified entries - DN modified entries
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Entry implements Cloneable
+{
+    /** the change type */
+    private int changeType;
+
+    /** the modification item list */
+    private List modificationList;
+
+    private Map modificationItems;
+
+    /** the dn of the ldif entry */
+    private String dn;
+
+    /** The new superior */
+    private String newSuperior;
+
+    /** The new rdn */
+    private String newRdn;
+
+    /** The delete old rdn flag */
+    private boolean deleteOldRdn;
+
+    /** attributes of the entry */
+    private BasicAttributes attributeList;
+
+    /** The possible change types */
+    public final static int ADD = 0;
+
+    public final static int MODIFY = 1;
+
+    public final static int MODDN = 2;
+
+    public final static int MODRDN = 3;
+
+    public final static int DELETE = 4;
+
+    /** The control */
+    private Control control;
+
+    /**
+     * Creates a new Entry object.
+     */
+    public Entry()
+    {
+        changeType = ADD; // Default LDIF content
+        modificationList = new LinkedList();
+        modificationItems = new HashMap();
+        dn = null;
+        attributeList = new BasicAttributes( true );
+        control = null;
+    }
+
+    /**
+     * Set the Distinguished Name
+     * 
+     * @param dn
+     *            The Distinguished Name
+     */
+    public void setDn( String dn )
+    {
+        this.dn = dn;
+    }
+
+    /**
+     * Set the modification type
+     * 
+     * @param changeType
+     *            The change type
+     * 
+     */
+    public void setChangeType( int changeType )
+    {
+        this.changeType = changeType;
+    }
+
+    /**
+     * Set the change type
+     * 
+     * @param changeType
+     *            The change type
+     */
+    public void setChangeType( String changeType )
+    {
+        if ( "add".equals( changeType ) )
+        {
+            this.changeType = ADD;
+        }
+        else if ( "modify".equals( changeType ) )
+        {
+            this.changeType = MODIFY;
+        }
+        else if ( "moddn".equals( changeType ) )
+        {
+            this.changeType = MODDN;
+        }
+        else if ( "modrdn".equals( changeType ) )
+        {
+            this.changeType = MODRDN;
+        }
+        else if ( "delete".equals( changeType ) )
+        {
+            this.changeType = DELETE;
+        }
+    }
+
+    /**
+     * Add a modification item (used by modify operations)
+     * 
+     * @param ModificationItem
+     *            The modification to be added
+     */
+    public void addModificationItem( ModificationItem modification )
+    {
+        if ( changeType == MODIFY )
+        {
+            modificationList.add( modification );
+            modificationItems.put( modification.getAttribute().getID(), modification );
+        }
+    }
+
+    /**
+     * Add a modification item (used by modify operations)
+     * 
+     * @param modOp
+     *            The operation. One of : DirContext.ADD_ATTRIBUTE
+     *            DirContext.REMOVE_ATTRIBUTE DirContext.REPLACE_ATTRIBUTE
+     * 
+     * @param attr
+     *            The attribute to be added
+     */
+    public void addModificationItem( int modOp, Attribute attr ) throws NamingException
+    {
+        if ( changeType == MODIFY )
+        {
+            if ( modificationItems.containsKey( attr.getID() ) )
+            {
+                ModificationItem item = (ModificationItem) modificationItems.get( attr.getID()
);
+                Attribute attribute = item.getAttribute();
+
+                Enumeration attrs = attr.getAll();
+
+                while ( attrs.hasMoreElements() )
+                {
+                    attribute.add( attrs.nextElement() );
+                }
+            }
+            else
+            {
+                ModificationItem item = new ModificationItem( modOp, attr );
+                modificationList.add( item );
+                modificationItems.put( attr.getID(), item );
+            }
+        }
+    }
+
+    /**
+     * Add a modification item
+     * 
+     * @param modOp
+     *            The operation. One of : DirContext.ADD_ATTRIBUTE
+     *            DirContext.REMOVE_ATTRIBUTE DirContext.REPLACE_ATTRIBUTE
+     * 
+     * @param id
+     *            The attribute's ID
+     * @param value
+     *            The attribute's value
+     */
+    public void addModificationItem( int modOp, String id, Object value ) throws NamingException
+    {
+        if ( changeType == MODIFY )
+        {
+            BasicAttribute attr = new BasicAttribute( id, value );
+
+            if ( modificationItems.containsKey( id ) )
+            {
+                ModificationItem item = (ModificationItem) modificationItems.get( id );
+                
+                if ( item.getModificationOp() != modOp )
+                {
+                    // This is an error : we can't have two different 
+                    // modifications of the same attribute for the same entry
+                    
+                    throw new NamingException( "Bad modification" );
+                }
+                
+                Attribute attribute = item.getAttribute();
+
+                attribute.add( value );
+            }
+            else
+            {
+                ModificationItem item = new ModificationItem( modOp, attr );
+                modificationList.add( item );
+                modificationItems.put( id, item );
+            }
+        }
+    }
+
+    /**
+     * Add an attribute to the entry
+     * 
+     * @param attr
+     *            The attribute to be added
+     */
+    public void addAttribute( Attribute attr )
+    {
+        attributeList.put( attr );
+    }
+
+    /**
+     * Add an attribute to the entry
+     * 
+     * @param id
+     *            The attribute ID
+     * 
+     * @param value
+     *            The attribute value
+     * 
+     */
+    public void addAttribute( String id, Object value )
+    {
+        Attribute attr = get( id );
+
+        if ( attr != null )
+        {
+            attr.add( value );
+        }
+        else
+        {
+            attributeList.put( id, value );
+        }
+    }
+
+    /**
+     * Add an attribute value to an existing attribute
+     * 
+     * @param id
+     *            The attribute ID
+     * 
+     * @param value
+     *            The attribute value
+     * 
+     */
+    public void putAttribute( String id, Object value )
+    {
+        Attribute attribute = attributeList.get( id );
+
+        if ( attribute != null )
+        {
+            attribute.add( value );
+        }
+        else
+        {
+            attributeList.put( id, value );
+        }
+    }
+
+    /**
+     * Get the change type
+     * 
+     * @return The change type. One of : ADD = 0; MODIFY = 1; MODDN = 2; MODRDN =
+     *         3; DELETE = 4;
+     */
+    public int getChangeType()
+    {
+        return changeType;
+    }
+
+    /**
+     * @return The list of modification items
+     */
+    public List getModificationItems()
+    {
+        return modificationList;
+    }
+
+    /**
+     * @return The entry Distinguished name
+     */
+    public String getDn()
+    {
+        return dn;
+    }
+
+    /**
+     * @return The number of entry modifications
+     */
+    public int size()
+    {
+        return modificationList.size();
+    }
+
+    /**
+     * Returns a attribute given it's id
+     * 
+     * @param attributeId
+     *            The attribute Id
+     * @return The attribute if it exists
+     */
+    public Attribute get( String attributeId )
+    {
+        if ( "dn".equalsIgnoreCase( attributeId ) )
+        {
+            return new BasicAttribute( "dn", dn );
+        }
+
+        return attributeList.get( attributeId );
+    }
+
+    /**
+     * Get the entry's attributes
+     * 
+     * @return An Attributes
+     */
+    public Attributes getAttributes()
+    {
+        if ( isEntry() )
+        {
+            return attributeList;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * @return True, if the old RDN should be deleted.
+     */
+    public boolean isDeleteOldRdn()
+    {
+        return deleteOldRdn;
+    }
+
+    /**
+     * Set the flage deleteOldRdn
+     * 
+     * @param deleteOldRdn
+     *            True if the old RDN should be deleted
+     */
+    public void setDeleteOldRdn( boolean deleteOldRdn )
+    {
+        this.deleteOldRdn = deleteOldRdn;
+    }
+
+    /**
+     * @return The new RDN
+     */
+    public String getNewRdn()
+    {
+        return newRdn;
+    }
+
+    /**
+     * Set the new RDN
+     * 
+     * @param newRdn
+     *            The new RDN
+     */
+    public void setNewRdn( String newRdn )
+    {
+        this.newRdn = newRdn;
+    }
+
+    /**
+     * @return The new superior
+     */
+    public String getNewSuperior()
+    {
+        return newSuperior;
+    }
+
+    /**
+     * Set the new superior
+     * 
+     * @param newSuperior
+     *            The new Superior
+     */
+    public void setNewSuperior( String newSuperior )
+    {
+        this.newSuperior = newSuperior;
+    }
+
+    /**
+     * @return True if the entry is an ADD entry
+     */
+    public boolean isChangeAdd()
+    {
+        return changeType == ADD;
+    }
+
+    /**
+     * @return True if the entry is a DELETE entry
+     */
+    public boolean isChangeDelete()
+    {
+        return changeType == DELETE;
+    }
+
+    /**
+     * @return True if the entry is a MODDN entry
+     */
+    public boolean isChangeModDn()
+    {
+        return changeType == MODDN;
+    }
+
+    /**
+     * @return True if the entry is a MODRDN entry
+     */
+    public boolean isChangeModRdn()
+    {
+        return changeType == MODRDN;
+    }
+
+    /**
+     * @return True if the entry is a MODIFY entry
+     */
+    public boolean isChangeModify()
+    {
+        return changeType == MODIFY;
+    }
+
+    public boolean isEntry()
+    {
+        return changeType == ADD;
+    }
+
+    /**
+     * @return The associated control, if any
+     */
+    public Control getControl()
+    {
+        return control;
+    }
+
+    /**
+     * Add a control to the entry
+     * 
+     * @param control
+     *            The control
+     */
+    public void setControl( Control control )
+    {
+        this.control = control;
+    }
+
+    /**
+     * Clone method
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+        Entry clone = (Entry) super.clone();
+
+        if ( modificationList != null )
+        {
+            for ( Iterator iter = modificationList.iterator(); iter.hasNext(); )
+            {
+                ModificationItem modif = (ModificationItem) ( iter.next() );
+                ModificationItem modifClone = new ModificationItem( modif.getModificationOp(),
(Attribute) modif.getAttribute()
+                        .clone() );
+                clone.modificationList.add( modifClone );
+            }
+        }
+
+        if ( modificationItems != null )
+        {
+            for ( Iterator iter = modificationItems.entrySet().iterator(); iter.hasNext();
)
+            {
+                Object key = iter.next();
+                ModificationItem modif = (ModificationItem) ( modificationItems.get( key
) );
+                ModificationItem modifClone = new ModificationItem( modif.getModificationOp(),
(Attribute) modif.getAttribute()
+                        .clone() );
+                clone.modificationItems.put( key, modifClone );
+            }
+
+        }
+
+        if ( attributeList != null )
+        {
+            try
+            {
+                NamingEnumeration attrs = attributeList.getAll();
+
+                while ( attrs.hasMore() )
+                {
+                    Attribute attribute = (BasicAttribute) attrs.nextElement();
+                    Attribute attrClone = new BasicAttribute( attribute.getID() );
+
+                    for ( NamingEnumeration iter = attribute.getAll(); iter.hasMoreElements();
)
+                    {
+                        Object value = iter.next();
+
+                        if ( value instanceof String )
+                        {
+                            attrClone.add( value );
+                        }
+                        else if ( value instanceof byte[] )
+                        {
+                            int length = ( (byte[]) value ).length;
+                            byte[] valueClone = new byte[length];
+                            System.arraycopy( value, 0, valueClone, 0, length );
+                            attrClone.add( valueClone );
+                        }
+                    }
+
+                    clone.attributeList.put( attrClone );
+                }
+            }
+            catch (NamingException ne)
+            {
+                throw new CloneNotSupportedException( ne.getMessage() );
+            }
+        }
+
+        return clone;
+    }
+    
+    /**
+     * Dumps the attributes
+     */
+    private String dumpAttributes()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        try
+        {
+            for ( NamingEnumeration attrs = attributeList.getAll(); attrs.hasMoreElements();
)
+            {
+                Attribute attribute = (Attribute) attrs.nextElement();
+    
+                sb.append( "        ").append( attribute.getID() ).append( ":\n" );
+    
+                for ( NamingEnumeration values = attribute.getAll(); values.hasMoreElements();
)
+                {
+                    Object value = values.nextElement();
+                    
+                    if ( value instanceof String )
+                    {
+                        sb.append(  "            " ).append( (String)value ).append('\n'
);
+                    }
+                    else
+                    {
+                        sb.append(  "            " ).append( StringTools.dumpBytes( (byte[])
value ) ).append('\n' );
+                    }
+                }
+            }
+        }
+        catch ( NamingException ne )
+        {
+            return "";
+        }
+        
+        return sb.toString();
+    }
+    
+    /**
+     * Dumps the modifications
+     */
+    private String dumpModificationItems()
+    {
+        StringBuffer sb = new StringBuffer();
+        
+        for ( Iterator iter = modificationList.iterator(); iter.hasNext(); )
+        {
+            ModificationItem modif = (ModificationItem) ( iter.next() );
+            
+            sb.append( "            Operation: " );
+            
+            switch ( modif.getModificationOp() )
+            {
+                case DirContext.ADD_ATTRIBUTE :
+                    sb.append( "ADD\n" );
+                    break;
+                    
+                case DirContext.REMOVE_ATTRIBUTE :
+                    sb.append( "REMOVE\n" );
+                    break;
+                    
+                case DirContext.REPLACE_ATTRIBUTE :
+                    sb.append( "REPLACE \n" );
+                    break;
+            }
+            
+            Attribute attribute = modif.getAttribute();
+            
+            sb.append( "                Attribute: " ).append( attribute.getID() ).append(
'\n' );
+            
+            if ( attribute.size() != 0 )
+            {
+                try
+                {
+                    for ( NamingEnumeration values = attribute.getAll(); values.hasMoreElements();
)
+                    {
+                        Object value = values.nextElement();
+    
+                        if ( value instanceof String )
+                        {
+                            sb.append(  "                " ).append( (String)value ).append('\n'
);
+                        }
+                        else
+                        {
+                            sb.append(  "                " ).append( StringTools.dumpBytes(
(byte[]) value ) ).append('\n' );
+                        }
+                    }
+                }
+                catch ( NamingException ne )
+                {
+                    return "";
+                }
+            }
+        }
+        
+        return sb.toString();
+    }
+    
+    /**
+     * Return a String representing the Entry
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append( "Entry : " ).append( dn ).append( '\n' );
+
+        if ( control != null )
+        {
+            sb.append( "    Control : " ).append(  control ).append( '\n' );
+        }
+        
+        switch ( changeType )
+        {
+            case ADD :
+                sb.append( "    Change type is ADD\n" );
+                sb.append( "        Attributes : \n" );
+                sb.append( dumpAttributes() );
+                break;
+                
+            case MODIFY :
+                sb.append( "    Change type is MODIFY\n" );
+                sb.append( "        Modifications : \n" );
+                sb.append( dumpModificationItems() );
+                break;
+                
+            case DELETE :
+                sb.append( "    Change type is DELETE\n" );
+                break;
+                
+            case MODDN :
+            case MODRDN :
+                sb.append( "    Change type is ").append( changeType == MODDN ? "MODDN\n"
: "MODRDN\n" );
+                sb.append( "    Delete old RDN : " ).append( deleteOldRdn ? "true\n" : "false\n"
);
+                sb.append( "    New RDN : " ).append( newRdn ).append( '\n' );
+                
+                if ( StringTools.isEmpty( newSuperior ) == false )
+                {
+                    sb.append( "    New superior : " ).append( newSuperior ).append( '\n'
);
+                }
+
+                break;
+        }
+        
+        return sb.toString();
+    }
+}

Modified: directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java
URL: http://svn.apache.org/viewvc/directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java?rev=409468&r1=409467&r2=409468&view=diff
==============================================================================
--- directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java
(original)
+++ directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java
Thu May 25 14:01:09 2006
@@ -54,77 +54,77 @@
      *            the multi map of single and multivalued attributes.
      * @return the LDIF as a String.
      */
-    public String compose( MultiMap a_attrHash )
+    public String compose( MultiMap attrHash )
     {
-        Object l_val = null;
-        String l_key = null;
-        Iterator l_keys = a_attrHash.keySet().iterator();
-        Iterator l_values = null;
-        Collection l_valueCol = null;
-        StringWriter l_sw = new StringWriter();
-        PrintWriter l_out = new PrintWriter( l_sw );
+        Object val = null;
+        String key = null;
+        Iterator keys = attrHash.keySet().iterator();
+        Iterator values = null;
+        Collection valueCol = null;
+        StringWriter sw = new StringWriter();
+        PrintWriter out = new PrintWriter( sw );
 
-        while ( l_keys.hasNext() )
+        while ( keys.hasNext() )
         {
-            l_key = ( String ) l_keys.next();
-            l_valueCol = ( Collection ) a_attrHash.get( l_key );
-            l_values = l_valueCol.iterator();
+            key = ( String ) keys.next();
+            valueCol = ( Collection ) attrHash.get( key );
+            values = valueCol.iterator();
 
-            if ( l_valueCol.isEmpty() )
+            if ( valueCol.isEmpty() )
             {
                 continue;
             }
-            else if ( l_valueCol.size() == 1 )
+            else if ( valueCol.size() == 1 )
             {
-                l_out.print( l_key );
-                l_out.print( ':' );
-                l_val = l_values.next();
+                out.print( key );
+                out.print( ':' );
+                val = values.next();
 
-                if ( l_val.getClass().isArray() )
+                if ( val.getClass().isArray() )
                 {
-                    l_out.print( ": " );
-                    l_out.println( base64encode( ( byte[] ) l_val ) );
+                    out.print( ": " );
+                    out.println( base64encode( ( byte[] ) val ) );
                 }
                 else
                 {
-                    l_out.print( ' ' );
-                    l_out.println( l_val );
+                    out.print( ' ' );
+                    out.println( val );
                 }
                 continue;
             }
 
-            while ( l_values.hasNext() )
+            while ( values.hasNext() )
             {
-                l_out.print( l_key );
-                l_out.print( ':' );
-                l_val = l_values.next();
+                out.print( key );
+                out.print( ':' );
+                val = values.next();
 
-                if ( l_val.getClass().isArray() )
+                if ( val.getClass().isArray() )
                 {
-                    l_out.print( ": " );
-                    l_out.println( base64encode( ( byte[] ) l_val ) );
+                    out.print( ": " );
+                    out.println( base64encode( ( byte[] ) val ) );
                 }
                 else
                 {
-                    l_out.print( ' ' );
-                    l_out.println( l_val );
+                    out.print( ' ' );
+                    out.println( val );
                 }
             }
         }
 
-        return l_sw.getBuffer().toString();
+        return sw.getBuffer().toString();
     }
 
 
     /**
      * Encodes an binary data into a base64 String.
      * 
-     * @param a_byteArray
+     * @param byteArray
      *            the value of a binary attribute.
      * @return the encoded binary data as a char array.
      */
-    public char[] base64encode( byte[] a_byteArray )
+    public char[] base64encode( byte[] byteArray )
     {
-        return Base64.encode( a_byteArray );
+        return Base64.encode( byteArray );
     }
 }

Added: directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
URL: http://svn.apache.org/viewvc/directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java?rev=409468&view=auto
==============================================================================
--- directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
(added)
+++ directory/releases/shared/0.9.5.1/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
Thu May 25 14:01:09 2006
@@ -0,0 +1,118 @@
+/* 
+ *   Copyright 2006 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.directory.shared.ldap.ldif;
+
+import javax.naming.ldap.Control;
+
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * The LdifControl class stores a control defined for an entry found in a ldif
+ * file.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdifControl implements Control
+{
+    static final long serialVersionUID = 1L;
+
+    /** The control OID */
+    private OID oid;
+
+    /** The control criticality */
+    private boolean criticality;
+
+    /** The control BER encoded value */
+    private byte[] value;
+
+    /**
+     * Create a new Control
+     * 
+     * @param oid
+     *            OID of the created control
+     */
+    public LdifControl( OID oid )
+    {
+        this.oid = oid;
+        criticality = false;
+        value = null;
+    }
+
+    /**
+     * Returns the criticality of the current control
+     */
+    public boolean isCritical()
+    {
+        return criticality;
+    }
+
+    /**
+     * Set the criticality
+     * 
+     * @param criticality
+     *            True or false.
+     */
+    public void setCriticality( boolean criticality )
+    {
+        this.criticality = criticality;
+    }
+
+    /**
+     * Return the control's OID as a String
+     */
+    public String getID()
+    {
+        return oid.toString();
+    }
+
+    /**
+     * Set the control's OID
+     * 
+     * @param oid
+     *            The control's OID
+     */
+    public void setOid( OID oid )
+    {
+        this.oid = oid;
+    }
+
+    /**
+     * Returns the BER encoded value of the control
+     */
+    public byte[] getEncodedValue()
+    {
+        return value;
+    }
+
+    /**
+     * Set the BER encoded value of the control
+     * 
+     * @param value
+     *            BER encodec value
+     */
+    public void setValue( byte[] value )
+    {
+        this.value = value;
+    }
+
+    public String toString()
+    {
+        return "LdifControl : {" + oid.toString() + ", " + criticality + ", " + StringTools.dumpBytes(
value ) + "}";
+    }
+}



Mime
View raw message