001: /******************************************************************
002: * File: XSDBaseStringType.java
003: * Created by: Dave Reynolds
004: * Created on: 09-Feb-03
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: XSDBaseStringType.java,v 1.14 2008/01/02 12:04:04 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.datatypes.xsd.impl;
010:
011: import com.hp.hpl.jena.datatypes.xsd.*;
012: import com.hp.hpl.jena.graph.impl.LiteralLabel;
013: import com.hp.hpl.jena.shared.impl.JenaParameters;
014:
015: /**
016: * Base implementation for all string datatypes derinved from
017: * xsd:string. The only purpose of this place holder is
018: * to support the isValidLiteral tests across string types.
019: *
020: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
021: * @version $Revision: 1.14 $ on $Date: 2008/01/02 12:04:04 $
022: */
023: public class XSDBaseStringType extends XSDDatatype {
024:
025: /**
026: * Constructor.
027: * @param typeName the name of the XSD type to be instantiated, this is
028: * used to lookup a type definition from the Xerces schema factory.
029: */
030: public XSDBaseStringType(String typeName) {
031: super (typeName);
032: }
033:
034: /**
035: * Constructor.
036: * @param typeName the name of the XSD type to be instantiated, this is
037: * used to lookup a type definition from the Xerces schema factory.
038: * @param javaClass the java class for which this xsd type is to be
039: * treated as the cannonical representation
040: */
041: public XSDBaseStringType(String typeName, Class javaClass) {
042: super (typeName, javaClass);
043: }
044:
045: // Functionality moved to XSDDatatype but old code left here temporarily until
046: // we're sure the change is correct.
047: //
048: // /**
049: // * Test whether the given LiteralLabel is a valid instance
050: // * of this datatype. This takes into accound typing information
051: // * as well as lexical form - for example an xsd:string is
052: // * never considered valid as an xsd:integer (even if it is
053: // * lexically legal like "1").
054: // */
055: // public boolean isValidLiteral(LiteralLabel lit) {
056: // RDFDatatype dt = lit.getDatatype();
057: // if ( dt == null && lit.language().equals("") ) return true;
058: // if ( this.equals(dt) ) return true;
059: // if (dt instanceof XSDBaseStringType) {
060: // return isValid(lit.getLexicalForm());
061: // } else {
062: // return false;
063: // }
064: // }
065:
066: /**
067: * Compares two instances of values of the given datatype.
068: * This ignores lang tags and optionally allows plain literals to
069: * equate to strings. The latter option is currently set by a static
070: * global flag in LiteralLabel.
071: */
072: public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
073: // value1 will have been used to dispatch here so we know value1 is an xsdstring or extension
074: if ((value2.getDatatype() == null && JenaParameters.enablePlainLiteralSameAsString)
075: || (value2.getDatatype() instanceof XSDBaseStringType)) {
076: return value1.getValue().equals(value2.getValue());
077: } else {
078: return false;
079: }
080: }
081:
082: }
083:
084: /*
085: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
086: All rights reserved.
087:
088: Redistribution and use in source and binary forms, with or without
089: modification, are permitted provided that the following conditions
090: are met:
091:
092: 1. Redistributions of source code must retain the above copyright
093: notice, this list of conditions and the following disclaimer.
094:
095: 2. Redistributions in binary form must reproduce the above copyright
096: notice, this list of conditions and the following disclaimer in the
097: documentation and/or other materials provided with the distribution.
098:
099: 3. The name of the author may not be used to endorse or promote products
100: derived from this software without specific prior written permission.
101:
102: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
103: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
104: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
105: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
106: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
107: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
108: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
109: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
111: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112: */
|