KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > datatypes > xsd > impl > XSDBaseStringType


1 /******************************************************************
2  * File: XSDBaseStringType.java
3  * Created by: Dave Reynolds
4  * Created on: 09-Feb-03
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: XSDBaseStringType.java,v 1.11 2005/02/21 12:02:20 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.datatypes.xsd.impl;
11
12 import com.hp.hpl.jena.datatypes.xsd.*;
13 import com.hp.hpl.jena.graph.impl.LiteralLabel;
14 import com.hp.hpl.jena.shared.impl.JenaParameters;
15
16 /**
17  * Base implementation for all string datatypes derinved from
18  * xsd:string. The only purpose of this place holder is
19  * to support the isValidLiteral tests across string types.
20  *
21  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
22  * @version $Revision: 1.11 $ on $Date: 2005/02/21 12:02:20 $
23  */

24 public class XSDBaseStringType extends XSDDatatype {
25
26     /**
27      * Constructor.
28      * @param typeName the name of the XSD type to be instantiated, this is
29      * used to lookup a type definition from the Xerces schema factory.
30      */

31     public XSDBaseStringType(String JavaDoc typeName) {
32         super(typeName);
33     }
34     
35     /**
36      * Constructor.
37      * @param typeName the name of the XSD type to be instantiated, this is
38      * used to lookup a type definition from the Xerces schema factory.
39      * @param javaClass the java class for which this xsd type is to be
40      * treated as the cannonical representation
41      */

42     public XSDBaseStringType(String JavaDoc typeName, Class JavaDoc javaClass) {
43         super(typeName, javaClass);
44     }
45
46     
47 // Functionality moved to XSDDatatype but old code left here temporarily until
48
// we're sure the change is correct.
49
//
50
// /**
51
// * Test whether the given LiteralLabel is a valid instance
52
// * of this datatype. This takes into accound typing information
53
// * as well as lexical form - for example an xsd:string is
54
// * never considered valid as an xsd:integer (even if it is
55
// * lexically legal like "1").
56
// */
57
// public boolean isValidLiteral(LiteralLabel lit) {
58
// RDFDatatype dt = lit.getDatatype();
59
// if ( dt == null && lit.language().equals("") ) return true;
60
// if ( this.equals(dt) ) return true;
61
// if (dt instanceof XSDBaseStringType) {
62
// return isValid(lit.getLexicalForm());
63
// } else {
64
// return false;
65
// }
66
// }
67

68     /**
69      * Compares two instances of values of the given datatype.
70      * This ignores lang tags and optionally allows plain literals to
71      * equate to strings. The latter option is currently set by a static
72      * global flag in LiteralLabel.
73      */

74     public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
75         // value1 will have been used to dispatch here so we know value1 is an xsdstring or extension
76
if ((value2.getDatatype() == null && JenaParameters.enablePlainLiteralSameAsString) ||
77              (value2.getDatatype() instanceof XSDBaseStringType)) {
78                 return value1.getValue().equals(value2.getValue());
79         } else {
80                 return false;
81         }
82     }
83
84  }
85
86 /*
87     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
88     All rights reserved.
89
90     Redistribution and use in source and binary forms, with or without
91     modification, are permitted provided that the following conditions
92     are met:
93
94     1. Redistributions of source code must retain the above copyright
95        notice, this list of conditions and the following disclaimer.
96
97     2. Redistributions in binary form must reproduce the above copyright
98        notice, this list of conditions and the following disclaimer in the
99        documentation and/or other materials provided with the distribution.
100
101     3. The name of the author may not be used to endorse or promote products
102        derived from this software without specific prior written permission.
103
104     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
105     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
106     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
107     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
108     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
109     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
110     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
111     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
112     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
113     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114 */

115
Popular Tags