Class XSOMParser


  • public final class XSOMParser
    extends java.lang.Object
    Parses possibly multiple W3C XML Schema files and compose them into one grammar.
    Author:
    Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    • Constructor Summary

      Constructors 
      Constructor Description
      XSOMParser()
      Deprecated.
      Unsafe, use XSOMParser(factory) instead with security features initialized by setting XMLConstants.FEATURE_SECURE_PROCESSING feature.
      XSOMParser​(XMLParser parser)
      Creates a new XSOMParser that reads XML Schema from non-standard inputs.
      XSOMParser​(javax.xml.parsers.SAXParserFactory factory)
      Creates a new XSOMParser that uses the given SAXParserFactory for creating new SAX parsers.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AnnotationParserFactory getAnnotationParserFactory()  
      java.util.Set<SchemaDocument> getDocuments()
      Gets the set of SchemaDocument that represents parsed documents so far.
      org.xml.sax.EntityResolver getEntityResolver()  
      org.xml.sax.ErrorHandler getErrorHandler()  
      org.xml.sax.ContentHandler getParserHandler()
      Gets the parser implemented as a ContentHandler.
      XSSchemaSet getResult()
      Gets the parsed result.
      void parse​(java.io.File schema)
      Parses a new XML Schema document.
      void parse​(java.io.InputStream is)
      Parses a new XML Schema document.
      void parse​(java.io.Reader reader)
      Parses a new XML Schema document.
      void parse​(java.lang.String systemId)
      Parses a new XML Schema document.
      void parse​(java.net.URL url)
      Parses a new XML Schema document.
      void parse​(org.xml.sax.InputSource source)
      Parses a new XML Schema document.
      void setAnnotationParser​(AnnotationParserFactory factory)
      Sets the annotation parser factory.
      void setAnnotationParser​(java.lang.Class annParser)
      Sets the annotation parser.
      void setEntityResolver​(org.xml.sax.EntityResolver resolver)
      Set an entity resolver that is used to resolve things like <xsd:import> and <xsd:include>.
      void setErrorHandler​(org.xml.sax.ErrorHandler errorHandler)
      Set an error handler that receives all the errors encountered during the parsing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XSOMParser

        public XSOMParser()
        Deprecated.
        Unsafe, use XSOMParser(factory) instead with security features initialized by setting XMLConstants.FEATURE_SECURE_PROCESSING feature.
        Creates a new XSOMParser by using a SAX parser from JAXP.
      • XSOMParser

        public XSOMParser​(javax.xml.parsers.SAXParserFactory factory)
        Creates a new XSOMParser that uses the given SAXParserFactory for creating new SAX parsers. The caller needs to configure it properly. Don't forget to call setNamespaceAware(true) or you'll see some strange errors.
      • XSOMParser

        public XSOMParser​(XMLParser parser)
        Creates a new XSOMParser that reads XML Schema from non-standard inputs. By implementing the XMLParser interface, XML Schema can be read from something other than XML.
        Parameters:
        parser - This parser will be called to parse XML Schema documents.
    • Method Detail

      • parse

        public void parse​(java.io.InputStream is)
                   throws org.xml.sax.SAXException
        Parses a new XML Schema document.

        When using this method, XSOM does not know the system ID of this document, therefore, when this stream contains relative references to other schemas, XSOM will fail to resolve them. To specify an system ID with a stream, use InputSource

        Throws:
        org.xml.sax.SAXException
      • parse

        public void parse​(java.io.Reader reader)
                   throws org.xml.sax.SAXException
        Parses a new XML Schema document.

        When using this method, XSOM does not know the system ID of this document, therefore, when this reader contains relative references to other schemas, XSOM will fail to resolve them. To specify an system ID with a reader, use InputSource

        Throws:
        org.xml.sax.SAXException
      • parse

        public void parse​(java.io.File schema)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
        Parses a new XML Schema document.
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • parse

        public void parse​(java.net.URL url)
                   throws org.xml.sax.SAXException
        Parses a new XML Schema document.
        Throws:
        org.xml.sax.SAXException
      • parse

        public void parse​(java.lang.String systemId)
                   throws org.xml.sax.SAXException
        Parses a new XML Schema document.
        Throws:
        org.xml.sax.SAXException
      • parse

        public void parse​(org.xml.sax.InputSource source)
                   throws org.xml.sax.SAXException
        Parses a new XML Schema document.

        Note that if the InputSource does not have a system ID, XSOM will fail to resolve them.

        Throws:
        org.xml.sax.SAXException
      • getParserHandler

        public org.xml.sax.ContentHandler getParserHandler()
        Gets the parser implemented as a ContentHandler. One can feed XML Schema as SAX events to this interface to parse a schema. To parse multiple schema files, feed multiple sets of events.

        If you don't send a complete event sequence from a startDocument event to an endDocument event, the state of XSOMParser can become unstable. This sometimes happen when you encounter an error while generating SAX events. Don't call the getResult method in that case.

        This way of reading XML Schema can be useful when XML Schema is not available as a stand-alone XML document. For example, one can feed XML Schema inside a WSDL document.

      • getResult

        public XSSchemaSet getResult()
                              throws org.xml.sax.SAXException
        Gets the parsed result. Don't call this method until you parse all the schemas.
        Returns:
        If there was any parse error, this method returns null. To receive error information, specify your error handler through the setErrorHandler method.
        Throws:
        org.xml.sax.SAXException - This exception will never be thrown unless it is thrown by an error handler.
      • getDocuments

        public java.util.Set<SchemaDocument> getDocuments()
        Gets the set of SchemaDocument that represents parsed documents so far.
        Returns:
        can be empty but never null.
      • getEntityResolver

        public org.xml.sax.EntityResolver getEntityResolver()
      • setEntityResolver

        public void setEntityResolver​(org.xml.sax.EntityResolver resolver)
        Set an entity resolver that is used to resolve things like <xsd:import> and <xsd:include>.
      • getErrorHandler

        public org.xml.sax.ErrorHandler getErrorHandler()
      • setErrorHandler

        public void setErrorHandler​(org.xml.sax.ErrorHandler errorHandler)
        Set an error handler that receives all the errors encountered during the parsing.
      • setAnnotationParser

        public void setAnnotationParser​(java.lang.Class annParser)
        Sets the annotation parser. Annotation parser can be used to parse application-specific annotations inside a schema.

        For each annotation, new instance of this class will be created and used to parse <xs:annotation>.

      • setAnnotationParser

        public void setAnnotationParser​(AnnotationParserFactory factory)
        Sets the annotation parser factory.

        The specified factory will be used to create AnnotationParsers.