/** * Map a Jena graph node to a Mulgara value. * * @param x The Jena Node to convert. * @param session A session to use for blank node persistence. * @return A Mulgara Value. * @throws URISyntaxException When creating a URIReference that refers to an invalid URI. */ static Value n2v(Node x, Session session) throws URISyntaxException { if (x.isURI()) return new URIReferenceImpl(new URI(x.getURI())); if (x.isLiteral()) { // The return types are Mulgara LiteralImpl if (x.getLiteralDatatypeURI() != null) { return new LiteralImpl(x.getLiteralLexicalForm(), new URI(x.getLiteralDatatypeURI())); } if (x.getLiteralLanguage() != null) { return new LiteralImpl(x.getLiteralLexicalForm(), x.getLiteralLanguage()); } return new LiteralImpl(x.getLiteralLexicalForm()); } if (x.isBlank()) { // is this a previously encountered Jena-allocated node? Value bn = nodesToValues.get(x); if (bn != null) return bn; // May be a Mulgara-allocated bNode (and so we we have seen before) String blankLabel = x.getBlankNodeLabel(); if (blankLabel.startsWith(LABEL)) { long id = Long.parseLong(blankLabel.substring(LABEL_LEN)); return new BlankNodeImpl(BlankNodeImpl.counterToNode(id)); } // It's not - it's a Jena one. if (skolemizedBlankNodes) { String skol = bNodeScheme + x.getBlankNodeLabel(); return new URIReferenceImpl(new URI(skol)); } // Not a Mulgara-allocated bNode. Create a new mapping. BlankNodeImpl v = new BlankNodeImpl(); nodesToValues.put(x, v); valuesToNodes.put(v.getNodeId(), x); return v; } throw new RuntimeException("Can't convert from Jena node : " + x); }