TransformDatatypeFF extends FunctionBase2 { @Override public NodeValue exec(NodeValue v1, NodeValue v2) { try { if (!(v2.isIRI() || v2.isString())) { throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(v2.asNode())); } String datatypeURI; if (v2.isIRI()) { datatypeURI = v2.asNode().getURI(); } else { datatypeURI = v2.asString(); } GeometryWrapper geometry = GeometryWrapper.extract(v1, GeometryLiteralIndex.GeometryIndex.PRIMARY); Literal convertedGeom = geometry.asLiteral(datatypeURI); return NodeValue.makeNode(convertedGeom.getLexicalForm(), convertedGeom.getDatatype()); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } }  @Override NodeValue exec(NodeValue v1, NodeValue v2);  }
@Test public void testExec_string() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeString(WKTDatatype.URI); TransformDatatypeFF instance = new TransformDatatypeFF(); NodeValue expResult = NodeValue.makeNode("<http: NodeValue result = instance.exec(v1, v2); assertEquals(expResult, result); }
@Test public void testExec_URI() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeNode(NodeFactory.createURI(WKTDatatype.URI)); TransformDatatypeFF instance = new TransformDatatypeFF(); NodeValue expResult = NodeValue.makeNode("<http: NodeValue result = instance.exec(v1, v2); assertEquals(expResult, result); }
@Test(expected = ExprEvalException.class) public void testExec_fail() { NodeValue v1 = NodeValue.makeNode("<gml:Point xmlns:gml=\"http: NodeValue v2 = NodeValue.makeInteger(8); TransformDatatypeFF instance = new TransformDatatypeFF(); NodeValue expResult = NodeValue.makeNode("<http: NodeValue result = instance.exec(v1, v2); assertEquals(expResult, result); }