Converters { public static Object makeNodeOrPath(Object o, PrefixMapping pMapping) { if (o == null) { return Node.ANY; } if (o instanceof Path) { return o; } if (o instanceof FrontsNode) { return checkVar(((FrontsNode) o).asNode()); } if (o instanceof Node) { return checkVar((Node)o); } if (o instanceof String) { try { final Path p = PathParser.parse((String) o, pMapping); if (p instanceof P_Link) { return ((P_Link)p).getNode(); } return p; } catch (final Exception e) { } } return makeNode( o, pMapping ); } private  Converters(); static Node checkVar(Node n ); static Node makeLiteral(Object o); static Node makeLiteral(String value, String typeUri); static Node makeNode(Object o, PrefixMapping pMapping); static Object makeNodeOrPath(Object o, PrefixMapping pMapping); static Var makeVar(Object o); static String quoted(String q); static Collection<Node> makeValueNodes( Iterator<?> iter, PrefixMapping prefixMapping );  }
@Test public void makeNodeOrPathTest() { PrefixMapping pMap = PrefixMapping.Factory.create(); pMap.setNsPrefixes(PrefixMapping.Standard ); Object n = Converters.makeNodeOrPath(null, pMap); assertEquals(Node.ANY, n); n = Converters.makeNodeOrPath(RDF.type, pMap); assertEquals(RDF.type.asNode(), n); Node n2 = NodeFactory.createBlankNode(); n = Converters.makeNodeOrPath(n2, pMap); assertEquals(n2, n); pMap.setNsPrefix("demo", "http: n = Converters.makeNodeOrPath("demo:type", pMap); assertEquals(NodeFactory.createURI("http: n = Converters.makeNodeOrPath("<one>", pMap); assertEquals(NodeFactory.createURI("one"), n); UUID uuid = UUID.randomUUID(); try { Converters.makeNodeOrPath( uuid, pMap); fail( "Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } TypeMapper.getInstance().registerDatatype(new UuidDataType()); n = Converters.makeNodeOrPath( uuid, pMap); LiteralLabel ll = LiteralLabelFactory.createTypedLiteral(uuid); assertEquals(NodeFactory.createLiteral(ll), n); n = Converters.makeNodeOrPath( NodeFactory.createVariable("foo"), pMap); assertTrue( n instanceof Var ); Node node = (Node)n; assertTrue( node.isVariable()); assertEquals( "foo", node.getName()); n = Converters.makeNodeOrPath( "'text'@en", pMap); assertTrue( n instanceof Node ); node = (Node)n; assertEquals( "text", node.getLiteralLexicalForm()); assertEquals( "en", node.getLiteralLanguage()); n = Converters.makeNodeOrPath( "<one>/<two>", pMap); assertTrue( n instanceof Path ); Path pth = (Path)n; assertEquals( "<one>/<two>", pth.toString() ); }