uk.ac.soton.ecs.grimoires.server.impl
Class Jena

java.lang.Object
  extended byuk.ac.soton.ecs.grimoires.server.impl.Jena

public final class Jena
extends Object

A class defining convenience functions to manipulate the Jena Triple store.


Constructor Summary
Jena()
           
 
Method Summary
static void addTripleIfObjectNotNull(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, String propertyNS, String propertyName, Object object)
           
static void deleteEntity(com.hp.hpl.jena.rdf.model.Model readingModel, ModelChanges changes, Key key, String keyRelationNS, String keyRelationName)
          Remove from the store an entity (with a given key) and all resources related to the entity.
static void deleteResource(com.hp.hpl.jena.rdf.model.Model model, ModelChanges changes, com.hp.hpl.jena.rdf.model.Resource entity, com.hp.hpl.jena.rdf.model.Property exclude, com.hp.hpl.jena.rdf.model.Property fromBag)
          Remove a resource and its descendents from the store model: RDF model to read from changes: the changes model entity: the resource of the entity to delete exclude: if not null, the resource refered to by this property will not be deleted fromBag: if both exclude and fromBag are not null, reference to the entity will be removed from fromBag
static void deleteResource(com.hp.hpl.jena.rdf.model.Model model, ModelChanges changes, com.hp.hpl.jena.rdf.model.Resource entity, String referenceType)
          This function calculates the the property to exclude and the bag to delete from using the referenceType parameter.
static Key ensureUniqueKey(com.hp.hpl.jena.rdf.model.Model readingModel, ModelChanges changes, Key key, String keyRelationNS, String keyRelation)
          If the given key's value is null or empty (the way to specify addition in UDDIv2) then set the key's value to a newly generate string, if the key is not null or empty (the way to specify update in UDDIv2) then remove the existing entity with that key.
static String generateRdqlQuery(GenerationResults conceptQuery)
           
static String generateRdqlQuery(SupportsRDQLQuery concept)
          Should be removed when all APIs converted to using RDQLGenerator
static com.hp.hpl.jena.rdf.model.Model getAttachedTree(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource parent, String relationNamespace, String relationName, com.hp.hpl.jena.rdf.model.Resource root)
          Return all statements the given resource is a subject or ancestor of, plus the relation attaching the root resource to its parent
static com.hp.hpl.jena.rdf.model.RDFNode getBagElement(com.hp.hpl.jena.rdf.model.Bag from, int index)
          Returns the nth element of a bag or null if it does not exist.
static com.hp.hpl.jena.rdf.model.Resource getKeyedResource(com.hp.hpl.jena.rdf.model.Model model, String propertyNamespace, String propertyName, Key key)
          Returns the resource with the given relation to a string literal.
static String getResourceKey(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource resource, String propertyNamespace, String propertyName)
          Returns the key for a resource representing a keyed resource.
static com.hp.hpl.jena.rdf.model.Model getResourceTree(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource root)
          Return all statements the given resource is a subject or ancestor of Recursive adds are done using getResourceBabyTree which handles cyclic relationship within the RDF model
static com.hp.hpl.jena.rdf.model.Bag getUniqueBag(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, String propertyNamespace, String propertyName)
          Same as getUniqueObject but used when the object should be a Bag.
static com.hp.hpl.jena.rdf.model.RDFNode getUniqueObject(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, com.hp.hpl.jena.rdf.model.Property relation)
          Used when a resource is expected to be the subject of one and only one relation of a given type, this convenience method returns the first object found, or null if none exist.
static com.hp.hpl.jena.rdf.model.RDFNode getUniqueObject(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, String propertyNamespace, String propertyName)
          Used when a resource is expected to be the subject of one and only one relation of a given type, this convenience method returns the first object found, or null if none exist.
static boolean isType(com.hp.hpl.jena.rdf.model.Model model, com.hp.hpl.jena.rdf.model.Resource subject, String typeNS, String typeName)
           
static com.hp.hpl.jena.rdf.model.Bag newTypedBag(com.hp.hpl.jena.rdf.model.Model model, String type)
          Create a new Bag resource with an associated RDF type.
static Vector processQuery(com.hp.hpl.jena.rdf.model.Model model, GenerationResults rdqlQuery, String variableName)
          Create a new Bag resource with an associated RDF type and containing a list of Strings, where those Strings are gathered from the TextHolder objects given to this method.
static Vector processQuery(com.hp.hpl.jena.rdf.model.Model m, String rdqlQuery, String variableName)
          Returns a vector of resources matching variableName in rdqlQuery.
static Vector processQuery(com.hp.hpl.jena.rdf.model.Model m, String rdqlQuery, String[] variableNames)
          Returns a vector of resources matching variableName in rdqlQuery.
static void setRDFType(com.hp.hpl.jena.rdf.model.Model m, com.hp.hpl.jena.rdf.model.Resource r, String resourceURI)
           
static void setRDFType(com.hp.hpl.jena.rdf.model.Resource r, com.hp.hpl.jena.rdf.model.RDFNode typeResource)
           
static Hashtable usualNamespaces()
          Should be removed when all APIs converted to using RDQLGenerator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jena

public Jena()
Method Detail

addTripleIfObjectNotNull

public static void addTripleIfObjectNotNull(com.hp.hpl.jena.rdf.model.Model model,
                                            com.hp.hpl.jena.rdf.model.Resource subject,
                                            String propertyNS,
                                            String propertyName,
                                            Object object)

deleteEntity

public static void deleteEntity(com.hp.hpl.jena.rdf.model.Model readingModel,
                                ModelChanges changes,
                                Key key,
                                String keyRelationNS,
                                String keyRelationName)
Remove from the store an entity (with a given key) and all resources related to the entity.


deleteResource

public static void deleteResource(com.hp.hpl.jena.rdf.model.Model model,
                                  ModelChanges changes,
                                  com.hp.hpl.jena.rdf.model.Resource entity,
                                  com.hp.hpl.jena.rdf.model.Property exclude,
                                  com.hp.hpl.jena.rdf.model.Property fromBag)
Remove a resource and its descendents from the store model: RDF model to read from changes: the changes model entity: the resource of the entity to delete exclude: if not null, the resource refered to by this property will not be deleted fromBag: if both exclude and fromBag are not null, reference to the entity will be removed from fromBag


deleteResource

public static void deleteResource(com.hp.hpl.jena.rdf.model.Model model,
                                  ModelChanges changes,
                                  com.hp.hpl.jena.rdf.model.Resource entity,
                                  String referenceType)
This function calculates the the property to exclude and the bag to delete from using the referenceType parameter. Then it calls deleteResource(Model model, ModelChanges changes, Resource entity, Property exclude, Property fromBag) to delete the resource


ensureUniqueKey

public static Key ensureUniqueKey(com.hp.hpl.jena.rdf.model.Model readingModel,
                                  ModelChanges changes,
                                  Key key,
                                  String keyRelationNS,
                                  String keyRelation)
If the given key's value is null or empty (the way to specify addition in UDDIv2) then set the key's value to a newly generate string, if the key is not null or empty (the way to specify update in UDDIv2) then remove the existing entity with that key. The result of this method is to ensure that the key has a value that is valid for addition and that no other entity is saved with that key.


getAttachedTree

public static com.hp.hpl.jena.rdf.model.Model getAttachedTree(com.hp.hpl.jena.rdf.model.Model model,
                                                              com.hp.hpl.jena.rdf.model.Resource parent,
                                                              String relationNamespace,
                                                              String relationName,
                                                              com.hp.hpl.jena.rdf.model.Resource root)
Return all statements the given resource is a subject or ancestor of, plus the relation attaching the root resource to its parent


getBagElement

public static com.hp.hpl.jena.rdf.model.RDFNode getBagElement(com.hp.hpl.jena.rdf.model.Bag from,
                                                              int index)
Returns the nth element of a bag or null if it does not exist.


getKeyedResource

public static com.hp.hpl.jena.rdf.model.Resource getKeyedResource(com.hp.hpl.jena.rdf.model.Model model,
                                                                  String propertyNamespace,
                                                                  String propertyName,
                                                                  Key key)
Returns the resource with the given relation to a string literal. Primarily useful for finding resources by their key, e.g. services, metadata. Returns null if no resource with this key found.


getResourceKey

public static String getResourceKey(com.hp.hpl.jena.rdf.model.Model model,
                                    com.hp.hpl.jena.rdf.model.Resource resource,
                                    String propertyNamespace,
                                    String propertyName)
                             throws StoreException
Returns the key for a resource representing a keyed resource.

Throws:
StoreException

getResourceTree

public static com.hp.hpl.jena.rdf.model.Model getResourceTree(com.hp.hpl.jena.rdf.model.Model model,
                                                              com.hp.hpl.jena.rdf.model.Resource root)
Return all statements the given resource is a subject or ancestor of Recursive adds are done using getResourceBabyTree which handles cyclic relationship within the RDF model


getUniqueBag

public static com.hp.hpl.jena.rdf.model.Bag getUniqueBag(com.hp.hpl.jena.rdf.model.Model model,
                                                         com.hp.hpl.jena.rdf.model.Resource subject,
                                                         String propertyNamespace,
                                                         String propertyName)
Same as getUniqueObject but used when the object should be a Bag. This is required only because of a Jena bug that means that some stored Bags are returned only as Resources.


getUniqueObject

public static com.hp.hpl.jena.rdf.model.RDFNode getUniqueObject(com.hp.hpl.jena.rdf.model.Model model,
                                                                com.hp.hpl.jena.rdf.model.Resource subject,
                                                                com.hp.hpl.jena.rdf.model.Property relation)
Used when a resource is expected to be the subject of one and only one relation of a given type, this convenience method returns the first object found, or null if none exist.


getUniqueObject

public static com.hp.hpl.jena.rdf.model.RDFNode getUniqueObject(com.hp.hpl.jena.rdf.model.Model model,
                                                                com.hp.hpl.jena.rdf.model.Resource subject,
                                                                String propertyNamespace,
                                                                String propertyName)
Used when a resource is expected to be the subject of one and only one relation of a given type, this convenience method returns the first object found, or null if none exist.


isType

public static boolean isType(com.hp.hpl.jena.rdf.model.Model model,
                             com.hp.hpl.jena.rdf.model.Resource subject,
                             String typeNS,
                             String typeName)

newTypedBag

public static final com.hp.hpl.jena.rdf.model.Bag newTypedBag(com.hp.hpl.jena.rdf.model.Model model,
                                                              String type)
                                                       throws com.hp.hpl.jena.rdf.model.RDFException
Create a new Bag resource with an associated RDF type.

Throws:
com.hp.hpl.jena.rdf.model.RDFException

processQuery

public static Vector processQuery(com.hp.hpl.jena.rdf.model.Model model,
                                  GenerationResults rdqlQuery,
                                  String variableName)
Create a new Bag resource with an associated RDF type and containing a list of Strings, where those Strings are gathered from the TextHolder objects given to this method.


processQuery

public static Vector processQuery(com.hp.hpl.jena.rdf.model.Model m,
                                  String rdqlQuery,
                                  String variableName)
Returns a vector of resources matching variableName in rdqlQuery. This method will execute rdqlQuery on the triple store. We assume that the query contains a select statement over a single variableName. The result will be returned in a Vector.


processQuery

public static Vector processQuery(com.hp.hpl.jena.rdf.model.Model m,
                                  String rdqlQuery,
                                  String[] variableNames)
Returns a vector of resources matching variableName in rdqlQuery. This method will execute rdqlQuery on the triple store. We assume that the query contains a select statement over a series of variableNames. The result will be returned in a Vector.


setRDFType

public static final void setRDFType(com.hp.hpl.jena.rdf.model.Model m,
                                    com.hp.hpl.jena.rdf.model.Resource r,
                                    String resourceURI)
                             throws com.hp.hpl.jena.rdf.model.RDFException
Throws:
com.hp.hpl.jena.rdf.model.RDFException

setRDFType

public static final void setRDFType(com.hp.hpl.jena.rdf.model.Resource r,
                                    com.hp.hpl.jena.rdf.model.RDFNode typeResource)
                             throws com.hp.hpl.jena.rdf.model.RDFException
Throws:
com.hp.hpl.jena.rdf.model.RDFException

generateRdqlQuery

public static String generateRdqlQuery(SupportsRDQLQuery concept)
Should be removed when all APIs converted to using RDQLGenerator


generateRdqlQuery

public static String generateRdqlQuery(GenerationResults conceptQuery)

usualNamespaces

public static Hashtable usualNamespaces()
Should be removed when all APIs converted to using RDQLGenerator