org.universAAL.middleware.rdf
Class Resource

Package class diagram package Resource
java.lang.Object
  extended by org.universAAL.middleware.rdf.Resource
Direct Known Subclasses:
CallMessage, FinalizedResource, TypeExpression, UnmodifiableResource

public class Resource
extends Object

The base class for all RDF and OWL classes.

Author:
mtazari - Saied Tazari, Carsten Stockloew

Field Summary
protected static String ANON_URI_PREFIX
          URI prefix for anonymous Resources.
protected  boolean blockAddingTypes
          A resource can have one or more RDF types which are represented in this class as a property with key (RDF predicate) 'rdf:type' and an ArrayList as value (RDF object).
protected  boolean isXMLLiteral
          true, if this resource is an XML Literal.
protected  int ns_delim_index
          For a given URIref, 'ns_delim_index' is the index of the delimiter (the symbol '#'), or -1 if there is no delimiter.
static String PROP_RDF_FIRST
          URI of the first element of an RDF list.
static String PROP_RDF_REST
          URI of the remaining elements of an RDF list.
static String PROP_RDF_TYPE
          URI for rdf:type.
static String PROP_RDFS_COMMENT
          URI for RDF comments.
static String PROP_RDFS_LABEL
          URI for RDF labels.
static int PROP_SERIALIZATION_FULL
          Legal return values for getPropSerializationType(String).
static int PROP_SERIALIZATION_OPTIONAL
          Legal return values for getPropSerializationType(String).
static int PROP_SERIALIZATION_REDUCED
          Legal return values for getPropSerializationType(String).
static int PROP_SERIALIZATION_UNDEFINED
          Legal return values for getPropSerializationType(String).
static String PROP_uAAL_INVOLVED_HUMAN_USER
          URI for properties linking to the user involved.
protected  Hashtable props
          The properties denote the RDF triples of this resource, realized as Hashtable.
static String RDF_EMPTY_LIST
          URI for empty RDF lists, or the end of an RDF list.
static String RDF_NAMESPACE
          URI of RDF namespace.
static String RDFS_NAMESPACE
          URI of RDFS namespace.
static String TYPE_RDF_LIST
          URI for RDF lists.
static String TYPE_RDFS_CLASS
          URI for RDFS class.
static String uAAL_NAMESPACE_PREFIX
          URI prefix for the universAAL namespace.
static String uAAL_SERVICE_NAMESPACE
          URI for the universAAL service namespace.
static String uAAL_VOCABULARY_NAMESPACE
          URI for the universAAL namespace.
protected  String uri
          URI of this resource, or URIref (URI plus fragment identifier, separated by the symbol '#').
 
Constructor Summary
  Resource()
          Constructor to create a new Resource with anonymous URI.
  Resource(boolean isXMLLiteral)
          Constructor to create a new Resource with anonymous URI.
  Resource(String uri)
          Constructor to create a new Resource with the specified URI.
  Resource(String uri, boolean isXMLLiteral)
          Constructor to create a new Resource with the specified URI.
protected Resource(String uriPrefix, int numProps)
          Creates an instance of Resource with a URI that is created by appending a unique ID to the given 'uriPrefix'.
 
Method Summary
 void addMultiLangProp(String propURI, LangString ls)
          Add a new String literal (with optional language tag) to a multi-value property.
 boolean addType(String typeURI, boolean blockFurtherTypes)
          Set or add the type of this Resource.
 List asList()
          If this Resource represents an RDF List, retrieve the elements as List.
 void asList(List l)
          If this Resource represents an RDF List, retrieve the elements as List.
static Resource asRDFList(List members, boolean isXMLLiteral)
          Creates a new Resource instance which is treated as an RDF list and contains the specified list of elements.
 boolean changeProperty(String propURI, Object value)
          Change the value (RDF object) of the specified property (RDF predicate) to the given object.
 Resource copy(boolean isXMLLiteral)
          Create a copy of this resource.
 Resource deepCopy()
          Create a deep copy of this Resource, i.e. create a new Resource for this object and for the resources of all properties.
 boolean equals(Object other)
          Determines if this Resource equals the specified Resource.
static String generateAnonURI()
          Create a new anonymous URI.
 String getDefaultLang()
          Get the default language.
 String getFilename()
          Get the filename of the URI which is the part after the last '/' and before the symbols '?'
 String getLocalName()
          Get the local name which is the part of the URI after the delimiter ('#').
 LangString getMultiLangProp(String propURI, String lang, boolean includeDefault)
          Get a String literal (with optional language tag) from a multi-value property.
 String getNamespace()
          Get the namespace of the URI which is the start of the URI including the delimiter ('#').
 String getOrConstructLabel(String type)
          If this resource has no original label, constructs one for it without changing the resource itself.
 Object getProperty(String propURI)
          Get the RDF object for a specified property.
 Enumeration getPropertyURIs()
          Get all properties, i.e. all RDF predicates for this Resource.
 int getPropSerializationType(String propURI)
          Answers if the given property has to be considered when serializing this individual in a minimized way, and if not ignore-able, whether its value should be presented in its full form or can be reduced.
static Resource getResource(String classURI, String instanceURI)
          Get a Resource with the given class and instance URI.
 String getResourceComment()
          Get the Resource comment.
 String getResourceLabel()
          Get the Resource label.
 Object getStaticFieldValue(String fieldName, Object defaultValue)
          Helper method to get the static field of the java class with the given field name.
 String getType()
          Returns the URI of the first type added to the list of types of this resource.
 String[] getTypes()
          Returns the URIs of all known types of this resource.
 String getURI()
          Get the URI.
 int hashCode()
          Get the hash code for this Resource, calculated from the URI.
 boolean hasProperty(String propURI)
          Determines if this Resource has the specified property.
 boolean hasQualifiedName()
          Determines if this Resource has a qualified, i.e. the URI has a delimiter ('#').
 boolean isAnon()
          Determines if this Resource has an anonymous URI.
static boolean isAnon(String uri)
          Determines if the specified URI is an anonymous URI, i.e. it is either null or starts with the the String typical for anonymous URIs.
 boolean isBlockingAddingTypes()
          Determines whether this Resource does not allow to add new type information.
 boolean isClosedCollection(String propURI)
          Returns true if the value of the given property should be treated as an rdf:List.
static boolean isQualifiedName(String uri)
          Determines if the specified URI is a qualified name (see StringUtils.isQualifiedName(String) ) and is not an anonymous URI.
 boolean isWellFormed()
          Returns true, if the state of the resource is valid, otherwise false.
 void literal()
          Make this object an XMLLiteral
 int numberOfProperties()
          Returns the number of properties, i.e. the number of RDF predicates for this Resource.
 boolean representsQualifiedURI()
           
 boolean serializesAsXMLLiteral()
          Resources to be serialized and parsed as rdf:XMLLiteral must overwrite this method and return true.
 boolean setProperty(String propURI, Object value)
          Adds a statement with this resource as the subject, the given propURI as the predicate and the given value as the object.
 boolean setPropertyPath(String[] propPath, Object value)
          Set the given value at the end of the given property path, but does not force the setting.
 boolean setPropertyPath(String[] propPath, Object value, boolean force)
          Set the given value at the end of the given property path.
 boolean setPropertyPathFromOffset(String[] propPath, int fromIndex, Object value, boolean force)
          Change or add the Resource at the end of the given property path to the given value.
 void setResourceComment(String comment)
          Set the Resource comment.
 void setResourceLabel(String label)
          Set the Resource label.
 String toString()
          Get a String representation of this Resource; returns the URI.
 String toStringRecursive()
          Debug method: get a string of this RDF graph.
 String toStringRecursive(String prefix, boolean prefixAtStart, Hashtable visitedElements)
          Debug method: get a string of this RDF graph.
 void unliteral()
          Make this object not being an XMLLiteral
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ANON_URI_PREFIX

protected static final String ANON_URI_PREFIX
URI prefix for anonymous Resources.

See Also:
Constant Field Values

RDF_NAMESPACE

public static final String RDF_NAMESPACE
URI of RDF namespace.

See Also:
Constant Field Values

RDFS_NAMESPACE

public static final String RDFS_NAMESPACE
URI of RDFS namespace.

See Also:
Constant Field Values

RDF_EMPTY_LIST

public static final String RDF_EMPTY_LIST
URI for empty RDF lists, or the end of an RDF list.

See Also:
Constant Field Values

PROP_RDF_FIRST

public static final String PROP_RDF_FIRST
URI of the first element of an RDF list.

See Also:
Constant Field Values

PROP_RDF_REST

public static final String PROP_RDF_REST
URI of the remaining elements of an RDF list.

See Also:
Constant Field Values

PROP_RDF_TYPE

public static final String PROP_RDF_TYPE
URI for rdf:type.

See Also:
Constant Field Values

PROP_RDFS_COMMENT

public static final String PROP_RDFS_COMMENT
URI for RDF comments.

See Also:
Constant Field Values

PROP_RDFS_LABEL

public static final String PROP_RDFS_LABEL
URI for RDF labels.

See Also:
Constant Field Values

TYPE_RDFS_CLASS

public static final String TYPE_RDFS_CLASS
URI for RDFS class.

See Also:
Constant Field Values

TYPE_RDF_LIST

public static final String TYPE_RDF_LIST
URI for RDF lists.

See Also:
Constant Field Values

uAAL_NAMESPACE_PREFIX

public static final String uAAL_NAMESPACE_PREFIX
URI prefix for the universAAL namespace.

See Also:
Constant Field Values

uAAL_SERVICE_NAMESPACE

public static final String uAAL_SERVICE_NAMESPACE
URI for the universAAL service namespace.

See Also:
Constant Field Values

uAAL_VOCABULARY_NAMESPACE

public static final String uAAL_VOCABULARY_NAMESPACE
URI for the universAAL namespace.

See Also:
Constant Field Values

PROP_uAAL_INVOLVED_HUMAN_USER

public static final String PROP_uAAL_INVOLVED_HUMAN_USER
URI for properties linking to the user involved.

See Also:
Constant Field Values

PROP_SERIALIZATION_UNDEFINED

public static final int PROP_SERIALIZATION_UNDEFINED
Legal return values for getPropSerializationType(String). PROP_SERIALIZATION_UNDEFINED says that, when serializing an instance of this class in a minimized way, it is undefined whether a property can be ignored.

See Also:
Constant Field Values

PROP_SERIALIZATION_OPTIONAL

public static final int PROP_SERIALIZATION_OPTIONAL
Legal return values for getPropSerializationType(String). PROP_SERIALIZATION_OPTIONAL says that, when serializing an instance of this class in a minimized way, a property can be ignored.

See Also:
Constant Field Values

PROP_SERIALIZATION_REDUCED

public static final int PROP_SERIALIZATION_REDUCED
Legal return values for getPropSerializationType(String). PROP_SERIALIZATION_REDUCED says that, when serializing an instance of this class in a minimized way, a property must be included but the value can be represented in its reduced form.

See Also:
Constant Field Values

PROP_SERIALIZATION_FULL

public static final int PROP_SERIALIZATION_FULL
Legal return values for getPropSerializationType(String). PROP_SERIALIZATION_FULL says that, when serializing an instance of this class in a minimized way, a property must be included in its full form.

See Also:
Constant Field Values

uri

protected final String uri
URI of this resource, or URIref (URI plus fragment identifier, separated by the symbol '#').


ns_delim_index

protected final int ns_delim_index
For a given URIref, 'ns_delim_index' is the index of the delimiter (the symbol '#'), or -1 if there is no delimiter.


props

protected final Hashtable props
The properties denote the RDF triples of this resource, realized as Hashtable. The RDF subject is this Resource itself, the key of the Hashtable is the RDF predicate and the value of the Hashtable is the RDF object, which can be a literal or another resource. See setProperty(String propURI, Object value) for more information.


blockAddingTypes

protected boolean blockAddingTypes
A resource can have one or more RDF types which are represented in this class as a property with key (RDF predicate) 'rdf:type' and an ArrayList as value (RDF object). Types are added by calling addType(String typeURI, boolean blockFurtherTypes). If only one type is possible, this attribute indicates that not more than one type can be added.


isXMLLiteral

protected boolean isXMLLiteral
true, if this resource is an XML Literal.

Constructor Detail

Resource

public Resource()
Constructor to create a new Resource with anonymous URI.


Resource

public Resource(boolean isXMLLiteral)
Constructor to create a new Resource with anonymous URI. The Resource may be an XML Literal.


Resource

public Resource(String uri)
Constructor to create a new Resource with the specified URI.


Resource

public Resource(String uri,
                boolean isXMLLiteral)
Constructor to create a new Resource with the specified URI. The Resource may be an XML Literal.


Resource

protected Resource(String uriPrefix,
                   int numProps)
Creates an instance of Resource with a URI that is created by appending a unique ID to the given 'uriPrefix'. This constructor has a pseudo parameter 'numProps' in order to make it distinct from the other constructor that also takes a string. Later versions of Resource may decide to make some use of numProps in some way, however.

Parameters:
uriPrefix - Prefix of the URI.
numProps - Not used.
Method Detail

asRDFList

public static final Resource asRDFList(List members,
                                       boolean isXMLLiteral)
Creates a new Resource instance which is treated as an RDF list and contains the specified list of elements.

Parameters:
members - The elements of the list. This will be treated as separate Resources to be part of the resulting list.
isXMLLiteral - true, if the resources in the list are XML Literals.
Returns:
A Resource which represents the list.

generateAnonURI

public static final String generateAnonURI()
Create a new anonymous URI. The URI starts with the typical String for anonymous URIs followed by a unique ID.


getResource

public static Resource getResource(String classURI,
                                   String instanceURI)
Get a Resource with the given class and instance URI.

Parameters:
classURI - The URI of the class.
instanceURI - The URI of the instance.
Returns:
The Resource object with the given 'instanceURI', or a new Resource, if it does not exist.
See Also:
OntologyManagement.getResource(String, String)

isAnon

public static final boolean isAnon(String uri)
Determines if the specified URI is an anonymous URI, i.e. it is either null or starts with the the String typical for anonymous URIs.

See Also:
ANON_URI_PREFIX

isQualifiedName

public static final boolean isQualifiedName(String uri)
Determines if the specified URI is a qualified name (see StringUtils.isQualifiedName(String) ) and is not an anonymous URI.


addType

public boolean addType(String typeURI,
                       boolean blockFurtherTypes)
Set or add the type of this Resource. The type complies to rdf:type. A Resource can have multiple types.

Parameters:
typeURI - URI of the type.
blockFurtherTypes - If true, no further types can be added.

asList

public List asList()
If this Resource represents an RDF List, retrieve the elements as List.

Returns:
The list containing the elements of this RDF list.

asList

public void asList(List l)
If this Resource represents an RDF List, retrieve the elements as List.

Parameters:
l - The list to store the elements of this RDF list.

changeProperty

public boolean changeProperty(String propURI,
                              Object value)
Change the value (RDF object) of the specified property (RDF predicate) to the given object. If the value can't be set, it is ensured that the original value is restored.

Parameters:
propURI - The value has to be changed for this property.
value - The new value.
Returns:
true, if the value could be set.

copy

public Resource copy(boolean isXMLLiteral)
Create a copy of this resource. This method only creates a copy of this resource and the property references, but not of the property values. If all resources of the RDF graph should be copied, use deepCopy().

Returns:
the copied resource as a non-specialized instance of Resource, not a subclass of it (Note: future versions may change this and return a specialized copy).
See Also:
#copyAsNonXMLLiteral()

deepCopy

public Resource deepCopy()
Create a deep copy of this Resource, i.e. create a new Resource for this object and for the resources of all properties. The copied resources are specialized according to the type information stored in the rdf:type property.

Returns:
The copied Resource.

equals

public boolean equals(Object other)
Determines if this Resource equals the specified Resource.

Overrides:
equals in class Object

getResourceComment

public String getResourceComment()
Get the Resource comment. Convenient method to retrieve rdfs:comment.

Returns:
the comment of this resource.

getResourceLabel

public String getResourceLabel()
Get the Resource label. Convenient method to retrieve rdfs:label.

Returns:
the label of this resource.

getDefaultLang

public String getDefaultLang()
Get the default language. The language has the form of a language tag according to ISO 639-1 (e.g. "en").

Returns:
the default language.

getOrConstructLabel

public String getOrConstructLabel(String type)
If this resource has no original label, constructs one for it without changing the resource itself.

Parameters:
type - The optional type to be used instead of the return value of 'getType()' when constructing a label
Returns:
if there is an original label, that one is returned; otherwise a label constructed on-the-fly will be returned

getLocalName

public String getLocalName()
Get the local name which is the part of the URI after the delimiter ('#').

Returns:
The local name of the URI of this resource.
See Also:
getNamespace(), getFilename()

getNamespace

public String getNamespace()
Get the namespace of the URI which is the start of the URI including the delimiter ('#'). It is the URI without the local name.

Returns:
The namespace of the URI of this resource.
See Also:
getLocalName(), getFilename()

getFilename

public String getFilename()
Get the filename of the URI which is the part after the last '/' and before the symbols '?' and '#'.

Returns:
The filename of the URI of this resource.
See Also:
getLocalName(), getNamespace()

getProperty

public Object getProperty(String propURI)
Get the RDF object for a specified property.

Parameters:
propURI - URI of the property.
Returns:
The object for the given property.

getPropertyURIs

public Enumeration getPropertyURIs()
Get all properties, i.e. all RDF predicates for this Resource.


getPropSerializationType

public int getPropSerializationType(String propURI)
Answers if the given property has to be considered when serializing this individual in a minimized way, and if not ignore-able, whether its value should be presented in its full form or can be reduced. The return value must be one of PROP_SERIALIZATION_OPTIONAL, PROP_SERIALIZATION_REDUCED, or PROP_SERIALIZATION_FULL. It can be assumed that the given property is one of those returned by getPropertyURIs().
Decision criterion should be if the value of this property is absolutely necessary when this resource is being sent to a remote node. If the subclass rates it as unlikely that the receiver side would need this info, the answer should be PROP_SERIALIZATION_OPTIONAL in favor of lower communication traffic and higher performance even at risk of a possible additional query on the receiver side for fetching this info. With the same rationale, if a property should be included in the process of serialization, it is preferable to include it in a reduced form; in this case the return value should be PROP_SERIALIZATION_REDUCED, otherwise PROP_SERIALIZATION_FULL can be returned. Subclasses should normally overwrite this method as this default implementation returns always PROP_SERIALIZATION_FULL.


getStaticFieldValue

public Object getStaticFieldValue(String fieldName,
                                  Object defaultValue)
Helper method to get the static field of the java class with the given field name. If the field is not defined in this class, the given default value is returned.

Parameters:
fieldName - Name of the static field of the java class to retrieve.
defaultValue - Default value, if the field could not be retrieved.
Returns:
The value of the field.

getType

public String getType()
Returns the URI of the first type added to the list of types of this resource.


getTypes

public String[] getTypes()
Returns the URIs of all known types of this resource.


getURI

public String getURI()
Get the URI.


hashCode

public int hashCode()
Get the hash code for this Resource, calculated from the URI.

Overrides:
hashCode in class Object

hasProperty

public boolean hasProperty(String propURI)
Determines if this Resource has the specified property.


hasQualifiedName

public boolean hasQualifiedName()
Determines if this Resource has a qualified, i.e. the URI has a delimiter ('#').


isAnon

public boolean isAnon()
Determines if this Resource has an anonymous URI.


isClosedCollection

public boolean isClosedCollection(String propURI)
Returns true if the value of the given property should be treated as an rdf:List. Serializers can use this to determine if a multi-valued property should be serialized using the concept of rdf:List or the property should appear as often as the number of values assigned to the property. The default behavior is that a property associated with an instance of List is assumed to be a closed collection (unless it is specifically an instance of OpenCollection). Subclasses can change this, if needed.


isBlockingAddingTypes

public boolean isBlockingAddingTypes()
Determines whether this Resource does not allow to add new type information.

Returns:
true, if this Resource does not allow to add new type information.

isWellFormed

public boolean isWellFormed()
Returns true, if the state of the resource is valid, otherwise false.

Subclasses should overwrite this methods as the default implementation returns always true.


numberOfProperties

public int numberOfProperties()
Returns the number of properties, i.e. the number of RDF predicates for this Resource.


representsQualifiedURI

public boolean representsQualifiedURI()

serializesAsXMLLiteral

public boolean serializesAsXMLLiteral()
Resources to be serialized and parsed as rdf:XMLLiteral must overwrite this method and return true. Serializers and parsers can use this as a hint.


setResourceComment

public void setResourceComment(String comment)
Set the Resource comment. Convenient method to set rdfs:comment.


setResourceLabel

public void setResourceLabel(String label)
Set the Resource label. Convenient method to set rdfs:label.


addMultiLangProp

public void addMultiLangProp(String propURI,
                             LangString ls)
Add a new String literal (with optional language tag) to a multi-value property.

Parameters:
propURI - URI of the property. Typical values are PROP_RDFS_LABEL or PROP_RDFS_COMMENT.
ls - The String to add.

getMultiLangProp

public LangString getMultiLangProp(String propURI,
                                   String lang,
                                   boolean includeDefault)
Get a String literal (with optional language tag) from a multi-value property.

Parameters:
propURI - URI of the property. Typical values are PROP_RDFS_LABEL or PROP_RDFS_COMMENT.
lang - The preferred language.
includeDefault - If no String with the preferred language could be found, this variable determines if a String without language specifier could also be returned.
Returns:
The value of the multi-value property.

setProperty

public boolean setProperty(String propURI,
                           Object value)
Adds a statement with this resource as the subject, the given propURI as the predicate and the given value as the object. Subclasses must override this in order to decide if the statement to be added fits the general class constraints. If not, the call of this method should be ignored. For each property only one single call may be made to this method, unless subsequent calls to this method for setting the value of the same property are treated as an update for an update-able property. Multi-valued properties must be set using an instance of List. The differentiation, if a such list should be treated as an rdf:List, can be made with the help of isClosedCollection(String). The default implementation here accepts all property-value pairs blindly except for rdf:type which is handled if the value is a type URI, a Resource or a java.util.List of them.

Note: The setting of the property rdf:type is being handled by this class via the final methods addType(String, boolean), getType(), and getTypes(). Although these methods give the view of handling type URIs as strings, but in reality the types are stored as direct instances of this class. So, the subclasses should ignore calls for setting rdf:type; if not, then the subclass must pay attention that the value should be a List of direct instances of this class so that (1) the toString() method returns just the URI and (2) the serializers get no problems with the value. Also, settings via subclasses may be overwritten by this class if a subsequent call to addType(String, boolean) is made.

Returns:
true if the property changed as a result of the call

setPropertyPath

public boolean setPropertyPath(String[] propPath,
                               Object value)
Set the given value at the end of the given property path, but does not force the setting.

See Also:
setPropertyPathFromOffset(String[], int, Object, boolean)

setPropertyPath

public boolean setPropertyPath(String[] propPath,
                               Object value,
                               boolean force)
Set the given value at the end of the given property path.

See Also:
setPropertyPathFromOffset(String[], int, Object, boolean)

setPropertyPathFromOffset

public boolean setPropertyPathFromOffset(String[] propPath,
                                         int fromIndex,
                                         Object value,
                                         boolean force)
Change or add the Resource at the end of the given property path to the given value. This method starts from this Resource and follows the given property path through the RDF graph. If a property from the path does not yet exist, a new anonymous Resource is automatically created. At the end of the property path, the given value is set as RDF object with the last property from the path as RDF predicate.

Parameters:
propPath - The set of properties defining the path through the RDF graph.
fromIndex - The property path is evaluated from this index on; if 'fromIndex' is greater than zero, then some entries at the beginning are just ignored.
value - The value to set at the end of the property path
force - Determines if setting the value has to be forced. If true, changeProperty(String, Object) is called, otherwise setProperty(String, Object) is called.
Returns:
true, if the operation was successful.

toString

public String toString()
Get a String representation of this Resource; returns the URI.

Overrides:
toString in class Object

toStringRecursive

public String toStringRecursive()
Debug method: get a string of this RDF graph.

Returns:
The graph as string.

toStringRecursive

public String toStringRecursive(String prefix,
                                boolean prefixAtStart,
                                Hashtable visitedElements)
Debug method: get a string of this RDF graph.

Parameters:
prefix - Indention string that every line starts with.
prefixAtStart - True iff the first line should start with the prefix string.
Returns:
The graph as string.

unliteral

public void unliteral()
Make this object not being an XMLLiteral


literal

public void literal()
Make this object an XMLLiteral



Copyright © 2014 universAAL Consortium. All Rights Reserved.