1 25 package org.objectweb.jonas_ws.wsgen.generator.axis.wsdl2java; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.Map ; 32 33 import javax.wsdl.WSDLException; 34 import javax.xml.parsers.DocumentBuilder ; 35 import javax.xml.parsers.DocumentBuilderFactory ; 36 import javax.xml.parsers.ParserConfigurationException ; 37 38 import org.w3c.dom.Document ; 39 import org.xml.sax.SAXException ; 40 41 import org.apache.axis.wsdl.WSDL2Java; 42 import org.apache.axis.wsdl.gen.Parser; 43 44 import org.objectweb.jonas_ws.wsgen.WsGenException; 45 import org.objectweb.jonas_ws.wsgen.generator.axis.AxisWsClientGenerator; 46 47 51 public class JOnASWSDL2Java extends WSDL2Java { 52 53 56 private JOnASEmitter jEmitter; 57 58 61 private String wsdlURL = null; 62 63 66 private Document wsdlDoc = null; 67 68 71 public JOnASWSDL2Java() { 72 super(); 73 jEmitter = (JOnASEmitter) getParser(); 75 } 76 77 80 protected Parser createParser() { 81 return new JOnASEmitter(); 82 } 84 89 private void setup(AxisWsClientGenerator wsc) throws WsGenException { 90 setupEmitter(wsc); 91 setupWSDL(wsc); 92 } 93 94 99 private void setupWSDL(AxisWsClientGenerator wsc) throws WsGenException { 100 try { 101 if (wsc.getArchive().isPacked()) { 102 String jarpath = wsc.getArchive().getRootFile().getCanonicalFile().toURL().toExternalForm(); 104 wsdlURL = "jar:" + jarpath + "!/" + wsc.getRef().getWsdlFileName(); 105 } else { 106 wsdlURL = new File (wsc.getArchive().getRootFile(), wsc.getRef().getWsdlFileName()).toURL() 108 .toExternalForm(); 109 } 110 111 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 112 factory.setNamespaceAware(true); 113 DocumentBuilder builder = factory.newDocumentBuilder(); 114 wsdlDoc = builder.parse(wsdlURL); 115 } catch (ParserConfigurationException pce) { 116 throw new WsGenException("", pce); 117 } catch (IOException ioe) { 118 throw new WsGenException("", ioe); 119 } catch (SAXException se) { 120 throw new WsGenException("", se); 121 } 122 } 123 124 128 private void setupEmitter(AxisWsClientGenerator wsc) { 129 jEmitter.setDebug(wsc.getConfig().isDebug()); 130 jEmitter.setVerbose(wsc.getConfig().isVerbose()); 131 jEmitter.setNamespaceMap(convert2HashMap(wsc.getRef().getMappingFile().getMappings())); 132 jEmitter.setOutputDir(wsc.getSources().getPath()); 133 } 134 135 140 private HashMap convert2HashMap(Map m) { 141 HashMap ns2pkg = new HashMap (); 142 for (Iterator i = m.keySet().iterator(); i.hasNext();) { 143 String ns = (String ) i.next(); 144 ns2pkg.put(ns, m.get(ns)); 145 } 146 return ns2pkg; 147 } 148 149 160 public void run(AxisWsClientGenerator wsc) throws WsGenException, IOException , SAXException , WSDLException, ParserConfigurationException { 161 setup(wsc); 162 parser.run(wsdlURL, wsdlDoc); 163 } 165 } | Popular Tags |