KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > dom > TypeInfoImpl


1 package net.sf.saxon.dom;
2
3 import net.sf.saxon.type.SchemaType;
4 import net.sf.saxon.type.AnyType;
5 import net.sf.saxon.Configuration;
6 import org.w3c.dom.TypeInfo JavaDoc;
7
8 /**
9  * This class implements the DOM TypeInfo interface as a wrapper over the Saxon SchemaType
10  * interface.
11  */

12
13 public class TypeInfoImpl implements TypeInfo JavaDoc {
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 JavaDoc getTypeName() {
33         return config.getNamePool().getLocalName(schemaType.getNameCode());
34     }
35
36     /**
37      * Get the namespace name of the type (a system-allocated name if anonymous). Needed to implement the
38      * DOM level 3 TypeInfo interface.
39      */

40
41     public String JavaDoc getTypeNamespace() {
42         return config.getNamePool().getURI(schemaType.getNameCode());
43     }
44
45     /**
46      * This method returns true if there is a derivation between the reference type definition, that is the TypeInfo
47      * on which the method is being called, and the other type definition, that is the one passed as parameters.
48      * This method implements the DOM Level 3 TypeInfo interface. It must be called only on a valid type.
49      * @param typeNamespaceArg the namespace of the "other" type
50      * @param typeNameArg the local name of the "other" type
51      * @param derivationMethod the derivation method: zero or more of {@link SchemaType#DERIVATION_RESTRICTION},
52      * {@link SchemaType#DERIVATION_EXTENSION}, {@link SchemaType#DERIVATION_LIST}, or {@link SchemaType#DERIVATION_UNION}.
53      * Zero means derived by any possible route.
54      */

55
56     public boolean isDerivedFrom(String JavaDoc typeNamespaceArg,
57                                  String JavaDoc typeNameArg,
58                                  int derivationMethod) throws IllegalStateException JavaDoc {
59         SchemaType base = schemaType.getBaseType();
60         int fingerprint = config.getNamePool().allocate("", typeNamespaceArg, typeNameArg);
61         if (derivationMethod==0 || (derivationMethod & schemaType.getDerivationMethod()) != 0) {
62             if (base.getFingerprint() == fingerprint) {
63                 return true;
64             } else if (base instanceof AnyType) {
65                 return false;
66             } else {
67                 return new TypeInfoImpl(config, base).isDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod);
68             }
69         }
70         return false;
71         // Note: if derivationMethod is RESTRICTION, this interpretation requires every step to be derived
72
// by restriction. An alternative interpretation is that at least one step must be derived by restriction.
73
}
74
75 }
76
77 //
78
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
79
// you may not use this file except in compliance with the License. You may obtain a copy of the
80
// License at http://www.mozilla.org/MPL/
81
//
82
// Software distributed under the License is distributed on an "AS IS" basis,
83
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
84
// See the License for the specific language governing rights and limitations under the License.
85
//
86
// The Original Code is: all this file.
87
//
88
// The Initial Developer of the Original Code is Saxonica Limited
89
//
90
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
91
//
92
// Contributor(s): none
93
//
94
Popular Tags