1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 26 import org.w3c.dom.Element ; 29 30 import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; 31 import com.hp.hpl.jena.graph.Node; 32 import com.hp.hpl.jena.rdf.model.AnonId; 33 import com.hp.hpl.jena.util.iterator.Map1; 34 35 36 44 public class DIGValueToNodeMapper 45 implements Map1 46 { 47 50 53 56 59 62 63 68 public Object map1( Object o ) { 69 if (o instanceof Element ) { 70 Element elem = (Element ) o; 72 73 if (elem.getNodeName().equals( DIGProfile.IVAL )) { 74 return Node.createLiteral( elem.getNodeValue(), null, XSDDatatype.XSDint ); 76 } 77 else if (elem.getNodeName().equals( DIGProfile.SVAL )) { 78 return Node.createLiteral( elem.getNodeValue(), null, XSDDatatype.XSDstring ); 80 } 81 else if (elem.hasAttribute( DIGProfile.NAME )) { 82 return convertNameToNode( elem.getAttribute( DIGProfile.NAME ) ); 83 } 84 } 85 else if (o instanceof String ) { 86 return convertNameToNode( (String ) o ); 87 } 88 89 throw new IllegalArgumentException ( "Cannot map value " + o + " to an RDF node because it is not a recognised type" ); 90 } 91 92 93 96 97 private Object convertNameToNode( String name ) { 98 if (name.startsWith( DIGAdapter.ANON_MARKER )) { 99 String anonID = name.substring( DIGAdapter.ANON_MARKER.length() ); 100 return Node.createAnon( new AnonId( anonID ) ); 101 } 102 else { 103 return Node.createURI( name ); 104 } 105 } 106 107 108 112 } 113 114 115 141 142 | Popular Tags |