01: package net.sf.saxon.dom;
02:
03: import net.sf.saxon.type.SchemaType;
04: import net.sf.saxon.type.AnyType;
05: import net.sf.saxon.Configuration;
06: import org.w3c.dom.TypeInfo;
07:
08: /**
09: * This class implements the DOM TypeInfo interface as a wrapper over the Saxon SchemaType
10: * interface.
11: */
12:
13: public class TypeInfoImpl implements TypeInfo {
14:
15: private Configuration config;
16: private SchemaType schemaType;
17:
18: /**
19: * Construct a TypeInfo based on a SchemaType
20: */
21:
22: public TypeInfoImpl(Configuration config, SchemaType type) {
23: this .config = config;
24: this .schemaType = type;
25: }
26:
27: /**
28: * Get the local name of the type (a system-allocated name if anonymous). Needed to implement the
29: * DOM level 3 TypeInfo interface.
30: */
31:
32: public String getTypeName() {
33: return config.getNamePool().getLocalName(
34: schemaType.getNameCode());
35: }
36:
37: /**
38: * Get the namespace name of the type (a system-allocated name if anonymous). Needed to implement the
39: * DOM level 3 TypeInfo interface.
40: */
41:
42: public String getTypeNamespace() {
43: return config.getNamePool().getURI(schemaType.getNameCode());
44: }
45:
46: /**
47: * This method returns true if there is a derivation between the reference type definition, that is the TypeInfo
48: * on which the method is being called, and the other type definition, that is the one passed as parameters.
49: * This method implements the DOM Level 3 TypeInfo interface. It must be called only on a valid type.
50: * @param typeNamespaceArg the namespace of the "other" type
51: * @param typeNameArg the local name of the "other" type
52: * @param derivationMethod the derivation method: zero or more of {@link SchemaType#DERIVATION_RESTRICTION},
53: * {@link SchemaType#DERIVATION_EXTENSION}, {@link SchemaType#DERIVATION_LIST}, or {@link SchemaType#DERIVATION_UNION}.
54: * Zero means derived by any possible route.
55: */
56:
57: public boolean isDerivedFrom(String typeNamespaceArg,
58: String typeNameArg, int derivationMethod)
59: throws IllegalStateException {
60: SchemaType base = schemaType.getBaseType();
61: int fingerprint = config.getNamePool().allocate("",
62: typeNamespaceArg, typeNameArg);
63: if (derivationMethod == 0
64: || (derivationMethod & schemaType.getDerivationMethod()) != 0) {
65: if (base.getFingerprint() == fingerprint) {
66: return true;
67: } else if (base instanceof AnyType) {
68: return false;
69: } else {
70: return new TypeInfoImpl(config, base)
71: .isDerivedFrom(typeNamespaceArg, typeNameArg,
72: derivationMethod);
73: }
74: }
75: return false;
76: // Note: if derivationMethod is RESTRICTION, this interpretation requires every step to be derived
77: // by restriction. An alternative interpretation is that at least one step must be derived by restriction.
78: }
79:
80: }
81:
82: //
83: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
84: // you may not use this file except in compliance with the License. You may obtain a copy of the
85: // License at http://www.mozilla.org/MPL/
86: //
87: // Software distributed under the License is distributed on an "AS IS" basis,
88: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
89: // See the License for the specific language governing rights and limitations under the License.
90: //
91: // The Original Code is: all this file.
92: //
93: // The Initial Developer of the Original Code is Saxonica Limited
94: //
95: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
96: //
97: // Contributor(s): none
98: //
|