org.universAAL.middleware.rdf
Class UnmodifiableResource

Package class diagram package UnmodifiableResource
java.lang.Object
  extended by org.universAAL.middleware.rdf.Resource
      extended by org.universAAL.middleware.rdf.UnmodifiableResource

public final class UnmodifiableResource
extends Resource

A Resource that can not be modified.

Author:
Carsten Stockloew

Field Summary
 
Fields inherited from class org.universAAL.middleware.rdf.Resource
ANON_URI_PREFIX, blockAddingTypes, isXMLLiteral, ns_delim_index, PROP_RDF_FIRST, PROP_RDF_REST, PROP_RDF_TYPE, PROP_RDFS_COMMENT, PROP_RDFS_LABEL, PROP_SERIALIZATION_FULL, PROP_SERIALIZATION_OPTIONAL, PROP_SERIALIZATION_REDUCED, PROP_SERIALIZATION_UNDEFINED, PROP_uAAL_INVOLVED_HUMAN_USER, props, RDF_EMPTY_LIST, RDF_NAMESPACE, RDFS_NAMESPACE, TYPE_RDF_LIST, TYPE_RDFS_CLASS, uAAL_NAMESPACE_PREFIX, uAAL_SERVICE_NAMESPACE, uAAL_VOCABULARY_NAMESPACE, uri
 
Constructor Summary
UnmodifiableResource(Resource r)
           
 
Method Summary
 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.
 boolean changeProperty(String propURI, Object value)
          Change the value (RDF object) of the specified property (RDF predicate) to the given object.
 Resource copy(boolean isXMLLitera)
          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.
 Class getClassOfUnmodifiable()
           
 String getLocalName()
          Get the local name which is the part of the URI after the delimiter ('#').
 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.
 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.
static Object getUnmodifiable(Object o)
          Get an unmodifiable version of the given object.
 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 instanceOf(Class c)
           
 boolean isAnon()
          Determines if this Resource has an anonymous URI.
 boolean isClosedCollection(String propURI)
          Returns true if the value of the given property should be treated as an rdf:List.
 boolean isWellFormed()
          Returns true, if the state of the resource is valid, otherwise false.
 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.
 
Methods inherited from class org.universAAL.middleware.rdf.Resource
addMultiLangProp, asRDFList, generateAnonURI, getDefaultLang, getFilename, getMultiLangProp, getResource, isAnon, isBlockingAddingTypes, isQualifiedName, literal, unliteral
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnmodifiableResource

public UnmodifiableResource(Resource r)
Method Detail

getUnmodifiable

public static Object getUnmodifiable(Object o)
Get an unmodifiable version of the given object. If the parameter is a Resource, an UnmodifiableResource is returned. If the parameter is a List, an UnmodifiableResourceList is returned.

Parameters:
o - The object for which an unmodifiable version should be returned.
Returns:
The unmodifiable version.

changeProperty

public boolean changeProperty(String propURI,
                              Object value)
Description copied from class: Resource
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.

Overrides:
changeProperty in class Resource
Parameters:
propURI - The value has to be changed for this property.
value - The new value.
Returns:
true, if the value could be set.
See Also:
Resource.changeProperty(String, Object)

getProperty

public final Object getProperty(String propURI)
Description copied from class: Resource
Get the RDF object for a specified property.

Overrides:
getProperty in class Resource
Parameters:
propURI - URI of the property.
Returns:
The object for the given property.
See Also:
Resource.getProperty(String)

setProperty

public boolean setProperty(String propURI,
                           Object value)
Description copied from class: Resource
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 Resource.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 Resource.addType(String, boolean), Resource.getType(), and Resource.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 Resource.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 Resource.addType(String, boolean) is made.

Overrides:
setProperty in class Resource
Returns:
true if the property changed as a result of the call
See Also:
Resource.setProperty(String, Object)

setPropertyPath

public boolean setPropertyPath(String[] propPath,
                               Object value,
                               boolean force)
Description copied from class: Resource
Set the given value at the end of the given property path.

Overrides:
setPropertyPath in class Resource
See Also:
Resource.setPropertyPath(String[], Object, boolean)

setPropertyPath

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

Overrides:
setPropertyPath in class Resource
See Also:
Resource.setPropertyPath(String[], Object)

setPropertyPathFromOffset

public boolean setPropertyPathFromOffset(String[] propPath,
                                         int fromIndex,
                                         Object value,
                                         boolean force)
Description copied from class: Resource
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.

Overrides:
setPropertyPathFromOffset in class Resource
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, Resource.changeProperty(String, Object) is called, otherwise Resource.setProperty(String, Object) is called.
Returns:
true, if the operation was successful.
See Also:
Resource.setPropertyPathFromOffset(String[], int, Object, boolean)

asList

public List asList()
Description copied from class: Resource
If this Resource represents an RDF List, retrieve the elements as List.

Overrides:
asList in class Resource
Returns:
The list containing the elements of this RDF list.

asList

public void asList(List l)
Description copied from class: Resource
If this Resource represents an RDF List, retrieve the elements as List.

Overrides:
asList in class Resource
Parameters:
l - The list to store the elements of this RDF list.

copy

public Resource copy(boolean isXMLLitera)
Description copied from class: Resource
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 Resource.deepCopy().

Overrides:
copy in class Resource
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()
Description copied from class: Resource
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.

Overrides:
deepCopy in class Resource
Returns:
The copied Resource.

equals

public boolean equals(Object other)
Description copied from class: Resource
Determines if this Resource equals the specified Resource.

Overrides:
equals in class Resource

getOrConstructLabel

public String getOrConstructLabel(String type)
Description copied from class: Resource
If this resource has no original label, constructs one for it without changing the resource itself.

Overrides:
getOrConstructLabel in class Resource
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

getPropSerializationType

public int getPropSerializationType(String propURI)
Description copied from class: Resource
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 Resource.PROP_SERIALIZATION_OPTIONAL, Resource.PROP_SERIALIZATION_REDUCED, or Resource.PROP_SERIALIZATION_FULL. It can be assumed that the given property is one of those returned by Resource.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.

Overrides:
getPropSerializationType in class Resource

getResourceComment

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

Overrides:
getResourceComment in class Resource
Returns:
the comment of this resource.

getResourceLabel

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

Overrides:
getResourceLabel in class Resource
Returns:
the label of this resource.

getStaticFieldValue

public Object getStaticFieldValue(String fieldName,
                                  Object defaultValue)
Description copied from class: Resource
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.

Overrides:
getStaticFieldValue in class Resource
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.

hashCode

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

Overrides:
hashCode in class Resource

hasProperty

public boolean hasProperty(String propURI)
Description copied from class: Resource
Determines if this Resource has the specified property.

Overrides:
hasProperty in class Resource

isClosedCollection

public boolean isClosedCollection(String propURI)
Description copied from class: Resource
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.

Overrides:
isClosedCollection in class Resource

isWellFormed

public boolean isWellFormed()
Description copied from class: Resource
Returns true, if the state of the resource is valid, otherwise false.

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

Overrides:
isWellFormed in class Resource

representsQualifiedURI

public boolean representsQualifiedURI()
Overrides:
representsQualifiedURI in class Resource

serializesAsXMLLiteral

public boolean serializesAsXMLLiteral()
Description copied from class: Resource
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.

Overrides:
serializesAsXMLLiteral in class Resource

setResourceComment

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

Overrides:
setResourceComment in class Resource

setResourceLabel

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

Overrides:
setResourceLabel in class Resource

toString

public String toString()
Description copied from class: Resource
Get a String representation of this Resource; returns the URI.

Overrides:
toString in class Resource

toStringRecursive

public String toStringRecursive()
Description copied from class: Resource
Debug method: get a string of this RDF graph.

Overrides:
toStringRecursive in class Resource
Returns:
The graph as string.

toStringRecursive

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

Overrides:
toStringRecursive in class Resource
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.

numberOfProperties

public int numberOfProperties()
Description copied from class: Resource
Returns the number of properties, i.e. the number of RDF predicates for this Resource.

Overrides:
numberOfProperties in class Resource

isAnon

public boolean isAnon()
Description copied from class: Resource
Determines if this Resource has an anonymous URI.

Overrides:
isAnon in class Resource
See Also:
Resource.isAnon()

hasQualifiedName

public final boolean hasQualifiedName()
Description copied from class: Resource
Determines if this Resource has a qualified, i.e. the URI has a delimiter ('#').

Overrides:
hasQualifiedName in class Resource
See Also:
Resource.hasQualifiedName()

getURI

public final String getURI()
Description copied from class: Resource
Get the URI.

Overrides:
getURI in class Resource
See Also:
Resource.getURI()

getPropertyURIs

public final Enumeration getPropertyURIs()
Description copied from class: Resource
Get all properties, i.e. all RDF predicates for this Resource.

Overrides:
getPropertyURIs in class Resource
See Also:
Resource.getPropertyURIs()

addType

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

Overrides:
addType in class Resource
Parameters:
typeURI - URI of the type.
blockFurtherTypes - If true, no further types can be added.
See Also:
Resource.addType(String, boolean)

getLocalName

public final String getLocalName()
Description copied from class: Resource
Get the local name which is the part of the URI after the delimiter ('#').

Overrides:
getLocalName in class Resource
Returns:
The local name of the URI of this resource.
See Also:
Resource.getLocalName()

getNamespace

public final String getNamespace()
Description copied from class: Resource
Get the namespace of the URI which is the start of the URI including the delimiter ('#'). It is the URI without the local name.

Overrides:
getNamespace in class Resource
Returns:
The namespace of the URI of this resource.
See Also:
Resource.getNamespace()

getType

public final String getType()
Description copied from class: Resource
Returns the URI of the first type added to the list of types of this resource.

Overrides:
getType in class Resource
See Also:
Resource.getType()

getTypes

public final String[] getTypes()
Description copied from class: Resource
Returns the URIs of all known types of this resource.

Overrides:
getTypes in class Resource
See Also:
Resource.getTypes()

getClassOfUnmodifiable

public final Class getClassOfUnmodifiable()

instanceOf

public final boolean instanceOf(Class c)


Copyright © 2014 universAAL Consortium. All Rights Reserved.