Search in sources :

Example 6 with ElementRewriter

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

the class WhereHandler 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.query.getQueryPattern();
    if (e != null) {
        // clone the Element
        ElementRewriter rewriter = new ElementRewriter(Collections.emptyMap());
        e.visit(rewriter);
        Element clone = rewriter.getResult();
        Element mine = query.getQueryPattern();
        if (mine == null) {
            query.setQueryPattern(clone);
        } else {
            ElementGroup eg = null;
            if (mine instanceof ElementGroup) {
                eg = (ElementGroup) mine;
            } else {
                eg = new ElementGroup();
                eg.addElement(mine);
            }
            if (clone instanceof ElementGroup) {
                for (Element ele : ((ElementGroup) clone).getElements()) {
                    eg.addElement(ele);
                }
            } else {
                eg.addElement(clone);
            }
            query.setQueryPattern(eg);
        }
    }
    valuesHandler.addAll(whereHandler.valuesHandler);
}
Also used : ElementRewriter(org.apache.jena.arq.querybuilder.rewriters.ElementRewriter) Element(org.apache.jena.sparql.syntax.Element) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

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