thewebsemantic
Class RDF2Bean

java.lang.Object
  extended by thewebsemantic.Base
      extended by thewebsemantic.RDF2Bean

public class RDF2Bean
extends Base

RDF2Bean converts one or more RDF nodes into java beans. Normally these are nodes created by the Bean2RDF class. @Namespace annotation value of the Class.

See Also:
Bean2RDF

Field Summary
 
Fields inherited from class thewebsemantic.Base
binder, javaclass, JAVACLASS, m
 
Constructor Summary
RDF2Bean(com.hp.hpl.jena.ontology.OntModel model)
          Constructs and instance of RDF2Bean bound to a particular ontology model.
 
Method Summary
 boolean exists(java.lang.Class<?> c, java.lang.String id)
          returns true if matching individual is found in the model.
 java.lang.Object exists(java.lang.Object target)
          returns true if target exists in the model
 Filler fill(java.lang.Object o)
          Returns a Filler for this bean.
 void fill(java.lang.Object o, java.lang.String propertyName)
          fill or reload a non-functional property with values from the model.
<T> java.util.Collection<T>
load(java.lang.Class<T> c)
          Loads all individuals having RDF type which maps to Class c.
protected
<T> java.util.Collection<T>
load(java.lang.Class<T> c, boolean shallow, java.lang.String[] includes)
          load all rdf entries that map to the bean.
<T> T
load(java.lang.Class<T> c, int id)
          same as load(String) overloaded for id's of type integer.
<T> T
load(java.lang.Class<T> c, java.lang.String id)
          Loads an ontology individual as a java bean, based on annotations or bindings applied to Class c.
<T> java.util.Collection<T>
load(java.lang.Class<T> c, java.lang.String[] includes)
          Similar to load(Class c) except that you may include an array of property names to "include".
protected
<T> T
load(java.lang.Class<T> c, java.lang.String id, boolean shallow)
           
<T> T
load(java.lang.Class<T> c, java.lang.String id, java.lang.String[] includes)
          Similar to load(Class, String), with the ability to include non-functional Collection based properties.
 java.lang.Object load(java.lang.Object target)
          Loads an object from model with the same identifier as target.
<T> java.util.Collection<T>
loadDeep(java.lang.Class<T> c)
          Deeply loads all individuals having RDF type which matches Class c.
<T> T
loadDeep(java.lang.Class<T> c, int id)
          loadDeep will load a particular individual and all it's properties, recursively.
<T> T
loadDeep(java.lang.Class<T> c, java.lang.String id)
          Same as loadDeep(Class, String) overloaded for id's of type integer.
 
Methods inherited from class thewebsemantic.Base
isBound, t, toRdfProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RDF2Bean

public RDF2Bean(com.hp.hpl.jena.ontology.OntModel model)
Constructs and instance of RDF2Bean bound to a particular ontology model. Operations have potential to modify the model.

Parameters:
model - a Jena Ontology Model instance
Method Detail

loadDeep

public <T> java.util.Collection<T> loadDeep(java.lang.Class<T> c)
Deeply loads all individuals having RDF type which matches Class c. Depending on the density of your model this method has the potential to load the entire graph into memory as Java beans. For example, if you been has a hasFriends property, loadDeep() will load each friend, each friend's friends, and so on. Every reachable property that maps to a corresponing bean property will be loaded recursively.

Type Parameters:
T -
Parameters:
c - a java class which maps to individuals in your ontology.
Returns:
collection of java beans, all instances of Class c.

load

public <T> java.util.Collection<T> load(java.lang.Class<T> c)
Loads all individuals having RDF type which maps to Class c. Mappings are either based on Class annotations or bindings given at VM startup. load() is safe for dense graphs as it has a conservative or shallow policy. It loads all functional properties (where there is only one) but ignores bean properties of type Collection. All returned bean's Collection properties are initialized to size 0. Once loaded you may add to Collection properties and save. This will result in addition assertions being made in your jena ontology model, however, saving will not delete assertions unless the property is fully loaded. Consider the common customer/order scenario. We can load a customer, and fill the orders, leaving other properties alone: Collection customers = myRDF2Bean.load(Customer.class) ... myRDF2Bean.fill(aCustomer).with("orders"); foreach(Order o: aCustomer.getOrders())... You may also use this alternate method to fill collection properties: myRDF2Bean.fill(aCustomer, "orders");

Type Parameters:
T -
Parameters:
c -
Returns:
See Also:
Jenabean, Namespace

load

public <T> java.util.Collection<T> load(java.lang.Class<T> c,
                                        java.lang.String[] includes)
Similar to load(Class c) except that you may include an array of property names to "include". The properties should be of type Collection. This allows you to be specific about wich children you want unmarshalled from the ontology model into java objects. For instance, you may just need a customer, their outstanding orders, and their recent addresses. Assuming your ontology relates customers to many more non-functional properties, it'd save time to just load exacly what you need.

Type Parameters:
T -
Parameters:
c -
includes -
Returns:

load

protected <T> java.util.Collection<T> load(java.lang.Class<T> c,
                                           boolean shallow,
                                           java.lang.String[] includes)
load all rdf entries that map to the bean.

Type Parameters:
T -
Parameters:
c -
Returns:

loadDeep

public <T> T loadDeep(java.lang.Class<T> c,
                      int id)
           throws NotFoundException
loadDeep will load a particular individual and all it's properties, recursively. Beware, this could result in loading the entire model into memory as java objects depending on the density of your graph. Therefore use this method with care knowing that it's purpose is to load all information reachable via properties that bind to your objects.

Parameters:
c - java class of the bean. The class is converted to a URI based on its annotations or bindings.
id - unique id of the bean to find
Returns:
An instance of T, otherwise null
Throws:
NotFoundException
See Also:
Jenabean, Namespace

loadDeep

public <T> T loadDeep(java.lang.Class<T> c,
                      java.lang.String id)
           throws NotFoundException
Same as loadDeep(Class, String) overloaded for id's of type integer.

Parameters:
c -
id -
Returns:
Throws:
NotFoundException

load

public <T> T load(java.lang.Class<T> c,
                  java.lang.String id)
       throws NotFoundException
Loads an ontology individual as a java bean, based on annotations or bindings applied to Class c.

Type Parameters:
T -
Parameters:
c -
id -
Returns:
instance of Classc matching id from model, if one exists.
Throws:
NotFoundException

load

public <T> T load(java.lang.Class<T> c,
                  java.lang.String id,
                  java.lang.String[] includes)
       throws NotFoundException
Similar to load(Class, String), with the ability to include non-functional Collection based properties. includes should be an array of property names, for example, if you want to load a customer with their orders and recent purchases... RDF2Bean reader = new RDF2Bean(model); String[] includes = {"orders","recentPurchases"}; reader.load(Customer.class, "cust#2", includes);

Type Parameters:
T -
Parameters:
c -
id -
includes -
Returns:
Throws:
NotFoundException

load

public <T> T load(java.lang.Class<T> c,
                  int id)
       throws NotFoundException
same as load(String) overloaded for id's of type integer.

Type Parameters:
T -
Parameters:
c -
id -
Returns:
Throws:
NotFoundException

load

protected <T> T load(java.lang.Class<T> c,
                     java.lang.String id,
                     boolean shallow)
          throws NotFoundException
Throws:
NotFoundException

load

public java.lang.Object load(java.lang.Object target)
                      throws NotFoundException
Loads an object from model with the same identifier as target.

Parameters:
target -
Returns:
Throws:
NotFoundException

exists

public java.lang.Object exists(java.lang.Object target)
returns true if target exists in the model

Parameters:
target -
Returns:
Throws:
NotFoundException

fill

public Filler fill(java.lang.Object o)
Returns a Filler for this bean. When beans are loaded they are normally shallow, ie, their Collections are still empty. This allows the client to decide which lists (sometimes large) they'd like to work with. This provides a certain type of calling style: RDF2Bean rdf2bean = new RDF2Bean(model); ... rdf2bean.fill(myBean).with("children");

Parameters:
o -
Returns:

fill

public void fill(java.lang.Object o,
                 java.lang.String propertyName)
fill or reload a non-functional property with values from the model. This is usefull when you've recently shallow loaded a bean from the triple store. non-funtional properties can contain unlimited elements, so your app will need to be carefull regarding when it loads them. in Jenabean, non-functional properties are represented as properties of type java.util.Collection. RDF2Bean rdf2bean = new RDF2Bean(model); ... rdf2bean.fill(myBean,"children");

Parameters:
o -
propertyName -

exists

public boolean exists(java.lang.Class<?> c,
                      java.lang.String id)
returns true if matching individual is found in the model.

Parameters:
c -
id -
Returns: