Search in sources :

Example 1 with ElementRewriter

use of org.apache.jena.arq.querybuilder.rewriters.ElementRewriter in project jena by apache.

the class WhereProcessor method setVars.

/**
	 * replace the vars in the expressions with the nodes in the values map.
	 * Vars not listed in the values map are not changed.
	 * 
	 * Will return null if the whereClause is null.
	 * 
	 * @param values
	 *            the value map to use
	 * @return A new Element instance with the values changed.
	 */
public Element setVars(Map<Var, Node> values) {
    if (values.isEmpty() || whereClause == null) {
        return whereClause;
    }
    ElementRewriter r = new ElementRewriter(values);
    whereClause.visit(r);
    return r.getResult();
}
Also used : ElementRewriter(org.apache.jena.arq.querybuilder.rewriters.ElementRewriter)

Example 2 with ElementRewriter

use of org.apache.jena.arq.querybuilder.rewriters.ElementRewriter in project jena by apache.

the class WhereHandler method setVars.

@Override
public void setVars(Map<Var, Node> values) {
    if (values.isEmpty()) {
        return;
    }
    Element e = query.getQueryPattern();
    if (e != null) {
        ElementRewriter r = new ElementRewriter(values);
        e.visit(r);
        query.setQueryPattern(r.getResult());
    }
    valuesHandler.setVars(values);
}
Also used : ElementRewriter(org.apache.jena.arq.querybuilder.rewriters.ElementRewriter) Element(org.apache.jena.sparql.syntax.Element)

Example 3 with ElementRewriter

use of org.apache.jena.arq.querybuilder.rewriters.ElementRewriter in project jena by apache.

the class WhereQuadHolder method setVars.

/**
 * replace the vars in the expressions with the nodes in the values map. Vars
 * not listed in the values map are not changed.
 *
 * Will return null if the whereClause is null.
 *
 * @param values the value map to use
 * @return A new Element instance with the values changed.
 */
public WhereQuadHolder setVars(Map<Var, Node> values) {
    if (whereClause != null) {
        /* process when values are empty as rewriter handles Node_Variable to Var translation.
             *
             */
        ElementRewriter r = new ElementRewriter(values);
        whereClause.visit(r);
        whereClause = r.getResult();
    }
    return this;
}
Also used : ElementRewriter(org.apache.jena.arq.querybuilder.rewriters.ElementRewriter)

Example 4 with ElementRewriter

use of org.apache.jena.arq.querybuilder.rewriters.ElementRewriter in project jena by apache.

the class WhereQuadHolder method addAll.

/**
 * Add all where attributes from the Where Handler argument.
 *
 * @param whereHandler The Where Handler to copy from.
 */
public void addAll(WhereHandler whereHandler) {
    Element e = whereHandler.getQueryPattern();
    if (e != null) {
        // clone the Element
        ElementRewriter rewriter = new ElementRewriter(Collections.emptyMap());
        e.visit(rewriter);
        Element clone = rewriter.getResult();
        if (whereClause == null) {
            whereClause = clone;
        } else {
            ElementGroup eg = null;
            if (whereClause instanceof ElementGroup) {
                eg = (ElementGroup) whereClause;
            } else {
                eg = new ElementGroup();
                eg.addElement(whereClause);
            }
            if (clone instanceof ElementGroup) {
                for (Element ele : ((ElementGroup) clone).getElements()) {
                    eg.addElement(ele);
                }
            } else {
                eg.addElement(clone);
            }
            whereClause = eg;
        }
    }
}
Also used : ElementRewriter(org.apache.jena.arq.querybuilder.rewriters.ElementRewriter) Element(org.apache.jena.sparql.syntax.Element) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 5 with ElementRewriter

use of org.apache.jena.arq.querybuilder.rewriters.ElementRewriter in project jena by apache.

the class WhereProcessor method addAll.

/**
	 * Add all where attributes from the Where Handler argument.
	 * 
	 * @param whereHandler
	 *            The Where Handler to copy from.
	 */
public void addAll(WhereHandler whereHandler) {
    Element e = whereHandler.getQueryPattern();
    if (e != null) {
        // clone the Element
        ElementRewriter rewriter = new ElementRewriter(Collections.emptyMap());
        e.visit(rewriter);
        Element clone = rewriter.getResult();
        if (whereClause == null) {
            whereClause = clone;
        } else {
            ElementGroup eg = null;
            if (whereClause instanceof ElementGroup) {
                eg = (ElementGroup) whereClause;
            } else {
                eg = new ElementGroup();
                eg.addElement(whereClause);
            }
            if (clone instanceof ElementGroup) {
                for (Element ele : ((ElementGroup) clone).getElements()) {
                    eg.addElement(ele);
                }
            } else {
                eg.addElement(clone);
            }
            whereClause = eg;
        }
    }
}
Also used : ElementRewriter(org.apache.jena.arq.querybuilder.rewriters.ElementRewriter)

Aggregations

ElementRewriter (org.apache.jena.arq.querybuilder.rewriters.ElementRewriter)6 Element (org.apache.jena.sparql.syntax.Element)3 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)2