public class Resource extends Object
Modifier and Type | Field and Description |
---|---|
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.
|
static String |
NAMESPACE_PREFIX
URI prefix for the universAAL namespace.
|
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_INVOLVED_HUMAN_USER
URI for properties linking to the user involved.
|
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) . |
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 |
SERVICE_NAMESPACE
URI for the universAAL service namespace.
|
static String |
TYPE_RDF_LIST
URI for RDF lists.
|
static String |
TYPE_RDFS_CLASS
URI for RDFS class.
|
protected String |
uri
URI of this resource, or URIref (URI plus fragment identifier, separated
by the symbol '#').
|
static String |
VOCABULARY_NAMESPACE
URI for the universAAL namespace.
|
Modifier | Constructor and Description |
---|---|
|
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'.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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 '?' and '#'.
|
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.
|
String |
getOrConstructLabel(String type,
String lang)
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.
|
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.
|
String |
getResourceLabel(String lang)
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.
|
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.
|
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.
|
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
|
protected static final String ANON_URI_PREFIX
public static final String RDF_NAMESPACE
public static final String RDFS_NAMESPACE
public static final String RDF_EMPTY_LIST
public static final String PROP_RDF_FIRST
public static final String PROP_RDF_REST
public static final String PROP_RDF_TYPE
public static final String PROP_RDFS_COMMENT
public static final String PROP_RDFS_LABEL
public static final String TYPE_RDFS_CLASS
public static final String TYPE_RDF_LIST
public static final String NAMESPACE_PREFIX
public static final String SERVICE_NAMESPACE
public static final String VOCABULARY_NAMESPACE
public static final String PROP_INVOLVED_HUMAN_USER
public static final int PROP_SERIALIZATION_UNDEFINED
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.public static final int PROP_SERIALIZATION_OPTIONAL
getPropSerializationType(String)
.
PROP_SERIALIZATION_OPTIONAL
says that, when serializing an
instance of this class in a minimized way, a property can be ignored.public static final int PROP_SERIALIZATION_REDUCED
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.public static final int PROP_SERIALIZATION_FULL
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.protected final String uri
protected final int ns_delim_index
protected final Hashtable props
setProperty(String propURI, Object value)
for more information.protected boolean blockAddingTypes
addType(String typeURI, boolean blockFurtherTypes)
. If only one
type is possible, this attribute indicates that not more than one type
can be added.protected boolean isXMLLiteral
public Resource()
public Resource(boolean isXMLLiteral)
public Resource(String uri)
public Resource(String uri, boolean isXMLLiteral)
protected Resource(String uriPrefix, int numProps)
uriPrefix
- Prefix of the URI.numProps
- Not used.public static final Resource asRDFList(List members, boolean isXMLLiteral)
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.public static final String generateAnonURI()
public static Resource getResource(String classURI, String instanceURI)
classURI
- The URI of the class.instanceURI
- The URI of the instance.OntologyManagement.getResource(String, String)
public static final boolean isAnon(String uri)
ANON_URI_PREFIX
public static final boolean isQualifiedName(String uri)
StringUtils.isQualifiedName(String)
) and is not an anonymous URI.public boolean addType(String typeURI, boolean blockFurtherTypes)
typeURI
- URI of the type.blockFurtherTypes
- If true, no further types can be added.public List asList()
List
.public void asList(List l)
List
.l
- The list to store the elements of this RDF list.public boolean changeProperty(String propURI, Object value)
propURI
- The value has to be changed for this property.value
- The new value.public Resource copy(boolean isXMLLiteral)
deepCopy()
.Resource
, not a subclass of it (Note: future versions may
change this and return a specialized copy).#copyAsNonXMLLiteral()
public Resource deepCopy()
public boolean equals(Object other)
public String getResourceComment()
public String getResourceLabel()
public String getResourceLabel(String lang)
lang
- The preferred language. Should be one of the constants defined
in LangString
, e.g. LangString.LANG_ENGLISH
.public String getDefaultLang()
public String getOrConstructLabel(String type)
type
- The optional type to be used instead of the return value of
'getType()' when constructing a labelpublic String getOrConstructLabel(String type, String lang)
type
- The optional type to be used instead of the return value of
'getType()' when constructing a labellang
- The preferred language. Should be one of the constants defined
in LangString
, e.g. LangString.LANG_ENGLISH
.public String getLocalName()
getNamespace()
,
getFilename()
public String getNamespace()
getLocalName()
,
getFilename()
public String getFilename()
getLocalName()
,
getNamespace()
public Object getProperty(String propURI)
propURI
- URI of the property.public Enumeration getPropertyURIs()
public int getPropSerializationType(String propURI)
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()
. 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
.public Object getStaticFieldValue(String fieldName, Object defaultValue)
fieldName
- Name of the static field of the java class to retrieve.defaultValue
- Default value, if the field could not be retrieved.public String getType()
public String[] getTypes()
public String getURI()
public int hashCode()
public boolean hasProperty(String propURI)
public boolean hasQualifiedName()
public boolean isAnon()
public boolean isClosedCollection(String propURI)
List
is assumed to be a closed collection
(unless it is specifically an instance of OpenCollection
).
Subclasses can change this, if needed.public boolean isBlockingAddingTypes()
public boolean isWellFormed()
Subclasses should overwrite this methods as the default implementation returns always true.
public int numberOfProperties()
public boolean representsQualifiedURI()
public boolean serializesAsXMLLiteral()
public void setResourceComment(String comment)
comment
- the comment.public void setResourceLabel(String label)
label
- the label.public void addMultiLangProp(String propURI, LangString ls)
propURI
- URI of the property. Typical values are
PROP_RDFS_LABEL
or PROP_RDFS_COMMENT
.ls
- The String to add.public LangString getMultiLangProp(String propURI, String lang, boolean includeDefault)
propURI
- URI of the property. Typical values are
PROP_RDFS_LABEL
or PROP_RDFS_COMMENT
.lang
- The preferred language. Should be one of the constants defined
in LangString
, e.g. LangString.LANG_ENGLISH
.includeDefault
- If no String with the preferred language could be found, this
variable determines if a String without language specifier
could also be returned.public boolean setProperty(String propURI, Object value)
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.
public boolean setPropertyPath(String[] propPath, Object value)
public boolean setPropertyPath(String[] propPath, Object value, boolean force)
public boolean setPropertyPathFromOffset(String[] propPath, int fromIndex, Object value, boolean force)
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 pathforce
- Determines if setting the value has to be forced. If true,
changeProperty(String, Object)
is called, otherwise
setProperty(String, Object)
is called.public String toString()
public String toStringRecursive()
public String toStringRecursive(String prefix, boolean prefixAtStart, Hashtable visitedElements)
prefix
- Indention string that every line starts with.prefixAtStart
- True iff the first line should start with the prefix string.public void unliteral()
public void literal()
Copyright © 2018 universAAL Consortium. All rights reserved.