ws-woden-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkapu...@apache.org
Subject svn commit: r326319 - /incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
Date Wed, 19 Oct 2005 01:46:24 GMT
Author: jkaputin
Date: Tue Oct 18 18:46:11 2005
New Revision: 326319

URL: http://svn.apache.org/viewcvs?rev=326319&view=rev
Log:
Fixed a problem in reader.parseSchema() when running 
with IBM 1.42 jvm, which contains an implementation of 
Xerces 2.6 that expects a different version of 
DOMImplementationRegistry. If using the standard DOM L3
bootstrap code, a ClassCastException occurs in 
parseSchema(). Fix: try the standard DOM L3 code 
first and if we catch the exception, then use reflection
to bootstrap using the alternative class. Note, the Sun
JVMs and the IBM 1.5 JVM use the standard DOM L3 
code, statically at compile-time (so don't go through 
the reflection code). This will all eventually be 
replaced by ws-commons XmlSchema.

Modified:
    incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java

Modified: incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java?rev=326319&r1=326318&r2=326319&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java Tue Oct 18 18:46:11
2005
@@ -16,6 +16,8 @@
 package org.apache.woden.internal;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Hashtable;
@@ -51,6 +53,7 @@
 import org.apache.xerces.xs.XSLoader;
 import org.apache.xerces.xs.XSModel;
 import org.w3c.dom.Attr;
+import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -564,12 +567,52 @@
         
         try {
             //create an LSInput object to hold the schema string
+            DOMImplementationLS domImpl = null;
+            boolean useDom3Bootstrap = true;
+            Object domImplRegObj = null;
+            Method newInstanceMethod = null;
+            Method getDomImplMethod = null;
+            
             System.setProperty(DOMImplementationRegistry.PROPERTY,
             "org.apache.xerces.dom.DOMImplementationSourceImpl");
-            DOMImplementationRegistry domRegistry = DOMImplementationRegistry.newInstance();
             
-            DOMImplementationLS domImpl = 
-                (DOMImplementationLS)domRegistry.getDOMImplementation("LS");
+            try {
+                DOMImplementationRegistry domRegistry = DOMImplementationRegistry.newInstance();
+                
+                domImpl = (DOMImplementationLS)domRegistry.getDOMImplementation("LS");
+            } 
+            catch (ClassCastException e1) 
+            {
+                /*
+                 * This exception occurs with the IBM 1.42 JRE which contains an
+                 * implementation of Xerces (2.6?) that expects a different version
+                 * of DOMImplementationRegistry to the DOM Level 3 bootstrap used by
+                 * Xerces 2.7.1, on which Woden is dependent. Use Java reflection to
+                 * bootstrap with the expected version of DOMImplementationRegistry.
+                 */
+                useDom3Bootstrap = false;
+                
+                Class c = this.getClass().getClassLoader().loadClass(
+                        "org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry");
+
+                Method[] ms = c.getDeclaredMethods();
+                for(int i=0; i<ms.length; i++)
+                {
+                    if("newInstance".equals(ms[i].getName())) {
+                        newInstanceMethod = ms[i];
+                    }
+                    else if("getDOMImplementation".equals(ms[i].getName())) {
+                        getDomImplMethod = ms[i];
+                    }
+                }
+                
+                domImplRegObj = newInstanceMethod.invoke(new Object(), null);
+                
+                DOMImplementation di = (DOMImplementation) 
+                    getDomImplMethod.invoke(domImplRegObj, new Object[] {"LS"});
+                
+                domImpl = (DOMImplementationLS)di;
+            }
             
             LSInput lsInput = domImpl.createLSInput();
             
@@ -578,12 +621,28 @@
             lsInput.setStringData(schemaString);
             
             //Use DOM level 3 bootstrap to get an XSLoader
+            XSImplementation xsImpl = null;
             System.setProperty(DOMImplementationRegistry.PROPERTY,
             "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
-            DOMImplementationRegistry xsRegistry = DOMImplementationRegistry.newInstance();
             
-            XSImplementation xsImpl = 
-                (XSImplementation) xsRegistry.getDOMImplementation("XS-Loader");
+            if(useDom3Bootstrap)
+            {
+                DOMImplementationRegistry xsRegistry = DOMImplementationRegistry.newInstance();
+                
+                xsImpl = (XSImplementation) xsRegistry.getDOMImplementation("XS-Loader");
+            }
+            else
+            {
+                /*
+                 * Ditto the comment above about DOMImplementationRegistry in IBM 1.42 JRE.
+                 */
+                domImplRegObj = newInstanceMethod.invoke(new Object(), null);
+                
+                DOMImplementation di = (DOMImplementation) 
+                    getDomImplMethod.invoke(domImplRegObj, new Object[] {"XS-Loader"});
+                
+                xsImpl = (XSImplementation)di;
+            }
             
             XSLoader xsLoader = xsImpl.createXSLoader(null);
             
@@ -593,17 +652,6 @@
             //TODO handle a null xsmodel if an error is encountered
             schema.setSchemaContent(xsModel);
             
-            /* 
-             * print out the schema elements
-             * 
-             XSNamedMap xsNamedMap = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION);
-             System.out.println("\nInline schema elements (" + xsNamedMap.getLength() +"):");
-             for(int i = 0; i < xsNamedMap.getLength(); i++) 
-             {
-             System.out.println( (xsNamedMap.item(i)).getName() );
-             }
-             */
-            
         } catch (ClassCastException e) {
             getErrorReporter().reportError(
                     "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR,
e);
@@ -617,6 +665,9 @@
             getErrorReporter().reportError(
                     "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR,
e);
         } catch (IllegalAccessException e) {
+            getErrorReporter().reportError(
+                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR,
e);
+        } catch (InvocationTargetException e) {
             getErrorReporter().reportError(
                     "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR,
e);
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org


Mime
View raw message