info.sswap.impl.empire.model
Class Literal

java.lang.Object
  extended by info.sswap.impl.empire.model.ModelImpl
      extended by info.sswap.impl.empire.model.ElementImpl
          extended by info.sswap.impl.empire.model.Literal
All Implemented Interfaces:
com.clarkparsia.empire.SupportsRdfId, SSWAPElement, SSWAPLiteral, SSWAPModel

public class Literal
extends ElementImpl
implements SSWAPLiteral

Implementation of SSWAPElement that is a literal.

Author:
Blazej Bulka

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.clarkparsia.empire.SupportsRdfId
com.clarkparsia.empire.SupportsRdfId.BNodeKey, com.clarkparsia.empire.SupportsRdfId.RdfKey<T>, com.clarkparsia.empire.SupportsRdfId.URIKey
 
Field Summary
private  java.net.URI datatypeURI
           
private  java.lang.String language
           
private static int ODD_PRIME
          An arbitrary odd prime used in the hash function.
private  java.lang.String value
          The value of the literal.
 
Constructor Summary
Literal(Literal other)
          A copy constructor for a literal
Literal(java.lang.String value)
          Initializes the literal with the given value
Literal(java.lang.String value, java.net.URI datatypeURI, java.lang.String language)
          Creates a new literal with value, type information (optional) and language information (optional).
 
Method Summary
 void addComment(java.lang.String comment)
          Adds and rdfs:comment to this type.
 void addLabel(java.lang.String label)
          Adds an rdfs:label statement to this type.
 java.lang.Boolean asBoolean()
          Type-safe case of this element to a boolean.
 java.lang.Double asDouble()
          Type-safe cast of this element to a double.
 java.lang.Integer asInteger()
          Type-safe cast of this element to an integer.
 SSWAPLiteral asLiteral()
          Type-safe cast of this element to SSWAPLiteral.
private  void assertValidValue(java.lang.String value, java.net.URI datatypeURI)
          Checks whether the value of the literal conforms to its declared XSD datatype.
 java.lang.String asString()
          Type-safe cast of this element to a String.
 boolean equals(java.lang.Object o)
           
 java.net.URI getDatatypeURI()
          Gets the URI of the datatype.
 java.lang.String getLanguage()
          Gets the language of the literal (if specified)
 com.clarkparsia.empire.SupportsRdfId.RdfKey getRdfId()
          Gets the RDF identifier of the literal (method required by the interface).
 java.lang.String getValue()
           
 int hashCode()
          Overridden hash code method to make sure that the generated hashcodes are consistent with the overriden equals() method.
 boolean isLiteral()
          Notifies the caller that this SSWAPElement is a literal.
 void setRdfId(com.clarkparsia.empire.SupportsRdfId.RdfKey rdfId)
          Sets the RDF identifier (method required by the interface).
 
Methods inherited from class info.sswap.impl.empire.model.ElementImpl
asIndividual, asList, getComment, getJenaResource, getLabel, isAnonymous, isIndividual, isList
 
Methods inherited from class info.sswap.impl.empire.model.ModelImpl
addImport, assertModel, assertSourceModel, checkProfile, dereference, dereference, doClosure, getAllDependentObjects, getDependentObject, getDocument, getExpressivity, getImports, getInputStream, getNsPrefixMap, getReasoningService, getSourceModel, getTypeSignature, getURI, hasSourceModel, hasSourceModelWithEntityManager, isDereferenced, persist, rdfIdEquals, rdfIdHashCode, refresh, refreshSiblings, removeImport, removeNsPrefix, serialize, serialize, setDereferenced, setNsPrefix, setSourceModel, setURI, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface info.sswap.api.model.SSWAPElement
asIndividual, asList, getComment, getLabel, isIndividual, isList
 
Methods inherited from interface info.sswap.api.model.SSWAPModel
addImport, checkProfile, dereference, dereference, doClosure, getDocument, getImports, getInputStream, getNsPrefixMap, getReasoningService, getTypeSignature, getURI, isDereferenced, removeImport, removeNsPrefix, serialize, serialize, setNsPrefix, validate
 

Field Detail

value

private java.lang.String value
The value of the literal.


datatypeURI

private java.net.URI datatypeURI

language

private java.lang.String language

ODD_PRIME

private static final int ODD_PRIME
An arbitrary odd prime used in the hash function.

See Also:
Constant Field Values
Constructor Detail

Literal

public Literal(java.lang.String value)
Initializes the literal with the given value

Parameters:
value - the value of the literal

Literal

public Literal(java.lang.String value,
               java.net.URI datatypeURI,
               java.lang.String language)
        throws java.lang.IllegalArgumentException
Creates a new literal with value, type information (optional) and language information (optional).

Parameters:
value - the value of the literal (its lexical representation)
datatypeURI - the URI of the datatype (may be null)
language - the declared language of the literal (may be null)
Throws:
java.lang.IllegalArgumentException - if the lexical representation of the value is not valid given its declared XSD datatype.

Literal

Literal(Literal other)
A copy constructor for a literal

Parameters:
other - the literal to be copied
Method Detail

assertValidValue

private void assertValidValue(java.lang.String value,
                              java.net.URI datatypeURI)
                       throws java.lang.IllegalArgumentException
Checks whether the value of the literal conforms to its declared XSD datatype. The check is only performed when both value and datatypeURI are not null.

Parameters:
value - the value to be checked (the lexical representation of the value)
datatypeURI - the URI of the XSD datatype
Throws:
java.lang.IllegalArgumentException - if the value does not conform to its declared XSD datatype.

getRdfId

public com.clarkparsia.empire.SupportsRdfId.RdfKey getRdfId()
Gets the RDF identifier of the literal (method required by the interface). Since literals do not have any identifiers, this method always returns null.

Specified by:
getRdfId in interface com.clarkparsia.empire.SupportsRdfId
Returns:
always null

setRdfId

public void setRdfId(com.clarkparsia.empire.SupportsRdfId.RdfKey rdfId)
Sets the RDF identifier (method required by the interface). Since literals do not have any identifiers, this method always throws UnsupportedOperationException.

Specified by:
setRdfId in interface com.clarkparsia.empire.SupportsRdfId
Parameters:
rdfId - the RDF identifier
Throws:
java.lang.UnsupportedOperationException - always

isLiteral

public boolean isLiteral()
Notifies the caller that this SSWAPElement is a literal.

Specified by:
isLiteral in interface SSWAPElement
Overrides:
isLiteral in class ElementImpl
Returns:
always true

asLiteral

public SSWAPLiteral asLiteral()
Description copied from interface: SSWAPElement
Type-safe cast of this element to SSWAPLiteral. This is only possible for elements that are SSWAPLiterals.

Specified by:
asLiteral in interface SSWAPElement
Overrides:
asLiteral in class ElementImpl
Returns:
a SSWAPLiteral, if the element is actually a SSWAPLiteral, or null otherwise

asBoolean

public java.lang.Boolean asBoolean()
Description copied from interface: SSWAPElement
Type-safe case of this element to a boolean. This is only possible for elements that are literals and they represent a valid boolean value. The only valid boolean values are "true" and "false" (case insensitive).

Specified by:
asBoolean in interface SSWAPElement
Overrides:
asBoolean in class ElementImpl
Returns:
a boolean, if the element is a literal containing a valid boolean value (as defined above), or null otherwise.

asDouble

public java.lang.Double asDouble()
Description copied from interface: SSWAPElement
Type-safe cast of this element to a double. This is only possible for elements that are literals, and they contain a valid numerical data.

Specified by:
asDouble in interface SSWAPElement
Overrides:
asDouble in class ElementImpl
Returns:
a double, if the element is a literal containing a legal double, or null otherwise.

asInteger

public java.lang.Integer asInteger()
Description copied from interface: SSWAPElement
Type-safe cast of this element to an integer. This is only possible for elements that are literals, and they contain a valid integer data.

Specified by:
asInteger in interface SSWAPElement
Overrides:
asInteger in class ElementImpl
Returns:
an integer, if the element is a literal containing a legal integer, or null otherwise.

asString

public java.lang.String asString()
Description copied from interface: SSWAPElement
Type-safe cast of this element to a String. This is only possible for elements that are literals.

Specified by:
asString in interface SSWAPElement
Overrides:
asString in class ElementImpl
Returns:
a string, if the element is a literal, or null otherwise.

getValue

public java.lang.String getValue()
Returns:
the value

getDatatypeURI

public java.net.URI getDatatypeURI()
Description copied from interface: SSWAPLiteral
Gets the URI of the datatype. For the standard XSD datatypes, it is advised to use constants defined in XSD class (com.hp.hpl.jena.vocabulary); for example, XSD.xstring.toString() for "xsd:string" and XSD.anyURI.toString() for "xsd:anyURI".

Specified by:
getDatatypeURI in interface SSWAPLiteral
Returns:
the datatypeURI

getLanguage

public java.lang.String getLanguage()
Description copied from interface: SSWAPLiteral
Gets the language of the literal (if specified)

Specified by:
getLanguage in interface SSWAPLiteral
Returns:
the language

addLabel

public void addLabel(java.lang.String label)
Description copied from interface: SSWAPElement
Adds an rdfs:label statement to this type.

Specified by:
addLabel in interface SSWAPElement
Overrides:
addLabel in class ElementImpl
Parameters:
label - the label to be added

addComment

public void addComment(java.lang.String comment)
Description copied from interface: SSWAPElement
Adds and rdfs:comment to this type.

Specified by:
addComment in interface SSWAPElement
Overrides:
addComment in class ElementImpl
Parameters:
comment - the comment to be added to this type

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overridden hash code method to make sure that the generated hashcodes are consistent with the overriden equals() method.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashcode.


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.