001/*
002 * Copyright (c) 2004 World Wide Web Consortium,
003 *
004 * (Massachusetts Institute of Technology, European Research Consortium for
005 * Informatics and Mathematics, Keio University). All Rights Reserved. This
006 * work is distributed under the W3C(r) Software License [1] in the hope that
007 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
008 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
009 *
010 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
011 */
012
013package org.w3c.dom;
014
015/**
016 *  The <code>TypeInfo</code> interface represents a type referenced from
017 * <code>Element</code> or <code>Attr</code> nodes, specified in the schemas
018 * associated with the document. The type is a pair of a namespace URI and
019 * name properties, and depends on the document's schema.
020 * <p> If the document's schema is an XML DTD [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>], the values
021 * are computed as follows:
022 * <ul>
023 * <li> If this type is referenced from an
024 * <code>Attr</code> node, <code>typeNamespace</code> is
025 * <code>"http://www.w3.org/TR/REC-xml"</code> and <code>typeName</code>
026 * represents the <b>[attribute type]</b> property in the [<a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204/'>XML Information Set</a>]
027 * . If there is no declaration for the attribute, <code>typeNamespace</code>
028 *  and <code>typeName</code> are <code>null</code>.
029 * </li>
030 * <li> If this type is
031 * referenced from an <code>Element</code> node, <code>typeNamespace</code>
032 * and <code>typeName</code> are <code>null</code>.
033 * </li>
034 * </ul>
035 * <p> If the document's schema is an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
036 * , the values are computed as follows using the post-schema-validation
037 * infoset contributions (also called PSVI contributions):
038 * <ul>
039 * <li> If the <b>[validity]</b> property exists AND is <em>"invalid"</em> or <em>"notKnown"</em>: the {target namespace} and {name} properties of the declared type if
040 * available, otherwise <code>null</code>.
041 * <p ><b>Note:</b>  At the time of writing, the XML Schema specification does
042 * not require exposing the declared type. Thus, DOM implementations might
043 * choose not to provide type information if validity is not valid.
044 * </li>
045 * <li> If the <b>[validity]</b> property exists and is <em>"valid"</em>:
046 * <ol>
047 * <li> If <b>[member type definition]</b> exists:
048 * <ol>
049 * <li>If {name} is not absent, then expose {name} and {target
050 * namespace} properties of the <b>[member type definition]</b> property;
051 * </li>
052 * <li>Otherwise, expose the namespace and local name of the
053 * corresponding anonymous type name.
054 * </li>
055 * </ol>
056 * </li>
057 * <li> If the <b>[type definition]</b> property exists:
058 * <ol>
059 * <li>If {name} is not absent, then expose {name} and {target
060 * namespace} properties of the <b>[type definition]</b> property;
061 * </li>
062 * <li>Otherwise, expose the namespace and local name of the
063 * corresponding anonymous type name.
064 * </li>
065 * </ol>
066 * </li>
067 * <li> If the <b>[member type definition anonymous]</b> exists:
068 * <ol>
069 * <li>If it is false, then expose <b>[member type definition name]</b> and <b>[member type definition namespace]</b> properties;
070 * </li>
071 * <li>Otherwise, expose the namespace and local name of the
072 * corresponding anonymous type name.
073 * </li>
074 * </ol>
075 * </li>
076 * <li> If the <b>[type definition anonymous]</b> exists:
077 * <ol>
078 * <li>If it is false, then expose <b>[type definition name]</b> and <b>[type definition namespace]</b> properties;
079 * </li>
080 * <li>Otherwise, expose the namespace and local name of the
081 * corresponding anonymous type name.
082 * </li>
083 * </ol>
084 * </li>
085 * </ol>
086 * </li>
087 * </ul>
088 * <p ><b>Note:</b>  Other schema languages are outside the scope of the W3C
089 * and therefore should define how to represent their type systems using
090 * <code>TypeInfo</code>.
091 * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>Document Object Model (DOM) Level 3 Core Specification</a>.
092 * @since DOM Level 3
093 */
094public interface TypeInfo {
095    /**
096     *  The name of a type declared for the associated element or attribute,
097     * or <code>null</code> if unknown.
098     */
099    public String getTypeName();
100
101    /**
102     *  The namespace of the type declared for the associated element or
103     * attribute or <code>null</code> if the element does not have
104     * declaration or if no namespace information is available.
105     */
106    public String getTypeNamespace();
107
108    // DerivationMethods
109    /**
110     *  If the document's schema is an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
111     * , this constant represents the derivation by <a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#key-typeRestriction'>
112     * restriction</a> if complex types are involved, or a <a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-restriction'>
113     * restriction</a> if simple types are involved.
114     * <br>  The reference type definition is derived by restriction from the
115     * other type definition if the other type definition is the same as the
116     * reference type definition, or if the other type definition can be
117     * reached recursively following the {base type definition} property
118     * from the reference type definition, and all the <em>derivation methods</em> involved are restriction.
119     */
120    public static final int DERIVATION_RESTRICTION    = 0x00000001;
121    /**
122     *  If the document's schema is an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
123     * , this constant represents the derivation by <a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#key-typeExtension'>
124     * extension</a>.
125     * <br>  The reference type definition is derived by extension from the
126     * other type definition if the other type definition can be reached
127     * recursively following the {base type definition} property from the
128     * reference type definition, and at least one of the <em>derivation methods</em> involved is an extension.
129     */
130    public static final int DERIVATION_EXTENSION      = 0x00000002;
131    /**
132     *  If the document's schema is an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
133     * , this constant represents the <a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-union'>
134     * union</a> if simple types are involved.
135     * <br> The reference type definition is derived by union from the other
136     * type definition if there exists two type definitions T1 and T2 such
137     * as the reference type definition is derived from T1 by
138     * <code>DERIVATION_RESTRICTION</code> or
139     * <code>DERIVATION_EXTENSION</code>, T2 is derived from the other type
140     * definition by <code>DERIVATION_RESTRICTION</code>, T1 has {variety} <em>union</em>, and one of the {member type definitions} is T2. Note that T1 could be
141     * the same as the reference type definition, and T2 could be the same
142     * as the other type definition.
143     */
144    public static final int DERIVATION_UNION          = 0x00000004;
145    /**
146     *  If the document's schema is an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
147     * , this constant represents the <a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-list'>list</a>.
148     * <br> The reference type definition is derived by list from the other
149     * type definition if there exists two type definitions T1 and T2 such
150     * as the reference type definition is derived from T1 by
151     * <code>DERIVATION_RESTRICTION</code> or
152     * <code>DERIVATION_EXTENSION</code>, T2 is derived from the other type
153     * definition by <code>DERIVATION_RESTRICTION</code>, T1 has {variety} <em>list</em>, and T2 is the {item type definition}. Note that T1 could be the same as
154     * the reference type definition, and T2 could be the same as the other
155     * type definition.
156     */
157    public static final int DERIVATION_LIST           = 0x00000008;
158
159    /**
160     *  This method returns if there is a derivation between the reference
161     * type definition, i.e. the <code>TypeInfo</code> on which the method
162     * is being called, and the other type definition, i.e. the one passed
163     * as parameters.
164     * @param typeNamespaceArg  the namespace of the other type definition.
165     * @param typeNameArg  the name of the other type definition.
166     * @param derivationMethod  the type of derivation and conditions applied
167     *   between two types, as described in the list of constants provided
168     *   in this interface.
169     * @return  If the document's schema is a DTD or no schema is associated
170     *   with the document, this method will always return <code>false</code>
171     *   .  If the document's schema is an XML Schema, the method will
172     *   <code>true</code> if the reference type definition is derived from
173     *   the other type definition according to the derivation parameter. If
174     *   the value of the parameter is <code>0</code> (no bit is set to
175     *   <code>1</code> for the <code>derivationMethod</code> parameter),
176     *   the method will return <code>true</code> if the other type
177     *   definition can be reached by recursing any combination of {base
178     *   type definition}, {item type definition}, or {member type
179     *   definitions} from the reference type definition.
180     */
181    public boolean isDerivedFrom(String typeNamespaceArg,
182                                 String typeNameArg,
183                                 int derivationMethod);
184
185}