Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4966138

TypeInfo.getTypeName() returns null if the type is simple and anonymous

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Name: erR10175 Date: 12/10/2003


         
            If an element is declared using anonymous simple type, its type info name is null,
        i.e. the method TypeInfo.getTypeName() returns null.

        The documentation of the interface org.w3c.dom.TypeInfo reads:

        "If the document's schema is an XML Schema [XML Schema Part 1] , the values are computed
        as follows using the post-schema-validation infoset contributions (also called
        PSVI contributions):
        ...
          If the [validity] property exists and is "valid":
          1. ...
          2. ...
          3. ...
          4. If the [type definition anonymous] exists:
              1. ...
              2. Otherwise, expose the namespace and local name of the corresponding anonymous
                 type name. "

        This implies that the name of the TypeInfo is not null and not empty.

        This bug affects new test in JCK 1.5 (not integrated yet)
           api/org_w3c/dom/TypeInfo/index.html#TypeInfo[GetTypeName008]

        The bug is found in jdk1.5.0/beta/b30.

        To reproduce the bug place test.java, test.xsd and test.xml to your current
        directory, then compile and run test.java as shown in the log below:
        ------------------------------------------ test.java
        import org.w3c.dom.Document;
        import org.w3c.dom.TypeInfo;
        import javax.xml.XMLConstants;
        import javax.xml.parsers.DocumentBuilderFactory;

        class test {
            static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
            static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";

            public static void main(String[] args) throws Exception {

                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware(true);
                dbf.setValidating(true);
                dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI);
                dbf.setAttribute(SCHEMA_SOURCE, "test.xsd");

                Document document = dbf.newDocumentBuilder().parse("test.xml");

                TypeInfo type = document.getDocumentElement().getSchemaTypeInfo();

                String typeName = type.getTypeName();

                if (typeName == null) {
                    System.out.println("returned typeName is null");
                } else if (typeName.length() == 0) {
                    System.out.println("returned typeName is empty");
                } else {
                    System.out.println("OK");
                }
            }
        }
        ----------------------------------------------------

        ------------------------------------------- test.xsd
        <?xml version="1.0"?>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:testNS="testNS"
                    targetNamespace="testNS" elementFormDefault="qualified">
            <xsd:element name="test5">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string"/>
                </xsd:simpleType>
            </xsd:element>
        </xsd:schema>
        ----------------------------------------------------

        ------------------------------------------- test.xml
        <?xml version='1.0'?>
        <test5 xmlns="testNS">the test</test5>
        ----------------------------------------------------

        ------------------------------------------------ log
        $javac test.java && java -cp . -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b30)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b30, mixed mode)

        returned typeName is null
        ----------------------------------------------------

        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                kkawagucsunw Kohsuke Kawaguchi (Inactive)
                Reporter:
                reysunw Rey Rey (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: