neilg 2002/09/10 07:04:53 Modified: java/src/org/apache/html/dom HTMLDocumentImpl.java java/src/org/apache/xerces/dom CoreDOMImplementationImpl.java DOMValidationConfiguration.java java/src/org/apache/xerces/impl XMLDocumentFragmentScannerImpl.java XMLEntityManager.java XMLEntityScanner.java XMLScanner.java java/src/org/apache/xerces/impl/dv DTDDVFactory.java SchemaDVFactory.java java/src/org/apache/xerces/parsers AbstractDOMParser.java java/src/org/apache/xml/serialize SerializerFactory.java Log: fixing bug 9256. Now all Xerces class finding/loading is`cat ~/temp/mods` done using the ObjectFactory mechanism, and hence by using the context classloader when available. If the context classloader is unavailable or throws a ClassNotFoundException, then the system classloader is used as a fallback. Revision Changes Path 1.12 +6 -4 xml-xerces/java/src/org/apache/html/dom/HTMLDocumentImpl.java Index: HTMLDocumentImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/html/dom/HTMLDocumentImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- HTMLDocumentImpl.java 6 Aug 2002 20:08:48 -0000 1.11 +++ HTMLDocumentImpl.java 10 Sep 2002 14:04:52 -0000 1.12 @@ -65,6 +65,7 @@ import org.apache.xerces.dom.DocumentImpl; import org.apache.xerces.dom.NodeImpl; import org.apache.xerces.dom.AttrImpl; +import org.apache.xerces.util.ObjectFactory; import org.w3c.dom.DOMException; @@ -776,9 +777,10 @@ private static void populateElementType( String tagName, String className ) { try { - _elementTypesHTML.put( tagName, Class.forName( "org.apache.html.dom." + className ) ); - } catch ( ClassNotFoundException except ) { - new RuntimeException( "HTM019 OpenXML Error: Could not find class " + className + " implementing HTML element " + tagName + _elementTypesHTML.put( tagName, ObjectFactory.newInstance( "org.apache.html.dom." + className, + ObjectFactory.findClassLoader(), true) ); + } catch ( Exception except ) { + new RuntimeException( "HTM019 OpenXML Error: Could not find or execute class " + className + " implementing HTML element " + tagName + "\n" + className + "\t" + tagName); } } 1.17 +8 -9 xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java Index: CoreDOMImplementationImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- CoreDOMImplementationImpl.java 25 Jul 2002 19:16:11 -0000 1.16 +++ CoreDOMImplementationImpl.java 10 Sep 2002 14:04:52 -0000 1.17 @@ -76,6 +76,7 @@ // DOM Revalidation import org.apache.xerces.impl.RevalidationHandler; +import org.apache.xerces.util.ObjectFactory; /** * The DOMImplementation class is description of a particular @@ -286,10 +287,10 @@ // implement retrieving grammar based on schemaType if (fDOMRevalidator == null) { try { - fDOMRevalidator = (RevalidationHandler) (Class.forName("org.apache.xerces.impl.xs.XMLSchemaValidator")).newInstance(); - } catch (ClassNotFoundException ex){ - // will happen if this is DTD Only build - + // use context class loader. If it returns + // null, class.forName gets used. + fDOMRevalidator = (RevalidationHandler) + (ObjectFactory.newInstance("org.apache.xerces.impl.xs.XMLSchemaValidator", ObjectFactory.findClassLoader(), true)); } catch (Exception e){ } } @@ -300,10 +301,8 @@ catch (InterruptedException e){ try { - return (RevalidationHandler) (Class.forName("org.apache.xerces.impl.xs.XMLSchemaValidator")).newInstance(); - } catch (ClassNotFoundException ex){ - // will happen if this is DTD Only build - return null; + return (RevalidationHandler) + (ObjectFactory.newInstance("org.apache.xerces.impl.xs.XMLSchemaValidator", ObjectFactory.findClassLoader(), true)); } catch (Exception exception){ return null; 1.3 +5 -5 xml-xerces/java/src/org/apache/xerces/dom/DOMValidationConfiguration.java Index: DOMValidationConfiguration.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMValidationConfiguration.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DOMValidationConfiguration.java 19 Jun 2002 16:48:47 -0000 1.2 +++ DOMValidationConfiguration.java 10 Sep 2002 14:04:52 -0000 1.3 @@ -69,6 +69,7 @@ import org.apache.xerces.impl.XMLErrorReporter; import org.apache.xerces.impl.validation.ValidationManager; import org.apache.xerces.impl.msg.XMLMessageFormatter; +import org.apache.xerces.util.ObjectFactory; import org.apache.xerces.util.ParserConfigurationSettings; import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.MessageFormatter; @@ -274,10 +275,9 @@ if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) { MessageFormatter xmft = null; try { - xmft = (MessageFormatter)(Class.forName("org.apache.xerces.impl.xs.XSMessageFormatter")).newInstance(); - } catch (ClassNotFoundException ex){ - // will happen if this is DTD Only build - + xmft = (MessageFormatter)( + ObjectFactory.newInstance("org.apache.xerces.impl.xs.XSMessageFormatter", + ObjectFactory.findClassLoader(), true)); } catch (Exception exception){ } 1.17 +6 -5 xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java Index: XMLDocumentFragmentScannerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- XMLDocumentFragmentScannerImpl.java 22 Aug 2002 19:17:12 -0000 1.16 +++ XMLDocumentFragmentScannerImpl.java 10 Sep 2002 14:04:52 -0000 1.17 @@ -898,9 +898,10 @@ } while (true) { - if (!fEntityScanner.scanData("]]", fString)) { - if (fDocumentHandler != null && fString.length > 0) { - fDocumentHandler.characters(fString, null); + fStringBuffer.clear(); + if (!fEntityScanner.scanData("]]", fStringBuffer)) { + if (fDocumentHandler != null && fStringBuffer.length > 0) { + fDocumentHandler.characters(fStringBuffer, null); } int brackets = 2; while (fEntityScanner.skipChar(']')) { @@ -924,7 +925,7 @@ } else { if (fDocumentHandler != null) { - fDocumentHandler.characters(fString, null); + fDocumentHandler.characters(fStringBuffer, null); } int c = fEntityScanner.peekChar(); if (c != -1 && XMLChar.isInvalid(c)) { 1.41 +23 -27 xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java Index: XMLEntityManager.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- XMLEntityManager.java 5 Sep 2002 21:35:29 -0000 1.40 +++ XMLEntityManager.java 10 Sep 2002 14:04:52 -0000 1.41 @@ -79,6 +79,7 @@ import org.apache.xerces.impl.validation.ValidationManager; import org.apache.xerces.util.EncodingMap; +import org.apache.xerces.util.XMLStringBuffer; import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.URI; import org.apache.xerces.util.XMLChar; @@ -2740,7 +2741,7 @@ } // scanLiteral(int,XMLString):int /** - * Scans a range of character data up to the specicied delimiter, + * Scans a range of character data up to the specified delimiter, * setting the fields of the XMLString structure, appropriately. * <p> * <strong>Note:</strong> The characters are consumed. @@ -2769,8 +2770,16 @@ * @throws IOException Thrown if i/o error occurs. * @throws EOFException Thrown on end of file. */ - public boolean scanData(String delimiter, XMLString data) + public boolean scanData(String delimiter, XMLStringBuffer buffer) throws IOException { + boolean done = false; + int delimLen = delimiter.length(); + char charAt0 = delimiter.charAt(0); + int offset = fCurrentEntity.position; + int c = fCurrentEntity.ch[offset]; + int newlines = 0; + boolean external = fCurrentEntity.isExternal(); + do { if (DEBUG_BUFFER) { System.out.print("(scanData: "); print(); @@ -2778,9 +2787,6 @@ } // load more characters, if needed - int delimLen = delimiter.length(); - char charAt0 = delimiter.charAt(0); - //int limit = fCurrentEntity.count - delimLen + 1; if (fCurrentEntity.position == fCurrentEntity.count) { load(0, true); @@ -2794,7 +2800,7 @@ if (fCurrentEntity.position >= fCurrentEntity.count - delimLen) { // something must be wrong with the input: e.g., file ends an unterminated comment int length = fCurrentEntity.count - fCurrentEntity.position; - data.setValues(fCurrentEntity.ch, fCurrentEntity.position, length); + buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length); fCurrentEntity.columnNumber += fCurrentEntity.count; fCurrentEntity.position = fCurrentEntity.count; load(0,true); @@ -2802,10 +2808,9 @@ } // normalize newlines - int offset = fCurrentEntity.position; - int c = fCurrentEntity.ch[offset]; - int newlines = 0; - boolean external = fCurrentEntity.isExternal(); + offset = fCurrentEntity.position; + c = fCurrentEntity.ch[offset]; + newlines = 0; if (c == '\n' || (c == '\r' && external)) { if (DEBUG_BUFFER) { System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": "); @@ -2818,7 +2823,6 @@ newlines++; fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; - /***/ if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; fCurrentEntity.position = newlines; @@ -2826,7 +2830,6 @@ break; } } - /***/ if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') { fCurrentEntity.position++; offset++; @@ -2835,13 +2838,11 @@ else { newlines++; } - /***/ } else if (c == '\n') { newlines++; fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; - /***/ if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; fCurrentEntity.position = newlines; @@ -2850,14 +2851,6 @@ break; } } - /***/ - /*** NEWLINE NORMALIZATION *** - if (fCurrentEntity.ch[fCurrentEntity.position] == '\r' - && external) { - fCurrentEntity.position++; - offset++; - } - /***/ } else { fCurrentEntity.position--; @@ -2869,7 +2862,7 @@ } int length = fCurrentEntity.position - offset; if (fCurrentEntity.position == fCurrentEntity.count - 1) { - data.setValues(fCurrentEntity.ch, offset, length); + buffer.append(fCurrentEntity.ch, offset, length); if (DEBUG_BUFFER) { System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": "); print(); @@ -2885,7 +2878,6 @@ } // iterate over buffer looking for delimiter - boolean done = false; OUTER: while (fCurrentEntity.position < fCurrentEntity.count) { c = fCurrentEntity.ch[fCurrentEntity.position++]; if (c == charAt0) { @@ -2913,7 +2905,10 @@ } else if (XMLChar.isInvalid(c)) { fCurrentEntity.position--; - break; + int length = fCurrentEntity.position - offset; + fCurrentEntity.columnNumber += length - newlines; + buffer.append(fCurrentEntity.ch, offset, length); + return true; } } int length = fCurrentEntity.position - offset; @@ -2921,7 +2916,7 @@ if (done) { length -= delimLen; } - data.setValues(fCurrentEntity.ch, offset, length); + buffer.append (fCurrentEntity.ch, offset, length); // return true if string was skipped if (DEBUG_BUFFER) { @@ -2929,6 +2924,7 @@ print(); System.out.println(" -> " + done); } + } while (!done); return !done; } // scanData(String,XMLString) 1.5 +3 -2 xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java Index: XMLEntityScanner.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XMLEntityScanner.java 29 Jan 2002 01:15:09 -0000 1.4 +++ XMLEntityScanner.java 10 Sep 2002 14:04:52 -0000 1.5 @@ -63,6 +63,7 @@ import org.apache.xerces.xni.QName; import org.apache.xerces.xni.XMLLocator; import org.apache.xerces.xni.XMLString; +import org.apache.xerces.util.XMLStringBuffer; /** * This class allows various parser scanners to scan basic XML constructs @@ -288,7 +289,7 @@ * @throws IOException Thrown if i/o error occurs. * @throws EOFException Thrown on end of file. */ - public abstract boolean scanData(String delimiter, XMLString data) + public abstract boolean scanData(String delimiter, XMLStringBuffer data) throws IOException; /** 1.18 +5 -10 xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java Index: XMLScanner.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- XMLScanner.java 13 Aug 2002 22:57:08 -0000 1.17 +++ XMLScanner.java 10 Sep 2002 14:04:52 -0000 1.18 @@ -637,11 +637,10 @@ } } + fStringBuffer.clear(); // data - if (fEntityScanner.scanData("?>", data)) { - fStringBuffer.clear(); + if (fEntityScanner.scanData("?>", fStringBuffer)) { do { - fStringBuffer.append(data); int c = fEntityScanner.peekChar(); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { @@ -653,8 +652,7 @@ fEntityScanner.scanChar(); } } - } while (fEntityScanner.scanData("?>", data)); - fStringBuffer.append(data); + } while (fEntityScanner.scanData("?>", fStringBuffer)); data.setValues(fStringBuffer); } @@ -679,9 +677,7 @@ // text // REVISIT: handle invalid character, eof text.clear(); - while (fEntityScanner.scanData("--", fString)) { - text.append(fString); - /***/ + while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { @@ -694,7 +690,6 @@ } } } - text.append(fString); if (!fEntityScanner.skipChar('>')) { reportFatalError("DashDashInComment", null); } 1.6 +5 -9 xml-xerces/java/src/org/apache/xerces/impl/dv/DTDDVFactory.java Index: DTDDVFactory.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/DTDDVFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DTDDVFactory.java 24 Jul 2002 15:02:58 -0000 1.5 +++ DTDDVFactory.java 10 Sep 2002 14:04:52 -0000 1.6 @@ -58,6 +58,7 @@ package org.apache.xerces.impl.dv; import java.util.Hashtable; +import org.apache.xerces.util.ObjectFactory; /** * The factory to create and return DTD types. The implementation should @@ -95,14 +96,9 @@ try { // if the class name is not specified, use the default one - return (DTDDVFactory)(Class.forName(factoryClass).newInstance()); - } catch (ClassNotFoundException e1) { - throw new DVFactoryException("DTD factory class " + factoryClass + " not found."); - } catch (IllegalAccessException e2) { - throw new DVFactoryException("DTD factory class " + factoryClass + " found but cannot be loaded."); - } catch (InstantiationException e3) { - throw new DVFactoryException("DTD factory class " + factoryClass + " loaded but cannot be instantiated (no empty public constructor?)."); - } catch (ClassCastException e4) { + return (DTDDVFactory) + (ObjectFactory.newInstance(factoryClass, ObjectFactory.findClassLoader(), true)); + } catch (ClassCastException e) { throw new DVFactoryException("DTD factory class " + factoryClass + " does not extend from DTDDVFactory."); } } 1.9 +4 -8 xml-xerces/java/src/org/apache/xerces/impl/dv/SchemaDVFactory.java Index: SchemaDVFactory.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/SchemaDVFactory.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SchemaDVFactory.java 24 Jul 2002 15:02:58 -0000 1.8 +++ SchemaDVFactory.java 10 Sep 2002 14:04:52 -0000 1.9 @@ -58,6 +58,7 @@ package org.apache.xerces.impl.dv; import org.apache.xerces.util.SymbolHash; +import org.apache.xerces.util.ObjectFactory; /** * Defines a factory API that enables applications to <p> @@ -103,13 +104,8 @@ try { // if the class name is not specified, use the default one - return (SchemaDVFactory)(Class.forName( factoryClass).newInstance()); - } catch (ClassNotFoundException e1) { - throw new DVFactoryException("Schema factory class " + factoryClass + " not found."); - } catch (IllegalAccessException e2) { - throw new DVFactoryException("Schema factory class " + factoryClass + " found but cannot be loaded."); - } catch (InstantiationException e3) { - throw new DVFactoryException("Schema factory class " + factoryClass + " loaded but cannot be instantiated (no empty public constructor?)."); + return (SchemaDVFactory)(ObjectFactory.newInstance( + factoryClass, ObjectFactory.findClassLoader(), true)); } catch (ClassCastException e4) { throw new DVFactoryException("Schema factory class " + factoryClass + " does not extend from SchemaDVFactory."); } 1.72 +11 -5 xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java Index: AbstractDOMParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v retrieving revision 1.71 retrieving revision 1.72 diff -u -r1.71 -r1.72 --- AbstractDOMParser.java 26 Aug 2002 21:53:29 -0000 1.71 +++ AbstractDOMParser.java 10 Sep 2002 14:04:52 -0000 1.72 @@ -73,6 +73,8 @@ import org.apache.xerces.dom.PSVIElementNSImpl; import org.apache.xerces.dom.TextImpl; import org.apache.xerces.impl.Constants; +import org.apache.xerces.util.ObjectFactory; + // id types import org.apache.xerces.xni.psvi.AttributePSVI; import org.apache.xerces.impl.xs.psvi.XSAttributeDeclaration; @@ -370,7 +372,8 @@ // verify that this class exists and is of the right type try { - Class _class = Class.forName(documentClassName); + Class _class = ObjectFactory.findProviderClass(documentClassName, + ObjectFactory.findClassLoader(), true); //if (!_class.isAssignableFrom(Document.class)) { if (!Document.class.isAssignableFrom(_class)) { // REVISIT: message @@ -767,16 +770,19 @@ else { // use specified document class try { - Class documentClass = Class.forName(fDocumentClassName); + Class documentClass = ObjectFactory.findProviderClass(fDocumentClassName, + ObjectFactory.findClassLoader(), true); fDocument = (Document)documentClass.newInstance(); // if subclass of our own class that's cool too Class defaultDocClass = - Class.forName(CORE_DOCUMENT_CLASS_NAME); + ObjectFactory.findProviderClass(CORE_DOCUMENT_CLASS_NAME, + ObjectFactory.findClassLoader(), true); if (defaultDocClass.isAssignableFrom(documentClass)) { fDocumentImpl = (CoreDocumentImpl)fDocument; - Class psviDocClass = Class.forName(PSVI_DOCUMENT_CLASS_NAME); + Class psviDocClass = ObjectFactory.findProviderClass(PSVI_DOCUMENT_CLASS_NAME, + ObjectFactory.findClassLoader(), true); if (psviDocClass.isAssignableFrom(documentClass)) { fStorePSVI = true; } 1.7 +4 -2 xml-xerces/java/src/org/apache/xml/serialize/SerializerFactory.java Index: SerializerFactory.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/SerializerFactory.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SerializerFactory.java 29 Jan 2002 01:15:20 -0000 1.6 +++ SerializerFactory.java 10 Sep 2002 14:04:52 -0000 1.7 @@ -65,6 +65,7 @@ import java.util.Hashtable; import java.util.StringTokenizer; +import org.apache.xerces.util.ObjectFactory; /** * @@ -108,7 +109,8 @@ while ( token.hasMoreTokens() ) { className = token.nextToken(); try { - factory = (SerializerFactory) Class.forName( className ).newInstance(); + factory = (SerializerFactory) ObjectFactory.newInstance( className, + ObjectFactory.findClassLoader(), true); if ( _factories.containsKey( factory.getSupportedMethod() ) ) _factories.put( factory.getSupportedMethod(), factory ); } catch ( Exception except ) { }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]