nddelima 2004/06/18 14:36:17 Modified: java/src/org/apache/xerces/dom CoreDocumentImpl.java CoreDOMImplementationImpl.java Log: Fixes problems with DOMImplementation.getFeature and hasFeature, Node.getFeature and isSupported and support for Xalan's DOM XPath implementation. Revision Changes Path 1.73 +37 -27 xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java Index: CoreDocumentImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- CoreDocumentImpl.java 15 Jun 2004 22:13:16 -0000 1.72 +++ CoreDocumentImpl.java 18 Jun 2004 21:36:16 -0000 1.73 @@ -17,6 +17,7 @@ package org.apache.xerces.dom; import java.io.Serializable; +import java.lang.reflect.Constructor; import java.util.Enumeration; import java.util.Hashtable; @@ -130,9 +131,6 @@ transient DOMNormalizer domNormalizer = null; transient DOMConfigurationImpl fConfiguration= null; - // support of XPath API - transient Object fXPathEvaluator = null; - /** Table for quick check of child insertion. */ private final static int[] kidOK; @@ -482,20 +480,32 @@ boolean anyVersion = version == null || version.length() == 0; - if ((feature.equalsIgnoreCase("XPath") - || feature.equalsIgnoreCase("+XPath")) && - (anyVersion || version.equals("3.0"))) { - + // if a plus sign "+" is prepended to any feature name, implementations + // are considered in which the specified feature may not be directly + // castable DOMImplementation.getFeature(feature, version). Without a + // plus, only features whose interfaces are directly castable are + // considered. + if ((feature.equalsIgnoreCase("+XPath")) + && (anyVersion || version.equals("3.0"))) { + try { Class xpathClass = ObjectFactory.findProviderClass( - "org.apache.xpath.domapi.XPathEvaluatorImpl", - ObjectFactory.findClassLoader(), true); - fXPathEvaluator = xpathClass.newInstance(); - java.lang.reflect.Method setDocument = xpathClass.getMethod("setDoc", new Class[]{Document.class}); - setDocument.invoke(fXPathEvaluator, new Object[]{this}); - return fXPathEvaluator; - } - catch (Exception e){ + "org.apache.xpath.domapi.XPathEvaluatorImpl", + ObjectFactory.findClassLoader(), true); + Constructor xpathClassConstr = + xpathClass.getConstructor(new Class[] { Document.class }); + + // Check if the DOM XPath implementation implements + // the interface org.w3c.dom.XPathEvaluator + Class interfaces[] = xpathClass.getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + if (interfaces[i].getName().equals( + "org.w3c.dom.xpath.XPathEvaluator")) { + return xpathClassConstr.newInstance(new Object[] { this }); + } + } + return null; + } catch (Exception e) { return null; } } @@ -505,22 +515,22 @@ // // Document methods // - + // factory methods - + /** * Factory method; creates an Attribute having this Document as its * OwnerDoc. - * - * @param name The name of the attribute. Note that the attribute's value - * is _not_ established at the factory; remember to set it! - * - * @throws DOMException(INVALID_NAME_ERR) if the attribute name is not - * acceptable. + * + * @param name The name of the attribute. Note that the attribute's value is + * _not_ established at the factory; remember to set it! + * + * @throws DOMException(INVALID_NAME_ERR) + * if the attribute name is not acceptable. */ public Attr createAttribute(String name) - throws DOMException { - + throws DOMException { + if (errorChecking && !isXMLName(name,xml11Version)) { String msg = DOMMessageFormatter.formatMessage( @@ -530,7 +540,7 @@ throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } return new AttrImpl(this, name); - + } // createAttribute(String):Attr /** 1.32 +79 -47 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.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- CoreDOMImplementationImpl.java 24 Feb 2004 23:23:18 -0000 1.31 +++ CoreDOMImplementationImpl.java 18 Jun 2004 21:36:16 -0000 1.32 @@ -14,6 +14,7 @@ * limitations under the License. */ package org.apache.xerces.dom; + import org.apache.xerces.impl.RevalidationHandler; import org.apache.xerces.parsers.DOMParserImpl; import org.apache.xerces.util.XMLChar; @@ -59,7 +60,7 @@ // doctypes without owners, on an demand basis. Used for // compareDocumentPosition private int docAndDoctypeCounter = 0; - + // static /** Dom implementation singleton. */ static CoreDOMImplementationImpl singleton = @@ -78,53 +79,65 @@ * Test if the DOM implementation supports a specific "feature" -- * currently meaning language and level thereof. * - * @param feature The package name of the feature to test. + * @param feature The package name of the feature to test. * In Level 1, supported values are "HTML" and "XML" (case-insensitive). * At this writing, org.apache.xerces.dom supports only XML. * - * @param version The version number of the feature being tested. + * @param version The version number of the feature being tested. * This is interpreted as "Version of the DOM API supported for the * specified Feature", and in Level 1 should be "1.0" * - * @return true iff this implementation is compatable with the specified + * @return true iff this implementation is compatable with the specified * feature and version. */ - public boolean hasFeature(String feature, String version) { - - boolean anyVersion = version == null || version.length() == 0; - if (feature.startsWith("+")) { - feature = feature.substring(1); - } - // check if Xalan implementation is around and if yes report true for supporting - // XPath API - if ((feature.equalsIgnoreCase("XPath") - || feature.equalsIgnoreCase("+XPath")) - && (anyVersion || version.equals("3.0"))) { - try { - Class xpathClass = - ObjectFactory.findProviderClass( - "org.apache.xpath.domapi.XPathEvaluatorImpl", - ObjectFactory.findClassLoader(), - true); - } catch (Exception e) { - return false; - } - return true; - } - return ( - feature.equalsIgnoreCase("Core") - && (anyVersion - || version.equals("1.0") - || version.equals("2.0") - || version.equals("3.0"))) - || (feature.equalsIgnoreCase("XML") - && (anyVersion - || version.equals("1.0") - || version.equals("2.0") - || version.equals("3.0"))) - || (feature.equalsIgnoreCase("LS") - && (anyVersion || version.equals("3.0"))); - } // hasFeature(String,String):boolean + public boolean hasFeature(String feature, String version) { + + boolean anyVersion = version == null || version.length() == 0; + + // check if Xalan implementation is around and if yes report true for supporting + // XPath API + // if a plus sign "+" is prepended to any feature name, implementations + // are considered in which the specified feature may not be directly + // castable DOMImplementation.getFeature(feature, version). Without a + // plus, only features whose interfaces are directly castable are considered. + if ((feature.equalsIgnoreCase("+XPath")) + && (anyVersion || version.equals("3.0"))) { + try { + Class xpathClass = ObjectFactory.findProviderClass( + "org.apache.xpath.domapi.XPathEvaluatorImpl", + ObjectFactory.findClassLoader(), true); + + // Check if the DOM XPath implementation implements + // the interface org.w3c.dom.XPathEvaluator + Class interfaces[] = xpathClass.getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + if (interfaces[i].getName().equals( + "org.w3c.dom.xpath.XPathEvaluator")) { + return true; + } + } + } catch (Exception e) { + return false; + } + return true; + } + if (feature.startsWith("+")) { + feature = feature.substring(1); + } + return ( + feature.equalsIgnoreCase("Core") + && (anyVersion + || version.equals("1.0") + || version.equals("2.0") + || version.equals("3.0"))) + || (feature.equalsIgnoreCase("XML") + && (anyVersion + || version.equals("1.0") + || version.equals("2.0") + || version.equals("3.0"))) + || (feature.equalsIgnoreCase("LS") + && (anyVersion || version.equals("3.0"))); + } // hasFeature(String,String):boolean /** @@ -252,13 +265,32 @@ /** * DOM Level 3 WD - Experimental. - */ + */ public Object getFeature(String feature, String version) { - if (singleton.hasFeature(feature, version)){ - return singleton; - } - return null; - + if (singleton.hasFeature(feature, version)) { + if ((feature.equalsIgnoreCase("+XPath"))) { + try { + Class xpathClass = ObjectFactory.findProviderClass( + "org.apache.xpath.domapi.XPathEvaluatorImpl", + ObjectFactory.findClassLoader(), true); + + // Check if the DOM XPath implementation implements + // the interface org.w3c.dom.XPathEvaluator + Class interfaces[] = xpathClass.getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + if (interfaces[i].getName().equals( + "org.w3c.dom.xpath.XPathEvaluator")) { + return xpathClass.newInstance(); + } + } + } catch (Exception e) { + return null; + } + } else { + return singleton; + } + } + return null; } // DOM L3 LS
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]