001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: Node_Literal.java,v 1.19 2008/01/02 12:06:55 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph;
008:
009: import com.hp.hpl.jena.datatypes.RDFDatatype;
010: import com.hp.hpl.jena.graph.impl.*;
011: import com.hp.hpl.jena.shared.*;
012:
013: /**
014: An RDF node holding a literal value. Literals may have datatypes.
015: @author kers
016: */
017: public class Node_Literal extends Node_Concrete {
018: /* package */Node_Literal(Object label) {
019: super (label);
020: }
021:
022: public LiteralLabel getLiteral() {
023: return (LiteralLabel) label;
024: }
025:
026: public final Object getLiteralValue() {
027: return getLiteral().getValue();
028: }
029:
030: public final String getLiteralLexicalForm() {
031: return getLiteral().getLexicalForm();
032: }
033:
034: public final String getLiteralLanguage() {
035: return getLiteral().language();
036: }
037:
038: public final String getLiteralDatatypeURI() {
039: return getLiteral().getDatatypeURI();
040: }
041:
042: public final RDFDatatype getLiteralDatatype() {
043: return getLiteral().getDatatype();
044: }
045:
046: public final boolean getLiteralIsXML() {
047: return getLiteral().isXML();
048: }
049:
050: public String toString(PrefixMapping pm, boolean quoting) {
051: return ((LiteralLabel) label).toString(quoting);
052: }
053:
054: public boolean isLiteral() {
055: return true;
056: }
057:
058: /**
059: Literal nodes defer their indexing value to the component literal.
060: @see com.hp.hpl.jena.graph.Node#getIndexingValue()
061: */
062: public Object getIndexingValue() {
063: return getLiteral().getIndexingValue();
064: }
065:
066: public Object visitWith(NodeVisitor v) {
067: return v.visitLiteral(this , getLiteral());
068: }
069:
070: public boolean equals(Object other) {
071: return other instanceof Node_Literal
072: && label.equals(((Node_Literal) other).label);
073: }
074:
075: /**
076: * Test that two nodes are semantically equivalent.
077: * In some cases this may be the sames as equals, in others
078: * equals is stricter. For example, two xsd:int literals with
079: * the same value but different language tag are semantically
080: * equivalent but distinguished by the java equality function
081: * in order to support round tripping.
082: * <p>Default implementation is to use equals, subclasses should
083: * override this.</p>
084: */
085: public boolean sameValueAs(Object o) {
086: return o instanceof Node_Literal
087: && ((LiteralLabel) label)
088: .sameValueAs(((Node_Literal) o).getLiteral());
089: }
090:
091: public boolean matches(Node x) {
092: return sameValueAs(x);
093: }
094:
095: }
096:
097: /*
098: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
099: All rights reserved.
100:
101: Redistribution and use in source and binary forms, with or without
102: modification, are permitted provided that the following conditions
103: are met:
104:
105: 1. Redistributions of source code must retain the above copyright
106: notice, this list of conditions and the following disclaimer.
107:
108: 2. Redistributions in binary form must reproduce the above copyright
109: notice, this list of conditions and the following disclaimer in the
110: documentation and/or other materials provided with the distribution.
111:
112: 3. The name of the author may not be used to endorse or promote products
113: derived from this software without specific prior written permission.
114:
115: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
116: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
117: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
118: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
119: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
120: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
121: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
122: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
124: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
125: */
|