1 25 26 package org.objectweb.jonas_ws.wsgen.generator.axis; 27 28 import java.io.File ; 29 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 33 import org.apache.velocity.VelocityContext; 34 35 import org.objectweb.jonas_lib.I18n; 36 import org.objectweb.jonas_lib.genbase.GenBaseException; 37 import org.objectweb.jonas_lib.genbase.archive.Archive; 38 import org.objectweb.jonas_lib.genbase.archive.EjbJar; 39 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 40 import org.objectweb.jonas_lib.genbase.archive.WebApp; 41 import org.objectweb.jonas_lib.genbase.generator.Config; 42 import org.objectweb.jonas_lib.genbase.utils.XMLUtils; 43 import org.objectweb.jonas_lib.loader.AbsModuleClassLoader; 44 45 import org.objectweb.jonas_ws.deployment.api.MappingFile; 46 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 47 import org.objectweb.jonas_ws.wsgen.WsGenException; 48 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier; 49 import org.objectweb.jonas_ws.wsgen.generator.WsClientGenerator; 50 import org.objectweb.jonas_ws.wsgen.generator.axis.wsdl2java.JOnASWSDL2Java; 51 52 import org.objectweb.util.monolog.api.BasicLevel; 53 54 61 public class AxisWsClientGenerator extends WsClientGenerator { 62 63 64 private static JVelocity jvelocity = null; 65 66 69 private static final String CLIENT_CONFIG = "axis.clientConfigFile"; 70 71 74 private static final String WSDD_SUFFIX = ".wsdd"; 75 76 79 private static final String WSDD_PREFIX = "deploy-client-"; 80 81 82 private static int count = 0; 83 84 85 private File generated = null; 86 87 90 private static final String WEB_PREFIX = "WEB-INF/"; 91 92 95 private static I18n i18n = I18n.getInstance(AxisWsClientGenerator.class); 96 97 106 public AxisWsClientGenerator(Config config, ServiceRefDesc srd, WsClientDDModifier ddm, Archive archive) 107 throws GenBaseException, WsGenException { 108 super(config, srd, ddm, archive); 109 110 if (jvelocity == null) { 112 jvelocity = new JVelocity("deploy_client.vm"); 113 } 114 } 115 116 120 public void generate() throws WsGenException { 121 122 if ((getRef().getWsdlFileName() != null) 125 && !getRef().getServiceInterface().getName().equals("javax.xml.rpc.Service")) { 126 127 try { 128 J2EEArchive j2eeArchive = (J2EEArchive) getArchive(); 130 AbsModuleClassLoader cl = (AbsModuleClassLoader) j2eeArchive.getModuleClassloader(); 131 getConfig().setClasspath(getConfig().getClasspath() + cl.getClasspath()); 132 133 134 JOnASWSDL2Java jWsdl2Java = new JOnASWSDL2Java(); 135 jWsdl2Java.run(this); 136 getLogger().log(BasicLevel.INFO, "Web Services Classes successfully generated by Axis."); 137 } catch (Exception e) { 138 String err = getI18n().getMessage("AxisWsClientGenerator.generate.WSDL2Java"); 139 e.printStackTrace(System.err); 140 throw new WsGenException(err, e); 141 } 142 } 143 144 if (hasClientConfigFile(getRef())) { 150 String filename = WSDD_PREFIX + (count++) + WSDD_SUFFIX; 154 155 VelocityContext vctx = VContextFactory.getContext(getRef()); 156 157 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 158 getLogger().log(BasicLevel.DEBUG, "Creating '" + filename + "'"); 159 } 160 generated = new File (getSources(), filename); 161 162 jvelocity.generate(generated, vctx); 163 164 } 165 } 167 168 173 private boolean hasClientConfigFile(ServiceRefDesc ref) { 174 if (getConfig().isNoConfig()) { 176 return false; 177 } 178 179 MappingFile mf = ref.getMappingFile(); 180 181 if (mf != null) { 182 if (mf.getXmlTypeMappings().hasNext()) { 184 return true; 186 } else { 187 return (ref.getHandlerRefs().size() != 0); 190 } 191 } else { 192 return (ref.getHandlerRefs().size() != 0); 195 } 196 } 197 198 203 public void addFiles(Archive archive) throws WsGenException { 204 if (archive instanceof WebApp) { 205 archive.addDirectoryIn("WEB-INF/classes/", getClasses()); 206 207 if (generated != null) { 208 archive.addFileIn("WEB-INF/", generated); 209 210 if (!getModifier().hasJonasServiceRef()) { 212 if (!getArchive().getContainedFiles().contains("WEB-INF/jonas-web.xml")) { 213 createEmptyJonasWeb((J2EEArchive) archive); 215 } 216 Element jsr = getModifier().createJonasServiceRef(getRef().getServiceRefName()); 217 getModifier().setElement(jsr); 219 220 } 221 222 getModifier().addJonasInitParam(CLIENT_CONFIG, WEB_PREFIX + generated.getName()); 224 } 225 } else if (archive instanceof EjbJar) { 226 archive.addDirectory(getClasses()); 227 228 if (generated != null) { 229 archive.addFileIn("META-INF/", generated); 230 231 if (!getModifier().hasJonasServiceRef()) { 233 Element jsr = getModifier().createJonasServiceRef(getRef().getServiceRefName()); 234 getModifier().setElement(jsr); 236 } 237 238 getModifier().addJonasInitParam(CLIENT_CONFIG, "META-INF/" + generated.getName()); 240 } 241 } else { 242 archive.addDirectory(getClasses()); 243 244 if (generated != null) { 245 archive.addFileIn("META-INF/", generated); 246 247 if (!getModifier().hasJonasServiceRef()) { 249 if (!getArchive().getContainedFiles().contains("META-INF/jonas-client.xml")) { 250 createEmptyJonasClient((J2EEArchive) archive); 252 } 253 Element jsr = getModifier().createJonasServiceRef(getRef().getServiceRefName()); 254 getModifier().setElement(jsr); 256 257 } 258 259 getModifier().addJonasInitParam(CLIENT_CONFIG, "META-INF/" + generated.getName()); 261 } 262 } 263 } 264 265 269 private void createEmptyJonasWeb(J2EEArchive archive) { 270 Document doc = XMLUtils.newJonasWeb(); 271 archive.getDescriptors().put("WEB-INF/jonas-web.xml", doc); 272 getModifier().setDocument(doc); 273 } 274 275 279 private void createEmptyJonasClient(J2EEArchive archive) { 280 Document doc = XMLUtils.newJonasClient(); 281 archive.getDescriptors().put("META-INF/jonas-client.xml", doc); 282 getModifier().setDocument(doc); 283 } 284 285 288 public static I18n getI18n() { 289 return i18n; 290 } 291 } | Popular Tags |