From commits-return-18545-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Sat Jun 07 06:29:23 2008 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 5084 invoked from network); 7 Jun 2008 06:29:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Jun 2008 06:29:23 -0000 Received: (qmail 38517 invoked by uid 500); 7 Jun 2008 06:29:26 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 38480 invoked by uid 500); 7 Jun 2008 06:29:26 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 38471 invoked by uid 99); 7 Jun 2008 06:29:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jun 2008 23:29:26 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Jun 2008 06:28:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E010B2388A89; Fri, 6 Jun 2008 23:28:31 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r664290 [7/13] - in /directory/shared/branches/bigbang: ./ asn1/src/main/java/org/apache/directory/shared/asn1/ asn1/src/main/java/org/apache/directory/shared/asn1/ber/ asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/ asn1/s... Date: Sat, 07 Jun 2008 06:28:15 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080607062831.E010B2388A89@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/BranchNormalizedVisitor.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/BranchNormalizedVisitor.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/BranchNormalizedVisitor.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/BranchNormalizedVisitor.java Fri Jun 6 23:28:06 2008 @@ -20,12 +20,11 @@ package org.apache.directory.shared.ldap.filter; +import java.text.ParseException; +import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.TreeSet; -import java.util.Comparator; -import java.io.IOException; -import java.text.ParseException; /** @@ -68,16 +67,16 @@ { if ( !child.isLeaf() ) { - ExprNode newChild = (ExprNode)visit( child ); - - if ( newChild != null ) - { - set.add( newChild ); - } + ExprNode newChild = (ExprNode)visit( child ); + + if ( newChild != null ) + { + set.add( newChild ); + } } else { - set.add( child ); + set.add( child ); } } @@ -119,12 +118,10 @@ * @param filter * the filter to normalize * @return the normalized version of the filter - * @throws java.io.IOException - * if filter parser cannot be created * @throws java.text.ParseException * if the filter is malformed */ - public static String getNormalizedFilter( String filter ) throws IOException, ParseException + public static String getNormalizedFilter( String filter ) throws ParseException { ExprNode originalNode = FilterParser.parse( filter ); @@ -153,7 +150,7 @@ { public int compare( ExprNode o1, ExprNode o2 ) { - StringBuilder buf = new StringBuilder(); + StringBuilder buf = new StringBuilder(); buf.setLength( 0 ); Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java Fri Jun 6 23:28:06 2008 @@ -44,16 +44,21 @@ /** - * @see Object#hashCode() + * Creates a new Equality object. + * + * @param attribute the attribute name + * @param value the value to test for + * @param assertionType The node's type */ - public int hashCode() + protected EqualityNode( String attribute, Value value, AssertionType assertionType ) { - return super.hashCode(); + super( attribute, value, assertionType ); } - + /** * @see Object#toString() + * @return A string representing the AndNode */ public String toString() { Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExprNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExprNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExprNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExprNode.java Fri Jun 6 23:28:06 2008 @@ -71,10 +71,11 @@ * TODO - Why is this here? Why not put it in some utility class? * * @param buf the buffer to append to. + * @return The buffer in which the refinement has been appended * @throws UnsupportedOperationException if this node isn't a part of a refinement. * @return the refinement buffer */ - StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException; + StringBuilder printRefinementToBuffer( StringBuilder buf ); /** Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java Fri Jun 6 23:28:06 2008 @@ -129,6 +129,8 @@ /** * Sets the matching rule id as an OID string. + * + * @param matchingRuleId The maching rule ID */ public void setMatchingRuleId( String matchingRuleId ) { @@ -156,6 +158,8 @@ /** * Sets the value. + * + * @param value the value */ public final void setValue( String value) { @@ -164,16 +168,8 @@ /** - * @see ExprNode#printRefinementToBuffer(StringBuilder) - */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException - { - throw new UnsupportedOperationException( "ExtensibleNode can't be part of a refinement" ); - } - - - /** * @see Object#hashCode() + * @return the instance's hash code */ public int hashCode() { @@ -190,11 +186,12 @@ /** * @see java.lang.Object#toString() + * @return A string representing the AndNode */ public String toString() { - StringBuilder buf = new StringBuilder(); - + StringBuilder buf = new StringBuilder(); + buf.append( '(' ).append( getAttribute() ); buf.append( "-" ); buf.append( dnAttributes ); Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Fri Jun 6 23:28:06 2008 @@ -604,7 +604,7 @@ // StringTools.trimLeft( filter, pos ); // Check for the left '(' - if ( StringTools.isCharASCII( filter, pos.start, '(' ) == false ) + if ( !StringTools.isCharASCII( filter, pos.start, '(' ) ) { // No more node, get out if ( ( pos.start == 0 ) && ( pos.length != 0 ) ) @@ -634,7 +634,7 @@ // StringTools.trimLeft( filter, pos ); // Check that we have a right ')' - if ( StringTools.isCharASCII( filter, pos.start, ')' ) == false ) + if ( !StringTools.isCharASCII( filter, pos.start, ')' ) ) { throw new ParseException( "The filter has no right parenthese", pos.start ); } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterVisitor.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterVisitor.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterVisitor.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterVisitor.java Fri Jun 6 23:28:06 2008 @@ -49,6 +49,7 @@ * Visits a filter expression AST using a specific visitation order. * * @param node the node to visit + * @return node the resulting modified node */ Object visit( ExprNode node ); Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java Fri Jun 6 23:28:06 2008 @@ -44,16 +44,8 @@ /** - * @see Object#hashCode() - */ - public int hashCode() - { - return super.hashCode(); - } - - - /** * @see Object#toString() + * @return A string representing the AndNode */ public String toString() { Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java Fri Jun 6 23:28:06 2008 @@ -26,7 +26,7 @@ * @author Apache Directory Project * @version $Rev$ */ -public abstract class LeafNode extends AbstractExprNode +public class LeafNode extends AbstractExprNode { /** attribute on which this leaf is based */ private String attribute; @@ -36,6 +36,7 @@ * Creates a leaf node. * * @param attribute the attribute this node is based on + * @param assertionType the type of this leaf node */ protected LeafNode( String attribute, AssertionType assertionType ) { @@ -78,7 +79,28 @@ /** + * @see org.apache.directory.shared.ldap.filter.ExprNode#accept( + * org.apache.directory.shared.ldap.filter.FilterVisitor) + * + * @param visitor the filter expression tree structure visitor + * @return The modified element + */ + public final Object accept( FilterVisitor visitor ) + { + if ( visitor.canVisit( this ) ) + { + return visitor.visit( this ); + } + else + { + return null; + } + } + + + /** * @see Object#hashCode() + * @return the instance's hash code */ public int hashCode() { @@ -111,26 +133,9 @@ //noinspection SimplifiableIfStatement if ( other.getClass() != this.getClass() ) { - return false; + return false; } return attribute.equals( ( ( LeafNode ) other ).getAttribute() ); } - - - /** - * @see org.apache.directory.shared.ldap.filter.ExprNode#accept( - * org.apache.directory.shared.ldap.filter.FilterVisitor) - */ - public final Object accept( FilterVisitor visitor ) - { - if ( visitor.canVisit( this ) ) - { - return visitor.visit( this ); - } - else - { - return null; - } - } } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java Fri Jun 6 23:28:06 2008 @@ -44,16 +44,8 @@ /** - * @see Object#hashCode() - */ - public int hashCode() - { - return super.hashCode(); - } - - - /** * @see Object#toString() + * @return A string representing the AndNode */ public String toString() { Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/NotNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/NotNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/NotNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/NotNode.java Fri Jun 6 23:28:06 2008 @@ -38,14 +38,14 @@ * * @param childList the child nodes under this branch node. */ - public NotNode( List children ) + public NotNode( List childList ) { super( AssertionType.NOT ); - - if ( this.children.size() > 1 ) - { - throw new IllegalStateException( "Cannot add more than one element to a negation node." ); - } + + if ( childList != null ) + { + setChildren( childList ); + } } @@ -64,11 +64,11 @@ */ public void addNode( ExprNode node ) { - if ( children.size() >= 1 ) - { - throw new IllegalStateException( "Cannot add more than one element to a negation node." ); - } - + if ( ( children != null ) && ( children.size() >= 1 ) ) + { + throw new IllegalStateException( "Cannot add more than one element to a negation node." ); + } + children.add( node ); } @@ -80,11 +80,11 @@ */ public void addNodeToHead( ExprNode node ) { - if ( children.size() >= 1 ) - { - throw new IllegalStateException( "Cannot add more than one element to a negation node." ); - } - + if ( children.size() >= 1 ) + { + throw new IllegalStateException( "Cannot add more than one element to a negation node." ); + } + children.add( node ); } @@ -92,16 +92,16 @@ /** * Sets the list of children under this node. * - * @param list the list of children to set. + * @param childList the list of children to set. */ - public void setChildren( List list ) + public void setChildren( List childList ) { - if ( ( list != null ) && ( list.size() > 1 ) ) - { - throw new IllegalStateException( "Cannot add more than one element to a negation node." ); - } + if ( ( childList != null ) && ( childList.size() > 1 ) ) + { + throw new IllegalStateException( "Cannot add more than one element to a negation node." ); + } - children = list; + children = childList; } @@ -151,23 +151,26 @@ /** * @see ExprNode#printRefinementToBuffer(StringBuffer) + * + * @return The buffer in which the refinement has been appended + * @throws UnsupportedOperationException if this node isn't a part of a refinement. */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException + public StringBuilder printRefinementToBuffer( StringBuilder buf ) { buf.append( "not: {" ); boolean isFirst = true; for ( ExprNode node:children ) { - if ( isFirst ) - { - isFirst = false; - } - else - { - buf.append( ", " ); - } - + if ( isFirst ) + { + isFirst = false; + } + else + { + buf.append( ", " ); + } + node.printRefinementToBuffer( buf ); } @@ -181,6 +184,7 @@ * down. * * @see java.lang.Object#toString() + * @return A string representing the AndNode */ public String toString() { @@ -194,16 +198,4 @@ return buf.toString(); } - - - /** - * @see Object#hashCode() - */ - public int hashCode() - { - int hash = 37; - hash = hash*17 + AssertionType.NOT.hashCode(); - hash = hash*17 + ( annotations == null ? 0 : annotations.hashCode() ); - return hash; - } } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/OrNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/OrNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/OrNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/OrNode.java Fri Jun 6 23:28:06 2008 @@ -36,9 +36,9 @@ * * @param childList the child nodes under this branch node. */ - public OrNode( List children) + public OrNode( List childList) { - super( children, AssertionType.OR ); + super( childList, AssertionType.OR ); } @@ -99,23 +99,26 @@ /** * @see ExprNode#printRefinementToBuffer(StringBuffer) + * + * @return The buffer in which the refinement has been appended + * @throws UnsupportedOperationException if this node isn't a part of a refinement. */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException + public StringBuilder printRefinementToBuffer( StringBuilder buf ) { buf.append( "or: {" ); boolean isFirst = true; for ( ExprNode node:children ) { - if ( isFirst ) - { - isFirst = false; - } - else - { - buf.append( ", " ); - } - + if ( isFirst ) + { + isFirst = false; + } + else + { + buf.append( ", " ); + } + node.printRefinementToBuffer( buf ); } @@ -129,6 +132,7 @@ * down. * * @see java.lang.Object#toString() + * @return A string representing the AndNode */ public String toString() { @@ -139,17 +143,18 @@ for ( ExprNode child:getChildren() ) { - buf.append( child ); + buf.append( child ); } buf.append( ')' ); - + return buf.toString(); } /** * @see Object#hashCode() + * @return the instance's hash code */ public int hashCode() { @@ -188,18 +193,18 @@ if ( children.size() != otherChildren.size() ) { - return false; + return false; } for ( int i = 0; i < children.size(); i++ ) { - ExprNode child = children.get( i ); - ExprNode otherChild = children.get( i ); - - if ( !child.equals( otherChild ) ) - { - return false; - } + ExprNode child = children.get( i ); + ExprNode otherChild = children.get( i ); + + if ( !child.equals( otherChild ) ) + { + return false; + } } return true; Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/PresenceNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/PresenceNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/PresenceNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/PresenceNode.java Fri Jun 6 23:28:06 2008 @@ -42,11 +42,12 @@ /** * @see java.lang.Object#toString() + * @return A string representing the AndNode */ public String toString() { - StringBuilder buf = new StringBuilder(); - + StringBuilder buf = new StringBuilder(); + buf.append( '(' ).append( getAttribute() ).append( "=*" ); buf.append( super.toString() ); @@ -55,13 +56,4 @@ return buf.toString(); } - - - /** - * @see ExprNode#printRefinementToBuffer(StringBuilder) - */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException - { - throw new UnsupportedOperationException( "PresenceNode can't be part of a refinement" ); - } } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ScopeNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ScopeNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ScopeNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ScopeNode.java Fri Jun 6 23:28:06 2008 @@ -62,6 +62,7 @@ * Always returns true since a scope node has no children. * * @see ExprNode#isLeaf() + * @return true */ public boolean isLeaf() { @@ -103,17 +104,11 @@ /** - * @see ExprNode#printRefinementToBuffer(StringBuilder) - */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException - { - throw new UnsupportedOperationException( "ScopeNode can't be part of a refinement" ); - } - - - /** * @see org.apache.directory.shared.ldap.filter.ExprNode#accept( * org.apache.directory.shared.ldap.filter.FilterVisitor) + * + * @param visitor the filter expression tree structure visitor + * @return The modified element */ public Object accept( FilterVisitor visitor ) { @@ -123,13 +118,14 @@ } else { - return null; + return null; } } - + /** * @see Object#hashCode() + * @return the instance's hash code */ public int hashCode() { @@ -146,12 +142,13 @@ /** * @see Object#toString() + * @return A string representing the AndNode */ public String toString() { - StringBuilder buf = new StringBuilder(); - - buf.append( "(#{" ); + StringBuilder buf = new StringBuilder(); + + buf.append( "(#{" ); switch ( scope ) { @@ -172,16 +169,17 @@ default: buf.append( "UNKNOWN" ); + break; } - - buf.append( ", '" ); - buf.append( baseDn ); - buf.append( "', " ); - buf.append( aliasDerefAliases ); - buf.append( "}" ); - buf.append( super.toString() ); - buf.append( ')' ); - - return buf.toString(); + + buf.append( ", '" ); + buf.append( baseDn ); + buf.append( "', " ); + buf.append( aliasDerefAliases ); + buf.append( "}" ); + buf.append( super.toString() ); + buf.append( ')' ); + + return buf.toString(); } } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java Fri Jun 6 23:28:06 2008 @@ -35,13 +35,13 @@ /** the value */ protected Value value; - /** - * Constants for comparisons - * - * TODO - why are these here if not used? - */ - public final static boolean EVAL_GREATER = true; - public final static boolean EVAL_LESSER = false; + /* TODO - why are these here if not used? */ + /** Constants for comparisons : > */ + public static final boolean EVAL_GREATER = true; + + /* TODO - why are these here if not used? */ + /** Constants for comparisons : < */ + public static final boolean EVAL_LESSER = false; /** @@ -105,8 +105,10 @@ /** * @see ExprNode#printRefinementToBuffer(StringBuilder) + * @return The buffer in which the refinement has been appended + * @throws UnsupportedOperationException if this node isn't a part of a refinement. */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException + public StringBuilder printRefinementToBuffer( StringBuilder buf ) { if ( getAttribute() == null || !SchemaConstants.OBJECT_CLASS_AT.equalsIgnoreCase( getAttribute() ) ) { @@ -121,6 +123,7 @@ /** * @see Object#hashCode() + * @return the instance's hash code */ public int hashCode() { Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java Fri Jun 6 23:28:06 2008 @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; import javax.naming.NamingException; @@ -114,10 +113,10 @@ * Set the initial pattern * @param initialPattern The initial pattern */ - public void setInitial( String initialPattern ) - { - this.initialPattern = initialPattern; - } + public void setInitial( String initialPattern ) + { + this.initialPattern = initialPattern; + } /** * Gets the final fragment or suffix. @@ -134,10 +133,10 @@ * Set the final pattern * @param finalPattern The final pattern */ - public void setFinal( String finalPattern ) - { - this.finalPattern = finalPattern; - } + public void setFinal( String finalPattern ) + { + this.finalPattern = finalPattern; + } /** @@ -155,10 +154,10 @@ * Set the any patterns * @param anyPattern The any patterns */ - public void setAny( List anyPattern ) - { - this.anyPattern = anyPattern; - } + public void setAny( List anyPattern ) + { + this.anyPattern = anyPattern; + } /** @@ -176,10 +175,9 @@ * * @param normalizer the normalizer to use for pattern component normalization * @return the equivalent compiled regular expression - * @throws PatternSyntaxException if the regular expression is invalid * @throws NamingException if there are problems while normalizing */ - public final Pattern getRegex( Normalizer normalizer ) throws PatternSyntaxException, NamingException + public final Pattern getRegex( Normalizer normalizer ) throws NamingException { if ( ( anyPattern != null ) && ( anyPattern.size() > 0 ) ) { @@ -232,6 +230,7 @@ /** * @see Object#hashCode() + * @return the instance's hash code */ public int hashCode() { @@ -256,11 +255,12 @@ /** * @see java.lang.Object#toString() + * @return A string representing the AndNode */ public String toString() { - StringBuilder buf = new StringBuilder(); - + StringBuilder buf = new StringBuilder(); + buf.append( '(' ).append( getAttribute() ).append( '=' ); if ( null != initialPattern ) @@ -274,11 +274,11 @@ if ( null != anyPattern ) { - for ( String any:anyPattern ) - { - buf.append( any ); - buf.append( '*' ); - } + for ( String any:anyPattern ) + { + buf.append( any ); + buf.append( '*' ); + } } if ( null != finalPattern ) @@ -292,13 +292,4 @@ return buf.toString(); } - - - /** - * @see ExprNode#printRefinementToBuffer(StringBuilder) - */ - public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException - { - throw new UnsupportedOperationException( "SubstringNode can't be part of a refinement" ); - } } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java Fri Jun 6 23:28:06 2008 @@ -34,10 +34,19 @@ ModRdn( 3 ), Delete( 4 ); + /** Add ordinal value */ public static final int ADD_ORDINAL = 0; + + /** Modify ordinal value */ public static final int MODIFY_ORDINAL = 1; + + /** ModDN ordinal value */ public static final int MODDN_ORDINAL = 2; + + /** ModRDN ordinal value */ public static final int MODRDN_ORDINAL = 3; + + /** Delete ordinal value */ public static final int DELETE_ORDINAL = 4; /* the ordinal value for a change type */ @@ -60,7 +69,7 @@ * * @return the changeType */ - public final int getChangeType() + public int getChangeType() { return changeType; } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java Fri Jun 6 23:28:06 2008 @@ -22,7 +22,6 @@ import java.io.BufferedReader; import java.io.StringReader; import java.util.ArrayList; -import java.util.Iterator; import javax.naming.NamingException; import javax.naming.directory.Attribute; @@ -35,12 +34,16 @@ /** *
- *  <ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep> <ldif-content-change>
+ *  <ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep> 
+ *  <ldif-content-change>
  *  
  *  <ldif-content-change> ::= 
- *    <number> <oid> <options-e> <value-spec> <sep> <attrval-specs-e> <ldif-attrval-record-e> | 
- *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> <ldif-attrval-record-e> | 
- *    "control:" <fill> <number> <oid> <spaces-e> <criticality> <value-spec-e> <sep> <controls-e> 
+ *    <number> <oid> <options-e> <value-spec> <sep> <attrval-specs-e> 
+ *    <ldif-attrval-record-e> | 
+ *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> 
+ *    <ldif-attrval-record-e> | 
+ *    "control:" <fill> <number> <oid> <spaces-e> <criticality> 
+ *    <value-spec-e> <sep> <controls-e> 
  *        "changetype:" <fill> <changerecord-type> <ldif-change-record-e> |
  *    "changetype:" <fill> <changerecord-type> <ldif-change-record-e>
  *                              
@@ -60,7 +63,8 @@
  *                              
  *  <oid> ::= '.' <number> <oid> | e
  *                              
- *  <attrval-specs-e> ::= <number> <oid> <options-e> <value-spec> <sep> <attrval-specs-e> | 
+ *  <attrval-specs-e> ::= <number> <oid> <options-e> <value-spec> <sep> 
+ *  <attrval-specs-e> | 
  *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> | e
  *                              
  *  <value-spec-e> ::= <value-spec> | e
@@ -75,11 +79,15 @@
  *                              
  *  <chars-e> ::= <char> <chars-e> |  e
  *  
- *  <changerecord-type> ::= "add" <sep> <attributeType> <options-e> <value-spec> <sep> <attrval-specs-e> | 
+ *  <changerecord-type> ::= "add" <sep> <attributeType> <options-e> <value-spec> 
+ *  <sep> <attrval-specs-e> | 
  *    "delete" <sep> | 
- *    "modify" <sep> <mod-type> <fill> <attributeType> <options-e> <sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | 
- *    "moddn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> <0-1> <sep> <newsuperior-e> <sep> |
- *    "modrdn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> <0-1> <sep> <newsuperior-e> <sep>
+ *    "modify" <sep> <mod-type> <fill> <attributeType> <options-e> <sep> 
+ *    <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | 
+ *    "moddn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> <0-1> <sep> 
+ *    <newsuperior-e> <sep> |
+ *    "modrdn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> <0-1> <sep> 
+ *    <newsuperior-e> <sep>
  *  
  *  <newrdn> ::= ':' <fill> <safe-string> | "::" <fill> <base64-chars>
  *  
@@ -129,6 +137,7 @@
  * 
* * @author Apache Directory Project + * @version $Rev$, $Date$ */ public class LdifAttributesReader extends LdifReader { @@ -149,11 +158,10 @@ /** * Parse an AttributeType/AttributeValue * - * @param entry The entry where to store the value + * @param attributes The entry where to store the value * @param line The line to parse * @param lowerLine The same line, lowercased - * @throws NamingException - * If anything goes wrong + * @throws NamingException If anything goes wrong */ private void parseAttribute( Attributes attributes, String line, String lowerLine ) throws NamingException { @@ -192,6 +200,9 @@ * <dn-spec> <sep> <controls-e> <changerecord> <dn-spec> ::= "dn:" <fill> * <distinguishedName> | "dn::" <fill> <base64-distinguishedName> * <changerecord> ::= "changetype:" <fill> <change-op> + * + * @return The read entry + * @throws NamingException If the entry can't be read or is invalid */ private Attributes parseAttributes() throws NamingException { @@ -201,21 +212,14 @@ return null; } - String line = lines.get( 0 ); - Attributes attributes = new BasicAttributes( true ); // Now, let's iterate through the other lines - Iterator iter = lines.iterator(); - - String lowerLine = null; - - while ( iter.hasNext() ) + for ( String line:lines ) { // Each line could start either with an OID, an attribute type, with // "control:" or with "changetype:" - line = iter.next(); - lowerLine = line.toLowerCase(); + String lowerLine = line.toLowerCase(); // We have three cases : // 1) The first line after the DN is a "control:" -> this is an error Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposer.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposer.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposer.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposer.java Fri Jun 6 23:28:06 2008 @@ -42,5 +42,5 @@ * the entry to export to ldif * @return the ldif of an entry */ - String compose( MultiMap an_entry ); + String compose( MultiMap an_entry ); } Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifComposerImpl.java Fri Jun 6 23:28:06 2008 @@ -24,7 +24,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.Collection; -import java.util.Iterator; import org.apache.directory.shared.ldap.util.Base64; import org.apache.directory.shared.ldap.util.MultiMap; @@ -33,7 +32,109 @@ /** * An LDAP Data Interchange Format (LDIF) composer. * - * TODO Get the RFC for LDIF syntax in this javadoc. + *
+ *  <ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep> 
+ *  <ldif-content-change>
+ *  
+ *  <ldif-content-change> ::= 
+ *    <number> <oid> <options-e> <value-spec> <sep> <attrval-specs-e> 
+ *    <ldif-attrval-record-e> | 
+ *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> 
+ *    <ldif-attrval-record-e> | 
+ *    "control:" <fill> <number> <oid> <spaces-e> <criticality> 
+ *    <value-spec-e> <sep> <controls-e> 
+ *        "changetype:" <fill> <changerecord-type> <ldif-change-record-e> |
+ *    "changetype:" <fill> <changerecord-type> <ldif-change-record-e>
+ *                              
+ *  <ldif-attrval-record-e> ::= <seps> <dn-spec> <sep> <attributeType> 
+ *    <options-e> <value-spec> <sep> <attrval-specs-e> 
+ *    <ldif-attrval-record-e> | e
+ *                              
+ *  <ldif-change-record-e> ::= <seps> <dn-spec> <sep> <controls-e> 
+ *    "changetype:" <fill> <changerecord-type> <ldif-change-record-e> | e
+ *                              
+ *  <dn-spec> ::= "dn:" <fill> <safe-string> | "dn::" <fill> <base64-string>
+ *                              
+ *  <controls-e> ::= "control:" <fill> <number> <oid> <spaces-e> <criticality> 
+ *    <value-spec-e> <sep> <controls-e> | e
+ *                              
+ *  <criticality> ::= "true" | "false" | e
+ *                              
+ *  <oid> ::= '.' <number> <oid> | e
+ *                              
+ *  <attrval-specs-e> ::= <number> <oid> <options-e> <value-spec> <sep> 
+ *  <attrval-specs-e> | 
+ *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> | e
+ *                              
+ *  <value-spec-e> ::= <value-spec> | e
+ *  
+ *  <value-spec> ::= ':' <fill> <safe-string-e> | 
+ *    "::" <fill> <base64-chars> | 
+ *    ":<" <fill> <url>
+ *  
+ *  <attributeType> ::= <number> <oid> | <alpha> <chars-e>
+ *  
+ *  <options-e> ::= ';' <char> <chars-e> <options-e> |e
+ *                              
+ *  <chars-e> ::= <char> <chars-e> |  e
+ *  
+ *  <changerecord-type> ::= "add" <sep> <attributeType> 
+ *  <options-e> <value-spec> <sep> <attrval-specs-e> | 
+ *    "delete" <sep> | 
+ *    "modify" <sep> <mod-type> <fill> <attributeType> <options-e> 
+ *    <sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | 
+ *    "moddn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> 
+ *    <0-1> <sep> <newsuperior-e> <sep> |
+ *    "modrdn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> 
+ *    <0-1> <sep> <newsuperior-e> <sep>
+ *  
+ *  <newrdn> ::= ':' <fill> <safe-string> | "::" <fill> <base64-chars>
+ *  
+ *  <newsuperior-e> ::= "newsuperior" <newrdn> | e
+ *  
+ *  <mod-specs-e> ::= <mod-type> <fill> <attributeType> <options-e> 
+ *    <sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | e
+ *  
+ *  <mod-type> ::= "add:" | "delete:" | "replace:"
+ *  
+ *  <url> ::= <a Uniform Resource Locator, as defined in [6]>
+ *  
+ *  
+ *  
+ *  LEXICAL
+ *  -------
+ *  
+ *  <fill>           ::= ' ' <fill> | e
+ *  <char>           ::= <alpha> | <digit> | '-'
+ *  <number>         ::= <digit> <digits>
+ *  <0-1>            ::= '0' | '1'
+ *  <digits>         ::= <digit> <digits> | e
+ *  <digit>          ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
+ *  <seps>           ::= <sep> <seps-e> 
+ *  <seps-e>         ::= <sep> <seps-e> | e
+ *  <sep>            ::= 0x0D 0x0A | 0x0A
+ *  <spaces>         ::= ' ' <spaces-e>
+ *  <spaces-e>       ::= ' ' <spaces-e> | e
+ *  <safe-string-e>  ::= <safe-string> | e
+ *  <safe-string>    ::= <safe-init-char> <safe-chars>
+ *  <safe-init-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39] | 0x3B | [0x3D-0x7F]
+ *  <safe-chars>     ::= <safe-char> <safe-chars> | e
+ *  <safe-char>      ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
+ *  <base64-string>  ::= <base64-char> <base64-chars>
+ *  <base64-chars>   ::= <base64-char> <base64-chars> | e
+ *  <base64-char>    ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-9x5A] | [0x61-0x7A]
+ *  <alpha>          ::= [0x41-0x5A] | [0x61-0x7A]
+ *  
+ *  COMMENTS
+ *  --------
+ *  - The ldap-oid VN is not correct in the RFC-2849. It has been changed from 1*DIGIT 0*1("." 1*DIGIT) to
+ *  DIGIT+ ("." DIGIT+)*
+ *  - The mod-spec lacks a sep between *attrval-spec and "-".
+ *  - The BASE64-UTF8-STRING should be BASE64-CHAR BASE64-STRING
+ *  - The ValueSpec rule must accept multilines values. In this case, we have a LF followed by a 
+ *  single space before the continued value.
+ * 
+ * * @author Apache Directory Project * @version $Revision$ */ @@ -42,25 +143,17 @@ /** * Generates an LDIF from a multi map. * - * @param attrHash - * the multi map of single and multivalued attributes. + * @param attrHash the multi map of single and multivalued attributes. * @return the LDIF as a String. */ - public String compose( MultiMap attrHash ) + public String compose( MultiMap attrHash ) { - 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 ( keys.hasNext() ) + for ( String key:attrHash.keySet() ) { - key = keys.next(); - valueCol = ( Collection ) attrHash.get( key ); - values = valueCol.iterator(); + Collection valueCol = ( Collection ) attrHash.get( key ); if ( valueCol.isEmpty() ) { @@ -70,7 +163,7 @@ { out.print( key ); out.print( ':' ); - val = values.next(); + Object val = valueCol.iterator().next(); if ( val.getClass().isArray() ) { @@ -85,11 +178,10 @@ continue; } - while ( values.hasNext() ) + for ( Object val:valueCol ) { out.print( key ); out.print( ':' ); - val = values.next(); if ( val.getClass().isArray() ) { Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifControl.java Fri Jun 6 23:28:06 2008 @@ -30,10 +30,11 @@ * file. * * @author Apache Directory Project + * @version $Rev$, $Date$ */ public class LdifControl implements Control { - static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; /** The control OID */ private OID oid; @@ -59,6 +60,7 @@ /** * Returns the criticality of the current control + * @return true if the control is critical */ public boolean isCritical() { @@ -78,6 +80,7 @@ /** * Return the control's OID as a String + * @return The control's OID */ public String getID() { @@ -87,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 ) { @@ -97,6 +99,7 @@ /** * Returns the BER encoded value of the control + * @return the BER encoded value */ public byte[] getEncodedValue() { Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java Fri Jun 6 23:28:06 2008 @@ -20,12 +20,11 @@ package org.apache.directory.shared.ldap.ldif; -import org.apache.directory.shared.ldap.message.AttributeImpl; -import org.apache.directory.shared.ldap.message.AttributesImpl; -import org.apache.directory.shared.ldap.message.ModificationItemImpl; -import org.apache.directory.shared.ldap.name.LdapDN; -import org.apache.directory.shared.ldap.name.Rdn; -import org.apache.directory.shared.ldap.util.StringTools; +import java.io.Serializable; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import javax.naming.InvalidNameException; import javax.naming.NamingEnumeration; @@ -33,12 +32,15 @@ import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; +import javax.naming.directory.ModificationItem; import javax.naming.ldap.Control; -import java.io.Serializable; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; + +import org.apache.directory.shared.ldap.message.AttributeImpl; +import org.apache.directory.shared.ldap.message.AttributesImpl; +import org.apache.directory.shared.ldap.message.ModificationItemImpl; +import org.apache.directory.shared.ldap.name.LdapDN; +import org.apache.directory.shared.ldap.name.Rdn; +import org.apache.directory.shared.ldap.util.StringTools; /** @@ -52,9 +54,12 @@ * - DN modified entries * * @author Apache Directory Project + * @version $Rev$, $Date$ */ public class LdifEntry implements Cloneable, Serializable { + private static final long serialVersionUID = 2L; + /** Used in toArray() */ public static final ModificationItemImpl[] EMPTY_MODS = new ModificationItemImpl[0]; @@ -168,14 +173,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 ) { @@ -192,12 +195,11 @@ * 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 + * @param modOp The modification operation value + * @param id The attribute's ID + * @param value The attribute's value */ - public void addModificationItem( int modOp, String id, Object value ) throws NamingException + public void addModificationItem( int modOp, String id, Object value ) { if ( changeType == ChangeType.Modify ) { @@ -446,6 +448,11 @@ return changeType == ChangeType.Modify; } + /** + * Tells if the current entry is a added one + * + * @return true if the entry is added + */ public boolean isEntry() { return changeType == ChangeType.Add; @@ -472,6 +479,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 { @@ -481,8 +490,8 @@ { for ( ModificationItemImpl modif:modificationList ) { - ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(), (Attribute) modif.getAttribute() - .clone() ); + ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(), + (Attribute) modif.getAttribute().clone() ); clone.modificationList.add( modifClone ); } } @@ -492,8 +501,8 @@ for ( String key:modificationItems.keySet() ) { ModificationItemImpl modif = modificationItems.get( key ); - ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(), (Attribute) modif.getAttribute() - .clone() ); + ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(), + (Attribute) modif.getAttribute().clone() ); clone.modificationItems.put( key, modifClone ); } @@ -509,23 +518,32 @@ /** * Dumps the attributes + * @return A String representing the attributes */ private String dumpAttributes() { StringBuffer sb = new StringBuffer(); + Attribute attribute = null; try { - for ( NamingEnumeration attrs = attributes.getAll(); attrs.hasMoreElements(); ) + for ( NamingEnumeration attrs = attributes.getAll(); + attrs.hasMoreElements(); + attribute = attrs.nextElement()) { - Attribute attribute = attrs.nextElement(); - + if ( attribute == null ) + { + sb.append( " Null attribute\n" ); + continue; + } + 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' ); @@ -547,6 +565,7 @@ /** * Dumps the modifications + * @return A String representing the modifications */ private String dumpModificationItems() { @@ -569,6 +588,9 @@ case DirContext.REPLACE_ATTRIBUTE : sb.append( "REPLACE \n" ); break; + + default : + break; // Do nothing } Attribute attribute = modif.getAttribute(); @@ -579,10 +601,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' ); @@ -605,7 +628,7 @@ /** - * Return a String representing the Entry + * @return a String representing the Entry */ public String toString() { @@ -641,12 +664,15 @@ sb.append( " Delete old RDN : " ).append( deleteOldRdn ? "true\n" : "false\n" ); sb.append( " New RDN : " ).append( newRdn ).append( '\n' ); - if ( StringTools.isEmpty( newSuperior ) == false ) + if ( !StringTools.isEmpty( newSuperior ) ) { sb.append( " New superior : " ).append( newSuperior ).append( '\n' ); } break; + + default : + break; // Do nothing } return sb.toString(); @@ -654,7 +680,84 @@ /** + * @see Object#hashCode() + * + * @return the instance's hash code + */ + public int hashCode() + { + int result = 37; + + if ( dn != null ) + { + result = result*17 + dn.hashCode(); + } + + if ( changeType != null ) + { + result = result*17 + changeType.hashCode(); + + // Check each different cases + switch ( changeType ) + { + case Add : + // Checks the attributes + if ( attributes != null ) + { + result = result * 17 + attributes.hashCode(); + } + + break; + + case Delete : + // Nothing to compute + break; + + case Modify : + if ( modificationList != null ) + { + result = result * 17 + modificationList.hashCode(); + + for ( ModificationItem modification:modificationList ) + { + result = result * 17 + modification.hashCode(); + } + } + + break; + + case ModDn : + case ModRdn : + result = result * 17 + ( deleteOldRdn ? 1 : -1 ); + + if ( newRdn != null ) + { + result = result*17 + newRdn.hashCode(); + } + + if ( newSuperior != null ) + { + result = result*17 + newSuperior.hashCode(); + } + + break; + + default : + break; // do nothing + } + } + + if ( control != null ) + { + result = result * 17 + control.hashCode(); + } + + return result; + } + + /** * @see Object#equals(Object) + * @return true if both values are equal */ public boolean equals( Object o ) { @@ -666,7 +769,7 @@ if ( o == null ) { - return false; + return false; } if ( ! (o instanceof LdifEntry ) ) @@ -818,6 +921,9 @@ } break; + + default : + break; // do nothing } if ( control != null ) Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=664290&r1=664289&r2=664290&view=diff ============================================================================== --- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java (original) +++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Fri Jun 6 23:28:06 2008 @@ -57,12 +57,16 @@ /** *
- *  <ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep> <ldif-content-change>
+ *  <ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep> 
+ *  <ldif-content-change>
  *  
  *  <ldif-content-change> ::= 
- *    <number> <oid> <options-e> <value-spec> <sep> <attrval-specs-e> <ldif-attrval-record-e> | 
- *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> <ldif-attrval-record-e> | 
- *    "control:" <fill> <number> <oid> <spaces-e> <criticality> <value-spec-e> <sep> <controls-e> 
+ *    <number> <oid> <options-e> <value-spec> <sep> 
+ *    <attrval-specs-e> <ldif-attrval-record-e> | 
+ *    <alpha> <chars-e> <options-e> <value-spec> <sep> 
+ *    <attrval-specs-e> <ldif-attrval-record-e> | 
+ *    "control:" <fill> <number> <oid> <spaces-e> 
+ *    <criticality> <value-spec-e> <sep> <controls-e> 
  *        "changetype:" <fill> <changerecord-type> <ldif-change-record-e> |
  *    "changetype:" <fill> <changerecord-type> <ldif-change-record-e>
  *                              
@@ -82,7 +86,8 @@
  *                              
  *  <oid> ::= '.' <number> <oid> | e
  *                              
- *  <attrval-specs-e> ::= <number> <oid> <options-e> <value-spec> <sep> <attrval-specs-e> | 
+ *  <attrval-specs-e> ::= <number> <oid> <options-e> <value-spec> 
+ *  <sep> <attrval-specs-e> | 
  *    <alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> | e
  *                              
  *  <value-spec-e> ::= <value-spec> | e
@@ -97,11 +102,15 @@
  *                              
  *  <chars-e> ::= <char> <chars-e> |  e
  *  
- *  <changerecord-type> ::= "add" <sep> <attributeType> <options-e> <value-spec> <sep> <attrval-specs-e> | 
+ *  <changerecord-type> ::= "add" <sep> <attributeType> 
+ *  <options-e> <value-spec> <sep> <attrval-specs-e> | 
  *    "delete" <sep> | 
- *    "modify" <sep> <mod-type> <fill> <attributeType> <options-e> <sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | 
- *    "moddn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> <0-1> <sep> <newsuperior-e> <sep> |
- *    "modrdn" <sep> <newrdn> <sep> "deleteoldrdn:" <fill> <0-1> <sep> <newsuperior-e> <sep>
+ *    "modify" <sep> <mod-type> <fill> <attributeType> 
+ *    <options-e> <sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | 
+ *    "moddn" <sep> <newrdn> <sep> "deleteoldrdn:" 
+ *    <fill> <0-1> <sep> <newsuperior-e> <sep> |
+ *    "modrdn" <sep> <newrdn> <sep> "deleteoldrdn:" 
+ *    <fill> <0-1> <sep> <newsuperior-e> <sep>
  *  
  *  <newrdn> ::= ':' <fill> <safe-string> | "::" <fill> <base64-chars>
  *  
@@ -151,27 +160,45 @@
  * 
* * @author Apache Directory Project + * @version $Rev$, $Date$ */ -public class LdifReader implements Iterator +public class LdifReader implements Iterable { /** A logger */ private static final Logger LOG = LoggerFactory.getLogger( LdifReader.class ); - /** A private class to track the current position in a line */ - protected class Position - { - public int pos; - + /** + * A private class to track the current position in a line + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ + public class Position + { + /** The current position */ + private 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; @@ -191,7 +218,7 @@ protected int version; /** Type of element read */ - protected static final int ENTRY = 0; + protected static final int LDIF_ENTRY = 0; protected static final int CHANGE = 1; @@ -263,13 +290,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 +362,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 +429,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 +642,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 +683,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 +730,10 @@ * "false") ] [ ":" <fill> <SAFE-STRING-e> | "::" <fill> <BASE64-STRING> | ":<" * <fill> <url> ] * - * @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 +853,7 @@ * Parse an AttributeType/AttributeValue * * @param line The line to parse + * @return the parsed Attribute */ public static Attribute parseAttributeValue( String line ) { @@ -846,14 +876,10 @@ /** * Parse an AttributeType/AttributeValue * - * @param entry - * The entry where to store the value - * @param line - * The line to parse - * @param lowerLine - * The same line, lowercased - * @throws NamingException - * If anything goes wrong + * @param entry The entry where to store the value + * @param line The line to parse + * @param lowerLine The same line, lowercased + * @throws NamingException If anything goes wrong */ public void parseAttributeValue( LdifEntry entry, String line, String lowerLine ) throws NamingException { @@ -950,10 +976,9 @@ * ATTRIBUTE-DESCRIPTION SEP <attrval-specs-e> "-" SEP <attrval-specs-e> ::= * ATTRVAL-SPEC <attrval-specs> | 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 iter ) throws NamingException { @@ -1050,7 +1075,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 +1120,12 @@ * ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC <attrval-specs-e> "-" SEP * <attrval-specs-e> ::= ATTRVAL-SPEC <attrval-specs> | 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 iter, ChangeType operation, Control control ) throws NamingException + private void parseChange( LdifEntry entry, Iterator iter, ChangeType operation ) throws NamingException { // The changetype and operation has already been parsed. entry.setChangeType( operation ); @@ -1186,6 +1206,9 @@ * <dn-spec> <sep> <controls-e> <changerecord> <dn-spec> ::= "dn:" <fill> * <distinguishedName> | "dn::" <fill> <base64-distinguishedName> * <changerecord> ::= "changetype:" <fill> <change-op> + * + * @return the parsed ldifEntry + * @exception NamingException If the ldif file does not contain a valid entry */ private LdifEntry parseEntry() throws NamingException { @@ -1279,7 +1302,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 ) @@ -1299,7 +1322,7 @@ } parseAttributeValue( entry, line, lowerLine ); - type = ENTRY; + type = LDIF_ENTRY; } else { @@ -1309,7 +1332,7 @@ } } - if ( type == ENTRY ) + if ( type == LDIF_ENTRY ) { LOG.debug( "Read an entry : {}", entry ); } @@ -1527,26 +1550,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 ); } /** @@ -1596,8 +1618,9 @@ * Gets the next LDIF on the channel. * * @return the next LDIF as a String. + * @exception NoSuchElementException If we can't read the next entry */ - public LdifEntry next() throws NoSuchElementException + private LdifEntry nextInternal() { try { @@ -1613,6 +1636,7 @@ catch (NamingException ne) { error = ne; + throw new NoSuchElementException( ne.getMessage() ); } LOG.debug( "next(): -- returning ldif {}\n", entry ); @@ -1627,6 +1651,30 @@ } } + + /** + * Gets the next LDIF on the channel. + * + * @return the next LDIF as a String. + * @exception NoSuchElementException If we can't read the next entry + */ + public LdifEntry next() + { + return nextInternal(); + } + + + /** + * Tests to see if another LDIF is on the input channel. + * + * @return true if another LDIF is available false otherwise. + */ + private boolean hasNextInternal() + { + return null != prefetched; + } + + /** * Tests to see if another LDIF is on the input channel. * @@ -1636,25 +1684,53 @@ { LOG.debug( "hasNext(): -- returning {}", ( prefetched != null ) ? Boolean.TRUE : Boolean.FALSE ); - return null != prefetched; + return hasNextInternal(); } + /** * Always throws UnsupportedOperationException! * * @see java.util.Iterator#remove() */ - public void remove() + private void removeInternal() { throw new UnsupportedOperationException(); } + + /** + * Always throws UnsupportedOperationException! + * + * @see java.util.Iterator#remove() + */ + public void remove() + { + removeInternal(); + } + /** * @return An iterator on the file */ public Iterator iterator() { - return this; + return new Iterator() + { + public boolean hasNext() + { + return hasNextInternal(); + } + + public LdifEntry next() + { + return nextInternal(); + } + + public void remove() + { + throw new UnsupportedOperationException(); + } + }; } /** @@ -1695,19 +1771,20 @@ prefetched = parseEntry(); // When done, get the entries one by one. - while ( hasNext() ) + try { - LdifEntry entry = next(); - - if ( error != null ) - { - throw new NamingException( "Error while parsing ldif : " + error.getMessage() ); - } - else if ( entry != null ) + for ( LdifEntry entry:this ) { - entries.add( entry ); + if ( entry != null ) + { + entries.add( entry ); + } } } + catch ( NoSuchElementException nsee ) + { + throw new NamingException( "Error while parsing ldif : " + error.getMessage() ); + } return entries; }