Search in sources :

Example 21 with ExprEvalException

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);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 22 with ExprEvalException

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++;
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 23 with ExprEvalException

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());
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 24 with ExprEvalException

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);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 25 with ExprEvalException

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;
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) Node(org.apache.jena.graph.Node) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Aggregations

ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)32 Node (org.apache.jena.graph.Node)14 NodeValue (org.apache.jena.sparql.expr.NodeValue)13 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)3 BigInteger (java.math.BigInteger)2 GNode (org.apache.jena.sparql.util.graph.GNode)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Duration (javax.xml.datatype.Duration)1 ArgDecl (jena.cmd.ArgDecl)1 CmdException (jena.cmd.CmdException)1 CmdLineArgs (jena.cmd.CmdLineArgs)1 TerminationException (jena.cmd.TerminationException)1 Graph (org.apache.jena.graph.Graph)1 IRI (org.apache.jena.iri.IRI)1 Violation (org.apache.jena.iri.Violation)1 QueryExecException (org.apache.jena.query.QueryExecException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 SortCondition (org.apache.jena.query.SortCondition)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1