jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r554627 - /jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Date Mon, 09 Jul 2007 13:01:00 GMT
Author: jukka
Date: Mon Jul  9 06:00:59 2007
New Revision: 554627

URL: http://svn.apache.org/viewvc?view=rev&rev=554627
Log:
1.3: Merged revision 553213 (JCR-981)

Modified:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?view=diff&rev=554627&r1=554626&r2=554627
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Mon Jul  9 06:00:59 2007
@@ -38,6 +38,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.commons.collections.map.ReferenceMap;
@@ -230,6 +231,11 @@
     private final List exceptions = new ArrayList();
 
     /**
+     * Temporary relative path
+     */
+    private Path.PathBuilder tmpRelPath;
+
+    /**
      * Creates a new <code>XPathQueryBuilder</code> instance.
      *
      * @param statement the XPath statement.
@@ -356,6 +362,7 @@
                         RelationQueryNode isNull
                                 = new RelationQueryNode(queryNode,
                                         RelationQueryNode.OPERATION_NULL);
+                        applyRelativePath(isNull);
                         node.childrenAccept(this, isNull);
                         NotQueryNode notNode = (NotQueryNode) queryNode;
                         NAryQueryNode parent = (NAryQueryNode) notNode.getParent();
@@ -363,9 +370,10 @@
                         parent.addOperand(isNull);
                     } else {
                         // not null expression
-                        RelationQueryNode notNull
-                                = new RelationQueryNode(queryNode,
+                        RelationQueryNode notNull =
+                                new RelationQueryNode(queryNode,
                                         RelationQueryNode.OPERATION_NOT_NULL);
+                        applyRelativePath(notNull);
                         node.childrenAccept(this, notNull);
                         ((NAryQueryNode) queryNode).addOperand(notNull);
                     }
@@ -375,6 +383,15 @@
                     } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH
                             || queryNode.getType() == QueryNode.TYPE_RELATION) {
                         node.childrenAccept(this, queryNode);
+                    } else {
+                        // step within a predicate
+                        RelationQueryNode tmp = new RelationQueryNode(
+                                null, RelationQueryNode.OPERATION_NOT_NULL);
+                        node.childrenAccept(this, tmp);
+                        if (tmpRelPath == null) {
+                            tmpRelPath = new Path.PathBuilder();
+                        }
+                        tmpRelPath.addLast(tmp.getRelativePath().getNameElement());
                     }
                 }
                 break;
@@ -503,6 +520,26 @@
     }
 
     //----------------------< internal >----------------------------------------
+
+    /**
+     * Applies {@link #tmpRelPath} to <code>node</code> and reset the path to
+     * <code>null</code>.
+     *
+     * @param node a relation query node.
+     */
+    private void applyRelativePath(RelationQueryNode node) {
+        if (tmpRelPath != null) {
+            try {
+                Path relPath = tmpRelPath.getPath();
+                for (int i = 0; i < relPath.getLength(); i++) {
+                    node.addPathElement(relPath.getElement(i));
+                }
+            } catch (MalformedPathException e) {
+                // should never happen
+            }
+            tmpRelPath = null;
+        }
+    }
 
     /**
      * Creates a <code>LocationStepQueryNode</code> at the current position



Mime
View raw message