Class XMLMetaDataParser

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addComments​(java.lang.Object obj)
      Add current comments to the given entity.
      protected void addResult​(java.lang.Object result)
      Add a result to be returned from the current parse.
      void characters​(char[] ch, int start, int length)  
      void clear()
      Clears the cache of parsed resource names.
      protected void clearDeferredMetaData()  
      void comment​(char[] ch, int start, int length)  
      protected java.lang.ClassLoader currentClassLoader()
      Return the class loader to use when resolving resources and loading classes.
      protected java.lang.String[] currentComments()
      Array of comments for the current node, or empty array if none.
      protected int currentDepth()
      Return the parse depth.
      protected java.lang.String currentLocation()
      Return the current location within the source file.
      protected java.lang.String currentText()
      Return the text value within the current node.
      void endCDATA()  
      void endDTD()  
      protected abstract void endElement​(java.lang.String name)
      Override this method marking the end of some element.
      void endElement​(java.lang.String uri, java.lang.String name, java.lang.String qName)  
      void endEntity​(java.lang.String name)  
      void error​(org.xml.sax.SAXParseException se)  
      void fatalError​(org.xml.sax.SAXParseException se)  
      protected void finish()
      Override this method to finish up after a parse; this is only called if no errors are encountered during parsing.
      java.lang.ClassLoader getClassLoader()
      Classloader to use for class name resolution.
      protected java.io.Reader getDocType()
      Override this method to return any DOCTYPE declaration that should be dynamically included in xml documents that will be validated.
      protected org.xml.sax.SAXException getException​(java.lang.String msg)
      Returns a SAXException with the source file name and the given error message.
      protected org.xml.sax.SAXException getException​(Localizer.Message msg)
      Returns a SAXException with the source file name and the given error message.
      protected org.xml.sax.SAXException getException​(Localizer.Message msg, java.lang.Throwable cause)
      Returns a SAXException with the source file name and the given error message.
      org.xml.sax.ext.LexicalHandler getLexicalHandler()
      The lexical handler that should be registered with the SAX parser used by this class.
      Location getLocation()
      The XML document location.
      Log getLog()
      The log to write to.
      boolean getOverrideContextClassloader()  
      boolean getParseComments()
      Whether to parse element comments.
      boolean getParseText()
      Whether to parse element text.
      java.util.List getResults()
      Return the results from the last parse.
      protected java.lang.Object getSchemaSource()
      Implement to return the XML schema source for the document.
      protected java.io.File getSourceFile()
      Return the file of the source being parsed.
      boolean getSourceIsSystemId()
      Whether to use the source name as the XML system id.
      protected java.lang.String getSourceName()
      Return the name of the source file being parsed.
      java.lang.String getSuffix()
      Expected suffix for metadata resources, or null if unknown.
      protected void ignoreContent​(boolean ignoreEnd)
      Ignore all content below the current element.
      boolean isCaching()
      Whether parsed resource names are cached to avoid duplicate parsing.
      boolean isParsing()  
      boolean isValidating()
      Whether this is a validating parser.
      void parse​(java.io.File file)
      Parse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.
      void parse​(java.io.Reader xml, java.lang.String sourceName)
      Parse the metadata in the given reader.
      void parse​(java.lang.Class cls, boolean topDown)
      Parse all possible metadata locations for the given class, going top-down or bottom-up.
      void parse​(java.lang.String rsrc)
      Parse the given resource.
      void parse​(java.net.URL url)
      Parse the given resource.
      void parse​(MetaDataIterator itr)
      Parse the metadata supplied by the given iterator.
      protected boolean parsed​(java.lang.String src)
      Return true if the given source is parsed.
      protected void parseNewResource​(java.io.Reader xml, java.lang.String sourceName)
      Parse a previously-unseen source.
      protected void reset()
      Override this method to clear any state and ready the parser for a new document.
      void setCaching​(boolean caching)
      Whether parsed resource names are cached to avoid duplicate parsing.
      void setClassLoader​(java.lang.ClassLoader loader)
      Classloader to use for class name resolution.
      void setDocumentLocator​(org.xml.sax.Locator locator)  
      void setLexicalHandler​(org.xml.sax.ext.LexicalHandler lh)
      The lexical handler that should be registered with the SAX parser used by this class.
      void setLocation​(Location location)
      The XML document location.
      void setLog​(Log log)
      The log to write to.
      void setOverrideContextClassloader​(boolean overrideCCL)  
      void setParseComments​(boolean comments)
      Whether to parse element comments.
      void setParseText​(boolean text)
      Whether to parse element text.
      void setParsing​(boolean parsing)  
      void setSourceIsSystemId​(boolean systemId)
      Whether to use the source name as the XML system id.
      void setSuffix​(java.lang.String suffix)
      Expected suffix for metadata resources, or null if unknown.
      void setValidating​(boolean validating)
      Whether this is a validating parser.
      void startCDATA()  
      void startDTD​(java.lang.String name, java.lang.String publicId, java.lang.String systemId)  
      void startElement​(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)  
      protected abstract boolean startElement​(java.lang.String name, org.xml.sax.Attributes attrs)
      Override this method marking the start of some element.
      void startEntity​(java.lang.String name)  
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
      • Methods inherited from class java.lang.Object

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

      • _extendedNamespace

        protected int _extendedNamespace
      • _openjpaNamespace

        protected int _openjpaNamespace
    • Constructor Detail

      • XMLMetaDataParser

        public XMLMetaDataParser()
    • Method Detail

      • getOverrideContextClassloader

        public boolean getOverrideContextClassloader()
      • setOverrideContextClassloader

        public void setOverrideContextClassloader​(boolean overrideCCL)
      • isParsing

        public boolean isParsing()
      • setParsing

        public void setParsing​(boolean parsing)
      • getParseText

        public boolean getParseText()
        Whether to parse element text.
      • setParseText

        public void setParseText​(boolean text)
        Whether to parse element text.
      • getParseComments

        public boolean getParseComments()
        Whether to parse element comments.
      • setParseComments

        public void setParseComments​(boolean comments)
        Whether to parse element comments.
      • getLocation

        public Location getLocation()
        The XML document location.
      • getLexicalHandler

        public org.xml.sax.ext.LexicalHandler getLexicalHandler()
        The lexical handler that should be registered with the SAX parser used by this class. Since the org.xml.sax.ext package is not a required part of SAX2, this handler might not be used by the parser.
      • setLexicalHandler

        public void setLexicalHandler​(org.xml.sax.ext.LexicalHandler lh)
        The lexical handler that should be registered with the SAX parser used by this class. Since the org.xml.sax.ext package is not a required part of SAX2, this handler might not be used by the parser.
      • setLocation

        public void setLocation​(Location location)
        The XML document location.
      • getSourceIsSystemId

        public boolean getSourceIsSystemId()
        Whether to use the source name as the XML system id.
      • setSourceIsSystemId

        public void setSourceIsSystemId​(boolean systemId)
        Whether to use the source name as the XML system id.
      • isValidating

        public boolean isValidating()
        Whether this is a validating parser.
      • setValidating

        public void setValidating​(boolean validating)
        Whether this is a validating parser.
      • getSuffix

        public java.lang.String getSuffix()
        Expected suffix for metadata resources, or null if unknown.
      • setSuffix

        public void setSuffix​(java.lang.String suffix)
        Expected suffix for metadata resources, or null if unknown.
      • isCaching

        public boolean isCaching()
        Whether parsed resource names are cached to avoid duplicate parsing.
      • setCaching

        public void setCaching​(boolean caching)
        Whether parsed resource names are cached to avoid duplicate parsing.
      • getLog

        public Log getLog()
        The log to write to.
      • setLog

        public void setLog​(Log log)
        The log to write to.
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Classloader to use for class name resolution.
      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader loader)
        Classloader to use for class name resolution.
        Specified by:
        setClassLoader in interface MetaDataParser
      • getResults

        public java.util.List getResults()
        Description copied from interface: MetaDataParser
        Return the results from the last parse.
        Specified by:
        getResults in interface MetaDataParser
      • parse

        public void parse​(java.lang.String rsrc)
                   throws java.io.IOException
        Description copied from interface: MetaDataParser
        Parse the given resource.
        Specified by:
        parse in interface MetaDataParser
        Throws:
        java.io.IOException
      • parse

        public void parse​(java.net.URL url)
                   throws java.io.IOException
        Description copied from interface: MetaDataParser
        Parse the given resource.
        Specified by:
        parse in interface MetaDataParser
        Throws:
        java.io.IOException
      • parse

        public void parse​(java.io.File file)
                   throws java.io.IOException
        Description copied from interface: MetaDataParser
        Parse the given file, which may be a directory, in which case it will be scanned recursively for metadata files.
        Specified by:
        parse in interface MetaDataParser
        Throws:
        java.io.IOException
      • parse

        public void parse​(java.lang.Class cls,
                          boolean topDown)
                   throws java.io.IOException
        Description copied from interface: MetaDataParser
        Parse all possible metadata locations for the given class, going top-down or bottom-up. If the class is null, only top-level locations will be parsed.
        Specified by:
        parse in interface MetaDataParser
        Throws:
        java.io.IOException
      • parse

        public void parse​(java.io.Reader xml,
                          java.lang.String sourceName)
                   throws java.io.IOException
        Description copied from interface: MetaDataParser
        Parse the metadata in the given reader.
        Specified by:
        parse in interface MetaDataParser
        Parameters:
        xml - reader containing the metadata to parse
        sourceName - the name of the source being parsed, for use in error messages
        Throws:
        java.io.IOException
      • parse

        public void parse​(MetaDataIterator itr)
                   throws java.io.IOException
        Description copied from interface: MetaDataParser
        Parse the metadata supplied by the given iterator.
        Specified by:
        parse in interface MetaDataParser
        Throws:
        java.io.IOException
      • parseNewResource

        protected void parseNewResource​(java.io.Reader xml,
                                        java.lang.String sourceName)
                                 throws java.io.IOException
        Parse a previously-unseen source. All parsing methods delegate to this one.
        Throws:
        java.io.IOException
      • parsed

        protected boolean parsed​(java.lang.String src)
        Return true if the given source is parsed. Otherwise, record that it will be parsed.
      • clear

        public void clear()
        Description copied from interface: MetaDataParser
        Clears the cache of parsed resource names.
        Specified by:
        clear in interface MetaDataParser
      • error

        public void error​(org.xml.sax.SAXParseException se)
                   throws org.xml.sax.SAXException
        Specified by:
        error in interface org.xml.sax.ErrorHandler
        Overrides:
        error in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • fatalError

        public void fatalError​(org.xml.sax.SAXParseException se)
                        throws org.xml.sax.SAXException
        Specified by:
        fatalError in interface org.xml.sax.ErrorHandler
        Overrides:
        fatalError in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • setDocumentLocator

        public void setDocumentLocator​(org.xml.sax.Locator locator)
        Specified by:
        setDocumentLocator in interface org.xml.sax.ContentHandler
        Overrides:
        setDocumentLocator in class org.xml.sax.helpers.DefaultHandler
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String name,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attrs)
                          throws org.xml.sax.SAXException
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String name,
                               java.lang.String qName)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.xml.sax.helpers.DefaultHandler
      • comment

        public void comment​(char[] ch,
                            int start,
                            int length)
                     throws org.xml.sax.SAXException
        Specified by:
        comment in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • startCDATA

        public void startCDATA()
                        throws org.xml.sax.SAXException
        Specified by:
        startCDATA in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • endCDATA

        public void endCDATA()
                      throws org.xml.sax.SAXException
        Specified by:
        endCDATA in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • startDTD

        public void startDTD​(java.lang.String name,
                             java.lang.String publicId,
                             java.lang.String systemId)
                      throws org.xml.sax.SAXException
        Specified by:
        startDTD in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • endDTD

        public void endDTD()
                    throws org.xml.sax.SAXException
        Specified by:
        endDTD in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • startEntity

        public void startEntity​(java.lang.String name)
                         throws org.xml.sax.SAXException
        Specified by:
        startEntity in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • endEntity

        public void endEntity​(java.lang.String name)
                       throws org.xml.sax.SAXException
        Specified by:
        endEntity in interface org.xml.sax.ext.LexicalHandler
        Throws:
        org.xml.sax.SAXException
      • startElement

        protected abstract boolean startElement​(java.lang.String name,
                                                org.xml.sax.Attributes attrs)
                                         throws org.xml.sax.SAXException
        Override this method marking the start of some element. If this method returns false, the content of the element and the end element event will be ignored.
        Throws:
        org.xml.sax.SAXException
      • endElement

        protected abstract void endElement​(java.lang.String name)
                                    throws org.xml.sax.SAXException
        Override this method marking the end of some element.
        Throws:
        org.xml.sax.SAXException
      • addResult

        protected void addResult​(java.lang.Object result)
        Add a result to be returned from the current parse.
      • finish

        protected void finish()
        Override this method to finish up after a parse; this is only called if no errors are encountered during parsing. Subclasses should call super.finish() to resolve superclass state.
      • reset

        protected void reset()
        Override this method to clear any state and ready the parser for a new document. Subclasses should call super.reset() to clear superclass state.
      • getSchemaSource

        protected java.lang.Object getSchemaSource()
                                            throws java.io.IOException
        Implement to return the XML schema source for the document. Returns null by default. May return:
        • String pointing to schema URI.
        • InputStream containing schema contents.
        • InputSource containing schema contents.
        • File containing schema contents.
        • Array of any of the above elements.
        Throws:
        java.io.IOException
      • getDocType

        protected java.io.Reader getDocType()
                                     throws java.io.IOException
        Override this method to return any DOCTYPE declaration that should be dynamically included in xml documents that will be validated. Returns null by default.
        Throws:
        java.io.IOException
      • getSourceName

        protected java.lang.String getSourceName()
        Return the name of the source file being parsed.
      • getSourceFile

        protected java.io.File getSourceFile()
        Return the file of the source being parsed.
      • addComments

        protected void addComments​(java.lang.Object obj)
        Add current comments to the given entity. By default, assumes entity is Commentable.
      • currentComments

        protected java.lang.String[] currentComments()
        Array of comments for the current node, or empty array if none.
      • currentText

        protected java.lang.String currentText()
        Return the text value within the current node.
      • currentLocation

        protected java.lang.String currentLocation()
        Return the current location within the source file.
      • currentDepth

        protected int currentDepth()
        Return the parse depth. Within the root element, the depth is 0, within the first nested element, it is 1, and so forth.
      • currentClassLoader

        protected java.lang.ClassLoader currentClassLoader()
        Return the class loader to use when resolving resources and loading classes.
      • ignoreContent

        protected void ignoreContent​(boolean ignoreEnd)
        Ignore all content below the current element.
        Parameters:
        ignoreEnd - whether to ignore the end element event
      • getException

        protected org.xml.sax.SAXException getException​(java.lang.String msg)
        Returns a SAXException with the source file name and the given error message.
      • getException

        protected org.xml.sax.SAXException getException​(Localizer.Message msg)
        Returns a SAXException with the source file name and the given error message.
      • getException

        protected org.xml.sax.SAXException getException​(Localizer.Message msg,
                                                        java.lang.Throwable cause)
        Returns a SAXException with the source file name and the given error message.
      • clearDeferredMetaData

        protected void clearDeferredMetaData()