JOnASWSDL2Java.java

00001 
00025 package org.objectweb.jonas_ws.wsgen.generator.axis.wsdl2java;
00026 
00027 import java.io.File;
00028 import java.io.IOException;
00029 import java.util.HashMap;
00030 import java.util.Iterator;
00031 import java.util.Map;
00032 
00033 import javax.wsdl.WSDLException;
00034 import javax.xml.parsers.DocumentBuilder;
00035 import javax.xml.parsers.DocumentBuilderFactory;
00036 import javax.xml.parsers.ParserConfigurationException;
00037 
00038 import org.w3c.dom.Document;
00039 import org.xml.sax.SAXException;
00040 
00041 import org.apache.axis.wsdl.WSDL2Java;
00042 import org.apache.axis.wsdl.gen.Parser;
00043 
00044 import org.objectweb.jonas_ws.wsgen.WsGenException;
00045 import org.objectweb.jonas_ws.wsgen.generator.axis.AxisWsClientGenerator;
00046 
00051 public class JOnASWSDL2Java extends WSDL2Java {
00052 
00056     private JOnASEmitter jEmitter;
00057 
00061     private String wsdlURL = null;
00062 
00066     private Document wsdlDoc = null;
00067 
00071     public JOnASWSDL2Java() {
00072         super();
00073         // just cast it once
00074         jEmitter = (JOnASEmitter) getParser();
00075     }
00076 
00080     protected Parser createParser() {
00081         return new JOnASEmitter();
00082     } // createParser
00083 
00089     private void setup(AxisWsClientGenerator wsc) throws WsGenException {
00090         setupEmitter(wsc);
00091         setupWSDL(wsc);
00092     }
00093 
00099     private void setupWSDL(AxisWsClientGenerator wsc) throws WsGenException {
00100         try {
00101             if (wsc.getArchive().isPacked()) {
00102                 // URL Loading
00103                 String jarpath = wsc.getArchive().getRootFile().getCanonicalFile().toURL().toExternalForm();
00104                 wsdlURL = "jar:" + jarpath + "!/" + wsc.getRef().getWsdlFileName();
00105             } else {
00106                 // File Loading
00107                 wsdlURL = new File(wsc.getArchive().getRootFile(), wsc.getRef().getWsdlFileName()).toURL()
00108                         .toExternalForm();
00109             }
00110 
00111             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
00112             factory.setNamespaceAware(true);
00113             DocumentBuilder builder = factory.newDocumentBuilder();
00114             wsdlDoc = builder.parse(wsdlURL);
00115         } catch (ParserConfigurationException pce) {
00116             throw new WsGenException("", pce);
00117         } catch (IOException ioe) {
00118             throw new WsGenException("", ioe);
00119         } catch (SAXException se) {
00120             throw new WsGenException("", se);
00121         }
00122     }
00123 
00128     private void setupEmitter(AxisWsClientGenerator wsc) {
00129         jEmitter.setDebug(wsc.getConfig().isDebug());
00130         jEmitter.setVerbose(wsc.getConfig().isVerbose());
00131         jEmitter.setNamespaceMap(convert2HashMap(wsc.getRef().getMappingFile().getMappings()));
00132         jEmitter.setOutputDir(wsc.getSources().getPath());
00133     }
00134 
00140     private HashMap convert2HashMap(Map m) {
00141         HashMap ns2pkg = new HashMap();
00142         for (Iterator i = m.keySet().iterator(); i.hasNext();) {
00143             String ns = (String) i.next();
00144             ns2pkg.put(ns, m.get(ns));
00145         }
00146         return ns2pkg;
00147     }
00148 
00160     public void run(AxisWsClientGenerator wsc) throws WsGenException, IOException, SAXException, WSDLException, ParserConfigurationException {
00161         setup(wsc);
00162         parser.run(wsdlURL, wsdlDoc);
00163     } // run
00164 
00165 }

Generated on Tue Feb 15 15:06:01 2005 for JOnAS by  doxygen 1.3.9.1