@Override public FunctionCall visit(ASTSHA224 node, Object data) throws VisitorException { throw new VisitorException("hash function SHA-224 is currently not supported"); }
private TupleExpr buildQueryModel(Node qc) throws MalformedQueryException { TupleExprBuilder tupleExprBuilder = new TupleExprBuilder(SimpleValueFactory.getInstance()); try { return (TupleExpr)qc.jjtAccept(tupleExprBuilder, null); } catch (VisitorException e) { throw new MalformedQueryException(e.getMessage(), e); } }
throw new MalformedQueryException(e.getMessage(), e);
@Override public Object visit(ASTBlankNode node, Object data) throws VisitorException { throw new VisitorException( "Blank nodes must be replaced with variables before building the query model"); }
tupleExpr = (TupleExpr) qc.jjtAccept(tupleExprBuilder, null); } catch (final VisitorException e) { throw new MalformedQueryException(e.getMessage(), e);
@Override public Object visit(ASTQName node, Object data) throws VisitorException { throw new VisitorException("QNames must be resolved before building the query model"); }
tupleExpr = (TupleExpr) qc.jjtAccept(tupleExprBuilder, null); } catch (final VisitorException e) { throw new MalformedQueryException(e.getMessage(), e);
private String findVarName(String bnodeID) throws VisitorException { if (bnodeID == null) return null; String varName = conversionMap.get(bnodeID); if (varName == null && usedBNodeIDs.contains(bnodeID)) throw new VisitorException( "BNodeID already used in another scope: " + bnodeID); return varName; }
@Override public ValueConstant visit(ASTIRI node, Object data) throws VisitorException { IRI uri; try { uri = valueFactory.createIRI(node.getValue()); } catch (IllegalArgumentException e) { // invalid URI throw new VisitorException(e.getMessage()); } return new ValueConstant(uri); }
@Override public Object visit(ASTQName qnameNode, Object data) throws VisitorException { String qname = qnameNode.getValue(); int colonIdx = qname.indexOf(':'); assert colonIdx >= 0 : "colonIdx should be >= 0: " + colonIdx; String prefix = qname.substring(0, colonIdx); String localName = qname.substring(colonIdx + 1); String namespace = prefixMap.get(prefix); if (namespace == null) { throw new VisitorException("QName '" + qname + "' uses an undefined prefix"); } localName = processEscapes(localName); // Replace the qname node with a new IRI node in the parent node ASTIRI iriNode = new ASTIRI(SyntaxTreeBuilderTreeConstants.JJTIRI); iriNode.setValue(namespace + localName); qnameNode.jjtReplaceWith(iriNode); return null; }
@Override public Object visit(final ASTQName qnameNode, final Object data) throws VisitorException { final String qname = qnameNode.getValue(); final int colonIdx = qname.indexOf(':'); assert colonIdx >= 0 : "colonIdx should be >= 0: " + colonIdx; final String prefix = qname.substring(0, colonIdx); String localName = qname.substring(colonIdx + 1); String namespace = this.namespacesOut.get(prefix); if (namespace == null) { // [FC] added lookup of default namespace namespace = this.namespacesIn.get(prefix); } if (namespace == null) { throw new VisitorException("QName '" + qname + "' uses an undefined prefix"); } localName = processEscapesAndHex(localName); final ASTIRI iriNode = new ASTIRI(SyntaxTreeBuilderTreeConstants.JJTIRI); iriNode.setValue(namespace + localName); qnameNode.jjtReplaceWith(iriNode); return null; }
@Override public Object visit(final ASTQName qnameNode, final Object data) throws VisitorException { final String qname = qnameNode.getValue(); final int colonIdx = qname.indexOf(':'); assert colonIdx >= 0 : "colonIdx should be >= 0: " + colonIdx; final String prefix = qname.substring(0, colonIdx); String localName = qname.substring(colonIdx + 1); String namespace = this.prefixMap.get(prefix); if (namespace == null) { // [FC] added lookup of default namespace namespace = Data.getNamespaceMap().get(prefix); } if (namespace == null) { throw new VisitorException("QName '" + qname + "' uses an undefined prefix"); } localName = processEscapesAndHex(localName); final ASTIRI iriNode = new ASTIRI(SyntaxTreeBuilderTreeConstants.JJTIRI); iriNode.setValue(namespace + localName); qnameNode.jjtReplaceWith(iriNode); return null; }
@Override public Object visit(ASTString stringNode, Object data) throws VisitorException { String value = stringNode.getValue(); try { value = SPARQLUtil.decodeString(value); stringNode.setValue(value); } catch (IllegalArgumentException e) { // Invalid escape sequence throw new VisitorException(e.getMessage()); } return super.visit(stringNode, data); } }
@Override public BindingSet visit(ASTBindingSet node, Object data) throws VisitorException { @SuppressWarnings("unchecked") List<Var> vars = (List<Var>)data; List<String> names = new ArrayList<String>(vars.size()); for (Var var : vars) { names.add(var.getName()); } int numberOfBindingValues = node.jjtGetNumChildren(); if (numberOfBindingValues != vars.size()) { throw new VisitorException( "number of values in bindingset does not match variables in BINDINGS clause"); } Value[] values = new Value[numberOfBindingValues]; for (int i = 0; i < numberOfBindingValues; i++) { ValueExpr ve = (ValueExpr)node.jjtGetChild(i).jjtAccept(this, null); if (ve != null) { Value v = getValueForExpr(ve); values[i] = v; } } BindingSet result = new ListBindingSet(names, values); return result; }
private FunctionCall createFunctionCall(String uri, SimpleNode node, int minArgs, int maxArgs) throws VisitorException { FunctionCall functionCall = new FunctionCall(uri); int noOfArguments = node.jjtGetNumChildren(); if (noOfArguments > maxArgs || noOfArguments < minArgs) { throw new VisitorException( "unexpected number of arguments (" + noOfArguments + ") for function " + uri); } for (int i = 0; i < noOfArguments; i++) { Node argNode = node.jjtGetChild(i); functionCall.addArg((ValueExpr)argNode.jjtAccept(this, null)); } return functionCall; }
@Override public If visit(ASTIf node, Object data) throws VisitorException { If result = null; if (node.jjtGetNumChildren() < 3) { throw new VisitorException("IF construction missing required number of arguments"); } ValueExpr condition = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null); ValueExpr resultExpr = (ValueExpr)node.jjtGetChild(1).jjtAccept(this, null); ValueExpr alternative = (ValueExpr)node.jjtGetChild(2).jjtAccept(this, null); result = new If(condition, resultExpr, alternative); return result; }
@Override public ValueConstant visit(ASTRDFLiteral node, Object data) throws VisitorException { String label = (String)node.getLabel().jjtAccept(this, null); String lang = node.getLang(); ASTIRI datatypeNode = node.getDatatype(); Literal literal; if (datatypeNode != null) { IRI datatype; try { datatype = valueFactory.createIRI(datatypeNode.getValue()); } catch (IllegalArgumentException e) { // invalid URI throw new VisitorException(e.getMessage()); } literal = valueFactory.createLiteral(label, datatype); } else if (lang != null) { literal = valueFactory.createLiteral(label, lang); } else { literal = valueFactory.createLiteral(label); } return new ValueConstant(literal); }
throw new VisitorException("duplicate use of alias '" + alias + "' in projection."); throw new VisitorException("projection alias '" + alias + "' was previously used"); throw new VisitorException("variable '" + var.getName() + "' in projection not present in GROUP BY."); throw new VisitorException("variable '" + elem.getTargetName() + "' in projection not present in GROUP BY."); throw new VisitorException("variable '" + elem.getSourceName() + "' in projection not present in GROUP BY.");
if (alias.equals(v.getName())) { if (!v.isConstant() && !v.isAnonymous()) { throw new VisitorException( String.format("BIND clause alias '%s' was previously used", alias));
@Override public TupleExpr visit(ASTDeleteClause node, Object data) throws VisitorException { TupleExpr result = (TupleExpr)data; // Collect construct triples GraphPattern parentGP = graphPattern; graphPattern = new GraphPattern(); // inherit scope & context graphPattern.setStatementPatternScope(parentGP.getStatementPatternScope()); graphPattern.setContextVar(parentGP.getContextVar()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { node.jjtGetChild(i).jjtAccept(this, data); } TupleExpr deleteExpr = graphPattern.buildTupleExpr(); // FIXME we should adapt the grammar so we can avoid doing this in // post-processing. VarCollector collector = new VarCollector(); deleteExpr.visit(collector); for (Var var : collector.getCollectedVars()) { if (var.isAnonymous() && !var.hasValue()) { // blank node in delete pattern, not allowed by SPARQL spec. throw new VisitorException("DELETE clause may not contain blank nodes"); } } graphPattern = parentGP; return deleteExpr; }