directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r656466 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif: LdifControl.java LdifEntry.java LdifReader.java LdifUtils.java
Date Wed, 14 May 2008 23:37:54 GMT
Author: elecharny
Date: Wed May 14 16:37:53 2008
New Revision: 656466

URL: http://svn.apache.org/viewvc?rev=656466&view=rev
Log:
o Updated and added missing Javadoc
o Fixed some other warnings

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java?rev=656466&r1=656465&r2=656466&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java
Wed May 14 16:37:53 2008
@@ -60,6 +60,7 @@
 
     /**
      * Returns the criticality of the current control
+     * @return <code>true</code> if the control is critical
      */
     public boolean isCritical()
     {
@@ -79,6 +80,7 @@
 
     /**
      * Return the control's OID as a String
+     * @return The control's OID
      */
     public String getID()
     {
@@ -88,8 +90,7 @@
     /**
      * Set the control's OID
      * 
-     * @param oid
-     *            The control's OID
+     * @param oid The control's OID
      */
     public void setOid( OID oid )
     {
@@ -98,6 +99,7 @@
 
     /**
      * Returns the BER encoded value of the control
+     * @return the BER encoded value
      */
     public byte[] getEncodedValue()
     {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=656466&r1=656465&r2=656466&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
Wed May 14 16:37:53 2008
@@ -53,6 +53,7 @@
  * - DN modified entries
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
  */
 public class LdifEntry implements Cloneable, Serializable
 {
@@ -171,14 +172,12 @@
     /**
      * Add a modification item (used by modify operations)
      * 
-     * @param modOp
-     *            The operation. One of : DirContext.ADD_ATTRIBUTE
+     * @param modOp The operation. One of : DirContext.ADD_ATTRIBUTE
      *            DirContext.REMOVE_ATTRIBUTE DirContext.REPLACE_ATTRIBUTE
      * 
-     * @param attr
-     *            The attribute to be added
+     * @param attr The attribute to be added
      */
-    public void addModificationItem( int modOp, Attribute attr ) throws NamingException
+    public void addModificationItem( int modOp, Attribute attr )
     {
         if ( changeType == ChangeType.Modify )
         {
@@ -198,9 +197,8 @@
      * @param modOp The modification operation value
      * @param id The attribute's ID
      * @param value The attribute's value
-     * @throws NamingException if the modification can't be added 
      */
-    public void addModificationItem( int modOp, String id, Object value ) throws NamingException
+    public void addModificationItem( int modOp, String id, Object value )
     {
         if ( changeType == ChangeType.Modify )
         {
@@ -480,6 +478,8 @@
 
     /**
      * Clone method
+     * @return a clone of the current instance
+     * @exception CloneNotSupportedException If there is some problem while cloning the instance
      */
     public LdifEntry clone() throws CloneNotSupportedException
     {
@@ -517,23 +517,26 @@
     
     /**
      * Dumps the attributes
+     * @return A String representing the attributes
      */
     private String dumpAttributes()
     {
         StringBuffer sb = new StringBuffer();
+        Attribute attribute = null;
         
         try
         {
-            for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll();
attrs.hasMoreElements(); )
+            for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll();

+                  attrs.hasMoreElements(); 
+                  attribute = attrs.nextElement())
             {
-                Attribute attribute = attrs.nextElement();
-    
                 sb.append( "        ").append( attribute.getID() ).append( ":\n" );
-    
-                for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements();
)
+                Object value = null;
+                
+                for ( NamingEnumeration<?> values = attribute.getAll(); 
+                      values.hasMoreElements(); 
+                      value = values.nextElement())
                 {
-                    Object value = values.nextElement();
-                    
                     if ( value instanceof String )
                     {
                         sb.append(  "            " ).append( (String)value ).append('\n'
);
@@ -555,6 +558,7 @@
     
     /**
      * Dumps the modifications
+     * @return A String representing the modifications
      */
     private String dumpModificationItems()
     {
@@ -577,6 +581,9 @@
                 case DirContext.REPLACE_ATTRIBUTE :
                     sb.append( "REPLACE \n" );
                     break;
+                    
+                default :
+                    break; // Do nothing
             }
             
             Attribute attribute = modif.getAttribute();
@@ -587,10 +594,11 @@
             {
                 try
                 {
-                    for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements();
)
+                    Object value = null;
+                    for ( NamingEnumeration<?> values = attribute.getAll(); 
+                          values.hasMoreElements(); 
+                          value = values.nextElement() )
                     {
-                        Object value = values.nextElement();
-    
                         if ( value instanceof String )
                         {
                             sb.append(  "                " ).append( (String)value ).append('\n'
);
@@ -613,7 +621,7 @@
 
     
     /**
-     * Return a String representing the Entry
+     * @return a String representing the Entry
      */
     public String toString()
     {
@@ -655,6 +663,9 @@
                 }
 
                 break;
+                
+            default :
+                break; // Do nothing
         }
         
         return sb.toString();
@@ -663,6 +674,7 @@
     
     /**
      * @see Object#equals(Object)
+     * @return <code>true</code> if both values are equal
      */
     public boolean equals( Object o )
     {
@@ -826,6 +838,9 @@
                 }
                 
                 break;
+                
+            default :
+                break; // do nothing
         }
         
         if ( control != null )

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=656466&r1=656465&r2=656466&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
Wed May 14 16:37:53 2008
@@ -37,7 +37,6 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.NoSuchElementException;
 
 import javax.naming.InvalidNameException;
 import javax.naming.NamingException;
@@ -57,12 +56,16 @@
 
 /**
  * <pre>
- *  &lt;ldif-file&gt; ::= &quot;version:&quot; &lt;fill&gt; &lt;number&gt;
&lt;seps&gt; &lt;dn-spec&gt; &lt;sep&gt; &lt;ldif-content-change&gt;
+ *  &lt;ldif-file&gt; ::= &quot;version:&quot; &lt;fill&gt; &lt;number&gt;
&lt;seps&gt; &lt;dn-spec&gt; &lt;sep&gt; 
+ *  &lt;ldif-content-change&gt;
  *  
  *  &lt;ldif-content-change&gt; ::= 
- *    &lt;number&gt; &lt;oid&gt; &lt;options-e&gt; &lt;value-spec&gt;
&lt;sep&gt; &lt;attrval-specs-e&gt; &lt;ldif-attrval-record-e&gt;
| 
- *    &lt;alpha&gt; &lt;chars-e&gt; &lt;options-e&gt; &lt;value-spec&gt;
&lt;sep&gt; &lt;attrval-specs-e&gt; &lt;ldif-attrval-record-e&gt;
| 
- *    &quot;control:&quot; &lt;fill&gt; &lt;number&gt; &lt;oid&gt;
&lt;spaces-e&gt; &lt;criticality&gt; &lt;value-spec-e&gt; &lt;sep&gt;
&lt;controls-e&gt; 
+ *    &lt;number&gt; &lt;oid&gt; &lt;options-e&gt; &lt;value-spec&gt;
&lt;sep&gt; 
+ *    &lt;attrval-specs-e&gt; &lt;ldif-attrval-record-e&gt; | 
+ *    &lt;alpha&gt; &lt;chars-e&gt; &lt;options-e&gt; &lt;value-spec&gt;
&lt;sep&gt; 
+ *    &lt;attrval-specs-e&gt; &lt;ldif-attrval-record-e&gt; | 
+ *    &quot;control:&quot; &lt;fill&gt; &lt;number&gt; &lt;oid&gt;
&lt;spaces-e&gt; 
+ *    &lt;criticality&gt; &lt;value-spec-e&gt; &lt;sep&gt; &lt;controls-e&gt;

  *        &quot;changetype:&quot; &lt;fill&gt; &lt;changerecord-type&gt;
&lt;ldif-change-record-e&gt; |
  *    &quot;changetype:&quot; &lt;fill&gt; &lt;changerecord-type&gt;
&lt;ldif-change-record-e&gt;
  *                              
@@ -82,7 +85,8 @@
  *                              
  *  &lt;oid&gt; ::= '.' &lt;number&gt; &lt;oid&gt; | e
  *                              
- *  &lt;attrval-specs-e&gt; ::= &lt;number&gt; &lt;oid&gt; &lt;options-e&gt;
&lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; | 
+ *  &lt;attrval-specs-e&gt; ::= &lt;number&gt; &lt;oid&gt; &lt;options-e&gt;
&lt;value-spec&gt; 
+ *  &lt;sep&gt; &lt;attrval-specs-e&gt; | 
  *    &lt;alpha&gt; &lt;chars-e&gt; &lt;options-e&gt; &lt;value-spec&gt;
&lt;sep&gt; &lt;attrval-specs-e&gt; | e
  *                              
  *  &lt;value-spec-e&gt; ::= &lt;value-spec&gt; | e
@@ -97,11 +101,15 @@
  *                              
  *  &lt;chars-e&gt; ::= &lt;char&gt; &lt;chars-e&gt; |  e
  *  
- *  &lt;changerecord-type&gt; ::= &quot;add&quot; &lt;sep&gt; &lt;attributeType&gt;
&lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt;
| 
+ *  &lt;changerecord-type&gt; ::= &quot;add&quot; &lt;sep&gt; &lt;attributeType&gt;

+ *  &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt;
| 
  *    &quot;delete&quot; &lt;sep&gt; | 
- *    &quot;modify&quot; &lt;sep&gt; &lt;mod-type&gt; &lt;fill&gt;
&lt;attributeType&gt; &lt;options-e&gt; &lt;sep&gt; &lt;attrval-specs-e&gt;
&lt;sep&gt; '-' &lt;sep&gt; &lt;mod-specs-e&gt; | 
- *    &quot;moddn&quot; &lt;sep&gt; &lt;newrdn&gt; &lt;sep&gt;
&quot;deleteoldrdn:&quot; &lt;fill&gt; &lt;0-1&gt; &lt;sep&gt;
&lt;newsuperior-e&gt; &lt;sep&gt; |
- *    &quot;modrdn&quot; &lt;sep&gt; &lt;newrdn&gt; &lt;sep&gt;
&quot;deleteoldrdn:&quot; &lt;fill&gt; &lt;0-1&gt; &lt;sep&gt;
&lt;newsuperior-e&gt; &lt;sep&gt;
+ *    &quot;modify&quot; &lt;sep&gt; &lt;mod-type&gt; &lt;fill&gt;
&lt;attributeType&gt; 
+ *    &lt;options-e&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; &lt;sep&gt;
'-' &lt;sep&gt; &lt;mod-specs-e&gt; | 
+ *    &quot;moddn&quot; &lt;sep&gt; &lt;newrdn&gt; &lt;sep&gt;
&quot;deleteoldrdn:&quot; 
+ *    &lt;fill&gt; &lt;0-1&gt; &lt;sep&gt; &lt;newsuperior-e&gt;
&lt;sep&gt; |
+ *    &quot;modrdn&quot; &lt;sep&gt; &lt;newrdn&gt; &lt;sep&gt;
&quot;deleteoldrdn:&quot; 
+ *    &lt;fill&gt; &lt;0-1&gt; &lt;sep&gt; &lt;newsuperior-e&gt;
&lt;sep&gt;
  *  
  *  &lt;newrdn&gt; ::= ':' &lt;fill&gt; &lt;safe-string&gt; | &quot;::&quot;
&lt;fill&gt; &lt;base64-chars&gt;
  *  
@@ -151,27 +159,45 @@
  * </pre>
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
  */
 public class LdifReader implements Iterator<LdifEntry>
 {
     /** A logger */
     private static final Logger LOG = LoggerFactory.getLogger( LdifReader.class );
 
-    /** A private class to track the current position in a line */
+    /** 
+     * A private class to track the current position in a line 
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
     protected class Position
     {
-        public int pos;
+        /** The current position */
+        protected int pos;
 
+        /**
+         * Creates a new instance of Position.
+         */
         public Position()
         {
             pos = 0;
         }
 
+        /**
+         * Increment the current position by one
+         *
+         */
         public void inc()
         {
             pos++;
         }
 
+        /**
+         * Increment the current position by the given value
+         *
+         * @param val The value to add to the current position
+         */
         public void inc( int val )
         {
             pos += val;
@@ -263,13 +289,13 @@
     {
         File inf = new File( ldifFileName );
 
-        if ( inf.exists() == false )
+        if ( !inf.exists() )
         {
             LOG.error( "File {} cannot be found", inf.getAbsoluteFile() );
             throw new NamingException( "Cannot find file " + inf.getAbsoluteFile() );
         }
 
-        if ( inf.canRead() == false )
+        if ( !inf.canRead() )
         {
             LOG.error( "File {} cannot be read", inf.getName() );
             throw new NamingException( "Cannot read file " + inf.getName() );
@@ -335,13 +361,13 @@
      */
     public LdifReader( File in ) throws NamingException
     {
-        if ( in.exists() == false )
+        if ( !in.exists() )
         {
             LOG.error( "File {} cannot be found", in.getAbsoluteFile() );
             throw new NamingException( "Cannot find file " + in.getAbsoluteFile() );
         }
 
-        if ( in.canRead() == false )
+        if ( !in.canRead() )
         {
             LOG.error( "File {} cannot be read", in.getName() );
             throw new NamingException( "Cannot read file " + in.getName() );
@@ -402,6 +428,10 @@
      * ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
      * 
      * Check that the number is in the interval
+     * 
+     * @param document The document containing the number to parse
+     * @param position The current position in the document
+     * @return a String representing the parsed number
      */
     private static String parseNumber( char[] document, Position position )
     {
@@ -611,7 +641,7 @@
 
                         File file = new File( fileName );
 
-                        if ( file.exists() == false )
+                        if ( !file.exists() )
                         {
                             LOG.error( "File {} not found", fileName );
                             throw new NamingException( "Bad URL, file not found" );
@@ -652,17 +682,14 @@
                                 }
                                 finally
                                 {
-                                    if ( inf != null )
+                                    try
+                                    {
+                                        inf.close();
+                                    }
+                                    catch ( IOException ioe )
                                     {
-                                        try
-                                        {
-                                            inf.close();
-                                        }
-                                        catch ( IOException ioe )
-                                        {
-                                            LOG.error( "Error while closing the stream :
{}", ioe.getMessage() );
-                                            // Just do nothing ...
-                                        }
+                                        LOG.error( "Error while closing the stream : {}",
ioe.getMessage() );
+                                        // Just do nothing ...
                                     }
                                 }
                             }
@@ -702,9 +729,10 @@
      * "false") ] [ ":" &lt;fill&gt; &lt;SAFE-STRING-e&gt; | "::" &lt;fill&gt;
&lt;BASE64-STRING&gt; | ":<"
      * &lt;fill&gt; &lt;url&gt; ]
      * 
-     * @param line
-     *            The line containing the control
+     * @param line The line containing the control
      * @return A control
+     * @exception NamingException If the control has no OID or if the OID is incorrect,
+     * of if the criticality is not set when it's mandatory.
      */
     private Control parseControl( String line ) throws NamingException
     {
@@ -824,6 +852,7 @@
      * Parse an AttributeType/AttributeValue
      * 
      * @param line The line to parse
+     * @return the parsed Attribute
      */
     public static Attribute parseAttributeValue( String line )
     {
@@ -950,10 +979,9 @@
      * ATTRIBUTE-DESCRIPTION SEP &lt;attrval-specs-e&gt; "-" SEP &lt;attrval-specs-e&gt;
::=
      * ATTRVAL-SPEC &lt;attrval-specs&gt; | e *
      * 
-     * @param entry
-     *            The entry to feed
-     * @param iter
-     *            The lines
+     * @param entry The entry to feed
+     * @param iter The lines
+     * @exception NamingException If the modify operation is invalid
      */
     private void parseModify( LdifEntry entry, Iterator<String> iter ) throws NamingException
     {
@@ -1050,7 +1078,7 @@
 
                 String attributeType = line.substring( 0, colonIndex );
 
-                if ( attributeType.equalsIgnoreCase( modified ) == false )
+                if ( !attributeType.equalsIgnoreCase( modified ) )
                 {
                     LOG.error( "The modified attribute and the attribute value spec must
be equal" );
                     throw new NamingException( "Bad modify attribute" );
@@ -1095,17 +1123,12 @@
      * ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC &lt;attrval-specs-e&gt; "-"
SEP
      * &lt;attrval-specs-e&gt; ::= ATTRVAL-SPEC &lt;attrval-specs&gt; | e
      * 
-     * @param entry
-     *            The entry to feed
-     * @param iter
-     *            The lines iterator
-     * @param operation
-     *            The change operation (add, modify, delete, moddn or modrdn)
-     * @param control
-     *            The associated control, if any
-     * @return A modification entry
+     * @param entry The entry to feed
+     * @param iter The lines iterator
+     * @param operation The change operation (add, modify, delete, moddn or modrdn)
+     * @exception NamingException If the change operation is invalid
      */
-    private void parseChange( LdifEntry entry, Iterator<String> iter, ChangeType operation,
Control control ) throws NamingException
+    private void parseChange( LdifEntry entry, Iterator<String> iter, ChangeType operation
) throws NamingException
     {
         // The changetype and operation has already been parsed.
         entry.setChangeType( operation );
@@ -1186,6 +1209,9 @@
      * &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; &lt;changerecord&gt;
&lt;dn-spec&gt; ::= "dn:" &lt;fill&gt;
      * &lt;distinguishedName&gt; | "dn::" &lt;fill&gt; &lt;base64-distinguishedName&gt;
      * &lt;changerecord&gt; ::= "changetype:" &lt;fill&gt; &lt;change-op&gt;
+     * 
+     * @return the parsed ldifEntry
+     * @exception NamingException If the ldif file does not contain a valid entry 
      */
     private LdifEntry parseEntry() throws NamingException
     {
@@ -1279,7 +1305,7 @@
                 operation = parseChangeType( line );
 
                 // Parse the change operation in a separate function
-                parseChange( entry, iter, operation, control );
+                parseChange( entry, iter, operation );
                 changeTypeSeen = true;
             }
             else if ( line.indexOf( ':' ) > 0 )
@@ -1527,26 +1553,25 @@
 
         File file = new File( fileName );
 
-        if ( file.exists() == false )
+        if ( !file.exists() )
         {
             LOG.error( "Cannot parse the file {}, it does not exist", fileName );
             throw new NamingException( "Filename " + fileName + " not found." );
         }
 
         // Open the file and then get a channel from the stream
-        BufferedReader inf;
-
         try
         {
-            inf = new BufferedReader( new InputStreamReader( new FileInputStream( file ),
Charset.forName( encoding ) ) );
+            BufferedReader inf = new BufferedReader( new InputStreamReader( new FileInputStream(
file ), 
+                Charset.forName( encoding ) ) );
+
+            return parseLdif( inf );
         }
         catch (FileNotFoundException fnfe)
         {
             LOG.error( "Cannot find file {}", fileName );
             throw new NamingException( "Filename " + fileName + " not found." );
         }
-
-        return parseLdif( inf );
     }
 
     /**
@@ -1597,7 +1622,7 @@
      * 
      * @return the next LDIF as a String.
      */
-    public LdifEntry next() throws NoSuchElementException
+    public LdifEntry next()
     {
         try
         {
@@ -1627,6 +1652,7 @@
         }
     }
 
+    
     /**
      * Tests to see if another LDIF is on the input channel.
      * 
@@ -1639,6 +1665,7 @@
         return null != prefetched;
     }
 
+    
     /**
      * Always throws UnsupportedOperationException!
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=656466&r1=656465&r2=656466&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
Wed May 14 16:37:53 2008
@@ -19,6 +19,18 @@
  */
 package org.apache.directory.shared.ldap.ldif;
 
+import java.io.UnsupportedEncodingException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -27,21 +39,13 @@
 import org.apache.directory.shared.ldap.util.Base64;
 import org.apache.directory.shared.ldap.util.StringTools;
 
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
 
 
 /**
  * Some LDIF useful methods
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
  */
 public class LdifUtils
 {
@@ -148,6 +152,7 @@
      * 
      * @param ldif The LDIF string containing an attribute value
      * @return An Attributes instance
+     * @exception NamingException If the LDIF String cannot be converted to an Attributes
      */
     public static Attributes convertAttributesFromLdif( String ldif ) throws NamingException
     {
@@ -196,6 +201,7 @@
     /**
      * Convert an Entry to LDIF
      * @param entry the entry to convert
+     * @param length The maximum line's length 
      * @return the corresponding LDIF as a String
      * @throws NamingException If a naming exception is encountered.
      */
@@ -299,6 +305,9 @@
                             sb.append( "replace: " );
                             break;
                             
+                        default :
+                            break; // Do nothing
+                            
                     }
                     
                     sb.append( modification.getAttribute().getID() );
@@ -309,6 +318,9 @@
                 }
                 break;
                 
+            default :
+                break; // Do nothing
+                
         }
         
         sb.append( '\n' );
@@ -317,20 +329,22 @@
     }
     
     /**
-     * Base64 encode a String  
+     * Base64 encode a String
+     * @param str The string to encode
+     * @return the base 64 encoded string
      */
     private static String encodeBase64( String str )
     {
-        char[] encoded;
+        char[] encoded =null;
         
         try
         {
             // force encoding using UTF-8 charset, as required in RFC2849 note 7
-            encoded = Base64.encode( ( ( String ) str ).getBytes( "UTF-8" ) );
+            encoded = Base64.encode( str.getBytes( "UTF-8" ) );
         }
         catch ( UnsupportedEncodingException e )
         {
-            encoded = Base64.encode( ( ( String ) str ).getBytes() );
+            encoded = Base64.encode( str.getBytes() );
         }
         
         return new String( encoded );
@@ -469,9 +483,8 @@
      *
      * @param dn the dn of the added entry
      * @return a reverse LDIF
-     * @throws NamingException If something went wrong
      */
-    public static LdifEntry reverseAdd( LdapDN dn ) throws NamingException
+    public static LdifEntry reverseAdd( LdapDN dn )
     {
         LdifEntry entry = new LdifEntry();
         entry.setChangeType( ChangeType.Delete );
@@ -487,9 +500,8 @@
      * @param dn The deleted entry DN
      * @param deletedEntry The entry which has been deleted
      * @return A reverse LDIF
-     * @throws NamingException If something went wrong
      */
-    public static LdifEntry reverseDel( LdapDN dn, Attributes deletedEntry ) throws NamingException
+    public static LdifEntry reverseDel( LdapDN dn, Attributes deletedEntry )
     {
         LdifEntry entry = new LdifEntry();
         
@@ -519,8 +531,8 @@
     public static LdifEntry reverseModifyDn( LdapDN newSuperiorDn, LdapDN modifiedDn ) throws
NamingException
     {
         LdifEntry entry = new LdifEntry();
-        LdapDN currentParent;
-        LdapDN newDn;
+        LdapDN currentParent = null;
+        LdapDN newDn = null;
 
         if ( newSuperiorDn == null )
         {
@@ -551,11 +563,20 @@
     }
 
 
+    /**
+     * Revert a DN to it's previous version by removing the first RDN and adding the given
RDN
+     *
+     * @param t0 The initial Attributes
+     * @param t0_dn The initial DN
+     * @param t1_rdn The new RDN
+     * @return A new LDIF entry with a reverted DN
+     * @throws NamingException If the name reverting failed
+     */
     public static LdifEntry reverseRename( Attributes t0, LdapDN t0_dn, Rdn t1_rdn ) throws
NamingException
     {
         LdifEntry entry = new LdifEntry();
-        LdapDN parent;
-        LdapDN newDn;
+        LdapDN parent = null;
+        LdapDN newDn = null;
 
         if ( t1_rdn == null )
         {
@@ -659,7 +680,7 @@
     }
 
 
-    private static boolean reverseDoDeleteOldRdn( Attributes t0_entry, Rdn t1_rdn ) throws
NamingException
+    private static boolean reverseDoDeleteOldRdn( Attributes t0_entry, Rdn t1_rdn )
     {
         // Consider simple example changes (rename or move does not matter)
         // -------------------------------------------------------------------
@@ -790,6 +811,10 @@
                     reverseModification = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,
previous );
                     reverseModifications.add( 0, reverseModification );
                     break;
+                    
+                default :
+                    break; // Do nothing
+                    
             }
 
             AttributeUtils.applyModification( clonedEntry, modification );



Mime
View raw message