Class ResourceImpl

All Implemented Interfaces:
FrontsNode, RDFNode, Resource
Direct Known Subclasses:
ContainerImpl, OntResourceImpl, PropertyImpl, RDFListImpl

public class ResourceImpl extends EnhNode implements Resource
An implementation of Resource.
  • Field Details

  • Constructor Details

    • ResourceImpl

      public ResourceImpl(Node n, ModelCom m)
      the main constructor: make a new Resource in the given model, rooted in the given node. NOT FOR PUBLIC USE - used in ModelCom [and ContainerImpl]
    • ResourceImpl

      public ResourceImpl()
      Creates new ResourceImpl
    • ResourceImpl

      public ResourceImpl(ModelCom m)
    • ResourceImpl

      public ResourceImpl(Node n, EnhGraph m)
    • ResourceImpl

      public ResourceImpl(String uri)
    • ResourceImpl

      public ResourceImpl(String nameSpace, String localName)
    • ResourceImpl

      public ResourceImpl(AnonId id)
    • ResourceImpl

      public ResourceImpl(AnonId id, ModelCom m)
    • ResourceImpl

      public ResourceImpl(String uri, ModelCom m)
    • ResourceImpl

      public ResourceImpl(Resource r, ModelCom m)
    • ResourceImpl

      public ResourceImpl(String nameSpace, String localName, ModelCom m)
    • ResourceImpl

      public ResourceImpl(Statement statement, ModelCom m)
  • Method Details

    • visitWith

      public Object visitWith(RDFVisitor rv)
      Description copied from interface: RDFNode
      Apply the appropriate method of the visitor to this node's content and return the result.
      Specified by:
      visitWith in interface RDFNode
      Parameters:
      rv - an RDFVisitor with a method for URI/blank/literal nodes
      Returns:
      the result returned by the selected method
    • asResource

      public Resource asResource()
      Description copied from interface: RDFNode
      If this node is a Resource, answer that resource; otherwise throw an exception.
      Specified by:
      asResource in interface RDFNode
    • asLiteral

      public Literal asLiteral()
      Description copied from interface: RDFNode
      If this node is a Literal, answer that literal; otherwise throw an exception.
      Specified by:
      asLiteral in interface RDFNode
    • inModel

      public Resource inModel(Model m)
      Description copied from interface: Resource
      Override RDFNode.inModel() to produce a statically-typed Resource in the given Model.
      Specified by:
      inModel in interface RDFNode
      Specified by:
      inModel in interface Resource
      Parameters:
      m - a model to move the node to
      Returns:
      this, if it's already in m (or no model), a copy in m otherwise
    • getId

      public AnonId getId()
      Description copied from interface: Resource
      Returns an a unique identifier for anonymous resources.

      The id is unique within the scope of a particular implementation. All models within an implementation will use the same id for the same anonymous resource.

      This method is undefined if called on resources which are not anonymous and may raise an exception.

      Specified by:
      getId in interface Resource
      Returns:
      A unique id for an anonymous resource.
    • getURI

      public String getURI()
      Description copied from interface: Resource
      Return the URI of the resource, or null if it's a bnode or statement.
      Specified by:
      getURI in interface Resource
      Returns:
      The URI of the resource, or null if it's a bnode or statement.
    • getStmtTerm

      public Statement getStmtTerm()
      Description copied from interface: Resource
      Return the statement of this resource, or null if it is not an RDF-star triple term. This is not a resource for a reified statement.
      Specified by:
      getStmtTerm in interface Resource
      Returns:
      The statement of this resource,or null if it is not an RDF-star triple term.
    • getNameSpace

      public String getNameSpace()
      Description copied from interface: Resource
      Returns the namespace associated with this resource if it is a URI, else return null.

      The namespace is suitable for use with localname in in RDF/XML. XML does not allow QNames to start with a digit and this method reflects that restriction in the values for namespace and localname.

      See functions in SplitIRI for other split algorithms.

      Specified by:
      getNameSpace in interface Resource
      Returns:
      The namespace for this resource or null.
    • getLocalName

      public String getLocalName()
      Description copied from interface: Resource
      Returns the localname of this resource within its namespace if it is a URI else null.

      Note: XML requires QNames to start with a letter, not a digit, and this method reflects that restriction.

      See functions in SplitIRI for other split algorithms.

      Specified by:
      getLocalName in interface Resource
      Returns:
      The localname of this property within its namespace.
    • hasURI

      public boolean hasURI(String uri)
      Description copied from interface: Resource
      Answer true iff this Resource is a URI resource with the given URI. Using this is preferred to using getURI() and .equals().
      Specified by:
      hasURI in interface Resource
    • toString

      public String toString()
      Description copied from interface: Resource
      Return a string representation of the resource. Returns the URI of the resource unless the resource is anonymous in which case it returns the id of the resource enclosed in square brackets.
      Specified by:
      toString in interface RDFNode
      Specified by:
      toString in interface Resource
      Overrides:
      toString in class Object
      Returns:
      Return a string representation of the resource. if it is anonymous.
    • getRequiredProperty

      public Statement getRequiredProperty(Property p)
      Description copied from interface: Resource
      Get a property value of this resource.

      The model associated with the resource instance is searched for statements whose subject is this resource and whose predicate is p. If such a statement is found, it is returned. If several such statements are found, any one may be returned. If no such statements are found, an exception is thrown.

      Specified by:
      getRequiredProperty in interface Resource
      Parameters:
      p - The property sought.
      Returns:
      some (this, p, ?O) statement if one exists
    • getRequiredProperty

      public Statement getRequiredProperty(Property p, String lang)
      Description copied from interface: Resource
      Get a property value of this resource in a specified language.

      The model associated with the resource instance is searched for statements whose subject is this resource and whose predicate is p. If such a statement is found, it is returned. If several such statements are found, any one may be returned. If no such statements are found, an exception is thrown.

      Specified by:
      getRequiredProperty in interface Resource
      Parameters:
      p - The property sought.
      lang - The language of the statement with the property sought.
      Returns:
      some (this, p, ?O@lang) statement if one exists
    • getProperty

      public Statement getProperty(Property p)
      Description copied from interface: Resource
      Answer some statement (this, p, O) in the associated model. If there are several such statements, any one of them may be returned. If no such statements exist, null is returned - in this is differs from getRequiredProperty.
      Specified by:
      getProperty in interface Resource
      Parameters:
      p - the property sought
      Returns:
      a statement (this, p, O), or null if no such statements exist here
    • getProperty

      public Statement getProperty(Property p, String lang)
      Description copied from interface: Resource
      Answer some statement (this, p, O), in language lang, in the associated model. If there are several such statements, any one of them may be returned. If no such statements exist, null is returned - in this it differs from getRequiredProperty.
      Specified by:
      getProperty in interface Resource
      Parameters:
      p - The property sought.
      lang - The language of the property sought.
      Returns:
      some (this, p, ?O@lang) statement if one exists
    • listProperties

      public StmtIterator listProperties(Property p)
      Description copied from interface: Resource
      List all the values of the property p.

      Returns an iterator over all the statements in the associated model whose subject is this resource and whose predicate is p.

      Specified by:
      listProperties in interface Resource
      Parameters:
      p - The predicate sought.
      Returns:
      An iterator over the statements.
    • listProperties

      public StmtIterator listProperties(Property p, String lang)
      Description copied from interface: Resource
      Return an iterator over all the properties of this resource with a specific language.

      The model associated with this resource is searched and an iterator is returned which iterates over all the statements which have this resource as a subject.

      Specified by:
      listProperties in interface Resource
      Returns:
      An iterator over all the statements about this object.
    • listProperties

      public StmtIterator listProperties()
      Description copied from interface: Resource
      Return an iterator over all the properties of this resource.

      The model associated with this resource is search and an iterator is returned which iterates over all the statements which have this resource as a subject.

      Specified by:
      listProperties in interface Resource
      Returns:
      An iterator over all the statements about this object.
    • addLiteral

      public Resource addLiteral(Property p, boolean o)
      Description copied from interface: Resource
      Add the property p with the typed-literal value o to this resource, ie add (this, p, typed(o)) to this's model. Answer this resource. The typed literal is equal to one constructed by using this.getModel().createTypedLiteral(o).
      Specified by:
      addLiteral in interface Resource
    • addProperty

      public Resource addProperty(Property p, long o)
    • addLiteral

      public Resource addLiteral(Property p, long o)
      Description copied from interface: Resource
      Add the property p with the typed-literal value o to this resource, ie add (this, p, typed(o)) to this's model. Answer this resource. The typed literal is equal to one constructed by using this.getModel().createTypedLiteral(o).
      Specified by:
      addLiteral in interface Resource
    • addLiteral

      public Resource addLiteral(Property p, char o)
      Description copied from interface: Resource
      Add the property p with the typed-literal value o to this resource, ie add (this, p, typed(o)) to this's model. Answer this resource. The typed literal is equal to one constructed by using this.getModel().createTypedLiteral(o).
      Specified by:
      addLiteral in interface Resource
    • addProperty

      public Resource addProperty(Property p, float o)
    • addProperty

      public Resource addProperty(Property p, double o)
    • addLiteral

      public Resource addLiteral(Property p, double o)
      Description copied from interface: Resource
      Add the property p with the typed-literal value o to this resource, ie add (this, p, typed(o)) to this's model. Answer this resource. The typed literal is equal to one constructed by using this.getModel().createTypedLiteral(o).
      Specified by:
      addLiteral in interface Resource
    • addLiteral

      public Resource addLiteral(Property p, float o)
      Description copied from interface: Resource
      Add the property p with the typed-literal value o to this resource, ie add (this, p, typed(o)) to this's model. Answer this resource. The typed literal is equal to one constructed by using this.getModel().createTypedLiteral(o).
      Specified by:
      addLiteral in interface Resource
    • addProperty

      public Resource addProperty(Property p, String o)
      Description copied from interface: Resource
      Add a property to this resource.

      A statement with this resource as the subject, p as the predicate and o as the object is added to the model associated with this resource.

      Specified by:
      addProperty in interface Resource
      Parameters:
      p - The property to be added.
      o - The value of the property to be added.
      Returns:
      This resource to allow cascading calls.
    • addProperty

      public Resource addProperty(Property p, String o, String l)
      Description copied from interface: Resource
      Add a property to this resource.

      A statement with this resource as the subject, p as the predicate and o as the object is added to the model associated with this resource.

      Specified by:
      addProperty in interface Resource
      Parameters:
      p - The property to be added.
      o - The value of the property to be added.
      l - the language of the property
      Returns:
      This resource to allow cascading calls.
    • addProperty

      public Resource addProperty(Property p, String lexicalForm, RDFDatatype datatype)
      Description copied from interface: Resource
      Add a property to this resource.

      A statement with this resource as the subject, p as the predicate and o as the object is added to the model associated with this resource.

      Specified by:
      addProperty in interface Resource
      Parameters:
      p - The property to be added.
      lexicalForm - The lexical form of the literal
      datatype - The datatype
      Returns:
      This resource to allow cascading calls.
    • addLiteral

      public Resource addLiteral(Property p, Object o)
      Description copied from interface: Resource
      Add the property p with the typed-literal value o to this resource, ie add (this, p, typed(o)) to this's model. Answer this resource. The typed literal is equal to one constructed by using this.getModel().createTypedLiteral(o).
      Specified by:
      addLiteral in interface Resource
    • addLiteral

      public Resource addLiteral(Property p, Literal o)
      Description copied from interface: Resource
      Add the property p with the pre-constructed Literal value o to this resource, ie add (this, p, o) to this's model. Answer this resource. NOTE thjat this is distinct from the other addLiteral methods in that the Literal is not turned into a Literal.
      Specified by:
      addLiteral in interface Resource
    • addProperty

      public Resource addProperty(Property p, RDFNode o)
      Description copied from interface: Resource
      Add a property to this resource.

      A statement with this resource as the subject, p as the predicate and o as the object is added to the model associated with this resource.

      Specified by:
      addProperty in interface Resource
      Parameters:
      p - The property to be added.
      o - The value of the property to be added.
      Returns:
      This resource to allow cascading calls.
    • hasProperty

      public boolean hasProperty(Property p)
      Description copied from interface: Resource
      Determine whether this resource has any values for a given property.
      Specified by:
      hasProperty in interface Resource
      Parameters:
      p - The property sought.
      Returns:
      true if and only if this resource has at least one value for the property.
    • hasLiteral

      public boolean hasLiteral(Property p, boolean o)
      Description copied from interface: Resource
      Answer true iff this resource has the value o for property p. o is interpreted as a typed literal with the appropriate RDF type.
      Specified by:
      hasLiteral in interface Resource
    • hasLiteral

      public boolean hasLiteral(Property p, long o)
      Description copied from interface: Resource
      Answer true iff this resource has the value o for property p. o is interpreted as a typed literal with the appropriate RDF type.
      Specified by:
      hasLiteral in interface Resource
    • hasLiteral

      public boolean hasLiteral(Property p, char o)
      Description copied from interface: Resource
      Answer true iff this resource has the value o for property p. o is interpreted as a typed literal with the appropriate RDF type.
      Specified by:
      hasLiteral in interface Resource
    • hasLiteral

      public boolean hasLiteral(Property p, double o)
      Description copied from interface: Resource
      Answer true iff this resource has the value o for property p. o is interpreted as a typed literal with the appropriate RDF type.
      Specified by:
      hasLiteral in interface Resource
    • hasLiteral

      public boolean hasLiteral(Property p, float o)
      Description copied from interface: Resource
      Answer true iff this resource has the value o for property p. o is interpreted as a typed literal with the appropriate RDF type.
      Specified by:
      hasLiteral in interface Resource
    • hasProperty

      public boolean hasProperty(Property p, String o)
      Description copied from interface: Resource
      Test if this resource has a given property with a given value.
      Specified by:
      hasProperty in interface Resource
      Parameters:
      p - The property sought.
      o - The value of the property sought.
      Returns:
      true if and only if this resource has property p with value o.
    • hasProperty

      public boolean hasProperty(Property p, String o, String l)
      Description copied from interface: Resource
      Test if this resource has a given property with a given value.
      Specified by:
      hasProperty in interface Resource
      Parameters:
      p - The property sought.
      o - The value of the property sought.
      l - The language of the property sought.
      Returns:
      true if and only if this resource has property p with value o.
    • hasLiteral

      public boolean hasLiteral(Property p, Object o)
      Description copied from interface: Resource
      Answer true iff this resource has the value o for property p. o is interpreted as a typed literal with the appropriate RDF type.
      Specified by:
      hasLiteral in interface Resource
    • hasProperty

      public boolean hasProperty(Property p, RDFNode o)
      Description copied from interface: Resource
      Test if this resource has a given property with a given value.
      Specified by:
      hasProperty in interface Resource
      Parameters:
      p - The property sought.
      o - The value of the property sought.
      Returns:
      true if and only if this resource has property p with value o.
    • removeProperties

      public Resource removeProperties()
      Description copied from interface: Resource
      Delete all the properties for this resource from the associated model.
      Specified by:
      removeProperties in interface Resource
      Returns:
      This resource to permit cascading.
    • removeAll

      public Resource removeAll(Property p)
      Description copied from interface: Resource
      Delete all the statements with predicate p for this resource from its associated model.
      Specified by:
      removeAll in interface Resource
      Parameters:
      p - the property to remove
      Returns:
      this resource, to permit cascading
    • begin

      public Resource begin()
      Description copied from interface: Resource
      Begin a transaction in the associated model.
      Specified by:
      begin in interface Resource
      Returns:
      This resource to permit cascading.
    • abort

      public Resource abort()
      Description copied from interface: Resource
      Abort the transaction in the associated model.
      Specified by:
      abort in interface Resource
      Returns:
      This resource to permit cascading.
    • commit

      public Resource commit()
      Description copied from interface: Resource
      Commit the transaction in the associated model.
      Specified by:
      commit in interface Resource
      Returns:
      This resource to permit cascading.
    • getModel

      public Model getModel()
      Description copied from interface: RDFNode
      Return the model associated with this resource. If the Resource was not created by a Model, the result may be null.
      Specified by:
      getModel in interface RDFNode
      Returns:
      The model associated with this resource.
    • getPropertyResourceValue

      public Resource getPropertyResourceValue(Property p)
      Description copied from interface: Resource
      Answer some resource R for which this.hasProperty( p, R ), or null if no such R exists.
      Specified by:
      getPropertyResourceValue in interface Resource