Package org.exoplatform.services.jcr.impl.core.query

Examples of org.exoplatform.services.jcr.impl.core.query.LocationStepQueryNode


       */
      boolean needsMerge()
      {
         for (Iterator it = operands.iterator(); it.hasNext();)
         {
            LocationStepQueryNode step = (LocationStepQueryNode) it.next();
            if (step.getIncludeDescendants() && step.getNameTest() == null)
            {
               return true;
            }
         }
         return false;
View Full Code Here


      // use //* if no path has been set
      PathQueryNode pathNode = root.getLocationNode();
      pathNode.setAbsolute(true);
      if (pathConstraints.size() == 0)
      {
         LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
         step.setNameTest(null);
         step.setIncludeDescendants(true);
         pathNode.addPathStep(step);
      }
      else
      {
         try
         {
            while (pathConstraints.size() > 1)
            {
               // merge path nodes
               MergingPathQueryNode path = null;
               for (Iterator it = pathConstraints.iterator(); it.hasNext();)
               {
                  path = (MergingPathQueryNode) it.next();
                  if (path.needsMerge())
                  {
                     break;
                  }
                  else
                  {
                     path = null;
                  }
               }
               if (path == null)
               {
                  throw new IllegalArgumentException("Invalid combination of jcr:path clauses");
               }
               else
               {
                  pathConstraints.remove(path);
                  MergingPathQueryNode[] paths =
                           (MergingPathQueryNode[]) pathConstraints.toArray(new MergingPathQueryNode[pathConstraints
                                    .size()]);
                  paths = path.doMerge(paths);
                  pathConstraints.clear();
                  pathConstraints.addAll(Arrays.asList(paths));
               }
            }
         }
         catch (NoSuchElementException e)
         {
            throw new IllegalArgumentException("Invalid combination of jcr:path clauses", e);
         }
         MergingPathQueryNode path = (MergingPathQueryNode) pathConstraints.get(0);
         LocationStepQueryNode[] steps = path.getPathSteps();
         for (int i = 0; i < steps.length; i++)
         {
            LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
            step.setNameTest(steps[i].getNameTest());
            step.setIncludeDescendants(steps[i].getIncludeDescendants());
            step.setIndex(steps[i].getIndex());
            pathNode.addPathStep(step);
         }
      }

      if (constraintNode.getNumOperands() == 1)
View Full Code Here

                  throw new IllegalArgumentException("Illegal name: " + name);
               }
            }
            // if name test is % this means also search descendants
            boolean descendant = name == null;
            LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
            step.setNameTest(qName);
            step.setIncludeDescendants(descendant);
            if (index > 0)
            {
               step.setIndex(index);
            }
            pathNode.addPathStep(step);
         }
      }
      pathConstraints.add(pathNode);
View Full Code Here

            }
            break;
         case JJTTEXTTEST :
            if (queryNode.getType() == QueryNode.TYPE_LOCATION)
            {
               LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
               loc.setNameTest(JCR_XMLTEXT);
            }
            break;
         case JJTTYPENAME :
            if (queryNode.getType() == QueryNode.TYPE_LOCATION)
            {
               LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
               String ntName = ((SimpleNode) node.jjtGetChild(0)).getValue();
               try
               {
                  InternalQName nt = resolver.parseJCRName(ntName).getInternalName();
                  NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt);
                  loc.addPredicate(nodeType);
               }
               catch (RepositoryException e)
               {
                  exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
               }
View Full Code Here

    *          the parent <code>PathQueryNode</code>.
    * @return the created <code>LocationStepQueryNode</code>.
    */
   private LocationStepQueryNode createLocationStep(SimpleNode node, NAryQueryNode parent)
   {
      LocationStepQueryNode queryNode = null;
      boolean descendant = false;
      Node p = node.jjtGetParent();
      for (int i = 0; i < p.jjtGetNumChildren(); i++)
      {
         SimpleNode c = (SimpleNode) p.jjtGetChild(i);
         if (c == node)
         {
            queryNode = factory.createLocationStepQueryNode(parent);
            queryNode.setNameTest(null);
            queryNode.setIncludeDescendants(descendant);
            parent.addOperand(queryNode);
            break;
         }
         descendant = (c.getId() == JJTSLASHSLASH || c.getId() == JJTROOTDESCENDANTS);
      }
View Full Code Here

            if (node.jjtGetNumChildren() == 3)
            {
               boolean descendant = false;
               if (queryNode.getType() == QueryNode.TYPE_LOCATION)
               {
                  LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                  // remember if descendant axis
                  descendant = loc.getIncludeDescendants();
                  queryNode = loc.getParent();
                  ((NAryQueryNode) queryNode).removeOperand(loc);
               }
               if (queryNode.getType() == QueryNode.TYPE_PATH)
               {
                  PathQueryNode pathNode = (PathQueryNode) queryNode;
View Full Code Here

    */
   private static QueryRootNode createMatchAllNodesQuery(QueryNodeFactory factory)
   {
      QueryRootNode allNodesQueryNode = factory.createQueryRootNode();
      PathQueryNode pathNode = factory.createPathQueryNode(allNodesQueryNode);
      LocationStepQueryNode lsNode = factory.createLocationStepQueryNode(pathNode);
      lsNode.setNameTest(null);
      lsNode.setIncludeDescendants(true);
      pathNode.addPathStep(lsNode);
      pathNode.setAbsolute(true);
      allNodesQueryNode.setLocationNode(pathNode);
      return allNodesQueryNode;
   }
View Full Code Here

      // use //* if no path has been set
      PathQueryNode pathNode = root.getLocationNode();
      pathNode.setAbsolute(true);
      if (pathConstraints.size() == 0)
      {
         LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
         step.setNameTest(null);
         step.setIncludeDescendants(true);
         pathNode.addPathStep(step);
      }
      else
      {
         try
         {
            while (pathConstraints.size() > 1)
            {
               // merge path nodes
               MergingPathQueryNode path = null;
               for (Iterator<MergingPathQueryNode> it = pathConstraints.iterator(); it.hasNext();)
               {
                  path = it.next();
                  if (path.needsMerge())
                  {
                     break;
                  }
                  else
                  {
                     path = null;
                  }
               }
               if (path == null)
               {
                  throw new IllegalArgumentException("Invalid combination of jcr:path clauses");
               }
               else
               {
                  pathConstraints.remove(path);
                  MergingPathQueryNode[] paths =
                     (MergingPathQueryNode[])pathConstraints.toArray(new MergingPathQueryNode[pathConstraints.size()]);
                  paths = path.doMerge(paths);
                  pathConstraints.clear();
                  pathConstraints.addAll(Arrays.asList(paths));
               }
            }
         }
         catch (NoSuchElementException e)
         {
            throw new IllegalArgumentException("Invalid combination of jcr:path clauses", e);
         }
         MergingPathQueryNode path = (MergingPathQueryNode)pathConstraints.get(0);
         LocationStepQueryNode[] steps = path.getPathSteps();
         for (int i = 0; i < steps.length; i++)
         {
            LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
            step.setNameTest(steps[i].getNameTest());
            step.setIncludeDescendants(steps[i].getIncludeDescendants());
            step.setIndex(steps[i].getIndex());
            pathNode.addPathStep(step);
         }
      }

      if (constraintNode.getNumOperands() == 1)
View Full Code Here

               }

            }
            // if name test is % this means also search descendants
            boolean descendant = name == null;
            LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
            step.setNameTest(qName);
            step.setIncludeDescendants(descendant);
            if (index > 0)
            {
               step.setIndex(index);
            }
            pathNode.addPathStep(step);
         }
      }
      pathConstraints.add(pathNode);
View Full Code Here

                    }
                }
                break;
            case JJTTEXTTEST:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    loc.setNameTest(JCR_XMLTEXT);
                }
                break;
            case JJTTYPENAME:
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    String ntName = ((SimpleNode) node.jjtGetChild(0)).getValue();
                    try {
                        InternalQName nt = resolver.parseJCRName(ntName).getInternalName();
                        NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt);
                        loc.addPredicate(nodeType);
                    } catch (NamespaceException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    } catch (RepositoryException e) {
                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
                    }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.core.query.LocationStepQueryNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.