PA4RDF will convert to/from any registered typed literal including the standard Java primitives and wrapped primitive types.
If the return type or parameter of an @Predicate annotated is another @Subject annotated class PA4RDF will automatically create and map the class as appropriate.
To perform the conversion the following steps are taken:
The RDFDatatype associated with the return type is looked up using the TypeMapper. If found the return type value is created using the the RDFDatatype.
Otherwise: if the return type class is annotated with @Subject the class is automatically created by the entity manager.
Otherwise: if the return type is an instance of RDFNode the graph node is returned.
Otherwise: if the return type is the URI class the URI of the graph node is returned.
Otherwise: null is returned.
Java Type | RDF Type |
---|---|
byte[] | http://www.w3.org/2001/XMLSchema#base64Binary |
char | http://www.w3.org/2001/XMLSchema#string |
com.hp.hpl.jena.datatypes.xsd.XSDDateTime | http://www.w3.org/2001/XMLSchema#dateTime |
com.hp.hpl.jena.datatypes.xsd.XSDDuration | http://www.w3.org/2001/XMLSchema#duration |
java.lang.Boolean | http://www.w3.org/2001/XMLSchema#boolean |
java.lang.Byte | http://www.w3.org/2001/XMLSchema#byte |
java.lang.Double | http://www.w3.org/2001/XMLSchema#double |
java.lang.Float | http://www.w3.org/2001/XMLSchema#float |
java.lang.Integer | http://www.w3.org/2001/XMLSchema#int |
java.lang.Long | http://www.w3.org/2001/XMLSchema#long |
java.lang.Short | http://www.w3.org/2001/XMLSchema#short |
java.lang.String | http://www.w3.org/2001/XMLSchema#normalizedString |
java.math.BigDecimal | http://www.w3.org/2001/XMLSchema#decimal |
java.math.BigInteger | http://www.w3.org/2001/XMLSchema#integer |
java.net.URI | http://www.w3.org/2001/XMLSchema#anyURI |
Thus is a @Property annotated setter method takes a Float argument the data type as stored in the graph will be http://www.w3.org/2001/XMLSchema#float.
Primitive data types are automatically converted to their non-primitive form as necessary. One caveat: if the return type of a @Property annotated method is a primitive and the data element does not exist in the graph a NullPointerException is thrown.
Additional data types may be registered using the standard Jena process:
1 Create a class that extends com.hp.hpl.jena.datatypes.RDFDatatype. 2 Register the class with the com.hp.hpl.jena.datatypes.TypeMapper.
com.hp.hpl.jena.datatypes. rtype = new MyDatatype(); com.hp.hpl.jena.datatypes.TypeMapper.getInstance().registerDatatype(rtype);
Registered data types may be displayed using org.xenei.jena.entities.DumpDataTypes