axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r562635 - /webservices/axis2/branches/java/1_3/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java
Date Sat, 04 Aug 2007 01:01:33 GMT
Author: dims
Date: Fri Aug  3 18:01:32 2007
New Revision: 562635

URL: http://svn.apache.org/viewvc?view=rev&rev=562635
Log:
Fix for   AXIS2-3043  - wsdl2java using jaxbri data binding fails. Many thanks to dkulp!

Modified:
    webservices/axis2/branches/java/1_3/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java

Modified: webservices/axis2/branches/java/1_3/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_3/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java?view=diff&rev=562635&r1=562634&r2=562635
==============================================================================
--- webservices/axis2/branches/java/1_3/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java
(original)
+++ webservices/axis2/branches/java/1_3/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java
Fri Aug  3 18:01:32 2007
@@ -26,9 +26,9 @@
 import com.sun.tools.xjc.api.S2JJAXBModel;
 import com.sun.tools.xjc.api.SchemaCompiler;
 import com.sun.tools.xjc.api.XJC;
-import com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl;
 import org.apache.axis2.util.SchemaUtil;
 import org.apache.axis2.util.URLProcessor;
+import org.apache.axis2.util.XMLUtils;
 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
 import org.apache.axis2.wsdl.databinding.DefaultTypeMapper;
 import org.apache.axis2.wsdl.databinding.JavaTypeMapper;
@@ -36,23 +36,29 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.commons.schema.XmlSchema;
-import org.w3c.dom.Element;
 import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXParseException;
+import org.w3c.dom.Element;
 import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 import javax.xml.namespace.QName;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.StringReader;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.ArrayList;
 
 public class CodeGenerationUtility {
     private static final Log log = LogFactory.getLog(CodeGenerationUtility.class);
@@ -114,31 +120,40 @@
                 SchemaCompiler sc = XJC.createSchemaCompiler();
                 XmlSchema schema = (XmlSchema)schemas.get(i);
 
-                String pkg = null;
                 if (nsMap != null) {
-                    pkg = (String)nsMap.get(schema.getTargetNamespace());
-                }
-                if (pkg == null) {
-                    pkg = extractNamespace(schema);
+                    Iterator iterator = nsMap.entrySet().iterator();
+                    while(iterator.hasNext()){
+                        Map.Entry entry = (Map.Entry) iterator.next();
+                        String namespace = (String) entry.getKey();
+                        String pkg = (String)nsMap.get(namespace);
+                        registerNamespace(sc, namespace, pkg);
+                    }
+                } else {
+                    String namespace = schema.getTargetNamespace();
+                    String pkg = extractNamespace(schema);
+                    registerNamespace(sc, namespace, pkg);
                 }
-                sc.setDefaultPackageName(pkg);
 
                 sc.setEntityResolver(resolver);
 
                 sc.setErrorListener(new ErrorListener(){
                     public void error(SAXParseException saxParseException) {
+                        log.error(saxParseException.getMessage());
                         log.debug(saxParseException.getMessage(), saxParseException);
                     }
 
                     public void fatalError(SAXParseException saxParseException) {
+                        log.error(saxParseException.getMessage());
                         log.debug(saxParseException.getMessage(), saxParseException);
                     }
 
                     public void warning(SAXParseException saxParseException) {
+                        log.warn(saxParseException.getMessage());
                         log.debug(saxParseException.getMessage(), saxParseException);
                     }
 
                     public void info(SAXParseException saxParseException) {
+                        log.info(saxParseException.getMessage());
                         log.debug(saxParseException.getMessage(), saxParseException);
                     }
                 });
@@ -176,6 +191,38 @@
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
+    }
+
+    private static void registerNamespace(SchemaCompiler sc, String namespace, String pkgName)
throws Exception {
+        Document doc = XMLUtils.newDocument();
+        Element rootElement = doc.createElement("schema");
+        rootElement.setAttribute("xmlns", "http://www.w3.org/2001/XMLSchema");
+        rootElement.setAttribute("xmlns:jaxb", "http://java.sun.com/xml/ns/jaxb");
+        rootElement.setAttribute("jaxb:version", "2.0");
+        rootElement.setAttribute("targetNamespace", namespace);
+        Element annoElement = doc.createElement("annotation");
+        Element appInfo = doc.createElement("appinfo");
+        Element schemaBindings = doc.createElement("jaxb:schemaBindings");
+        Element pkgElement = doc.createElement("jaxb:package");
+        pkgElement.setAttribute("name", pkgName);
+        annoElement.appendChild(appInfo);
+        appInfo.appendChild(schemaBindings);
+        schemaBindings.appendChild(pkgElement);
+        rootElement.appendChild(annoElement);
+        File file = File.createTempFile("customized",".xsd");
+        FileOutputStream stream = new FileOutputStream(file);
+        try {
+            Result result = new StreamResult(stream);
+            Transformer xformer = TransformerFactory.newInstance().newTransformer();
+            xformer.transform(new DOMSource(rootElement), result);
+            stream.flush();
+            stream.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        InputSource ins = new InputSource(file.toURI().toString());
+        sc.parseSchema(ins);
+        file.delete();
     }
 
     private static String extractNamespace(XmlSchema schema) {



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


Mime
View raw message