1 package org.objectweb.celtix.tools.common.model; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 import java.util.logging.Logger ; 9 10 import javax.jws.soap.SOAPBinding; 11 import javax.jws.soap.SOAPBinding.ParameterStyle; 12 import javax.jws.soap.SOAPBinding.Style; 13 import javax.jws.soap.SOAPBinding.Use; 14 import javax.wsdl.Definition; 15 import javax.wsdl.WSDLException; 16 import javax.wsdl.factory.WSDLFactory; 17 18 import com.sun.xml.bind.api.JAXBRIContext; 19 import com.sun.xml.bind.api.TypeReference; 20 21 import org.objectweb.celtix.common.i18n.Message; 22 import org.objectweb.celtix.common.logging.LogUtils; 23 import org.objectweb.celtix.tools.common.ToolException; 24 import org.objectweb.celtix.tools.processors.java2.JavaToWSDLProcessor; 25 26 public class WSDLModel { 27 private static final Logger LOG = LogUtils.getL7dLogger(JavaToWSDLProcessor.class); 28 protected JAXBRIContext jaxbContext; 29 30 private Definition definition; 31 32 private String wsdlLocation; 33 34 private String serviceName; 35 36 private String targetNameSpace; 37 38 private String portTypeName; 39 40 private String portName; 41 42 private String packageName; 43 44 private final List <JavaMethod> methods = new ArrayList <JavaMethod>(); 45 46 private final Map <String , String > schemaNSFileMap = new HashMap <String , String >(); 47 48 private Style style = SOAPBinding.Style.DOCUMENT; 50 51 private Use use = SOAPBinding.Use.LITERAL; 52 53 private ParameterStyle paraStyle = SOAPBinding.ParameterStyle.WRAPPED; 54 55 public WSDLModel() throws ToolException { 56 try { 57 WSDLFactory wsdlFactory = WSDLFactory.newInstance(); 58 definition = wsdlFactory.newDefinition(); 59 } catch (WSDLException e) { 60 Message message = new Message("FAIL_TO_CREATE_WSDL_DEFINITION", LOG); 61 throw new ToolException(message, e); 62 } 63 } 64 65 public void setWsdllocation(String loc) { 66 this.wsdlLocation = loc; 67 } 68 69 public String getWsdllocation() { 70 return this.wsdlLocation; 71 72 } 73 74 public void setServiceName(String name) { 75 this.serviceName = name; 76 } 77 78 public String getServiceName() { 79 return this.serviceName; 80 } 81 82 public String getPortTypeName() { 83 return this.portTypeName; 84 } 85 86 public void setPortTypeName(String pname) { 87 this.portTypeName = pname; 88 } 89 90 public void setPortName(String name) { 91 this.portName = name; 92 } 93 94 public String getPortName() { 95 return this.portName; 96 } 97 98 public void setTargetNameSpace(String space) { 99 this.targetNameSpace = space; 100 } 101 102 public String getTargetNameSpace() { 103 return this.targetNameSpace; 104 } 105 106 public Definition getDefinition() { 107 return this.definition; 108 } 109 110 public String getPackageName() { 111 return this.packageName; 112 } 113 114 public void setPackageName(String name) { 115 this.packageName = name; 116 } 117 118 public void addJavaMethod(JavaMethod jmothd) { 119 this.methods.add(jmothd); 120 } 121 122 public List <JavaMethod> getJavaMethods() { 123 return this.methods; 124 } 125 126 public void createJAXBContext() throws ToolException { 127 List <TypeReference> types = this.getAllTypeReference(); 128 Class [] clzzs = new Class [types.size()]; 129 int i = 0; 130 for (TypeReference typeref : types) { 131 clzzs[i++] = (Class )typeref.type; 132 } 133 try { 134 jaxbContext = JAXBRIContext.newInstance(clzzs, types, this.getTargetNameSpace(), false); 135 136 } catch (Exception e) { 137 Message message = new Message("CREATE_JAXBRICONTEXT_EXCEPTION", LOG); 138 throw new ToolException(message, e); 139 } 140 141 } 142 143 146 public List <TypeReference> getAllTypeReference() { 147 List <TypeReference> types = new ArrayList <TypeReference>(); 148 for (JavaMethod m : methods) { 149 WSDLParameter request = m.getRequest(); 150 if (request.getTypeReference() != null && m.isWrapperStyle()) { 151 types.add(request.getTypeReference()); 152 153 } else { 154 Iterator ite2 = request.getChildren().iterator(); 155 while (ite2.hasNext()) { 156 JavaParameter jp = (JavaParameter)ite2.next(); 157 if (jp.getTypeReference() != null) { 158 types.add(jp.getTypeReference()); 159 160 } 161 } 162 } 163 if (!m.isOneWay()) { 164 WSDLParameter response = m.getResponse(); 165 if (response.getTypeReference() != null && m.isWrapperStyle()) { 166 types.add(response.getTypeReference()); 167 168 } else { 169 Iterator ite2 = response.getChildren().iterator(); 170 while (ite2.hasNext()) { 171 JavaParameter jp = (JavaParameter)ite2.next(); 172 if (jp.getTypeReference() != null) { 173 types.add(jp.getTypeReference()); 174 175 } 176 } 177 } 178 } 179 Iterator ite3 = m.getWSDLExceptions().iterator(); 180 while (ite3.hasNext()) { 181 org.objectweb.celtix.tools.common.model.WSDLException wsdlEx = 182 (org.objectweb.celtix.tools.common.model.WSDLException)ite3.next(); 183 types.add(wsdlEx.getDetailTypeReference()); 184 } 185 } 186 187 return types; 188 } 189 190 public JAXBRIContext getJaxbContext() { 191 return this.jaxbContext; 192 } 193 194 public void setStyle(Style s) { 195 this.style = s; 196 } 197 198 public Style getStyle() { 199 return this.style; 200 } 201 202 public void setUse(Use u) { 203 this.use = u; 204 } 205 206 public ParameterStyle getParameterStyle() { 207 return paraStyle; 208 } 209 210 public void setPrameterStyle(ParameterStyle pstyle) { 211 paraStyle = pstyle; 212 } 213 214 public Use getUse() { 215 return this.use; 216 } 217 218 public boolean isDocLit() { 219 if (this.style == Style.DOCUMENT && this.use == Use.LITERAL) { 220 return true; 221 } 222 return false; 223 } 224 225 public boolean isWrapped() { 226 return this.paraStyle == SOAPBinding.ParameterStyle.WRAPPED; 227 } 228 229 public boolean isRPC() { 230 return (this.style == SOAPBinding.Style.RPC) && (this.use == SOAPBinding.Use.LITERAL) 231 && (this.paraStyle == SOAPBinding.ParameterStyle.WRAPPED); 232 } 233 234 public Map <String , String > getSchemaNSFileMap() { 235 return this.schemaNSFileMap; 236 } 237 238 public void addSchemaNSFileToMap(String schemaNS, String filename) { 239 this.schemaNSFileMap.put(schemaNS, filename); 240 } 241 242 } 243 | Popular Tags |