net.java.rdf.sommer
Interface Mapper

All Known Implementing Classes:
Mapping, SesameMapper

public interface Mapper

This is the interface the clients use to Map objects to a graph, (as well as remove them).

Author:
Henry Story

Nested Class Summary
static interface Mapper.Init
          Different RDF stores usually require very different initialisations.
 
Method Summary
<T> T
addObject(T object)
          Insert the object and all its dependent objects into the graph
 boolean addObjects(java.lang.Object... objects)
          Insert all objects
 void addStatements(java.util.Collection<Statement> statements)
          Add the following statements to the writeable graph.
 boolean clear()
          Delete this graph, and all objects associated to it.
 void cogitate(java.util.List<Inferencer> inferenceList)
          run the inferencers on this graph one after the other
<T> T
createObjectWithId(java.lang.String uri, java.lang.Class<T> clazz)
          Create an object of type with a given uri
 void enableInferencing(boolean on)
           
 boolean equals(java.lang.Object mapped1, java.lang.Object mapped2)
          Equality of mapped objects.
<T> java.util.Collection<T>
getAllObjectsOfType(java.lang.Class<T> clazz)
           
 java.util.List<java.lang.Class> getClassesOf(java.lang.String uri)
          find the classes of the object with id uri
<T> T
getObjectById(java.lang.String uri, java.lang.Class<T> clazz)
          Fetch an object of type with a given uri.
 java.lang.String graphId()
           
 void importFrom(java.io.Reader r, java.lang.String baseUri, java.lang.String mimeType)
          Deprecated. one should have to specify the context one is importing stuff from. Right?
 void importInto(java.io.Reader r, java.lang.String baseUri, java.lang.String mimeType, java.lang.String context)
          import graph serialisation into the given context.
 boolean isInferencingEnabled()
           
 boolean isMapped(java.lang.Object obj)
          note: We should be able to ask the object directly now that it implements SommerMapable except of course that we are adding this directly
 void output(java.io.OutputStream out)
          Output the contents of this graph todo: add type of output (N3,rdf/xml)
 void output(java.io.Writer out)
          Output the contents of this graph todo: add type of output (N3,rdf/xml)
 void preload(java.lang.Class... classes)
          Sometimes one needs to preload a bunch of annotated classes in order to take account of hierarchies.
<T> java.util.Collection<T>
queryByExample(java.lang.Object eg, java.lang.Class<T> clazz)
          Query the map by giving an example object, and return all objects that fit the example.
 boolean remove(java.lang.Object obj)
          remove all statements concerning the resource this object is mapped to.
 void removeStatements(java.util.Collection<Statement> statements)
          remove the following statements from the graphs.
 long size()
          The Size in triples of the graph, mapped to.
 boolean unmap(java.lang.Object obj)
          This will remove the object from the map, but the relations will remain in the database.
 

Method Detail

enableInferencing

void enableInferencing(boolean on)

isInferencingEnabled

boolean isInferencingEnabled()

importFrom

void importFrom(java.io.Reader r,
                java.lang.String baseUri,
                java.lang.String mimeType)
                throws java.io.IOException,
                       GraphUpdateException,
                       ParseException
Deprecated. one should have to specify the context one is importing stuff from. Right?

Parameters:
r - a Reader on the rdf
baseUri - the base to resolve relative uri from
mimeType - of the rdf serialisation: rdfxml, n3, turtle, ntriples, ...
Throws:
java.io.IOException
GraphUpdateException
ParseException

importInto

void importInto(java.io.Reader r,
                java.lang.String baseUri,
                java.lang.String mimeType,
                java.lang.String context)
                throws java.io.IOException,
                       GraphUpdateException,
                       ParseException
import graph serialisation into the given context. Add the context to the list of contexts we are working with *

Parameters:
r - the reader containing the serialisation of the graph
baseUri - the base uri to xxx relative uris
mimeType - format of the serialisation ( currently the mime type)
context - the context to drop the information into
Throws:
java.io.IOException
GraphUpdateException
ParseException

clear

boolean clear()
Delete this graph, and all objects associated to it.


isMapped

boolean isMapped(java.lang.Object obj)
note: We should be able to ask the object directly now that it implements SommerMapable except of course that we are adding this directly

Parameters:
obj -
Returns:
true if the object is mapped, false otherwise

getClassesOf

java.util.List<java.lang.Class> getClassesOf(java.lang.String uri)
find the classes of the object with id uri

Parameters:
uri - the id of the object looked for
Returns:
a list of classes

getObjectById

<T> T getObjectById(java.lang.String uri,
                    java.lang.Class<T> clazz)
Fetch an object of type with a given uri. Note. There may be a good case for having a similar method that can also take a literal.

Parameters:
uri - the id of the object
clazz - the type of the object looked for
Returns:
null if none available in the database or an object mapped (if there is already an object mapped to that id, it should return that one)

createObjectWithId

<T> T createObjectWithId(java.lang.String uri,
                         java.lang.Class<T> clazz)
Create an object of type with a given uri

Parameters:
uri - the id of the object
clazz - the type of the object looked for
Returns:
an object (null only if the class has no @rdf annotation?)

getAllObjectsOfType

<T> java.util.Collection<T> getAllObjectsOfType(java.lang.Class<T> clazz)

addObject

<T> T addObject(T object)
Insert the object and all its dependent objects into the graph

Parameters:
object - the object whose relations should be added to the graph
Returns:
the same object, for method chaining

addObjects

boolean addObjects(java.lang.Object... objects)
Insert all objects

Parameters:
objects -
Returns:

addStatements

void addStatements(java.util.Collection<Statement> statements)
Add the following statements to the writeable graph. The Subject and Object of the Statement can be mapped objects, in which case their id will be used. If they are not mapped objects, what should one do? Map them first and then add the statement?

Parameters:
statements -

removeStatements

void removeStatements(java.util.Collection<Statement> statements)
remove the following statements from the graphs. (this may require making diffs of non writeable graphs)

Parameters:
statements -

remove

boolean remove(java.lang.Object obj)
remove all statements concerning the resource this object is mapped to. The object will no longer appear in the rdf graph after this. note: On inferencing graphs this may not lead to the resource being removed if the resource is implied by other facts in the database. todo: this needs to be looked at a lot more carefully todo: is it a good thing to be able to remove an object? It could be quite a problem, as it could invalidate a number of other objects...

Parameters:
obj -
Returns:
false if it never was part of the graph

unmap

boolean unmap(java.lang.Object obj)
This will remove the object from the map, but the relations will remain in the database. todo: understand what this would mean for all the objects in points to or all objects pointed to it return true if unmapped, false if object was never mapped


output

void output(java.io.OutputStream out)
Output the contents of this graph todo: add type of output (N3,rdf/xml)


output

void output(java.io.Writer out)
Output the contents of this graph todo: add type of output (N3,rdf/xml)


size

long size()
The Size in triples of the graph, mapped to.

Returns:
the size of the graph, or -1 if there was a problem finding out

graphId

java.lang.String graphId()

equals

boolean equals(java.lang.Object mapped1,
               java.lang.Object mapped2)
Equality of mapped objects. As far as the mapper knows these two objects are equals. Inferencing graphs will do a better job of finding object equality than non inferencing graphs. We can't use Object.equals(o) because that is too closely tied to the hash signature. In the graph equality between objects can be discovered over time, as new relations are added to the database. Equality between object may possibly also be broken, as relations are altered. if either object is not mapped, then this returns false if both objects are mapped and == then this is true if there is a owl:sameAs relation between them then it is true else it is false.

Parameters:
mapped1 - a mapped object
mapped2 - another mapped objects
Returns:
as far as this mapper knows mapped1 and mapped2 are the same

queryByExample

<T> java.util.Collection<T> queryByExample(java.lang.Object eg,
                                           java.lang.Class<T> clazz)
Query the map by giving an example object, and return all objects that fit the example. Here the example is an object with @rdf annotated fields. Only looks at fields with values. Note: objects with simple literal values such as char, int, etc... are always set. So beware.

Parameters:
eg - example object. Should not be a mapped object or an object with a id specified by @rdf URI id since otherwise the only object returneable would be the one given. The object can have fields that are set either to mapped or unmapped objects.
clazz - of objects to return (should this not just be the same as the class of o?
Returns:
a Collection of objects of the given that fit the example.

preload

void preload(java.lang.Class... classes)
Sometimes one needs to preload a bunch of annotated classes in order to take account of hierarchies. We want to be able to have the most specific java class possible instantiate an rdf object. But we cannot walk down a java class hierarchy. see Mapping.mostSpecific(clazz,uri);


cogitate

void cogitate(java.util.List<Inferencer> inferenceList)
run the inferencers on this graph one after the other