use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class substring method exec.
@Override
public NodeValue exec(List<NodeValue> args) {
if (args.size() != 2 && args.size() != 3)
throw new ExprEvalException("substring: Wrong number of arguments: " + args.size() + " : [wanted 2 or 3]");
NodeValue v1 = args.get(0);
NodeValue v2 = args.get(1);
NodeValue v3 = null;
if (args.size() == 3) {
v3 = args.get(2);
return XSDFuncOp.javaSubstring(v1, v2, v3);
}
return XSDFuncOp.javaSubstring(v1, v2);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class AccumulatorExpr method accumulate.
@Override
public final void accumulate(Binding binding, FunctionEnv functionEnv) {
NodeValue nv = ExprLib.evalOrNull(expr, binding, functionEnv);
if (nv != null) {
if (makeDistinct) {
if (values.contains(nv))
return;
values.add(nv);
}
try {
accumulate(nv, binding, functionEnv);
accCount++;
return;
} catch (ExprEvalException ex) {
}
// Drop to error case.
}
accumulateError(binding, functionEnv);
errorCount++;
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class NodeFunctions method iri.
public static Node iri(Node nv, String baseIRI) {
if (nv.isURI())
return nv;
if (nv.isBlank()) {
// Skolemization of blank nodes to IRIs : Don't ask, just don't ask.
String x = nv.getBlankNodeLabel();
return NodeFactory.createURI("_:" + x);
}
// Simple literal or xsd:string
String str = simpleLiteralOrXSDString(nv);
if (str == null)
throw new ExprEvalException("Can't make an IRI from " + nv);
IRI iri = null;
String iriStr = nv.getLiteralLexicalForm();
// Level of checking?
if (baseIRI != null) {
IRI base = iriFactory.create(baseIRI);
iri = base.create(iriStr);
} else
iri = iriFactory.create(iriStr);
if (!iri.isAbsolute())
throw new ExprEvalException("Relative IRI string: " + iriStr);
if (warningsForIRIs && iri.hasViolation(false)) {
String msg = "unknown violation from IRI library";
Iterator<Violation> iter = iri.violations(false);
if (iter.hasNext()) {
Violation viol = iter.next();
msg = viol.getShortMessage();
}
Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri);
}
return NodeFactory.createURI(iri.toString());
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class FN_FormatNumber method exec.
@Override
public NodeValue exec(List<NodeValue> args) {
if (args.size() != 2 && args.size() != 3)
throw new ExprEvalException("Function '" + Lib.className(this) + "' takes two or three arguments");
NodeValue value = args.get(0);
NodeValue picture = args.get(1);
NodeValue decimalFormatName = null;
if (args.size() == 3)
decimalFormatName = args.get(2);
return XSDFuncOp.formatNumber(value, picture, decimalFormatName);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class SystemVar method exec.
// Need to intercept exec so we can get to the FunctionEnv
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
// Ignore arguments.
Object obj = env.getContext().get(systemSymbol);
if (obj == null)
throw new ExprEvalException("null for system symbol: " + systemSymbol);
if (!(obj instanceof Node))
throw new ExprEvalException("Not a Node: " + Lib.className(obj));
Node n = (Node) obj;
// if ( n == null )
// throw new ExprEvalException("No value for system variable: "+systemSymbol) ;
// NodeValue.makeNode could have a cache.
NodeValue nv = NodeValue.makeNode(n);
return nv;
}
Aggregations