1 /* 2 * Copyright 2001-2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.apache.geronimo.ews.ws4j2ee.context.impl; 18 19 import org.apache.axis.wsdl.fromJava.Emitter; 20 import org.apache.axis.wsdl.symbolTable.BindingEntry; 21 import org.apache.axis.wsdl.symbolTable.PortTypeEntry; 22 import org.apache.axis.wsdl.symbolTable.ServiceEntry; 23 import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext; 24 import org.apache.geronimo.ews.ws4j2ee.context.JaxRpcMapperContext; 25 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault; 26 import org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenerationFault; 27 import org.apache.geronimo.ews.ws4j2ee.toWs.dd.JaxRpcMappingFileWriter; 28 29 import javax.wsdl.Operation; 30 import javax.wsdl.Port; 31 import javax.xml.namespace.QName; 32 import java.io.InputStream; 33 import java.io.Writer; 34 import java.lang.reflect.Method; 35 import java.util.HashMap; 36 37 /*** 38 * This class wrap the JAXRPCMapper and only expose a interface to 39 * the rest of the WS4j2ee. 40 * 41 * @author hemapani 42 */ 43 public class AxisEmitterBasedJaxRpcMapperContext implements JaxRpcMapperContext { 44 private Emitter emitter; 45 private J2EEWebServiceContext j2eewscontext; 46 private HashMap methods = new HashMap(); 47 48 public AxisEmitterBasedJaxRpcMapperContext(Emitter emitter, J2EEWebServiceContext j2eewscontext) { 49 this.emitter = emitter; 50 this.j2eewscontext = j2eewscontext; 51 Method[] methods = emitter.getCls().getMethods(); 52 for (int i = 0; i < methods.length; i++) { 53 this.methods.put(methods[i].getName(), methods[i]); 54 } 55 } 56 57 /*** 58 * @param messageQName 59 * @return 60 */ 61 public String getExceptionType(QName messageQName) { 62 throw new UnsupportedOperationException(); 63 //return jaxrpcmapper.getExceptionType(messageQName); 64 } 65 66 /*** 67 * @param bEntry 68 * @param operation 69 * @return 70 */ 71 public String getJavaMethodName(BindingEntry bEntry, Operation operation) { 72 return operation.getName(); 73 } 74 75 /*** 76 * @param bEntry 77 * @param operation 78 * @param position 79 * @return 80 */ 81 public String getJavaMethodParamType(BindingEntry bEntry, 82 Operation operation, 83 int position, QName type) { 84 Method m = (Method) this.methods.get(operation.getName()); 85 //axis do not map the method names or types 86 //so this should do 87 if (m == null) 88 throw new UnrecoverableGenerationFault("logic expected is differnet .. worng" + 89 "design decision"); 90 return m.getParameterTypes()[position].getName(); 91 } 92 93 /*** 94 * @param bEntry 95 * @param operation 96 * @return 97 */ 98 public String getJavaMethodReturnType(BindingEntry bEntry, 99 Operation operation) { 100 Method m = (Method) this.methods.get(operation.getName()); 101 //axis do not map the method names or types 102 //so this should do 103 if (m == null) 104 throw new UnrecoverableGenerationFault("logic expected is differnet .. worng" + 105 "design decision"); 106 return m.getReturnType().getName(); 107 } 108 109 /*** 110 * @param typeQName 111 * @return 112 */ 113 public String getJavaType(QName typeQName) { 114 throw new UnsupportedOperationException(); 115 // return jaxrpcmapper.getJavaType(typeQName); 116 } 117 118 /*** 119 * @param port 120 * @return 121 */ 122 public String getPortName(Port port) { 123 return emitter.getServicePortName(); 124 } 125 126 /*** 127 * @param ptEntry 128 * @param bEntry 129 * @return 130 */ 131 public String getServiceEndpointInterfaceName(PortTypeEntry ptEntry, 132 BindingEntry bEntry) { 133 return emitter.getPortTypeName(); 134 } 135 136 /*** 137 * @param entry 138 * @return 139 */ 140 public String getServiceInterfaceName(ServiceEntry entry) { 141 return emitter.getServiceElementName(); 142 } 143 144 /*** 145 * @param path 146 */ 147 public void loadMappingFromDir(String path) { 148 throw new UnsupportedOperationException(); 149 } 150 151 /*** 152 * @param is 153 */ 154 public void loadMappingFromInputStream(InputStream is) { 155 throw new UnsupportedOperationException(); 156 } 157 158 public void serialize(Writer out) throws GenerationFault { 159 JaxRpcMappingFileWriter w = new JaxRpcMappingFileWriter(out, emitter, j2eewscontext); 160 w.write(); 161 // 162 // try { 163 // JAXBContext jc = JAXBContext.newInstance("org.apache.geronimo.ews.jaxrpcmapping.descriptor"); 164 // ObjectFactory objFactory = new ObjectFactory(); 165 // 166 // JavaWsdlMapping jaxrpcmap = objFactory.createJavaWsdlMapping(); 167 // jaxrpcmap.setVersion(new BigDecimal("1.0")); 168 // 169 ////adding pckage mappings 170 // Map map = emitter.getNamespaceMap(); 171 // if (map != null) { 172 // Iterator packages = map.keySet().iterator(); 173 // while (packages.hasNext()) { 174 // PackageMappingType pkgmap = objFactory.createPackageMappingType(); 175 // //set the package name 176 // FullyQualifiedClassType packagename = objFactory.createFullyQualifiedClassType(); 177 // String pkg = (String) packages.next(); 178 // String jaxrpcsei = j2eewscontext.getMiscInfo().getJaxrpcSEI(); 179 // if(pkg == null){ 180 // //TODO this is temporrary work around to make sure 181 // //the mapping is defined. 182 // String pkgName = Utils.getPackageNameFromQuallifiedName(jaxrpcsei); 183 // String val = (String)map.get(pkgName); 184 // if(val == null){ 185 // val = Utils.javapkgToURI(pkgName); 186 // packagename.setValue(pkgName); 187 // pkgmap.setPackageType(packagename); 188 // //set the namespace URI 189 // XsdAnyURIType nsuri = objFactory.createXsdAnyURIType(); 190 // nsuri.setValue(val); 191 // pkgmap.setNamespaceURI(nsuri); 192 // }else{ 193 // continue; 194 // } 195 // }else if(pkg.equals(jaxrpcsei)){ 196 // continue; 197 // }else{ 198 // packagename.setValue(pkg); 199 // pkgmap.setPackageType(packagename); 200 // //set the namespace URI 201 // XsdAnyURIType nsuri = objFactory.createXsdAnyURIType(); 202 // nsuri.setValue((String) map.get(pkg)); 203 // pkgmap.setNamespaceURI(nsuri); 204 // 205 // } 206 // //done :) add the package type 207 // jaxrpcmap.getPackageMapping().add(pkgmap); 208 // } 209 // } 210 // 211 ////adding Service mappings 212 ///////////////////////////// 213 // Service service = j2eewscontext.getWSDLContext().gettargetService().getService(); 214 // org.apache.geronimo.ews.jaxrpcmapping.descriptor.JavaWsdlMappingType.ServiceInterfaceMapping servciemaping = objFactory.createJavaWsdlMappingTypeServiceInterfaceMapping(); 215 // 216 // 217 // //get the sevice QName 218 // XsdQNameType serviceName = objFactory.createXsdQNameType(); 219 // serviceName.setValue(service.getQName()); 220 // servciemaping.setWsdlServiceName(serviceName); 221 // 222 // //set the service java Name 223 // FullyQualifiedClassType serviceJavaName = objFactory.createFullyQualifiedClassType(); 224 // 225 // String name = emitter.getCls().getName(); 226 // int index = name.lastIndexOf('.'); 227 // String packageName = ""; 228 // if (index > 0) 229 // packageName = name.substring(0, index + 1); 230 // 231 // serviceJavaName.setValue(packageName + emitter.getServiceElementName()); 232 // 233 // servciemaping.setServiceInterface(serviceJavaName); 234 // jaxrpcmap.getServiceInterfaceMappingAndServiceEndpointInterfaceMapping().add(servciemaping); 235 // 236 // 237 // 238 // Port wsdlport = j2eewscontext.getWSDLContext().getTargetPort(); 239 // Binding binding = wsdlport.getBinding(); 240 // 241 // //create a portmap 242 // PortMappingType portmap = objFactory.createPortMappingType(); 243 // //java port name 244 // org.apache.geronimo.ews.jaxrpcmapping.descriptor.String javaportname = objFactory.createString(); 245 // javaportname.setValue(emitter.getServicePortName()); 246 // portmap.setJavaPortName(javaportname); 247 // //wsdl port name 248 // org.apache.geronimo.ews.jaxrpcmapping.descriptor.String wsdlportname = objFactory.createString(); 249 // wsdlportname.setValue(wsdlport.getName()); 250 // portmap.setPortName(wsdlportname); 251 // 252 // servciemaping.getPortMapping().add(portmap); 253 // 254 // if (binding == null) 255 // throw new UnrecoverableGenerationFault("no port discription not match with the wsdl file"); 256 // 257 // org.apache.geronimo.ews.jaxrpcmapping.descriptor.JavaWsdlMappingType.ServiceEndpointInterfaceMapping seimapping = objFactory.createJavaWsdlMappingTypeServiceEndpointInterfaceMapping(); 258 // 259 ////set java SEI name 260 // FullyQualifiedClassType seijavaName = objFactory.createFullyQualifiedClassType(); 261 // seijavaName.setValue(emitter.getCls().getName()); 262 // seimapping.setServiceEndpointInterface(seijavaName); 263 ////set the wsdl finding name 264 // XsdQNameType bindingQName = objFactory.createXsdQNameType(); 265 // bindingQName.setValue(binding.getQName()); 266 // seimapping.setWsdlBinding(bindingQName); 267 ////set the wsdl port type 268 // XsdQNameType portTypeQName = objFactory.createXsdQNameType(); 269 // portTypeQName.setValue(binding.getPortType().getQName()); 270 // seimapping.setWsdlPortType(portTypeQName); 271 // 272 ////add the operation mappings 273 // Iterator ops = binding.getPortType().getOperations().iterator(); 274 // 275 // while (ops.hasNext()) { 276 // ServiceEndpointMethodMappingType seimethodmapping = objFactory.createServiceEndpointMethodMappingType(); 277 // Operation op = (Operation) ops.next(); 278 // 279 // //set the java method name 280 // org.apache.geronimo.ews.jaxrpcmapping.descriptor.String javamethodname = objFactory.createString(); 281 // javamethodname.setValue(op.getName()); 282 // seimethodmapping.setJavaMethodName(javamethodname); 283 // 284 // //TODO not sure what this WrappedElement do. FIXIT 285 // //seimethodmapping.setWrappedElement(); 286 // 287 // //set wsdl method name 288 // org.apache.geronimo.ews.jaxrpcmapping.descriptor.String wsdlmethodname = objFactory.createString(); 289 // wsdlmethodname.setValue(op.getName()); 290 // seimethodmapping.setWsdlOperation(wsdlmethodname); 291 // 292 // //this work only when the method names are same 293 // //im printing it so that it is easier for user to change 294 // //it am sure that no body will writing nor webservices.xml 295 // //or jaxrpcmapping.xml files if there is a short cut. 296 // 297 // 298 // //set return type 299 // Method mtd = (Method) methods.get(op.getName()); 300 // Class ret = mtd.getReturnType(); 301 // if(ret!= null && !("void".equals(ret.toString()))){ 302 // //create return type Map 303 // WsdlReturnValueMappingType retvalmap = objFactory.createWsdlReturnValueMappingType(); 304 // 305 // FullyQualifiedClassType retValjavaName = objFactory.createFullyQualifiedClassType(); 306 // retValjavaName.setValue(ret.getName()); 307 // retvalmap.setMethodReturnValue(retValjavaName); 308 // 309 // //set return type info 310 // Map parts = op.getOutput().getMessage().getParts(); 311 // if (parts != null) { 312 // Iterator partIt = parts.values().iterator(); 313 // if (partIt.hasNext()) { 314 // //set wsdl message type 315 // WsdlMessageType messageType = objFactory.createWsdlMessageType(); 316 // messageType.setValue(op.getOutput().getMessage().getQName()); 317 // retvalmap.setWsdlMessage(messageType); 318 // 319 // //set wsdl message part type 320 // WsdlMessagePartNameType messagePartName = objFactory.createWsdlMessagePartNameType(); 321 // messagePartName.setValue(((Part) partIt.next()).getName()); 322 // retvalmap.setWsdlMessagePartName(messagePartName); 323 // } 324 // 325 // } 326 // 327 // seimethodmapping.setWsdlReturnValueMapping(retvalmap); 328 // 329 // } 330 // 331 // 332 // 333 // //create method param parts mappings 334 // int position = 0; 335 // Class[] params = ((Method) methods.get(op.getName())).getParameterTypes(); 336 // 337 // Iterator parmIt = null; 338 // Map parameters = op.getInput().getMessage().getParts(); 339 // if (parameters != null) { 340 // parmIt = parameters.values().iterator(); 341 // } 342 // 343 // while (parmIt != null && parmIt.hasNext()) { 344 // Part part = (Part) parmIt.next(); 345 // //create parts mapping 346 // MethodParamPartsMappingType partsMapping = objFactory.createMethodParamPartsMappingType(); 347 // //set parameter position 348 // XsdNonNegativeIntegerType pos = objFactory.createXsdNonNegativeIntegerType(); 349 // pos.setValue(new BigInteger(Integer.toString(position))); 350 // partsMapping.setParamPosition(pos); 351 // 352 // //set parameter java typr 353 // JavaTypeType javaType = objFactory.createJavaTypeType(); 354 // javaType.setValue(params[position].getName()); 355 // partsMapping.setParamType(javaType); 356 // 357 // //set message mapping 358 // WsdlMessageMappingType msgmappingType = objFactory.createWsdlMessageMappingType(); 359 // //set mode 360 // ParameterModeType mode = objFactory.createParameterModeType(); 361 // mode.setValue("IN"); 362 // msgmappingType.setParameterMode(mode); 363 // //TODO Im a not sure what to do with the header 364 // //msgmappingType.setSoapHeader(); 365 // //set wsdl message type 366 // WsdlMessageType messageType = objFactory.createWsdlMessageType(); 367 // messageType.setValue(op.getInput().getMessage().getQName()); 368 // msgmappingType.setWsdlMessage(messageType); 369 // //set wsdl message part type 370 // WsdlMessagePartNameType messagePartName = objFactory.createWsdlMessagePartNameType(); 371 // messagePartName.setValue(part.getName()); 372 // msgmappingType.setWsdlMessagePartName(messagePartName); 373 // 374 // partsMapping.setWsdlMessageMapping(msgmappingType); 375 // seimethodmapping.getMethodParamPartsMapping().add(partsMapping); 376 // } 377 // 378 // seimapping.getServiceEndpointMethodMapping().add(seimethodmapping); 379 // 380 // } 381 // jaxrpcmap.getServiceInterfaceMappingAndServiceEndpointInterfaceMapping().add(seimapping); 382 // 383 ////axis do not support XML type mapping or Exception 384 ////maping to be specifed so I do not brother tp print them out. 385 ////jaxrpcmap.getExceptionMapping(); 386 ////jaxrpcmap.getJavaXmlTypeMapping(); 387 // 388 // Marshaller m = jc.createMarshaller(); 389 // m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 390 // m.marshal(jaxrpcmap, out); 391 // 392 // Unmarshaller u = jc.createUnmarshaller(); 393 // } catch (Exception e) { 394 // e.printStackTrace(); 395 // throw GenerationFault.createGenerationFault(e); 396 // } 397 } 398 399 public String getPackageMappingClassName(int index) { 400 throw new UnsupportedOperationException(); 401 } 402 403 public int getPackageMappingCount() { 404 throw new UnsupportedOperationException(); 405 } 406 407 public String getPackageMappingURI(int index) { 408 throw new UnsupportedOperationException(); 409 } 410 411 }