1 18 19 package com.hp.hpl.jena.ontology.daml.impl; 22 23 24 27 import com.hp.hpl.jena.rdf.model.Resource; 28 import com.hp.hpl.jena.datatypes.*; 29 import com.hp.hpl.jena.enhanced.*; 30 import com.hp.hpl.jena.graph.Node; 31 import com.hp.hpl.jena.ontology.*; 32 import com.hp.hpl.jena.ontology.daml.*; 33 import com.hp.hpl.jena.util.iterator.ClosableIterator; 34 import com.hp.hpl.jena.vocabulary.*; 35 36 import java.util.Iterator ; 37 38 import org.apache.commons.logging.LogFactory; 39 40 41 42 49 public class DAMLDataInstanceImpl 50 extends DAMLInstanceImpl 51 implements DAMLDataInstance 52 { 53 56 57 60 65 public static Implementation factory = new Implementation() { 66 public EnhNode wrap( Node n, EnhGraph eg ) { 67 if (canWrap( n, eg )) { 68 return new DAMLDataInstanceImpl( n, eg ); 69 } 70 else { 71 throw new ConversionException( "Cannot convert node " + n.toString() + " to DAMLDataInstance" ); 72 } 73 } 74 75 public boolean canWrap( Node node, EnhGraph eg ) { 76 return eg.asGraph().contains( node, RDF.type.asNode(), Node.ANY ); 77 } 78 }; 79 80 83 84 87 95 public DAMLDataInstanceImpl( Node n, EnhGraph g ) { 96 super( n, g ); 97 } 98 99 100 103 104 110 public RDFDatatype getDatatype() { 111 for (Iterator i = listRDFTypes( true ); i.hasNext(); ) { 113 Resource rType = (Resource) i.next(); 114 if (rType.isAnon()) { 115 continue; 116 } 117 118 RDFDatatype dt = TypeMapper.getInstance().getTypeByName( rType.getURI() ); 119 120 if (dt != null) { 121 if (i instanceof ClosableIterator) { 123 ((ClosableIterator) i).close(); 124 } 125 126 return dt; 127 } 128 } 129 130 return null; 131 } 132 133 134 141 public Object getValue() { 142 if (hasProperty( RDF.value )) { 143 RDFDatatype dType = getDatatype(); 144 145 if (dType == null) { 146 LogFactory.getLog( getClass() ).warn( "No RDFDatatype defined for DAML data instance " + this ); 147 } 148 else { 149 return dType.parse( getRequiredProperty( RDF.value ).getString() ); 150 } 151 } 152 153 return null; 154 } 155 156 157 163 public void setValue( Object value ) { 164 setPropertyValue( RDF.value, "", getModel().createTypedLiteral( value, getDatatype() ) ); 165 } 166 167 168 169 172 173 177 178 } 179 180 181 210 211 | Popular Tags |