com.hp.hpl.jena.daml.common
Class DAMLCommonImpl

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.common.ResourceImpl
        |
        +--com.hp.hpl.jena.daml.common.DAMLCommonImpl
All Implemented Interfaces:
DAMLCommon, RDFNode, Resource, ResourceI
Direct Known Subclasses:
DAMLClassImpl, DAMLDataInstanceImpl, DAMLDatatypeImpl, DAMLDisjointImpl, DAMLInstanceImpl, DAMLListImpl, DAMLOntologyImpl, DAMLPropertyImpl

public abstract class DAMLCommonImpl
extends ResourceImpl
implements DAMLCommon

Abstract super-class for all DAML resources (including properties). Defines shared implementations and common services, such as property manipulation, vocabulary management and rdf:type management. Also defines accessors for common properties, such as comment, label, and equivalentTo.

Version:
CVS info: $Id: DAMLCommonImpl.java,v 1.8 2002/03/05 14:14:53 ian_dickinson Exp $
Author:
Ian Dickinson, HP Labs (email)

Constructor Summary
DAMLCommonImpl(java.lang.String uri, DAMLModel model, DAMLVocabulary vocabulary)
          Constructor, takes the URI this value, and the underlying model it will be attached to.
DAMLCommonImpl(java.lang.String namespace, java.lang.String name, DAMLModel model, DAMLVocabulary vocabulary)
          Constructor, takes the name and namespace for this value, and the underlying model it will be attached to.
 
Method Summary
 java.util.Iterator getAll(Property property, boolean closed)
          Answer an iterator over a set of resources that are the objects of statements with subject this DAML object and predicate the given property.
 DAMLModel getDAMLModel()
          Answer the underlying model
 java.util.Iterator getEquivalenceSet()
          Answer the set of equivalent values to this value, but not including the value itself.
 java.util.Iterator getEquivalentValues()
          Answer an iterator over all of the DAML objects that are equivalent to this value under the daml:equivalentTo relation.
 int getNumPropertyValues(Property property)
          Answer the number of values a given property has with this value as subject.
 RDFNode getPropertyValue(Property property)
          Answer the value of a given RDF property for this DAML value, or null if it doesn't have one.
 NodeIterator getPropertyValues(Property property)
          Answer an iterator over the set of all values for a given RDF property.
 java.util.Iterator getRDFTypes(boolean closed)
          Answer an iterator over all of the types to which this class belongs.
 java.util.Iterator getSelfIterator()
          Answer an iterator that contains exactly this value.
 DAMLVocabulary getVocabulary()
          Answer the DAML+OIL vocabulary that corresponds to the namespace that this value was declared in.
 boolean hasRDFType(Resource damlClass)
          Answer true if this DAML value is a member of the class denoted by the given DAML class object.
 boolean hasRDFType(java.lang.String classURI)
          Answer true if this DAML value is a member of the class denoted by the given URI.
 LiteralAccessor prop_comment()
          Accessor for the property of the comment on the value, whose value is a literal (string).
 PropertyAccessor prop_equivalentTo()
          Property accessor for the 'equivalentTo' property of a DAML value.
 LiteralAccessor prop_label()
          Accessor for the property of the label on the value, whose value is a literal (string).
 PropertyAccessor prop_type()
          Property accessor for the 'rdf:type' property of a DAML value.
 void remove()
          Remove the DAML object from the model.
 void removeAll(Property prop)
          Remove all the values for a given property on this DAML resource.
 void removeProperty(Property property, RDFNode value)
          Remove the specific RDF property-value pair from this DAML resource.
 void replaceProperty(Property prop, RDFNode value)
          Replace the value of the named property with the given value.
 void setPropertyValue(Property property, RDFNode value)
          Set the value of the given property of this DAML value to the given value, encoded as an RDFNode.
 void setRDFType(Resource rdfClass)
          Set the RDF type property for this node in the underlying model, replacing any existing type property.
 void setRDFType(Resource rdfClass, boolean replace)
          Add an RDF type property for this node in the underlying model.
 java.lang.String toString()
          Return a readable representation of the DAML value
 
Methods inherited from class com.hp.hpl.mesa.rdf.jena.common.ResourceImpl
abort, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getEmbeddedResource, getId, getLocalName, getModel, getNameSpace, getProperty, getURI, hashCode, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, isAnon, listProperties, listProperties, port, removeProperties
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.Resource
abort, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getId, getLocalName, getModel, getNameSpace, getProperty, getURI, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, isAnon, listProperties, listProperties, removeProperties
 

Constructor Detail

DAMLCommonImpl

public DAMLCommonImpl(java.lang.String uri,
                      DAMLModel model,
                      DAMLVocabulary vocabulary)
Constructor, takes the URI this value, and the underlying model it will be attached to.
Parameters:
uri - The URI of the DAML value, or null for an anonymous node.
model - Reference to the DAML model that will contain statements about this DAML value.
vocabulary - The vocabulary for this value (defines the namespace). Can be null, in which case the vocabulary defaults to the most recent.

DAMLCommonImpl

public DAMLCommonImpl(java.lang.String namespace,
                      java.lang.String name,
                      DAMLModel model,
                      DAMLVocabulary vocabulary)
Constructor, takes the name and namespace for this value, and the underlying model it will be attached to.
Parameters:
namespace - The namespace the class inhabits, or null
name - The name of the DAML value
model - Reference to the DAML model that will contain statements about this DAML class.
vocabulary - The vocabulary for this value (defines the namespace). Can be null, in which case the vocabulary defaults to the most recent.
Method Detail

getDAMLModel

public DAMLModel getDAMLModel()
Answer the underlying model
Specified by:
getDAMLModel in interface DAMLCommon
Returns:
A DAML model

setRDFType

public void setRDFType(Resource rdfClass)
Set the RDF type property for this node in the underlying model, replacing any existing type property. To add a second or subsequent type statement to a resource, use setRDFType( Resource, false ) .
Specified by:
setRDFType in interface DAMLCommon
Parameters:
rdfClass - The RDF resource denoting the new value for the rdf:type property, which will replace any existing type property.

setRDFType

public void setRDFType(Resource rdfClass,
                       boolean replace)
Add an RDF type property for this node in the underlying model. If the replace flag is true, this type will replace any current type property for the node. Otherwise, the type will be in addition to any existing type property. Note that for most normal uses, a DAML resource should have at most one rdf:type property. One exception to this, in the March 2001 release, is when DatatypeProperties are marked as unique, unambiguous or transitive. This is achieved by the use of two rdf type properties.
Specified by:
setRDFType in interface DAMLCommon
Parameters:
rdfClass - The RDF resource denoting the class that will be new value for the rdf:type property.
replace - If true, the given class will replace any existing type property for this value, otherwise it will be added as an extra type statement.

hasRDFType

public boolean hasRDFType(java.lang.String classURI)
Answer true if this DAML value is a member of the class denoted by the given URI.
Specified by:
hasRDFType in interface DAMLCommon
Parameters:
classURI - String denoting the URI of the class to test against
Returns:
true if it can be shown that this DAML value is a member of the class, via rdf:type.

hasRDFType

public boolean hasRDFType(Resource damlClass)
Answer true if this DAML value is a member of the class denoted by the given DAML class object. This will traverse the class hierarchy, until every class and super-class for this DAML value has been examined. Depending on the depth of the hierarchy, this may be an expensive operation. Cycles are detected, however, so it is guaranteed to terminate.
Specified by:
hasRDFType in interface DAMLCommon
Parameters:
damlClass - Denotes a class to which this value may belong
Returns:
true if the value is a member of the class (or one of its sub-classes) via rdf:type.

getRDFTypes

public java.util.Iterator getRDFTypes(boolean closed)
Answer an iterator over all of the types to which this class belongs. Optionally, generate a closure by considering the closure of the set of classes over the class hierarchy (e.g. if 'fido' is the resource, the non-closed set of fido's classes might be {Dog, Vaccinated}, i.e. the set of classes for which rdf:type statements exist for fido, while the closed set might be {Dog, Vaccinated, Mammal, Pet, Vertebrate, Thing, MedicallyCertified}
Specified by:
getRDFTypes in interface DAMLCommon
Parameters:
closed - If true, generate the closed set by considering the super-classes of the known classes of this value.
Returns:
an iterator over the set of this value's classes (note: it is a set, so each class will only appear once)

getPropertyValue

public RDFNode getPropertyValue(Property property)
Answer the value of a given RDF property for this DAML value, or null if it doesn't have one. The value is returned as an RDFNode, from which the value can be extracted for literals. If there is more than one RDF statement with the given property for the current value, it is not defined which of the values will be returned.
Specified by:
getPropertyValue in interface DAMLCommon
Parameters:
property - An RDF property
Returns:
An RDFNode whose value is the value, or one of the values, of the given property. If the property is not defined, or an error occurs, returns null.

getPropertyValues

public NodeIterator getPropertyValues(Property property)
Answer an iterator over the set of all values for a given RDF property. Each value in the iterator will be an RDFNode, representing the value (object) of each statement in the underlying model.
Specified by:
getPropertyValues in interface DAMLCommon
Parameters:
property - The property whose values are sought
Returns:
An Iterator over the values of the property, each of which will be an RDFNode.

setPropertyValue

public void setPropertyValue(Property property,
                             RDFNode value)
Set the value of the given property of this DAML value to the given value, encoded as an RDFNode. Maintains the invariant that there is at most one value of the property for a given DAML object, so existing property values are first removed. To add multiple properties to a given DAML object, use addProperty.
Specified by:
setPropertyValue in interface DAMLCommon
Parameters:
property - The property to update
value - The new value of the property as an RDFNode, or null to effectively remove this property.

removeProperty

public void removeProperty(Property property,
                           RDFNode value)
Remove the specific RDF property-value pair from this DAML resource.
Specified by:
removeProperty in interface DAMLCommon
Parameters:
property - The property to be removed
value - The specific value of the property to be removed

removeAll

public void removeAll(Property prop)
Remove all the values for a given property on this DAML resource.
Specified by:
removeAll in interface DAMLCommon
Parameters:
prop - The RDF resource that defines the property to be removed

replaceProperty

public void replaceProperty(Property prop,
                            RDFNode value)
Replace the value of the named property with the given value. All existing values, if any, for the property are first removed.
Specified by:
replaceProperty in interface DAMLCommon
Parameters:
prop - The RDF property to be updated
value - The new value.

getNumPropertyValues

public int getNumPropertyValues(Property property)
Answer the number of values a given property has with this value as subject.
Specified by:
getNumPropertyValues in interface DAMLCommon
Parameters:
property - The property to be tested
Returns:
The number of statements with this value as subject and the given property as relation.

getAll

public java.util.Iterator getAll(Property property,
                                 boolean closed)
Answer an iterator over a set of resources that are the objects of statements with subject this DAML object and predicate the given property. Respects DAML semantics of equivalence, transitivity and the property hierarchy.
Specified by:
getAll in interface DAMLCommon
Parameters:
property - The property whose values are sought
closed - If true, and the given property is transitive, generate the closure over the given property from this value.
Returns:
An iterator of resources that are the objects of statements whose subject is this value (or one of its equivalents) and whose predicate is property or one of its equivalents

getVocabulary

public DAMLVocabulary getVocabulary()
Answer the DAML+OIL vocabulary that corresponds to the namespace that this value was declared in.
Specified by:
getVocabulary in interface DAMLCommon
Returns:
a vocabulary object

getEquivalentValues

public java.util.Iterator getEquivalentValues()
Answer an iterator over all of the DAML objects that are equivalent to this value under the daml:equivalentTo relation. The common method just tests this relation, getEquivalentValues() in sub-classes, such as DAMLClass, may extend this with specific additional semantics such as daml:sameClassAs.
Specified by:
getEquivalentValues in interface DAMLCommon
Returns:
an iterator ranging over every equivalent DAML value - each value of the iteration will be a damlCommon object.

getEquivalenceSet

public java.util.Iterator getEquivalenceSet()
Answer the set of equivalent values to this value, but not including the value itself. The iterator will range over a set: each element occurs only once.
Specified by:
getEquivalenceSet in interface DAMLCommon
Returns:
An iteration ranging over the set of values that are equivalent to this value, but not itself.

getSelfIterator

public java.util.Iterator getSelfIterator()
Answer an iterator that contains exactly this value. This is useful as we often use Iterators to stand for sets or collections, and two such iterators can be appended to form the union of the collections.
Returns:
an iterator whose sole value is this DAML value

toString

public java.lang.String toString()
Return a readable representation of the DAML value
Specified by:
toString in interface Resource
Overrides:
toString in class ResourceImpl
Returns:
a string denoting this value

remove

public void remove()
Remove the DAML object from the model. All of the RDF statements with this DAML value as its subject will be removed from the model, and this object will be removed from the indexes. It will be the responsibility of client code to ensure that references to this object are removed so that the object itself can be garbage collected.
Specified by:
remove in interface DAMLCommon

prop_label

public LiteralAccessor prop_label()
Accessor for the property of the label on the value, whose value is a literal (string).
Specified by:
prop_label in interface DAMLCommon
Returns:
Literal accessor for the label property

prop_comment

public LiteralAccessor prop_comment()
Accessor for the property of the comment on the value, whose value is a literal (string).
Specified by:
prop_comment in interface DAMLCommon
Returns:
Literal accessor for the comment property

prop_equivalentTo

public PropertyAccessor prop_equivalentTo()
Property accessor for the 'equivalentTo' property of a DAML value. This denotes that two terms have the same meaning. The spec helpfully says: for equivalentTo(X, Y), read X is an equivalent term to Y.
Specified by:
prop_equivalentTo in interface DAMLCommon
Returns:
Property accessor for 'equivalentTo'.

prop_type

public PropertyAccessor prop_type()
Property accessor for the 'rdf:type' property of a DAML value.
Specified by:
prop_type in interface DAMLCommon
Returns:
Property accessor for 'rdf:type'.


Copyright 2001 Hewlett-Packard. All Rights Reserved.