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

newSchema(Source) throws Exception for DOMSource & SAXSource

XMLWordPrintable

    • 1.3
    • generic
    • generic

        newSchema(Source) throws Exception for DOMSource & SAXSource

        Test program and sample schema file attached .
        To run the test program , edit 'testDirPath' and 'xmlPath' in Test3.java to point to the directory where sample schema is saved.

        TestProgram - Test3.java
        ------------------------

        import javax.xml.validation.Schema;
        import javax.xml.validation.SchemaFactory;

        import org.xml.sax.InputSource;
        import org.xml.sax.SAXException;

        import org.w3c.dom.Document;

        import javax.xml.transform.sax.SAXSource;
        import javax.xml.transform.dom.DOMSource;

        import javax.xml.parsers.ParserConfigurationException;
        import javax.xml.parsers.DocumentBuilderFactory;

        import java.io.IOException;
        import java.io.File;
        import java.io.FileInputStream;

        public class Test3 {
         
            String xmlPath = "";
            String testDirPath = "";
           
           // constructor
            Test3() {
              
            testDirPath = "/home/sa122568/Jaxp/test";
            xmlPath = testDirPath + "/xmlfiles/";
            
           }
        // main()
            public static void main(String[] argv) {
                
                Test3 test3 = new Test3();
                test3.checkSchemaFactory01();
                test3.checkSchemaFactory02();
           }
           
        // test for W3C XML Schema 1.0 - newSchema(Source schema)
        // supports and return a valid Schema instance
        // SAXSource - valid schema

          private void checkSchemaFactory01() {
                try {
        SchemaFactory sf01 = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        InputSource is01 = new InputSource (new FileInputStream(xmlPath + "test.xsd"));
        SAXSource saxSource01 = new SAXSource (is01);
        System.out.println("SAXSource created in checkSchemaFactory01()");
        Schema schema01 = sf01.newSchema(saxSource01);
        System.out.println(" Schema in checkSchemaFactory01()");
                    if (schema01 instanceof Schema){
        System.out.println("SchemaFactory01/checkSchemaFactory01() passed");
        }
        } catch (NullPointerException npe){
        System.out.println(" NullPointerException thrown in Test3/checkSchemaFactory01() - failed");
        } catch (UnsupportedOperationException uoe){
        System.out.println(" UnsupportedOperationException thrown in Test3/checkSchemaFactory01() ");
        } catch (SAXException saxe){
        System.out.println(" Operation supported but failed in Test3/checkSchemaFactory01() " + saxe.getMessage());
        } catch (IOException ioe ){
        System.out.println(" Exception thrown in Test3/checkSchemaFactory01() failed"+ioe.getMessage());
        } catch (Exception e ){
        System.out.println(" Exception thrown in Test3/checkSchemaFactory01() failed"+e.getMessage());
        }
            }


        // test for W3C XML Schema 1.0 - newSchema(Source schema)
        // supports and return a valid Schema instance
        // DOMSource - valid schema

          private void checkSchemaFactory02() {
                try {
                    Document document02 = null;
        SchemaFactory sf02 = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        DocumentBuilderFactory dbf02 = DocumentBuilderFactory.newInstance();
        dbf02.setNamespaceAware(true);
        document02 = dbf02.newDocumentBuilder().parse(new File(xmlPath + "test.xsd"));
        DOMSource domSource02 = new DOMSource(document02);
        System.out.println("DOMSource created in checkSchemaFactory02() ");
        Schema schema02 = sf02.newSchema(domSource02);
        System.out.println("Schema in checkSchemaFactory02()");
                    if (schema02 instanceof Schema){
        System.out.println("SchemaFactory01/checkSchemaFactory02() passed");
        }

        } catch (NullPointerException npe){
        System.out.println(" NullPointerException thrown in Test3/checkSchemaFactory02() - failed");
        } catch (UnsupportedOperationException uoe){
        System.out.println(" UnsupportedOperationException thrown in Test3/checkSchemaFactory02() ");
        } catch (SAXException saxe){
        System.out.println(" Operation supported but failed in Test3/checkSchemaFactory02() " + saxe.getMessage());
        } catch (IOException ioe ){
        System.out.println(" IOException thrown in Test3/checkSchemaFactory02() failed"+ioe.getMessage());
        } catch (Exception e ){
        System.out.println(" Exception thrown in Test3/checkSchemaFactory02() failed"+e.getMessage());
        }
            }


        }

        ---------------------------------
        verified in Tiger 1.5.0-beta2-b44
        ###@###.### 2004-03-30
        ---------------------------------

              kkawagucsunw Kohsuke Kawaguchi (Inactive)
              saksunw Sreejith Ak (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: