001: /******************************************************************
002: * File: XSDDatatype.java
003: * Created by: Dave Reynolds
004: * Created on: 09-Dec-02
005: *
006: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: XSDDatatype.java,v 1.15 2008/01/02 12:10:49 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.datatypes.xsd;
010:
011: import java.math.BigDecimal;
012: import java.math.BigInteger;
013: import java.io.Reader;
014: import java.util.*;
015:
016: import com.hp.hpl.jena.datatypes.*;
017: import com.hp.hpl.jena.datatypes.xsd.impl.*;
018: import com.hp.hpl.jena.graph.impl.LiteralLabel;
019:
020: import org.apache.xerces.impl.dv.util.Base64;
021: import org.apache.xerces.impl.dv.util.HexBin;
022: import org.apache.xerces.impl.dv.xs.DecimalDV;
023: import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
024: import org.apache.xerces.impl.dv.*;
025: import org.apache.xerces.impl.validation.ValidationState;
026: import org.apache.xerces.util.SymbolHash;
027:
028: import org.apache.xerces.parsers.XMLGrammarPreparser;
029: import org.apache.xerces.xni.grammars.XMLGrammarDescription;
030: import org.apache.xerces.xni.parser.XMLInputSource;
031: import org.apache.xerces.xs.XSConstants;
032: import org.apache.xerces.xs.XSTypeDefinition;
033: import org.apache.xerces.xs.XSNamedMap;
034: import org.apache.xerces.xni.grammars.XSGrammar;
035:
036: /**
037: * Representation of an XSD datatype based on the Xerces-2
038: * XSD implementation.
039: *
040: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
041: * @version $Revision: 1.15 $ on $Date: 2008/01/02 12:10:49 $
042: */
043: public class XSDDatatype extends BaseDatatype {
044:
045: //=======================================================================
046: // Global statics - define single instance for each import XSD type
047:
048: /** The xsd namespace */
049: public static final String XSD = "http://www.w3.org/2001/XMLSchema";
050:
051: /** Datatype representing xsd:float */
052: public static final XSDDatatype XSDfloat = new XSDFloat("float",
053: Float.class);
054:
055: /** Datatype representing xsd:double */
056: public static final XSDDatatype XSDdouble = new XSDDouble("double",
057: Double.class);
058:
059: /** Datatype representing xsd:int */
060: public static final XSDDatatype XSDint = new XSDBaseNumericType(
061: "int", Integer.class);
062:
063: /** Datatype representing xsd:long */
064: public static final XSDDatatype XSDlong = new XSDBaseNumericType(
065: "long", Long.class);
066:
067: /** Datatype representing xsd:short */
068: public static final XSDDatatype XSDshort = new XSDBaseNumericType(
069: "short", Short.class);
070:
071: /** Datatype representing xsd:byte */
072: public static final XSDDatatype XSDbyte = new XSDByteType("byte",
073: Byte.class);
074:
075: /** Datatype representing xsd:unsignedByte */
076: public static final XSDDatatype XSDunsignedByte = new XSDBaseNumericType(
077: "unsignedByte");
078:
079: /** Datatype representing xsd:unsignedShort */
080: public static final XSDDatatype XSDunsignedShort = new XSDBaseNumericType(
081: "unsignedShort");
082:
083: /** Datatype representing xsd:unsignedInt */
084: public static final XSDDatatype XSDunsignedInt = new XSDBaseNumericType(
085: "unsignedInt");
086:
087: /** Datatype representing xsd:unsignedLong */
088: public static final XSDDatatype XSDunsignedLong = new XSDBaseNumericType(
089: "unsignedLong");
090:
091: /** Datatype representing xsd:decimal */
092: public static final XSDDatatype XSDdecimal = new XSDBaseNumericType(
093: "decimal", BigDecimal.class);
094:
095: /** Datatype representing xsd:integer */
096: public static final XSDDatatype XSDinteger = new XSDBaseNumericType(
097: "integer", BigInteger.class);
098:
099: /** Datatype representing xsd:nonPositiveInteger */
100: public static final XSDDatatype XSDnonPositiveInteger = new XSDBaseNumericType(
101: "nonPositiveInteger");
102:
103: /** Datatype representing xsd:nonNegativeInteger */
104: public static final XSDDatatype XSDnonNegativeInteger = new XSDBaseNumericType(
105: "nonNegativeInteger");
106:
107: /** Datatype representing xsd:positiveInteger */
108: public static final XSDDatatype XSDpositiveInteger = new XSDBaseNumericType(
109: "positiveInteger");
110:
111: /** Datatype representing xsd:negativeInteger */
112: public static final XSDDatatype XSDnegativeInteger = new XSDBaseNumericType(
113: "negativeInteger");
114:
115: /** Datatype representing xsd:boolean */
116: public static final XSDDatatype XSDboolean = new XSDDatatype(
117: "boolean", Boolean.class);
118:
119: /** Datatype representing xsd:string */
120: public static final XSDDatatype XSDstring = new XSDBaseStringType(
121: "string", String.class);
122:
123: /** Datatype representing xsd:normalizedString */
124: public static final XSDDatatype XSDnormalizedString = new XSDBaseStringType(
125: "normalizedString", String.class);
126:
127: /** Datatype representing xsd:anyURI */
128: public static final XSDDatatype XSDanyURI = new XSDDatatype(
129: "anyURI");
130:
131: /** Datatype representing xsd:token */
132: public static final XSDDatatype XSDtoken = new XSDBaseStringType(
133: "token");
134:
135: /** Datatype representing xsd:Name */
136: public static final XSDDatatype XSDName = new XSDBaseStringType(
137: "Name");
138:
139: /** Datatype representing xsd:QName */
140: public static final XSDDatatype XSDQName = new XSDDatatype("QName");
141:
142: /** Datatype representing xsd:language */
143: public static final XSDDatatype XSDlanguage = new XSDBaseStringType(
144: "language");
145:
146: /** Datatype representing xsd:NMTOKEN */
147: public static final XSDDatatype XSDNMTOKEN = new XSDBaseStringType(
148: "NMTOKEN");
149:
150: /** Datatype representing xsd:ENTITY */
151: public static final XSDDatatype XSDENTITY = new XSDBaseStringType(
152: "ENTITY");
153:
154: /** Datatype representing xsd:ID */
155: public static final XSDDatatype XSDID = new XSDBaseStringType("ID");
156:
157: /** Datatype representing xsd:NCName */
158: public static final XSDDatatype XSDNCName = new XSDBaseStringType(
159: "NCName");
160:
161: /** Datatype representing xsd:IDREF */
162: public static final XSDDatatype XSDIDREF = new XSDDatatype("IDREF");
163:
164: /** Datatype representing xsd:NOTATION */
165: public static final XSDDatatype XSDNOTATION = new XSDDatatype(
166: "NOTATION");
167:
168: /** Datatype representing xsd:hexBinary */
169: public static final XSDDatatype XSDhexBinary = new XSDhexBinary(
170: "hexBinary");
171:
172: /** Datatype representing xsd:base64Binary */
173: public static final XSDDatatype XSDbase64Binary = new XSDbase64Binary(
174: "base64Binary");
175:
176: /** Datatype representing xsd:date */
177: public static final XSDDatatype XSDdate = new XSDDateType("date");
178:
179: /** Datatype representing xsd:time */
180: public static final XSDDatatype XSDtime = new XSDTimeType("time");
181:
182: /** Datatype representing xsd:dateTime */
183: public static final XSDDatatype XSDdateTime = new XSDDateTimeType(
184: "dateTime");
185:
186: /** Datatype representing xsd:duration */
187: public static final XSDDatatype XSDduration = new XSDDurationType();
188:
189: /** Datatype representing xsd:gDay */
190: public static final XSDDatatype XSDgDay = new XSDDayType("gDay");
191:
192: /** Datatype representing xsd:gMonth */
193: public static final XSDDatatype XSDgMonth = new XSDMonthType(
194: "gMonth");
195:
196: /** Datatype representing xsd:gYear */
197: public static final XSDDatatype XSDgYear = new XSDYearType("gYear");
198:
199: /** Datatype representing xsd:gYearMonth */
200: public static final XSDDatatype XSDgYearMonth = new XSDYearMonthType(
201: "gYearMonth");
202:
203: /** Datatype representing xsd:gMonthDay */
204: public static final XSDDatatype XSDgMonthDay = new XSDMonthDayType(
205: "gMonthDay");
206:
207: // The following are list rather than simple types and are omitted for now
208:
209: // /** Datatype representing xsd:ENTITIES */
210: // public static final XSDDatatype XSDENTITIES = new XSDBaseStringType("ENTITIES");
211: //
212: // /** Datatype representing xsd:NMTOKENS */
213: // public static final XSDDatatype XSDNMTOKENS = new XSDBaseStringType("NMTOKENS");
214: //
215: // /** Datatype representing xsd:IDREFS */
216: // public static final XSDDatatype XSDIDREFS = new XSDBaseStringType("IDREFS");
217:
218: //=======================================================================
219: // local variables
220:
221: /** the Xerces internal type declaration */
222: protected XSSimpleType typeDeclaration;
223:
224: /** the corresponding java primitive class, if any */
225: protected Class javaClass = null;
226:
227: /** Used to access the values and facets of any of the decimal numeric types */
228: static final DecimalDV decimalDV = new DecimalDV();
229:
230: //=======================================================================
231: // Methods
232:
233: /**
234: * Constructor.
235: * @param typeName the name of the XSD type to be instantiated, this is
236: * used to lookup a type definition from the Xerces schema factory.
237: */
238: public XSDDatatype(String typeName) {
239: super ("");
240: typeDeclaration = SchemaDVFactory.getInstance().getBuiltInType(
241: typeName);
242: uri = typeDeclaration.getNamespace() + "#"
243: + typeDeclaration.getName();
244: }
245:
246: /**
247: * Constructor.
248: * @param typeName the name of the XSD type to be instantiated, this is
249: * used to lookup a type definition from the Xerces schema factory.
250: * @param javaClass the java class for which this xsd type is to be
251: * treated as the cannonical representation
252: */
253: public XSDDatatype(String typeName, Class javaClass) {
254: this (typeName);
255: this .javaClass = javaClass;
256: }
257:
258: /**
259: * Constructor used when loading in external user defined XSD types -
260: * should only be used by the internals but public scope because
261: * the internals spread across multiple packages.
262: *
263: * @param xstype the XSSimpleType definition to be wrapped
264: * @param namespace the namespace for the type (used because the grammar loading doesn't seem to keep that)
265: */
266: public XSDDatatype(XSSimpleType xstype, String namespace) {
267: super ("");
268: typeDeclaration = xstype;
269: this .uri = namespace + "#" + typeDeclaration.getName();
270: }
271:
272: /**
273: * Parse a lexical form of this datatype to a value
274: * @throws DatatypeFormatException if the lexical form is not legal
275: */
276: public Object parse(String lexicalForm)
277: throws DatatypeFormatException {
278: try {
279: ValidationContext context = new ValidationState();
280: ValidatedInfo resultInfo = new ValidatedInfo();
281: Object result = typeDeclaration.validate(lexicalForm,
282: context, resultInfo);
283: return convertValidatedDataValue(resultInfo);
284: } catch (InvalidDatatypeValueException e) {
285: throw new DatatypeFormatException(lexicalForm, this ,
286: "during parse -" + e);
287: }
288: }
289:
290: /**
291: * Convert a value of this datatype out
292: * to lexical form.
293: */
294: public String unparse(Object value) {
295: return value.toString();
296: }
297:
298: /**
299: * Compares two instances of values of the given datatype.
300: * This ignores lang tags and defers to the equality function
301: * defined by the Xerces package - to be checked.
302: */
303: public boolean isEqual(LiteralLabel value1, LiteralLabel value2) {
304: return typeDeclaration.isEqual(value1.getValue(), value2
305: .getValue());
306: }
307:
308: /**
309: * If this datatype is used as the cannonical representation
310: * for a particular java datatype then return that java type,
311: * otherwise returns null.
312: */
313: public Class getJavaClass() {
314: return javaClass;
315: }
316:
317: /**
318: * Returns the Xerces datatype representation for this type, this
319: * is an XSSimpleType, in fact an XSSimpleTypeDecl.
320: */
321: public Object extendedTypeDefinition() {
322: return typeDeclaration;
323: }
324:
325: /**
326: * Create and register a set of types specified in a user schema file.
327: * We use the (illegal) DAML+OIL approach that the uriref of the type
328: * is the url of the schema file with fragment ID corresponding the
329: * the name of the type.
330: *
331: * @param uri the absolute uri of the schema file to be loaded
332: * @param reader the Reader stream onto the file (useful if you wish to load a cached copy of the schema file)
333: * @param encoding the encoding of the source file (can be null)
334: * @param tm the type mapper into which to load the definitions
335: * @return a List of strings giving the uri's of the newly defined datatypes
336: * @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
337: * in default mode for load which may provide diagnostic output direct to stderr)
338: */
339: public static List loadUserDefined(String uri, Reader reader,
340: String encoding, TypeMapper tm)
341: throws DatatypeFormatException {
342: return loadUserDefined(new XMLInputSource(null, uri, uri,
343: reader, encoding), tm);
344: }
345:
346: /**
347: * Create and register a set of types specified in a user schema file.
348: * We use the (illegal) DAML+OIL approach that the uriref of the type
349: * is the url of the schema file with fragment ID corresponding the
350: * the name of the type.
351: *
352: * @param uri the absolute uri of the schema file to be loaded, this should be a resolvable URL
353: * @param encoding the encoding of the source file (can be null)
354: * @param tm the type mapper into which to load the definitions
355: * @return a List of strings giving the uri's of the newly defined datatypes
356: * @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
357: * in default mode for load which may provide diagnostic output direct to stderr)
358: */
359: public static List loadUserDefined(String uri, String encoding,
360: TypeMapper tm) throws DatatypeFormatException {
361: return loadUserDefined(new XMLInputSource(null, uri, uri), tm);
362: }
363:
364: /**
365: * Internal implementation of loadUserDefined
366: *
367: * @param uri the absolute uri of the schema file to be loaded
368: * @param reader the Reader stream onto the file (useful if you wish to load a cached copy of the schema file)
369: * @param encoding the encoding of the source file (can be null)
370: * @param tm the type mapper into which to load the definitions
371: * @return a List of strings giving the uri's of the newly defined datatypes
372: * @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
373: * in default mode for load which may provide diagnostic output direct to stderr)
374: */
375: private static List loadUserDefined(XMLInputSource source,
376: TypeMapper tm) throws DatatypeFormatException {
377: XMLGrammarPreparser parser = new XMLGrammarPreparser();
378: parser
379: .registerPreparser(XMLGrammarDescription.XML_SCHEMA,
380: null);
381: try {
382: XSGrammar xsg = (XSGrammar) parser.preparseGrammar(
383: XMLGrammarDescription.XML_SCHEMA, source);
384: org.apache.xerces.xs.XSModel xsm = xsg.toXSModel();
385: XSNamedMap map = xsm
386: .getComponents(XSTypeDefinition.SIMPLE_TYPE);
387: int numDefs = map.getLength();
388: ArrayList names = new ArrayList(numDefs);
389: for (int i = 0; i < numDefs; i++) {
390: XSSimpleType xstype = (XSSimpleType) map.item(i);
391: // Filter built in types - only needed for 2.6.0
392: if (!XSD.equals(xstype.getNamespace())) {
393: //xstype.derivedFrom()
394: XSDDatatype definedType = new XSDGenericType(
395: xstype, source.getSystemId());
396: tm.registerDatatype(definedType);
397: names.add(definedType.getURI());
398: }
399: }
400: return names;
401: } catch (Exception e) {
402: e.printStackTrace(); // Temp
403: throw new DatatypeFormatException(e.toString());
404: }
405: }
406:
407: /**
408: * Convert a validated xerces data value into the corresponding java data value.
409: * This function is currently the most blatently xerces-version dependent part
410: * of this subsystem. In many cases it also involves reparsing data which has
411: * already been parsed as part of the validation.
412: *
413: * @param validatedInfo a fully populated Xerces data validation context
414: * @return the appropriate java wrapper type
415: */
416: public Object convertValidatedDataValue(ValidatedInfo validatedInfo)
417: throws DatatypeFormatException {
418: switch (validatedInfo.actualValueType) {
419: case XSConstants.BASE64BINARY_DT:
420: byte[] decoded = Base64
421: .decode(validatedInfo.normalizedValue);
422: return (Object) (decoded);
423:
424: case XSConstants.BOOLEAN_DT:
425: return (Boolean) validatedInfo.actualValue;
426:
427: case XSConstants.HEXBINARY_DT:
428: decoded = HexBin.decode(validatedInfo.normalizedValue);
429: return (Object) (decoded);
430:
431: case XSConstants.UNSIGNEDSHORT_DT:
432: case XSConstants.INT_DT:
433: return Integer
434: .valueOf(trimPlus(validatedInfo.normalizedValue));
435:
436: case XSConstants.UNSIGNEDINT_DT:
437: case XSConstants.LONG_DT:
438: return suitableInteger(trimPlus(validatedInfo.normalizedValue));
439:
440: case XSConstants.UNSIGNEDBYTE_DT:
441: case XSConstants.SHORT_DT:
442: case XSConstants.BYTE_DT:
443: return Integer
444: .valueOf(trimPlus(validatedInfo.normalizedValue));
445:
446: case XSConstants.UNSIGNEDLONG_DT:
447: case XSConstants.INTEGER_DT:
448: case XSConstants.NONNEGATIVEINTEGER_DT:
449: case XSConstants.NONPOSITIVEINTEGER_DT:
450: case XSConstants.POSITIVEINTEGER_DT:
451: case XSConstants.NEGATIVEINTEGER_DT:
452: case XSConstants.DECIMAL_DT:
453: Object xsdValue = validatedInfo.actualValue;
454: if (decimalDV.getTotalDigits(xsdValue) == 0) {
455: return new Integer(0);
456: }
457: if (decimalDV.getFractionDigits(xsdValue) >= 1) {
458: return new BigDecimal(
459: trimPlus(validatedInfo.normalizedValue));
460: }
461: // Can have 0 fractionDigits but still have a trailing .000
462: String lexical = trimPlus(validatedInfo.normalizedValue);
463: int dotx = lexical.indexOf('.');
464: if (dotx != -1) {
465: lexical = lexical.substring(0, dotx);
466: }
467: if (decimalDV.getTotalDigits(xsdValue) > 18) {
468: return new BigInteger(lexical);
469: } else {
470: return suitableInteger(lexical);
471: }
472:
473: default:
474: return parseValidated(validatedInfo.normalizedValue);
475: }
476: }
477:
478: /**
479: @param lexical
480: @return
481: */
482: protected Number suitableInteger(String lexical) {
483: long number = Long.parseLong(lexical);
484: return suitableInteger(number);
485: }
486:
487: /**
488: @param number
489: @return
490: */
491: protected Number suitableInteger(long number) {
492: if (number > Integer.MAX_VALUE || number < Integer.MIN_VALUE)
493: return new Long(number);
494: else
495: return new Integer((int) number);
496: }
497:
498: /**
499: * Parse a validated lexical form. Subclasses which use the default
500: * parse implementation and are not convered by the explicit convertValidatedData
501: * cases should override this.
502: */
503: public Object parseValidated(String lexical) {
504: return lexical;
505: }
506:
507: /**
508: * Test whether the given LiteralLabel is a valid instance
509: * of this datatype. This takes into accound typing information
510: * as well as lexical form - for example an xsd:string is
511: * never considered valid as an xsd:integer (even if it is
512: * lexically legal like "1").
513: */
514: public boolean isValidLiteral(LiteralLabel lit) {
515: return isBaseTypeCompatible(lit)
516: && isValid(lit.getLexicalForm());
517: }
518:
519: /**
520: * Test if the given typed value is in the right partition of the XSD type space.
521: * If this test passes then if the typed value has a legal lexical form for
522: * this type then it is a legal instance.
523: */
524: public boolean isBaseTypeCompatible(LiteralLabel lit) {
525: XSTypeDefinition base = getFoundingType();
526: RDFDatatype litDT = lit.getDatatype();
527: if (litDT instanceof XSDDatatype) {
528: XSTypeDefinition litBase = ((XSDDatatype) litDT)
529: .getFoundingType();
530: return base.equals(litBase);
531:
532: } else if (litDT == null && lit.language().equals("")) {
533: // Special RDF case, a plain literal is type compatible with and xsd:string-based type
534: return base.equals(XSDstring.typeDeclaration);
535: } else {
536: return false;
537: }
538: }
539:
540: /**
541: * Return the most specific type below xsd:anySimpleType that this type is derived from.
542: */
543: private XSTypeDefinition getFoundingType() {
544: XSTypeDefinition founding = typeDeclaration;
545: XSTypeDefinition parent = founding.getBaseType();
546: while (parent.getBaseType() != null) {
547: founding = parent;
548: parent = founding.getBaseType();
549: }
550: return founding;
551: }
552:
553: /**
554: * Helper function to return the substring of a validated number string
555: * omitting any leading + sign.
556: */
557: public static String trimPlus(String str) {
558: int i = str.indexOf('+');
559: if (i == -1) {
560: return str;
561: } else {
562: return str.substring(i + 1);
563: }
564: }
565:
566: /**
567: * Add all of the XSD pre-defined simple types to the given
568: * type mapper registry.
569: */
570: public static void loadXSDSimpleTypes(TypeMapper tm) {
571: tm.registerDatatype(new XSDDatatype("anySimpleType"));
572:
573: tm.registerDatatype(XSDdecimal);
574: tm.registerDatatype(XSDinteger);
575: tm.registerDatatype(XSDnonPositiveInteger);
576: tm.registerDatatype(XSDnonNegativeInteger);
577: tm.registerDatatype(XSDpositiveInteger);
578: tm.registerDatatype(XSDnegativeInteger);
579:
580: tm.registerDatatype(XSDbyte);
581: tm.registerDatatype(XSDunsignedByte);
582: tm.registerDatatype(XSDdouble);
583: tm.registerDatatype(XSDfloat);
584: tm.registerDatatype(XSDlong);
585: tm.registerDatatype(XSDunsignedInt);
586: tm.registerDatatype(XSDunsignedShort);
587: tm.registerDatatype(XSDunsignedLong);
588: tm.registerDatatype(XSDint);
589: tm.registerDatatype(XSDshort);
590:
591: tm.registerDatatype(XSDboolean);
592: tm.registerDatatype(XSDbase64Binary);
593: tm.registerDatatype(XSDhexBinary);
594:
595: tm.registerDatatype(XSDdate);
596: tm.registerDatatype(XSDtime);
597: tm.registerDatatype(XSDdateTime);
598: tm.registerDatatype(XSDduration);
599: tm.registerDatatype(XSDgYearMonth);
600: tm.registerDatatype(XSDgMonthDay);
601: tm.registerDatatype(XSDgMonth);
602: tm.registerDatatype(XSDgDay);
603: tm.registerDatatype(XSDgYear);
604:
605: tm.registerDatatype(XSDnormalizedString);
606: tm.registerDatatype(XSDstring);
607: tm.registerDatatype(XSDanyURI);
608:
609: tm.registerDatatype(XSDtoken);
610: tm.registerDatatype(XSDName);
611: tm.registerDatatype(XSDlanguage);
612: tm.registerDatatype(XSDQName);
613: tm.registerDatatype(XSDNMTOKEN);
614: tm.registerDatatype(XSDID);
615: tm.registerDatatype(XSDENTITY);
616: tm.registerDatatype(XSDNCName);
617: tm.registerDatatype(XSDNOTATION);
618: tm.registerDatatype(XSDIDREF);
619:
620: // tm.registerDatatype(XSDIDREFS);
621: // tm.registerDatatype(XSDENTITIES);
622: // tm.registerDatatype(XSDNMTOKENS);
623: }
624:
625: // Temporary - used bootstrap the above initialization code
626: public static void main(String[] args) {
627: SymbolHash types = SchemaDVFactory.getInstance()
628: .getBuiltInTypes();
629: int len = types.getLength();
630: Object[] values = new Object[len];
631: types.getValues(values, 0);
632: for (int i = 0; i < values.length; i++) {
633: if (values[i] instanceof XSSimpleTypeDecl) {
634: XSSimpleTypeDecl decl = (XSSimpleTypeDecl) values[i];
635: System.out
636: .println("tm.registerDatatype(new XSDDatatype(\""
637: + decl.getName() + "\"));");
638: } else {
639: System.out.println(" - " + values[i]);
640: }
641: }
642: }
643:
644: public int getHashCode(byte[] bytes) {
645: int length = bytes.length;
646: return length == 0 ? 0 : (bytes[0] << 12)
647: ^ (bytes[length / 2] << 6) ^ (bytes[length - 1])
648: ^ length;
649: }
650:
651: }
652:
653: /*
654: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
655: All rights reserved.
656:
657: Redistribution and use in source and binary forms, with or without
658: modification, are permitted provided that the following conditions
659: are met:
660:
661: 1. Redistributions of source code must retain the above copyright
662: notice, this list of conditions and the following disclaimer.
663:
664: 2. Redistributions in binary form must reproduce the above copyright
665: notice, this list of conditions and the following disclaimer in the
666: documentation and/or other materials provided with the distribution.
667:
668: 3. The name of the author may not be used to endorse or promote products
669: derived from this software without specific prior written permission.
670:
671: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
672: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
673: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
674: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
675: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
676: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
677: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
678: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
679: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
680: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
681: */
|