directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1538363 - in /directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search: BranchNode.java FilterParser.java
Date Sun, 03 Nov 2013 13:48:39 GMT
Author: kayyagari
Date: Sun Nov  3 13:48:38 2013
New Revision: 1538363

URL: http://svn.apache.org/r1538363
Log:
fixed an issue with attaching child nodes

Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/BranchNode.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/FilterParser.java

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/BranchNode.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/BranchNode.java?rev=1538363&r1=1538362&r2=1538363&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/BranchNode.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/BranchNode.java
Sun Nov  3 13:48:38 2013
@@ -67,6 +67,11 @@ public class BranchNode extends FilterNo
         return rightNode;
     }
 
+    public boolean hasBothChildren()
+    {
+        return ( ( leftNode != null ) && ( rightNode != null ) );
+    }
+    
     @Override
     public String toString()
     {
@@ -77,7 +82,14 @@ public class BranchNode extends FilterNo
             sb.append( leftNode );
         }
         
-        sb.append( " AND " );
+        if( super.getOperator() == Operator.AND )
+        {
+            sb.append( " AND " );
+        }
+        else
+        {
+            sb.append( " OR " );
+        }
         
         if( rightNode != null )
         {

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/FilterParser.java?rev=1538363&r1=1538362&r2=1538363&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/FilterParser.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/search/FilterParser.java
Sun Nov  3 13:48:38 2013
@@ -77,9 +77,7 @@ public class FilterParser
 
         FilterNode node = null;
 
-        char prevChar = ' ';
-
-        while ( pos.val < len )
+        outer: while ( pos.val < len )
         {
             char c = filter.charAt( pos.val );
 
@@ -87,6 +85,10 @@ public class FilterParser
 
             switch ( c )
             {
+                case ' ':
+                    pos.increment();
+                    continue outer;
+                    
                 case '(':
                     String group = getWithinParenthesis( pos, filter );
                     next = parse( group );
@@ -96,29 +98,48 @@ public class FilterParser
                     next = parseNode( pos, filter );
             }
 
-            if ( next instanceof BranchNode )
-            {
-                if ( node != null )
-                {
-                    ( ( BranchNode ) next ).addNode( node );
-                }
+            
+            //System.out.println("====\n" + next + "\n======");
+            
+            node = addChildNode( node, next );
+        }
 
-                node = next;
-            }
-            else if ( node instanceof BranchNode )
+        return node;
+    }
+
+    private static FilterNode addChildNode( FilterNode parent, FilterNode child )
+    {
+        if( parent == null )
+        {
+            return child;
+        }
+        
+        if ( parent instanceof BranchNode )
+        {
+            BranchNode bn = ( BranchNode ) parent;
+            
+            if ( !bn.hasBothChildren() )
             {
-                ( ( BranchNode ) node ).addNode( next );
+                bn.addNode( child );
+                return parent;
             }
-            else if ( next != null )
+            else if( ( child != null ) && ( child instanceof BranchNode ) )
             {
-                node = next;
+                ( ( BranchNode ) child ).addNode( parent );
+                return child;
             }
         }
-
-        return node;
+        
+        if( child instanceof BranchNode )
+        {
+            ( ( BranchNode ) child ).addNode( parent );
+            return child;
+        }
+        
+        return null;
     }
 
-
+    
     private static FilterNode parseNode( Position pos, String filter )
     {
         FilterNode node = null;



Mime
View raw message