|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.viceversatech.rdfbeans.RDFBeanManager
public class RDFBeanManager
RDFBeans databinding functions are accessible as methods of a single RDFBeanManager class. An RDFBeanManager instance is created with a RDF2Go Model which provides an abstraction layer to access an underlying physical RDF storage. Currently, RDF2Go project provides implementations of Model interface (adapters) for Sesame 2.x and Jena frameworks. A Model instance is passed as an argument to the RDFBeanManager constructor. The Model implementations may require the model to be opened (initialized) before and closed after use. The following example illustrates how to setup RDFBeans databinding with a model adapter determined automatically via RDF2Go ModelFactory mechanism:
import com.viceversatech.rdfbeans.RDFBeanManager; import org.ontoware.rdf2go.ModelFactory; import org.ontoware.rdf2go.RDF2Go; import org.ontoware.rdf2go.model.Model; ... ModelFactory modelFactory = RDF2Go.getModelFactory(); Model model = modelFactory.createModel(); model.open(); RDFBeanManager manager = new RDFBeanManager(model); ... model.close();An example with hardcoded Sesame 2.x NativeStore model implementation:
import com.viceversatech.rdfbeans.RDFBeanManager; import org.ontoware.rdf2go.model.Model; import org.openrdf.rdf2go.RepositoryModel; import org.openrdf.repository.Repository; import org.openrdf.repository.sail.SailRepository; import org.openrdf.sail.nativerdf.NativeStore; ... Repository repository = new SailRepository(new NativeStore(new File("~/.sesame/test"))); repository.initialize(); Model model = new RepositoryModel(repository); model.open(); RDFBeanManager manager = new RDFBeanManager(model); ... model.close();For detailed information on RDF2Go configuration for specific triple store adapters, please refer to RDF2Go documentation.
Field Summary | |
---|---|
static org.ontoware.rdf2go.model.node.URI |
BINDINGCLASS_PROPERTY
|
static org.ontoware.rdf2go.model.node.URI |
BINDINGIFACE_PROPERTY
|
Constructor Summary | |
---|---|
RDFBeanManager(org.ontoware.rdf2go.model.Model model)
Creates new RDFBeanManager instance upon the given RDF2Go model. |
Method Summary | ||
---|---|---|
org.ontoware.rdf2go.model.node.Resource |
add(java.lang.Object o)
Marshall the state of an RDFBean object to an RDF resource (a set of triple statements) in the underlying RDF model. |
|
java.lang.Object |
create(org.ontoware.rdf2go.model.node.Resource r)
Create new dynamic proxy instance backed by an existing RDF resource. |
|
|
create(org.ontoware.rdf2go.model.node.Resource r,
java.lang.Class<T> iface)
Create new dynamic proxy instance that implements the specified RDFBean interface and backed by the specified RDF resource in the underlying RDF model. |
|
|
create(java.lang.String id,
java.lang.Class<T> iface)
Create new dynamic proxy instance that implements the specified RDFBean interface and backed by an RDF resource matching to the given RDFBean ID. |
|
void |
delete(org.ontoware.rdf2go.model.node.Resource r)
Delete the RDF resource from underlying model. |
|
void |
delete(java.lang.String stringId,
java.lang.Class rdfBeanClass)
Delete an RDF resource matching the specified RDFBean identifier from underlying model. |
|
java.lang.Object |
get(org.ontoware.rdf2go.model.node.Resource r)
Unmarshall an RDF resource to an RDFBean instance. |
|
|
get(org.ontoware.rdf2go.model.node.Resource r,
java.lang.Class<T> rdfBeanClass)
Unmarshall an RDF resource to an instance of the specified RDFBean class. |
|
|
get(java.lang.String stringId,
java.lang.Class<T> rdfBeanClass)
Unmarshall an RDF resource matching specified RDFBean identifier to an instance of the specified RDFBean class. |
|
|
getAll(java.lang.Class<T> rdfBeanClass)
Obtain an iterator over all instances of specified RDFBean class stored in the RDF model |
|
protected java.lang.Class<?> |
getBindingIface(org.ontoware.rdf2go.model.node.Resource r)
|
|
protected java.lang.Class<?> |
getBindingIface(org.ontoware.rdf2go.model.node.URI rdfType)
|
|
java.lang.ClassLoader |
getClassLoader()
Return the current ClassLoader for loading RDFBean classes. |
|
DatatypeMapper |
getDatatypeMapper()
Return a current DatatypeMapper implementation. |
|
org.ontoware.rdf2go.model.Model |
getModel()
Return the underlying RDF model. |
|
org.ontoware.rdf2go.model.node.Resource |
getResource(java.lang.String stringId,
java.lang.Class rdfBeanClass)
Resolve the RDFBean identifier to an RDF resource URI. |
|
boolean |
isAutocommit()
Check if autocommit mode is on |
|
boolean |
isResourceExist(org.ontoware.rdf2go.model.node.Resource r)
Check if a RDF resource exists in the underlying model. |
|
void |
setAutocommit(boolean autocommit)
Set autocommit mode. |
|
void |
setClassLoader(java.lang.ClassLoader classLoader)
Set a custom ClassLoader instance for loading RDFBean classes. |
|
void |
setDatatypeMapper(DatatypeMapper datatypeMapper)
Set a DatatypeMapper implementation. |
|
org.ontoware.rdf2go.model.node.Resource |
update(java.lang.Object o)
Marshall the state of an RDFBean object to update an existing RDF resource in the underlying RDF model. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final org.ontoware.rdf2go.model.node.URI BINDINGCLASS_PROPERTY
public static final org.ontoware.rdf2go.model.node.URI BINDINGIFACE_PROPERTY
Constructor Detail |
---|
public RDFBeanManager(org.ontoware.rdf2go.model.Model model)
model
- Method Detail |
---|
public org.ontoware.rdf2go.model.node.Resource add(java.lang.Object o) throws RDFBeanException
If the RDFBean object has not-null property, annotated with
RDFSubject
, the method returns absolute URI of RDF resource.
Otherwise, RDF BlankNode is returned.
If an RDF representation of the given unanonymous object already exists in the model, the method immediately returns the RDF resource without changing the model.
If autocommit mode is on (see setAutocommit(boolean)
), the
statements are commited into the RDF model in a single transaction.
Otherwise, the transaction is delayed until the commit()
method of the underlying Model implementation is invoked.
o
- RDFBean to add
RDFBeanException
- If the object is not a valid RDFBeanupdate(Object)
,
setAutocommit(boolean)
public org.ontoware.rdf2go.model.node.Resource update(java.lang.Object o) throws RDFBeanException
If no resource for the given object exists, or the object is anonymous
RDFBean represented with a BlankNode
, the method works like
add()
.
If autocommit mode is on (see setAutocommit(boolean)
), the
statements are commited into the RDF model in a single transaction.
Otherwise, the transaction is delayed until the commit()
method of the underlying Model implementation is invoked.
o
- RDFBean to update
RDFBeanException
- If the object is not a valid RDFBeanadd(Object)
,
setAutocommit(boolean)
public <T> T get(org.ontoware.rdf2go.model.node.Resource r, java.lang.Class<T> rdfBeanClass) throws RDFBeanException
r
- Resource URI (or BlankNode for anonymous RDFBeans).rdfBeanClass
- Java class of RDFBean
RDFBeanException
- If the class is not a valid RDFBean or an instance of this
class cannot be createdget(Resource)
,
get(String,Class)
,
getAll(Class)
public java.lang.Object get(org.ontoware.rdf2go.model.node.Resource r) throws RDFBeanException
The method tries to autodetect an RDFBean Java class using information added to the model at marshalling. If a binding class information is not found, RDFBeanException is thrown.
r
- Resource URI or BlankNode for anonymous RDFBeans.
RDFBeanException
- If the binding class cannot be detected, is not a valid
RDFBean or an instance of this class cannot be createdget(Resource,Class)
,
get(String,Class)
,
getAll(Class)
public <T> T get(java.lang.String stringId, java.lang.Class<T> rdfBeanClass) throws RDFBeanException
If a namespace prefix is defined in RDFSubject
declaration for
this RDFBean class, the provided identifier value is interpreted as a
local part of fully qualified RDFBean name (RDF resource URI). Otherwise,
the fully qualified name must be provided.
stringId
- RDFBean ID valuerdfBeanClass
- Java class of RDFBean
RDFBeanException
- If the class is not a valid RDFBean or an instance of this
class cannot be createdget(Resource)
,
get(Resource,Class)
,
getAll(Class)
public <T> org.ontoware.aifbcommons.collection.ClosableIterator<T> getAll(java.lang.Class<T> rdfBeanClass) throws RDFBeanException
The returned Iterator performs lazy unmarshalling of RDFBean objects (on
every next()
call) without any specific order. When
iterating is done, the caller must invoke the close()
method
of ClosableIterator to release the resources of the underlying RDF model
implementation.
rdfBeanClass
- Java class of RDFBeans
RDFBeanException
- If the class is not a valid RDFBeanpublic boolean isResourceExist(org.ontoware.rdf2go.model.node.Resource r)
r
- Resource URI or BlankNode
public org.ontoware.rdf2go.model.node.Resource getResource(java.lang.String stringId, java.lang.Class rdfBeanClass) throws RDFBeanException
If a namespace prefix is defined in RDFSubject
declaration for
this RDFBean class, the provided identifier value is interpreted as a
local part of fully qualified RDFBean name (RDF resource URI). Otherwise,
the fully qualified name must be provided.
stringId
- RDFBean ID valuerdfBeanClass
- Java class of RDFBean
RDFBeanException
- If the class is not a valid RDFBeanpublic void delete(org.ontoware.rdf2go.model.node.Resource r)
If autocommit mode is on (see setAutocommit(boolean)
), the
statements are removed from the RDF model as a single transaction.
Otherwise, the transaction is delayed until the commit()
method of the underlying Model implementation is invoked.
r
- Resource URIdelete(String,Class)
,
setAutocommit(boolean)
public void delete(java.lang.String stringId, java.lang.Class rdfBeanClass) throws RDFBeanException
If autocommit mode is on (see setAutocommit(boolean)
), the
statements are removed from the RDF model as a single transaction.
Otherwise, the transaction is delayed until the commit()
method of the underlying Model implementation is invoked.
stringId
- RDFBean ID valuerdfBeanClass
- Java class of RDFBean
RDFBeanException
- If the class is not a valid RDFBeandelete(Resource)
,
setAutocommit(boolean)
public <T> T create(org.ontoware.rdf2go.model.node.Resource r, java.lang.Class<T> iface) throws RDFBeanException
r
- Resource URIiface
- RDFBean interface
RDFBeanException
- If iface is not valid RDFBean interfacecreate(String,Class)
,
create(Resource)
public <T> T create(java.lang.String id, java.lang.Class<T> iface) throws RDFBeanException
If a namespace prefix is defined in RDFSubject
declaration for
this RDFBean interface, the provided identifier value is interpreted as a
local part of fully qualified RDFBean name (RDF resource URI). Otherwise,
the fully qualified name must be provided.
id
- RDFBean ID valueiface
- RDFBean interface
RDFBeanException
- if iface is not valid RDFBean interface or there is an error
resolving RDFBean identifiercreate(Resource,Class)
,
create(Resource)
public java.lang.Object create(org.ontoware.rdf2go.model.node.Resource r) throws RDFBeanException
The method tries to autodetect an RDFBean Java interface using information retrieved from the model. If a binding interface information is not found, RDFBeanException is thrown.
r
- Resource URI
RDFBeanException
- If interface bound to the RDF type is not foundcreate(Resource,Class)
,
create(String,Class)
protected java.lang.Class<?> getBindingIface(org.ontoware.rdf2go.model.node.Resource r) throws RDFBeanException
RDFBeanException
protected java.lang.Class<?> getBindingIface(org.ontoware.rdf2go.model.node.URI rdfType) throws RDFBeanException
RDFBeanException
public org.ontoware.rdf2go.model.Model getModel()
public boolean isAutocommit()
If autocommit mode is on, the transactions with the RDF model will be
immediately commited on invocation of add(Object)
, update(Object)
and
delete(Resource)
methods, as well as of the setter methods of the
dynamic proxy objects. Otherwise, the transactions must be commited by explicit
invocation of the commit()
method of the Model implementation.
By default, the autocommit mode is on.
setAutocommit(boolean)
public void setAutocommit(boolean autocommit)
If autocommit mode is on, the transactions with the RDF model will be
immediately commited on invocation of add(Object)
, update(Object)
and
delete(Resource)
methods, as well as of the setter methods of the
dynamic proxy objects. Otherwise, the transactions must be commited by explicit
invocation of the commit()
method of the Model implementation.
By default, the autocommit mode is on.
autocommit
- false to set the autocommit mode off or true to onisAutocommit()
public java.lang.ClassLoader getClassLoader()
By default, the classes are loaded by the ClassLoader of this RDFBeanManager.
setClassLoader(ClassLoader)
public void setClassLoader(java.lang.ClassLoader classLoader)
By default, the classes are loaded by the ClassLoader of this RDFBeanManager.
classLoader
- the ClassLoader instance to setgetClassLoader()
public DatatypeMapper getDatatypeMapper()
setDatatypeMapper(DatatypeMapper)
public void setDatatypeMapper(DatatypeMapper datatypeMapper)
datatypeMapper
- the datatypeMapper to setgetDatatypeMapper()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |