📄 rootxmlreadhandler.java
字号:
Log.debug ("Locating handler for " + manualDefinition.getBaseClass()); return loadHandlerClass(manualDefinition.getReadHandler()); } // check whether a multiplexer is defined ... // find multiplexer for this class... MultiplexMappingDefinition mplex = getFactoryLoader().getMultiplexDefinition(classToRead); if (mplex == null) { mplex = this.classToHandlerMapping.getMultiplexDefinition(classToRead); } if (mplex != null) { final String attributeValue = atts.getValue(mplex.getAttributeName()); if (attributeValue == null) { throw new XmlReaderException( "Multiplexer type attribute is not defined: " + mplex.getAttributeName() + " for " + classToRead ); } final MultiplexMappingEntry entry = mplex.getEntryForType(attributeValue); if (entry == null) { throw new XmlReaderException( "Invalid type attribute value: " + mplex.getAttributeName() + " = " + attributeValue ); } final Class c = loadClass(entry.getTargetClass()); if (!c.equals(mplex.getBaseClass())) { Log.debug( "Continue search on next level : " + c + " after " + mplex.getBaseClass() ); return findHandlerForClass(c, atts, history); } else { Log.debug ("Muliplexer is also generic definition ..."); } } // check for generic classes ... // and finally try the generic handler matches ... if (this.classToHandlerMapping.isGenericHandler(classToRead)) { return new GenericReadHandler (this.classToHandlerMapping.getFactoryForClass(classToRead)); } if (getFactoryLoader().isGenericHandler(classToRead)) { return new GenericReadHandler (getFactoryLoader().getFactoryForClass(classToRead)); } return null; } /** * Sets the root SAX handler. * * @param handler the SAX handler. */ protected void setRootHandler(final XmlReadHandler handler) { this.rootHandler = handler; } /** * Returns the root SAX handler. * * @return the root SAX handler. */ protected XmlReadHandler getRootHandler() { return this.rootHandler; } /** * ?? * * @param handler the handler. * @param tagName the tag name. * @param attrs the attributes. * * @throws XmlReaderException if there is a problem with the reader. * @throws SAXException if there is a problem with the parser. */ public void recurse(final XmlReadHandler handler, final String tagName, final Attributes attrs) throws XmlReaderException, SAXException { this.outerScopes.push(this.currentHandlers); this.currentHandlers = new Stack(); this.currentHandlers.push(handler); handler.startElement(tagName, attrs); } /** * Delegate to another handler. * * @param handler the new handler. * @param tagName the tag name. * @param attrs the attributes. * * @throws XmlReaderException if there is a problem with the reader. * @throws SAXException if there is a problem with the parser. */ public void delegate(final XmlReadHandler handler, final String tagName, final Attributes attrs) throws XmlReaderException, SAXException { this.currentHandlers.push(handler); handler.startElement(tagName, attrs); } /** * Hand control back to the previous handler. * * @param tagName the tagname. * * @throws SAXException if there is a problem with the parser. * @throws XmlReaderException if there is a problem with the reader. */ public void unwind(final String tagName) throws SAXException, XmlReaderException { this.currentHandlers.pop(); if (this.currentHandlers.isEmpty() && !this.outerScopes.isEmpty()) { this.currentHandlers = (Stack) this.outerScopes.pop(); } if (!this.currentHandlers.isEmpty()) { getCurrentHandler().endElement(tagName); } } /** * Returns the current handler. * * @return The current handler. */ protected XmlReadHandler getCurrentHandler() { return (XmlReadHandler) this.currentHandlers.peek(); } /** * Starts processing a document. * * @throws SAXException not in this implementation. */ public void startDocument() throws SAXException { this.outerScopes = new Stack(); this.currentHandlers = new Stack(); this.currentHandlers.push(this.rootHandler); } /** * Starts processing an element. * * @param uri the URI. * @param localName the local name. * @param qName the qName. * @param attributes the attributes. * * @throws SAXException if there is a parsing problem. */ public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { try { getCurrentHandler().startElement(qName, attributes); } catch (XmlReaderException xre) { throw new ParseException(xre, getLocator()); } } /** * Process character data. * * @param ch the character buffer. * @param start the start index. * @param length the length of the character data. * * @throws SAXException if there is a parsing error. */ public void characters(final char[] ch, final int start, final int length) throws SAXException { try { getCurrentHandler().characters(ch, start, length); } catch (SAXException se) { throw se; } catch (Exception e) { throw new ParseException(e, getLocator()); } } /** * Finish processing an element. * * @param uri the URI. * @param localName the local name. * @param qName the qName. * * @throws SAXException if there is a parsing error. */ public void endElement(final String uri, final String localName, final String qName) throws SAXException { try { getCurrentHandler().endElement(qName); } catch (XmlReaderException xre) { throw new ParseException(xre, getLocator()); } } /** * Loads the given class, and ignores all exceptions which may occur * during the loading. If the class was invalid, null is returned instead. * * @param className the name of the class to be loaded. * @return the class or null. * @throws XmlReaderException if there is a reader error. */ protected XmlReadHandler loadHandlerClass(final String className) throws XmlReaderException { try { final Class c = loadClass(className); return (XmlReadHandler) c.newInstance(); } catch (Exception e) { // ignore buggy classes for now .. throw new XmlReaderException("LoadHanderClass: Unable to instantiate " + className, e); } } /** * Loads the given class, and ignores all exceptions which may occur * during the loading. If the class was invalid, null is returned instead. * * @param className the name of the class to be loaded. * @return the class or null. * @throws XmlReaderException if there is a reader error. */ protected Class loadClass(final String className) throws XmlReaderException { if (className == null) { throw new XmlReaderException("LoadHanderClass: Class name not defined"); } try { final Class c = this.getClass().getClassLoader().loadClass(className); return c; } catch (Exception e) { // ignore buggy classes for now .. throw new XmlReaderException("LoadHanderClass: Unable to load " + className, e); } } /** * Receive an object for locating the origin of SAX document events. * * The locator allows the application to determine the end position of * any document-related event, even if the parser is not reporting an * error. Typically, the application will use this information for * reporting its own errors (such as character content that does not * match an application's business rules). The information returned by * the locator is probably not sufficient for use with a search engine. * * @param locator the locator. */ public void setDocumentLocator(final Locator locator) { this.locator = locator; } /** * Returns the current locator. * * @return the locator. */ public Locator getLocator() { return this.locator; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -