private UnaryTupleOperator visitTemplates(Resource templates)
throws OpenRDFException
{
List<ProjectionElemList> projElemLists = new ArrayList<ProjectionElemList>();
Iteration<? extends Resource, QueryEvaluationException> iter = Statements.listResources(templates,
store);
while (iter.hasNext()) {
Resource r = iter.next();
ProjectionElemList projElems = visitTemplate(r);
projElemLists.add(projElems);
}
UnaryTupleOperator expr;
if (projElemLists.size() > 1) {
MultiProjection proj = new MultiProjection();
proj.setProjections(projElemLists);
expr = proj;
}
else {
Projection proj = new Projection();
proj.setProjectionElemList(projElemLists.get(0));
expr = proj;
}
Reduced reduced = new Reduced();
reduced.setArg(expr);
tupleRoot = reduced;
SingletonSet stub = new SingletonSet();
expr.setArg(stub);
tupleNode = stub;
return expr;
}