01: package net.sf.saxon.value;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.om.NameChecker;
05: import net.sf.saxon.trans.XPathException;
06: import net.sf.saxon.type.*;
07:
08: /**
09: * An xs:NOTATION value.
10: */
11:
12: public final class NotationValue extends QNameValue {
13:
14: /**
15: * Constructor
16: * @param prefix The prefix part of the QName (not used in comparisons). Use null or "" to represent the
17: * default prefix.
18: * @param uri The namespace part of the QName. Use null or "" to represent the null namespace.
19: * @param localName The local part of the QName
20: */
21:
22: public NotationValue(String prefix, String uri, String localName,
23: NameChecker checker) throws XPathException {
24: super (prefix, uri, localName, checker);
25: }
26:
27: /**
28: * Convert to target data type
29: * @param requiredType an integer identifying the required atomic type
30: * @param context
31: * @return an AtomicValue, a value of the required type; or an ErrorValue
32: */
33:
34: public AtomicValue convertPrimitive(BuiltInAtomicType requiredType,
35: boolean validate, XPathContext context) {
36: switch (requiredType.getPrimitiveType()) {
37: case Type.ANY_ATOMIC:
38: case Type.ITEM:
39: case Type.QNAME:
40: case Type.STRING:
41: case Type.UNTYPED_ATOMIC:
42: return super .convertPrimitive(requiredType, validate,
43: context);
44: default:
45: ValidationException err = new ValidationException(
46: "Cannot convert NOTATION to "
47: + requiredType.getDisplayName());
48: err.setErrorCode("XPTY0004");
49: err.setIsTypeError(true);
50: return new ValidationErrorValue(err);
51: }
52: }
53:
54: /**
55: * Return the type of the expression
56: * @return Type.NOTATION (always)
57: * @param th
58: */
59:
60: public ItemType getItemType(TypeHierarchy th) {
61: return Type.NOTATION_TYPE;
62: }
63:
64: /**
65: * The toString() method returns the name in the form QName("uri", "local")
66: * @return the name in Clark notation: {uri}local
67: */
68:
69: public String toString() {
70: return "NOTATION(" + getClarkName() + ')';
71: }
72:
73: }
74:
75: //
76: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
77: // you may not use this file except in compliance with the License. You may obtain a copy of the
78: // License at http://www.mozilla.org/MPL/
79: //
80: // Software distributed under the License is distributed on an "AS IS" basis,
81: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
82: // See the License for the specific language governing rights and limitations under the License.
83: //
84: // The Original Code is: all this file.
85: //
86: // The Initial Developer of the Original Code is Michael H. Kay
87: //
88: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
89: //
90: // Contributor(s): none.
91: //
|