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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations