Persistence Annotation for RDF introduces three (3) annotations:
@Subject denotes a class or interface as mapping to an RDF Subject. Any subject in the triple store can be so mapped. This annotation takes two (2) arguments: * namespace (required) defines the default namespace for the @Predicate annotations. * types (optional) a list of uri strings that define types that the RDF Property underlying the Subject must have to be considered.
@Predicate denotes a method of an @Subject annotated class or interface as mapping to an RDF Predicate. The values of @Predicate annotated methods are the objects in the resulting triples.
When used on a non abstract class (as opposed to an abstract class or interface), the @Predicate annotation indicates that the method is implementing a predicate annotated abstract method.
@URI denotes a string method parameter that should be treated as a URI as opposed to a normal string value. May be used as an annotation on a parameter or as a type in an @Predicate annotation to indicate that the returned string must be a URI value.
In addition to the standard setX(), getX(), and isX() methods PA4RDF introduces four (4) more that exploit the RDF storage model. There is no requirement to use getter/setter pairs. Programmers may elect to annotate any or all of the methods. However, in some cases annotated methods automatically apply annotations to other methods if they exist. (See Usage Strategies for a discussion) The complete set of annotatable methods are:
setX() Set a single value. This method implies that only one X value may exist for the subject.
addX() Add another value. This method implies that the subject may have multiple X values.
removeX() Remove the predicate. This method removes the predicate/value pair as opposed to setting the value to null as setX(null) would do.
getX() get the value for single values or an instance of an iterator or collection of values for multiple value subjects. Three types of Collection are supported: List, Set and Queue. - If the value is a primitive type and there is no predicate a NullPointerException is thrown. - If the value is an Object type and there is no predicate null is returned. - If there are multiple values an arbitrary value is selected and returned.
isX() for boolean values returns true if the value of the predicate is true, false otherwise. If there are multiple values an arbitrary value is selected.
hasX() returns true if there is a value of X for the subject. This is an existential method and returns True if the predicate exists, false otherwise.
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.
For a complete discussion of data types and data type conversions see the Data Types page.