Package org.apache.oodt.xmlquery

Examples of org.apache.oodt.xmlquery.QueryElement


   * @param map The provided ontological mapping.
   * @return The parsed {@link Expression} tree.
   */
  public static Expression parse(Stack<QueryElement> queryStack, Mapping map) {

    QueryElement qe = null;

    if (!queryStack.empty()) {
      qe = (QueryElement) queryStack.pop();
    } else
      return null;

    if (qe.getRole().equalsIgnoreCase(XMLQUERY_LOGOP)) {

      String logOpType = qe.getValue();
      if (logOpType.equalsIgnoreCase(XMLQUERY_AND)) {
        return new AndExpression(parse(queryStack), parse(queryStack, map));
      } else if (logOpType.equalsIgnoreCase(XMLQUERY_OR)) {
        return new OrExpression(parse(queryStack), parse(queryStack, map));
      } else
        return null;

    } else if (qe.getRole().equalsIgnoreCase(XMLQUERY_RELOP)) {
      String relOpType = qe.getValue();
      QueryElement rhsQE = (QueryElement) queryStack.pop();
      QueryElement lhsQE = (QueryElement) queryStack.pop();

      String rhsVal = (String) rhsQE.getValue();
      String lhsVal = (String) lhsQE.getValue();

      if (map != null) {
        // convert the right hand side, using
        // the local name
        MappingField fld = map.getFieldByLocalName(lhsVal);
View Full Code Here


            return null;

        List<QueryElement> newSet = new Vector<QueryElement>();

        for (Iterator<QueryElement> i = origSet.iterator(); i.hasNext();) {
            QueryElement elem = i.next();
            if (elem.getRole().equals(XMLQueryHelper.ROLE_ELEMNAME)
                    && !mapping.constantField(elem.getValue())) {
                newSet.add(elem);

            }

        }
View Full Code Here

            return null;

        List<QueryElement> newSet = new Vector<QueryElement>();

        for (Iterator<QueryElement> i = origSet.iterator(); i.hasNext();) {
            QueryElement elem = i.next();
            if (elem.getRole().equals(XMLQueryHelper.ROLE_ELEMNAME)
                    && mapping.constantField(elem.getValue())) {
                newSet.add(elem);
            }
        }

        return newSet;
View Full Code Here

                // add one row
                newRes.getRows().add(new CDERow());
            }

            for (Iterator<QueryElement> i = constFlds.iterator(); i.hasNext();) {
                QueryElement elem = i.next();
                MappingField fld = this.mapping.getFieldByLocalName(elem
                        .getValue());

                for (Iterator<CDERow> j = newRes.getRows().iterator(); j
                        .hasNext();) {
                    CDERow row = j.next();
View Full Code Here

        if (elems == null || (elems != null && elems.size() == 0))
            return null;

        StringBuffer buf = new StringBuffer();
        for (Iterator<QueryElement> i = elems.iterator(); i.hasNext();) {
            QueryElement elem = i.next();
            buf.append(elem.getValue());
            buf.append(",");
        }

        buf.deleteCharAt(buf.length() - 1);
View Full Code Here

            boolean selectSet) throws Exception {
        // go through each query element: use the mapping fields
        // to translate the names

        for (Iterator<QueryElement> i = elemSet.iterator(); i.hasNext();) {
            QueryElement elem = i.next();
            if (elem.getRole().equals(XMLQueryHelper.ROLE_ELEMNAME)) {
                // do the translation
                String elemValue = elem.getValue();
                MappingField fld = this.mapping.getFieldByName(elemValue);
                // make sure fld is not null
                if (fld == null) {
                    continue;
                }

                // make sure scope is null, or if it's not null, then it's
                // FieldScope.QUERY

                if (fld.getScope() != null
                        && fld.getScope().equals(FieldScope.RETURN)) {
                    // skip
                    continue;
                }

                // check to see if it has a dbname attr, if not, then the name
                // stays
                // the same
                String newFldName = this.mapping.getFieldLocalName(fld);

                elem.setValue(newFldName);

                // now translate the domain vocab if there are translate funcs
                // present and this isn't the select set

                if (!selectSet && fld.getFuncs() != null
                        && fld.getFuncs().size() > 0) {
                    // the next query element should be
                    // XMLQueryHelper.ROLE_LITERAL
                    if (!i.hasNext())
                        break;
                    QueryElement litElem = i.next();
                    if (!litElem.getRole().equals(XMLQueryHelper.ROLE_LITERAL)) {
                        throw new Exception("next query element not "
                                + XMLQueryHelper.ROLE_LITERAL + "! role is "
                                + litElem.getRole() + " instead!");
                    }

                    for (Iterator<MappingFunc> j = fld.getFuncs().iterator(); j
                            .hasNext();) {
                        MappingFunc func = j.next();
                        CDEValue origVal = new CDEValue(fld.getName(),
                                litElem.getValue());
                        CDEValue newVal = func.translate(origVal);
                        litElem.setValue(newVal.getVal());
                    }

                }

            }
View Full Code Here

        assertNotNull(elemNames);
        assertEquals(1, elemNames.size()); // only 1 b/c one field is constant

        boolean gotSpecCollected = false;
        for (Iterator<QueryElement> i = elemNames.iterator(); i.hasNext();) {
            QueryElement elem = i.next();
            if (elem.getValue().equals("specimen.specimen_collected")) {
                gotSpecCollected = true;
            }

        }
View Full Code Here

            fail(e.getMessage());
        }
        assertNotNull(query.getSelectElementSet());
        assertEquals(1, query.getSelectElementSet().size());
        assertNotNull(query.getSelectElementSet().get(0));
        QueryElement elem = (QueryElement) query.getSelectElementSet().get(0);
        assertNotNull(elem.getValue());
        assertEquals("Expected: [" + expectedSpecimenFldName + "]: got: ["
                + elem.getValue() + "]", elem.getValue(),
                expectedSpecimenFldName);

    }
View Full Code Here

        if (xmlQuery.getWhereElementSet() != null
                && xmlQuery.getWhereElementSet().size() > 0) {
            for (Iterator i = xmlQuery.getWhereElementSet().iterator(); i
                    .hasNext();) {
                QueryElement elem = (QueryElement) i.next();
                if (elem.getRole().equals("elemName")) {
                    String elemName = elem.getValue();

                    // to get the elem value, we need to grab the next elem
                    // ensure it's a literal, and then grab it
                    QueryElement litElem = (QueryElement) i.next();
                    if (!litElem.getRole().equals("LITERAL")) {
                        LOG.log(Level.WARNING,
                                "next element not literal: element: ["
                                        + litElem + "]: malformed xml query!");
                        break;
                    }
                    String elemValue = litElem.getValue();
                    TermQueryCriteria crit = new TermQueryCriteria();
                    crit.setElementName(elemName);
                    crit.setValue(elemValue);
                    query.addCriterion(crit);
                }
View Full Code Here

    // Collect together the where- and from-sets, joined with an "and".
    List allElements = new ArrayList(query.getWhereElementSet());
    List fromElements = query.getFromElementSet();
    if (!fromElements.isEmpty()) {
      allElements.addAll(fromElements);
      allElements.add(new QueryElement("LOGOP", "AND"));
    }
   
    // For each item in the where-set
    for (Iterator i = allElements.iterator(); i.hasNext();) {
      QueryElement queryElement = (QueryElement) i.next();

      // Get the keyword and its type.
      String keyword = queryElement.getValue();
      String type = queryElement.getRole();

      if (type.equals("elemName")) {
        // It's an element name, so push the element name.
        stack.push(keyword);
      } else if (type.equals("LITERAL")) {
View Full Code Here

TOP

Related Classes of org.apache.oodt.xmlquery.QueryElement

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.