Search in sources :

Example 6 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class FunctionBase2 method exec.

@Override
public final NodeValue exec(List<NodeValue> args) {
    if (args == null)
        // The contract on the function interface is that this should not happen.
        throw new ARQInternalErrorException(Lib.className(this) + ": Null args list");
    if (args.size() != 2)
        throw new ExprEvalException(Lib.className(this) + ": Wrong number of arguments: Wanted 2, got " + args.size());
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    return exec(v1, v2);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 7 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class FunctionBase3 method exec.

@Override
public final NodeValue exec(List<NodeValue> args) {
    if (args == null)
        // The contract on the function interface is that this should not happen.
        throw new ARQInternalErrorException(Lib.className(this) + ": Null args list");
    if (args.size() != 3)
        throw new ExprEvalException(Lib.className(this) + ": Wrong number of arguments: Wanted 3, got " + args.size());
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    return exec(v1, v2, v3);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 8 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class FunctionBase4 method exec.

@Override
public final NodeValue exec(List<NodeValue> args) {
    if (args == null)
        // The contract on the function interface is that this should not happen.
        throw new ARQInternalErrorException(Lib.className(this) + ": Null args list");
    if (args.size() != 4)
        throw new ExprEvalException(Lib.className(this) + ": Wrong number of arguments: Wanted 4, got " + args.size());
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    return exec(v1, v2, v3, v4);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 9 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class NodeValue method _setByValue.

// Returns null for unrecognized literal.
private static NodeValue _setByValue(Node node) {
    // nodeToNodeValue should have dealt with it.
    if (NodeUtils.hasLang(node))
        return new NodeValueLang(node);
    LiteralLabel lit = node.getLiteral();
    String lex = lit.getLexicalForm();
    RDFDatatype datatype = lit.getDatatype();
    // Quick check.
    // Only XSD supported.
    // And (for testing) roman numerals.
    String datatypeURI = datatype.getURI();
    if (!datatypeURI.startsWith(xsdNamespace) && !SystemARQ.EnableRomanNumerals) {
        // Not XSD.
        return null;
    }
    try {
        // DatatypeFormatException - should not happen
        if (XSDstring.isValidLiteral(lit))
            // String - plain or xsd:string, or derived datatype.
            return new NodeValueString(lit.getLexicalForm(), node);
        if (!datatype.equals(XSDdecimal)) {
            // XSD integer and derived types 
            if (XSDinteger.isValidLiteral(lit)) {
                // .trim() implements the facet of whitespace collapse.
                // BigInteger does not accept such whitespace. 
                String s = node.getLiteralLexicalForm().trim();
                if (s.startsWith("+"))
                    // BigInteger does not accept leading "+"
                    s = s.substring(1);
                // Includes subtypes (int, byte, postiveInteger etc).
                // NB Known to be valid for type by now
                BigInteger integer = new BigInteger(s);
                return new NodeValueInteger(integer, node);
            }
        }
        if (datatype.equals(XSDdecimal) && XSDdecimal.isValidLiteral(lit)) {
            BigDecimal decimal = new BigDecimal(lit.getLexicalForm());
            return new NodeValueDecimal(decimal, node);
        }
        if (datatype.equals(XSDfloat) && XSDfloat.isValidLiteral(lit)) {
            // NB If needed, call to floatValue, then assign to double.
            // Gets 1.3f != 1.3d right
            float f = ((Number) lit.getValue()).floatValue();
            return new NodeValueFloat(f, node);
        }
        if (datatype.equals(XSDdouble) && XSDdouble.isValidLiteral(lit)) {
            double d = ((Number) lit.getValue()).doubleValue();
            return new NodeValueDouble(d, node);
        }
        if ((datatype.equals(XSDdateTime) || datatype.equals(XSDdateTimeStamp)) && XSDdateTime.isValid(lex)) {
            XSDDateTime dateTime = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDdate) && XSDdate.isValidLiteral(lit)) {
            // Jena datatype support works on masked dataTimes.
            XSDDateTime dateTime = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDtime) && XSDtime.isValidLiteral(lit)) {
            // Jena datatype support works on masked dataTimes.
            XSDDateTime time = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDgYear) && XSDgYear.isValidLiteral(lit)) {
            XSDDateTime time = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDgYearMonth) && XSDgYearMonth.isValidLiteral(lit)) {
            XSDDateTime time = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDgMonth) && XSDgMonth.isValidLiteral(lit)) {
            XSDDateTime time = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDgMonthDay) && XSDgMonthDay.isValidLiteral(lit)) {
            XSDDateTime time = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDgDay) && XSDgDay.isValidLiteral(lit)) {
            XSDDateTime time = (XSDDateTime) lit.getValue();
            return new NodeValueDT(lex, node);
        }
        if (datatype.equals(XSDduration) && XSDduration.isValid(lex)) {
            Duration duration = xmlDatatypeFactory.newDuration(lex);
            return new NodeValueDuration(duration, node);
        }
        if (datatype.equals(XSDyearMonthDuration) && XSDyearMonthDuration.isValid(lex)) {
            Duration duration = xmlDatatypeFactory.newDuration(lex);
            return new NodeValueDuration(duration, node);
        }
        if (datatype.equals(XSDdayTimeDuration) && XSDdayTimeDuration.isValid(lex)) {
            Duration duration = xmlDatatypeFactory.newDuration(lex);
            return new NodeValueDuration(duration, node);
        }
        if (datatype.equals(XSDboolean) && XSDboolean.isValidLiteral(lit)) {
            boolean b = (Boolean) lit.getValue();
            return new NodeValueBoolean(b, node);
        }
        // Not wired in
        if (SystemARQ.EnableRomanNumerals) {
            if (lit.getDatatypeURI().equals(RomanNumeralDatatype.get().getURI())) {
                Object obj = RomanNumeralDatatype.get().parse(lit.getLexicalForm());
                if (obj instanceof Integer)
                    return new NodeValueInteger(((Integer) obj).longValue());
                if (obj instanceof RomanNumeral)
                    return new NodeValueInteger(((RomanNumeral) obj).intValue());
                throw new ARQInternalErrorException("DatatypeFormatException: Roman numeral is unknown class");
            }
        }
    } catch (DatatypeFormatException ex) {
        // Should have been caught earlier by special test in nodeToNodeValue
        throw new ARQInternalErrorException("DatatypeFormatException: " + lit, ex);
    }
    return null;
}
Also used : RDFDatatype(org.apache.jena.datatypes.RDFDatatype) LiteralLabel(org.apache.jena.graph.impl.LiteralLabel) DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) Duration(javax.xml.datatype.Duration) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) XSDDateTime(org.apache.jena.datatypes.xsd.XSDDateTime) BigInteger(java.math.BigInteger)

Example 10 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class XSDFuncOp method fixupDate.

private static NodeValue fixupDate(NodeValue nv) {
    DateTimeStruct dts = DateTimeStruct.parseDate(nv.asNode().getLiteralLexicalForm());
    if (dts.timezone != null)
        return null;
    dts.timezone = defaultTimezone;
    nv = NodeValue.makeDate(dts.toString());
    if (!nv.isDate())
        throw new ARQInternalErrorException("Failed to reform an xsd:date");
    return nv;
}
Also used : DateTimeStruct(org.apache.jena.sparql.util.DateTimeStruct) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Aggregations

ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)34 Node (org.apache.jena.graph.Node)6 NodeValue (org.apache.jena.sparql.expr.NodeValue)6 ArrayList (java.util.ArrayList)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 Var (org.apache.jena.sparql.core.Var)4 BigDecimal (java.math.BigDecimal)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)3 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)3 BigInteger (java.math.BigInteger)2 CmdException (jena.cmd.CmdException)2 TerminationException (jena.cmd.TerminationException)2 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)2 Graph (org.apache.jena.graph.Graph)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 JenaException (org.apache.jena.shared.JenaException)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)2