DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20525>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20525

Invlalid ELEMENT_DECLARATION returned after printing the length of the components list

           Summary: Invlalid ELEMENT_DECLARATION returned after printing the
                    length of the components list
           Product: Xerces2-J
           Version: 2.4.0
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: XML Schema Structures
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]
                CC: [EMAIL PROTECTED]


Product version:  Xerces-J 2.4.0

OS version: Microsoft Windows 2000 [Version 5.00.2195]

JDK version: 
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

This seems to be a problem with the latest Xerces (2.4.0) as well as the one I 
was using last fall (2.2.0). Basically just calling getComponents 
(...).getLength method on an XSModel object causes a future call for components 
of ELEMENT_DECLARATION (there are possibly more variations for failure as well) 
to fail.

I have a test schema (see below) and when I query the grammar object (AFTER 
printing out the length of the components) for the ELEMENT_DECLARATION's, in 
one case I get an exception thrown from Xerces and in another case I get the 
ATTRIBUTE_DECLARATION's instead! Here is the code snippet:

        
        XMLSchemaLoader xmlSchemaLoader = new XMLSchemaLoader();

        XMLInputSource xmlInputSource = new XMLInputSource (null, schemaFile.
          getName (), schemaFile.toURI ().getPath ());

        FileInputStream inputStream = null;
        try
        {
                inputStream = new FileInputStream (schemaFile);
        }
        catch (Exception pException) { pException.printStackTrace (); }

        xmlInputSource.setByteStream (inputStream);


        // ***********************************************************
        // Variation 1 begin
        // ***********************************************************
        // Causes following exception:
        //java.lang.ArrayIndexOutOfBoundsException: 2
        //  at org.apache.xerces.util.SymbolHash.getValues(Unknown
        //    Source)
        //  at org.apache.xerces.impl.xs.util.XSNamedMapImpl.item(
        //  Unknown Source)
        XSGrammar schemaGrammar = null;
        try
        {
                schemaGrammar = (XSGrammar) xmlSchemaLoader.loadGrammar (
                  xmlInputSource);
        
                XSModel schemaModel = schemaGrammar.toXSModel();
        
                System.out.println ("Number of element components: " + 
schemaModel.
                  getComponents (XSConstants.ELEMENT_DECLARATION).getLength ());
        
                System.out.println ("Complex components begin:");
                XSNamedMap complexComponents = schemaModel.getComponents (
                  XSTypeDefinition.COMPLEX_TYPE);
                for (int i = 0; i < complexComponents.getLength (); i++)
                {
                        System.out.println ("\tNamespace:Name: " + 
complexComponents.
                          item (i).getNamespace () + ":" + 
complexComponents.item  (i).
                          getName ());
                }
                System.out.println ("Complex components end...\n\n");
        
                XSNamedMap elementComponents = schemaModel.getComponents (
                  XSConstants.ELEMENT_DECLARATION);
                System.out.println ("Element components begin (" + 
elementComponents.
                  getLength () + ")");
                for (int i = 0; i < elementComponents.getLength (); i++)
                {
                        // Exception thrown here ==> Buglet!!!
                        System.out.println ("\tNamespace:Name: " + 
elementComponents.
                          item (i).getNamespace () + ":" + 
elementComponents.item (i).
                          getName ());
                }
                System.out.println ("Element components end...\n");
        
                System.out.println ("Attribute components begin:");
                XSNamedMap attributeComponents = schemaModel.getComponents (
                  XSConstants.ATTRIBUTE_DECLARATION);
                for (int i = 0; i < attributeComponents.getLength (); i++)
                {
                        System.out.println ("\tNamespace:Name: " + 
attributeComponents.
                          item (i).getNamespace () + ":" + 
attributeComponents.item (i).
                          getName ());
                }
                System.out.println ("Attribute components end...\n");
        }
        catch (Exception pException)
        {
                pException.printStackTrace ();
        }
        // ***********************************************************
        // Variation 1 end
        // ***********************************************************
        
        
        
        // ***********************************************************
        // Variation 2 begin
        // ***********************************************************
        // Seems to cause the ATTRIBUTE_DECLARATION components to be
        // returned instead of ELEMENT_DECLARATION
        XSGrammar schemaGrammar = null;
        try
        {
                schemaGrammar = (XSGrammar) xmlSchemaLoader.loadGrammar (
                  xmlInputSource);
        
                XSModel schemaModel = schemaGrammar.toXSModel();
        
        
                System.out.println ("Number of complex components: " + 
schemaModel.
                  getComponents (XSTypeDefinition.COMPLEX_TYPE).getLength ());
                System.out.println ("Number of simple components: " + 
schemaModel.
                  getComponents (XSTypeDefinition.SIMPLE_TYPE).getLength ());
                
                System.out.println ("Number of element components: " + 
schemaModel.
                  getComponents (XSConstants.ELEMENT_DECLARATION).getLength ());
                
                System.out.println ("Number of attribute components: " + 
schemaModel.
                  getComponents (XSConstants.ATTRIBUTE_DECLARATION).getLength 
()); 
        
                System.out.println ("Complex components begin:");
                XSNamedMap complexComponents = schemaModel.getComponents (
                  XSTypeDefinition.COMPLEX_TYPE);
                for (int i = 0; i < complexComponents.getLength (); i++)
                {
                        System.out.println ("\tNamespace:Name: " + 
complexComponents.
                          item (i).getNamespace () + ":" + 
complexComponents.item  (i).
                          getName ());
                }
                System.out.println ("Complex components end...\n\n");
        
                XSNamedMap elementComponents = schemaModel.getComponents (
                  XSConstants.ELEMENT_DECLARATION);
                System.out.println ("Element components begin (" + 
elementComponents.
                  getLength () + ")");
                for (int i = 0; i < elementComponents.getLength (); i++)
                {
                        // Note: this shouldn't be null but it is!!! ==> 
buglet!!!
                        if (elementComponents.item  (i) == null)
                        {
                                System.out.println ("Element was null...");
                                continue;
                        }
                
                        System.out.println ("\tNamespace:Name: " + 
elementComponents.
                          item (i).getNamespace () + ":" + 
elementComponents.item (i).
                          getName ());
                }
                System.out.println ("Element components end...\n");
        
                System.out.println ("Attribute components begin:");
                XSNamedMap attributeComponents = schemaModel.getComponents (
                  XSConstants.ATTRIBUTE_DECLARATION);
                for (int i = 0; i < attributeComponents.getLength (); i++)
                {
                        System.out.println ("\tNamespace:Name: " + 
attributeComponents.
                          item (i).getNamespace () + ":" + 
attributeComponents.item (i).
                          getName ());
                }
                System.out.println ("Attribute components end...\n");
        }
        catch (Exception pException)
        {
                pException.printStackTrace ();
        }
        // ***********************************************************
        // Variation 2 end
        // ***********************************************************

<<< Test schema begin >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<?xml version = "1.0" ?>
        <schema xmlns = "http://www.w3.org/2001/XMLSchema";>
        
        <element name = "Customer">
                <complexType>
                        <sequence>
                                <element name = "FirstName" type = "string" />
                                <element name = "MiddleInitial" type 
= "string" />
                                <element name = "LastName" type = "string" />
                        </sequence>
                </complexType>
        </element>

        <element name = "SimpleElement" type = "string" />

        <complexType name = "TestComplexType">
                <attribute name = "testAttribute" type = "string"/>
        </complexType>

        <attribute name = "languageUsed" type = "language"/>

</schema>
<<< Test schema end >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to