RdfAnnotations
[edit] @rdf
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD, ElementType.PACKAGE, ElementType.PARAMETER, ElementType.TYPE } )
public @interface rdf {
String value();
}
[edit] @rdf on Interface
- Can only be used on a public interface;
- Maps the interface to one or more rdfs:Class URI;
- Interface is assigned to resources based its rdf:type property.
[edit] @rdf on Class
- Can only be used on a public class;
- Maps the class to one or more rdfs:Class URI;
- Resources use (or extend) the corresponding class based on its rdf:type property.
[edit] @rdf on java.util.Set Field member
- Can only be used on a private final field;
- Maps the field to a rdf:Property URI;
- Field is never null;
- Field emulates a java.util.Set of the property objects;
- isEmpty() would return true to indicate no matching statements.
[edit] @rdf on non-Set Field member
- Can only be used on a private field;
- Maps the field to a rdf:Property URI;
- Field is null to indicate no matching statements.
[edit] @rdf on java.util.Set Property Getter
- Can only be used on a public or protected method;
- Can only be used on methods with no parameters and a non-void return type;
- Maps the getter method to the rdf:Property URI;
- Method will never return null;
- Return value will emulates a java.util.Set of the property objects.
- isEmpty() would return true to indicate no matching statements.
[edit] @rdf on java.util.Set Property Setter
- Can only be used on a public or protected method;
- Can only be used on methods with one parameters and a void return type;
- Maps the setter method to the rdf:Property URI;
- Parameter value will replace triples matching the predicate URI.
[edit] @rdf on non-java.util.Set Property Getter
- Can only be used on a public or protected method;
- Can only be used on methods with no parameters and a non-void return type;
- Maps the getter to the rdf:Property URI;
- Null return value indicates no matching statements.
[edit] @rdf on non-java.util.Set Property Setter
- Can only be used on a public or protected method;
- Can only be used on methods with one parameters and a void return type;
- Maps the getter to the rdf:Property URI;
- Null parameter will remove all triples matching the predicate URI.
[edit] @rdf on Package
- Maps the package to a namespace
[edit] Pro Arguments
Easy upgrade for som(m)er and elmo users. For interfaces it is easy to see how annotating interfaces allows one to get automatic implementations of behavior (using dynamic proxy type objects for example). If you want to serialize a java object to rdf, you can just iterate through all the fields and getters.
[edit] Con Arguments
Assumes you would only have a getter and setter method foreach property.
- One can always create wrapper methods if needed.
[edit] See Also
Based on previous work in Elmo and Som(m)er:
- https://sommer.dev.java.net/
- http://www.openrdf.org/doc/elmo/1.0/user-guide/x129.html#AEN208
- http://www.openrdf.org/doc/elmo/1.0/xref/org/openrdf/concepts/foaf/Person.html
[edit] @iri
When @iri is placed on a
- Class declaration, the class is implemented by objects representing resources with an rdf:type of that URI.
- Interface declaration, the interface is implemented by objects representing resources with an rdf:type of that URI.
- Field member declaration, the object, @iri URI, and filed value is read and stored as a triple.
- Getter method declaration, the method is overridden (or implemented) to return the object value of this RDF property.
- Setter method declaration, the object, @iri URI, and method parameter is stored in the RDF store as a triple.
- Method declaration, it identifies a Message interface class by URI, that should be used as the invocation context for AOP methods.
- Annotation type declaration, indicates this annotation should be used when compiling RDF ontologies into Java classes for an owl:AnnotationProperty.
- Package declaration, identifies the namespace of classes declared within it.
- Parameter declaration, declares a parameter URI that can be retried from a Message class with an @iri of the same URI on a getter.
- Field static declaration, it is not used.
- Enum declaration, it is not used.
- Variable Local declaration, it is not used.
- Constructor declaration, it is not used.
[edit] @matching
The @matching annotation associates a Java class with a set of resources matching a URI patterns. The patterns may end with a '*' to match a prefix and may start with a '/' to be matched against any hierarchical URI path, query, and fragment parts.
[edit] @sparql
The @sparql annotation can be placed on methods to identify a named query, where the annotation value is either a URL referring to a SPARQL query, or a SPARQL query itself.
The @name annotation is placed on parameters that should be bound to SPARQL variables.
[edit] @RdfsClass
@RdfsClass takes a qname or a URI of the class which corresponds to the Java bean. When instances of the bean are persisted, or loaded from RDF, they must be of the rdf:type specified in this annotation.
@RdfsClass("foaf:Person")
[edit] @RdfProperty
@RdfProperty takes a qname or a URI of an rdf property and maps that to the property of the bean on which it is placed. It can be placed directly on a field, or on the getter and/or setter for that property. When persisting the value of the property is mapped to the specified RDF property. Persistence behavior, such as cascades or lazy loading is controlled by the standard JPA annotations.
@RdfProperty("foaf:knows")
@OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
private List<Person> knows = new ArrayList<Person>();
[edit] @RdfId
@RdfId is similar in function to the JPA annotation @Id and is used to coin the identifier of a bean. Otherwise, a URI is auto generated for new instances or the existing URI is used for already existing individuals.
@RdfId
@RdfProperty("foaf:mbox")
private String mbox;
[edit] @NamedGraph
The @NamedGraph annotation lets users control the named graph their beans are persisted. By default, the generated RDF is stored in the default no context graph, but the @Namespaces lets users persist the bean to either a specific named graph, or a named graph whose identifier is the same as the individual being persisted.
@NamedGraph(value = "http://example.org/myfoaf/", type = NamedGraph.NamedGraphType.Static)
[edit] @Namespaces
The @Namespaces annotation is used in Empire to facilitate defining prefix-uri pairs which can be used in your annotations, given the following declaration, you can then use "foaf:Person" or "dc:title" in your @RdfsClass or @RdfProperty annotations.
@Namespaces({"foaf", "http://xmlns.com/foaf/0.1/",
"dc", "http://purl.org/dc/elements/1.1/"})
[edit] Proposed in May 2011
[edit] @Iri
package org.openrdf.annotations;
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD, ElementType.PACKAGE, ElementType.PARAMETER, ElementType.TYPE } )
public @interface Iri {
String value();
}
[edit] @IdentifierProperty
package org.openrdf.annotations;
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.FIELD, ElementType.METHOD })
public @interface IdentifierProperty { }
[edit] @Matching
package org.openrdf.annotations;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Matching {
String[] value();
}
[edit] @Sparql / @Binding
package org.openrdf.annotations;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface sparql {
String value();
}
package org.openrdf.annotations;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Binding {
String[] value();
}