public java.net.URL convert(Node node) {
if (node == null)
return null;
if (node instanceof LanguageTagLiteral) {
throw new RDFDataException(
"Cannot convert a language tagged literal to a URI - it makes no sense");
}
try {
if (node instanceof URI) {
return new URL(node.asURI().toString());
}
if (node instanceof PlainLiteral) {
return new java.net.URL(node.asLiteral().getValue());
}
if (node instanceof DatatypeLiteral) {
URI datatype = node.asDatatypeLiteral().getDatatype();
if (datatype.equals(XSD._anyURI)) {
return new java.net.URL(node.asDatatypeLiteral().getValue());
} else {
throw new RDFDataException("Cannot convert from datatype "
+ datatype + " to URI");
}
}
} catch (MalformedURLException e) {
throw new RDFDataException("Could not convert <"
+ node.asLiteral().getValue() + "> to a java.net.URL", e);
}
throw new RDFDataException("Cannot convert from " + node.getClass()
+ " to URL");
}