001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026: import javax.wsdl.extensions.ExtensibilityElement;
027: import javax.wsdl.extensions.http.HTTPBinding;
028: import javax.wsdl.extensions.mime.MIMEContent;
029: import javax.wsdl.extensions.mime.MIMEMultipartRelated;
030: import javax.wsdl.extensions.mime.MIMEPart;
031: import javax.wsdl.extensions.soap.SOAPHeader;
032: import javax.xml.namespace.QName;
033:
034: import org.w3c.dom.Element;
035:
036: import org.apache.cxf.common.i18n.Message;
037: import org.apache.cxf.common.util.StringUtils;
038: import org.apache.cxf.service.model.BindingInfo;
039: import org.apache.cxf.service.model.BindingOperationInfo;
040: import org.apache.cxf.service.model.EndpointInfo;
041: import org.apache.cxf.service.model.InterfaceInfo;
042: import org.apache.cxf.service.model.MessageInfo;
043: import org.apache.cxf.service.model.MessagePartInfo;
044: import org.apache.cxf.service.model.OperationInfo;
045: import org.apache.cxf.service.model.ServiceInfo;
046: import org.apache.cxf.tools.common.ToolConstants;
047: import org.apache.cxf.tools.common.ToolContext;
048: import org.apache.cxf.tools.common.ToolException;
049: import org.apache.cxf.tools.common.extensions.soap.SoapBinding;
050: import org.apache.cxf.tools.common.extensions.soap.SoapBody;
051: import org.apache.cxf.tools.common.extensions.soap.SoapHeader;
052: import org.apache.cxf.tools.common.extensions.soap.SoapOperation;
053: import org.apache.cxf.tools.common.model.JavaAnnotation;
054: import org.apache.cxf.tools.common.model.JavaInterface;
055: import org.apache.cxf.tools.common.model.JavaMethod;
056: import org.apache.cxf.tools.common.model.JavaModel;
057: import org.apache.cxf.tools.common.model.JavaParameter;
058: import org.apache.cxf.tools.common.model.JavaPort;
059: import org.apache.cxf.tools.common.model.JavaServiceClass;
060: import org.apache.cxf.tools.common.model.JavaType;
061: import org.apache.cxf.tools.util.ClassCollector;
062: import org.apache.cxf.tools.util.NameUtil;
063: import org.apache.cxf.tools.util.SOAPBindingUtil;
064: import org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding;
065:
066: public class ServiceProcessor extends AbstractProcessor {
067:
068: private String soapOPAction = "SOAPACTION";
069:
070: private String soapOPStyle = "STYLE";
071:
072: private BindingType bindingType;
073:
074: private final int inHEADER = 1;
075:
076: private final int outHEADER = 2;
077:
078: private final int resultHeader = 3;
079:
080: private final int noHEADER = 0;
081:
082: private Object bindingObj;
083: private ServiceInfo service;
084:
085: private JAXWSBinding jaxwsBinding = new JAXWSBinding();
086:
087: public ServiceProcessor(ToolContext penv) {
088: super (penv);
089: }
090:
091: public void process(ServiceInfo si) throws ToolException {
092: if (si.getName() == null) {
093: return;
094: }
095: this .service = si;
096: processService(context.get(JavaModel.class));
097:
098: }
099:
100: private boolean isNameCollision(String packageName, String className) {
101: if (context.optionSet(ToolConstants.CFG_GEN_OVERWRITE)) {
102: return false;
103: }
104: ClassCollector collector = context.get(ClassCollector.class);
105: return collector.containTypesClass(packageName, className)
106: || collector.containSeiClass(packageName, className)
107: || collector.containExceptionClass(packageName,
108: className);
109: }
110:
111: private void processService(JavaModel model) throws ToolException {
112: JavaServiceClass sclz = new JavaServiceClass(model);
113: String name = NameUtil.mangleNameToClassName(service.getName()
114: .getLocalPart());
115: String namespace = service.getName().getNamespaceURI();
116: String packageName = ProcessorUtil.parsePackageName(namespace,
117: context.mapPackageName(namespace));
118:
119: //customizing
120: JAXWSBinding serviceBinding = service.getDescription()
121: .getExtensor(JAXWSBinding.class);
122: JAXWSBinding serviceBinding2 = service
123: .getExtensor(JAXWSBinding.class);
124:
125: //TODO : Handle service customized class
126: if (serviceBinding != null) {
127: if (serviceBinding.getPackage() != null) {
128: jaxwsBinding.setPackage(serviceBinding.getPackage());
129: }
130:
131: if (serviceBinding.isEnableAsyncMapping()) {
132: jaxwsBinding.setEnableAsyncMapping(true);
133: }
134:
135: if (serviceBinding.isEnableMime()) {
136: jaxwsBinding.setEnableMime(true);
137: }
138:
139: if (serviceBinding.isEnableWrapperStyle()) {
140: jaxwsBinding.setEnableWrapperStyle(true);
141: }
142: if (serviceBinding.getJaxwsClass() != null
143: && serviceBinding.getJaxwsClass().getClassName() != null) {
144: name = serviceBinding.getJaxwsClass().getClassName();
145: }
146: }
147: if (serviceBinding2 != null) {
148: if (serviceBinding2.getPackage() != null) {
149: jaxwsBinding.setPackage(serviceBinding2.getPackage());
150: }
151:
152: if (serviceBinding2.isEnableAsyncMapping()) {
153: jaxwsBinding.setEnableAsyncMapping(true);
154: }
155:
156: if (serviceBinding2.isEnableMime()) {
157: jaxwsBinding.setEnableMime(true);
158: }
159:
160: if (serviceBinding2.isEnableWrapperStyle()) {
161: jaxwsBinding.setEnableWrapperStyle(true);
162: }
163: if (serviceBinding2.getJaxwsClass() != null
164: && serviceBinding2.getJaxwsClass().getClassName() != null) {
165: name = serviceBinding2.getJaxwsClass().getClassName();
166: }
167: }
168:
169: sclz.setServiceName(service.getName().getLocalPart());
170: sclz.setNamespace(namespace);
171:
172: if (jaxwsBinding.getPackage() != null) {
173: packageName = jaxwsBinding.getPackage();
174: }
175: sclz.setPackageName(packageName);
176:
177: while (isNameCollision(packageName, name)) {
178: name = name + "_Service";
179: }
180: sclz.setName(name);
181:
182: if (model.getServiceClasses().containsKey(name)) {
183: sclz = model.getServiceClasses().get(name);
184: }
185:
186: Element handler = (Element) context
187: .get(ToolConstants.HANDLER_CHAIN);
188: sclz.setHandlerChains(handler);
189:
190: Collection<EndpointInfo> ports = service.getEndpoints();
191:
192: for (EndpointInfo port : ports) {
193: JavaPort javaport = processPort(model, port);
194: sclz.addPort(javaport);
195: }
196: model.addServiceClass(name, sclz);
197: }
198:
199: private JavaPort processPort(JavaModel model, EndpointInfo port)
200: throws ToolException {
201: JavaPort jport = new JavaPort(NameUtil
202: .mangleNameToClassName(port.getName().getLocalPart()));
203: jport.setPortName(port.getName().getLocalPart());
204: BindingInfo binding = port.getBinding();
205: jport.setBindingAdress(port.getAddress());
206: jport.setBindingName(binding.getName().getLocalPart());
207:
208: String namespace = binding.getInterface().getName()
209: .getNamespaceURI();
210: String packageName = ProcessorUtil.parsePackageName(namespace,
211: context.mapPackageName(namespace));
212: jport.setPackageName(packageName);
213:
214: InterfaceInfo infInfo = binding.getInterface();
215:
216: String portType = binding.getInterface().getName()
217: .getLocalPart();
218: jport.setPortType(portType);
219:
220: JAXWSBinding infBinding = infInfo
221: .getExtensor(JAXWSBinding.class);
222:
223: if (infBinding != null) {
224: if (infBinding.getJaxwsClass() != null
225: && !StringUtils.isEmpty(infBinding.getJaxwsClass()
226: .getClassName())) {
227: jport.setPortType(infBinding.getJaxwsClass()
228: .getClassName());
229: }
230:
231: if (!infBinding.isEnableAsyncMapping()) {
232: jaxwsBinding.setEnableAsyncMapping(false);
233: }
234:
235: if (!infBinding.isEnableWrapperStyle()) {
236: jaxwsBinding.setEnableWrapperStyle(false);
237: }
238:
239: if (infBinding.getPackage() != null) {
240: jaxwsBinding.setPackage(infBinding.getPackage());
241: }
242: }
243:
244: if (jaxwsBinding.getPackage() != null) {
245: jport.setPackageName(jaxwsBinding.getPackage());
246: }
247:
248: if (infBinding != null && infBinding.getJaxwsClass() != null
249: && infBinding.getJaxwsClass().getClassName() != null) {
250: String className = NameUtil
251: .mangleNameToClassName(infBinding.getJaxwsClass()
252: .getClassName());
253: jport.setInterfaceClass(className);
254: } else {
255: jport.setInterfaceClass(NameUtil
256: .mangleNameToClassName(portType));
257: }
258:
259: bindingType = getBindingType(binding);
260:
261: if (bindingType == null) {
262: org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
263: "BINDING_SPECIFY_ONE_PROTOCOL", LOG, binding
264: .getName());
265: throw new ToolException(msg);
266: }
267:
268: if (isSoapBinding()) {
269: SoapBinding spbd = SOAPBindingUtil.getProxy(
270: SoapBinding.class, this .bindingObj);
271: jport.setStyle(SOAPBindingUtil
272: .getSoapStyle(spbd.getStyle()));
273: jport.setTransURI(spbd.getTransportURI());
274: }
275:
276: Collection<BindingOperationInfo> operations = binding
277: .getOperations();
278: for (BindingOperationInfo bop : operations) {
279: processOperation(model, bop, binding);
280: }
281: return jport;
282: }
283:
284: private void processOperation(JavaModel model,
285: BindingOperationInfo bop, BindingInfo binding)
286: throws ToolException {
287: boolean enableOpMime = false;
288: JAXWSBinding bind = binding.getExtensor(JAXWSBinding.class);
289:
290: if (bind != null && bind.isEnableMime()) {
291: enableOpMime = true;
292: }
293:
294: JAXWSBinding bopBinding = bop.getExtensor(JAXWSBinding.class);
295:
296: if (bopBinding != null && bopBinding.isEnableMime()) {
297: enableOpMime = true;
298: if (bopBinding.getJaxwsPara() != null) {
299: jaxwsBinding.setJaxwsPara(bopBinding.getJaxwsPara());
300: }
301: }
302: JavaInterface jf = null;
303: for (JavaInterface jf2 : model.getInterfaces().values()) {
304: if (binding.getInterface().getName().getLocalPart().equals(
305: jf2.getWebServiceName())) {
306: jf = jf2;
307: }
308: }
309: if (isSoapBinding()) {
310: SoapBinding soapBinding = (SoapBinding) bindingObj;
311: if (SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()) == null) {
312: jf
313: .setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
314: } else {
315: jf.setSOAPStyle(SOAPBindingUtil
316: .getSoapStyle(soapBinding.getStyle()));
317: }
318: } else {
319: // REVISIT: fix for xml binding
320: jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
321: }
322:
323: Object[] methods = jf.getMethods().toArray();
324: for (int i = 0; i < methods.length; i++) {
325: JavaMethod jm = (JavaMethod) methods[i];
326: if (jm.getOperationName() != null
327: && jm.getOperationName().equals(
328: bop.getName().getLocalPart())) {
329: if (isSoapBinding()) {
330: // TODO: add customize here
331: //doCustomizeOperation(jf, jm, bop);
332: Map prop = getSoapOperationProp(bop);
333: String soapAction = prop.get(soapOPAction) == null ? ""
334: : (String) prop.get(soapOPAction);
335: String soapStyle = prop.get(soapOPStyle) == null ? ""
336: : (String) prop.get(soapOPStyle);
337: jm.setSoapAction(soapAction);
338: if (SOAPBindingUtil.getSoapStyle(soapStyle) == null
339: && this .bindingObj == null) {
340: org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
341: "BINDING_STYLE_NOT_DEFINED", LOG);
342: throw new ToolException(msg);
343: }
344: if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
345: jm.setSoapStyle(jf.getSOAPStyle());
346: } else {
347: jm.setSoapStyle(SOAPBindingUtil
348: .getSoapStyle(soapStyle));
349: }
350: } else {
351: // REVISIT: fix for xml binding
352: jm.setSoapStyle(jf.getSOAPStyle());
353: }
354:
355: if (jm.getSoapStyle().equals(
356: javax.jws.soap.SOAPBinding.Style.RPC)) {
357: jm.getAnnotationMap().remove("SOAPBinding");
358: }
359:
360: OperationProcessor processor = new OperationProcessor(
361: context);
362:
363: int headerType = isNonWrappable(bop);
364:
365: OperationInfo opinfo = bop.getOperationInfo();
366:
367: JAXWSBinding opBinding = (JAXWSBinding) opinfo
368: .getExtensor(JAXWSBinding.class);
369:
370: if (opBinding != null) {
371: if (opBinding.isEnableWrapperStyle()) {
372: jaxwsBinding.setEnableWrapperStyle(true);
373: } else {
374: jaxwsBinding.setEnableWrapperStyle(false);
375: if (!opBinding.isEnableAsyncMapping()) {
376: jaxwsBinding.setEnableAsyncMapping(false);
377: }
378: }
379:
380: if (opBinding.isEnableMime()) {
381: enableOpMime = true;
382: }
383: }
384: if (jaxwsBinding.isEnableMime() || enableOpMime) {
385: jm.setMimeEnable(true);
386: }
387:
388: if (jm.isWrapperStyle() && headerType > this .noHEADER
389: || !jaxwsBinding.isEnableWrapperStyle()
390: || jm.enableMime() && jm.isWrapperStyle()) {
391: // changed wrapper style
392:
393: jm.setWrapperStyle(false);
394: processor.processMethod(jm, bop.getOperationInfo(),
395: jaxwsBinding);
396: jm.getAnnotationMap().remove("ResponseWrapper");
397: jm.getAnnotationMap().remove("RequestWrapper");
398:
399: } else {
400: processor.processMethod(jm, bop.getOperationInfo(),
401: jaxwsBinding);
402:
403: }
404:
405: if (headerType == this .resultHeader) {
406: JavaAnnotation resultAnno = jm.getAnnotationMap()
407: .get("WebResult");
408: if (resultAnno != null) {
409: resultAnno.addArgument("header", "true", "");
410: }
411: }
412: processParameter(jm, bop);
413: }
414: }
415: }
416:
417: private void setParameterAsHeader(JavaParameter parameter) {
418: parameter.setHeader(true);
419: parameter.getAnnotation().addArgument("header", "true", "");
420: parameter.getAnnotation().addArgument("name",
421: parameter.getQName().getLocalPart());
422: parameter.getAnnotation().addArgument("targetNamespace",
423: parameter.getTargetNamespace());
424: }
425:
426: private void processParameter(JavaMethod jm,
427: BindingOperationInfo operation) throws ToolException {
428:
429: // process input
430:
431: List<ExtensibilityElement> inbindings = null;
432: if (operation.getInput() != null) {
433: inbindings = operation.getInput().getExtensors(
434: ExtensibilityElement.class);
435: if (inbindings == null) {
436: inbindings = new ArrayList<ExtensibilityElement>();
437: }
438: }
439: String use = null;
440: for (ExtensibilityElement ext : inbindings) {
441: if (SOAPBindingUtil.isSOAPBody(ext)) {
442: SoapBody soapBody = SOAPBindingUtil.getSoapBody(ext);
443: use = soapBody.getUse();
444: } else if (SOAPBindingUtil.isSOAPHeader(ext)) {
445: processSoapHeader(jm, operation, ext);
446: }
447: if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
448: processMultipart(jm, operation,
449: (MIMEMultipartRelated) ext, JavaType.Style.IN);
450: }
451: }
452:
453: // process output
454: if (operation.getOutput() != null) {
455: List<ExtensibilityElement> outbindings = operation
456: .getOutput().getExtensors(
457: ExtensibilityElement.class);
458: if (outbindings == null) {
459: outbindings = new ArrayList<ExtensibilityElement>();
460: }
461: for (ExtensibilityElement ext : outbindings) {
462: if (SOAPBindingUtil.isSOAPHeader(ext)) {
463: SoapHeader soapHeader = SOAPBindingUtil
464: .getSoapHeader(ext);
465: boolean found = false;
466: for (JavaParameter parameter : jm.getParameters()) {
467: if (soapHeader.getPart().equals(
468: parameter.getPartName())) {
469: setParameterAsHeader(parameter);
470: found = true;
471: }
472: }
473: if (jm.getReturn().getName().equals(
474: soapHeader.getPart())) {
475: found = true;
476: }
477: if (Boolean.valueOf((String) context
478: .get(ToolConstants.CFG_EXTRA_SOAPHEADER))
479: && !found) {
480: // Header can't be found in java method parameters, in
481: // different message
482: // other than messages used in porttype operation
483: ParameterProcessor processor = new ParameterProcessor(
484: context);
485: MessagePartInfo exPart = service.getMessage(
486: soapHeader.getMessage())
487: .getMessagePart(
488: new QName(soapHeader
489: .getMessage()
490: .getNamespaceURI(),
491: soapHeader.getPart()));
492: JavaParameter jp = processor
493: .addParameterFromBinding(jm, exPart,
494: JavaType.Style.OUT);
495: setParameterAsHeader(jp);
496: }
497: }
498: if (ext instanceof MIMEMultipartRelated
499: && jm.enableMime()) {
500: processMultipart(jm, operation,
501: (MIMEMultipartRelated) ext,
502: JavaType.Style.OUT);
503: }
504: }
505: }
506:
507: jm.setSoapUse(SOAPBindingUtil.getSoapUse(use));
508: if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle()
509: && javax.jws.soap.SOAPBinding.Use.ENCODED == jm
510: .getSoapUse()) {
511: System.err
512: .println("** Unsupported RPC-Encoded Style Use **");
513: }
514: if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle()
515: && javax.jws.soap.SOAPBinding.Use.LITERAL == jm
516: .getSoapUse()) {
517: return;
518: }
519: if (javax.jws.soap.SOAPBinding.Style.DOCUMENT == jm
520: .getSoapStyle()
521: && javax.jws.soap.SOAPBinding.Use.LITERAL == jm
522: .getSoapUse()) {
523: return;
524: }
525: }
526:
527: private void processSoapHeader(JavaMethod jm,
528: BindingOperationInfo operation, ExtensibilityElement ext) {
529: SoapHeader soapHeader = SOAPBindingUtil.getSoapHeader(ext);
530: for (JavaParameter parameter : jm.getParameters()) {
531: if (soapHeader.getPart().equals(parameter.getPartName())) {
532: setParameterAsHeader(parameter);
533: break;
534: }
535: }
536: }
537:
538: private static String getJavaTypeForMimeType(MIMEPart mPart) {
539: if (mPart.getExtensibilityElements().size() > 1) {
540: return "javax.activation.DataHandler";
541: } else {
542: ExtensibilityElement extElement = (ExtensibilityElement) mPart
543: .getExtensibilityElements().get(0);
544: if (extElement instanceof MIMEContent) {
545: MIMEContent mimeContent = (MIMEContent) extElement;
546: if ("image/jpeg".equals(mimeContent.getType())
547: || "image/gif".equals(mimeContent.getType())) {
548: return "java.awt.Image";
549: } else if ("text/xml".equals(mimeContent.getType())
550: || "application/xml".equals(mimeContent
551: .getType())) {
552: return "javax.xml.transform.Source";
553: } else {
554: return "javax.activation.DataHandler";
555: }
556: }
557: }
558: return "javax.activation.DataHandler";
559: }
560:
561: public void processMultipart(JavaMethod jm,
562: BindingOperationInfo operation, MIMEMultipartRelated ext,
563: JavaType.Style style) throws ToolException {
564: List mimeParts = ext.getMIMEParts();
565: Iterator itParts = mimeParts.iterator();
566: while (itParts.hasNext()) {
567: MIMEPart mPart = (MIMEPart) itParts.next();
568: Iterator extns = mPart.getExtensibilityElements()
569: .iterator();
570: while (extns.hasNext()) {
571: ExtensibilityElement extElement = (ExtensibilityElement) extns
572: .next();
573: if (extElement instanceof MIMEContent) {
574: MIMEContent mimeContent = (MIMEContent) extElement;
575: String mimeJavaType = getJavaTypeForMimeType(mPart);
576: if (JavaType.Style.IN.equals(style)) {
577: String paramName = ProcessorUtil
578: .mangleNameToVariableName(mimeContent
579: .getPart());
580: JavaParameter jp = jm.getParameter(paramName);
581: if (jp == null) {
582: Message message = new Message(
583: "MIMEPART_CANNOT_MAP", LOG,
584: mimeContent.getPart());
585: throw new ToolException(message);
586: }
587: if (!jp.getClassName().equals(mimeJavaType)) {
588: // jp.setType(mimeJavaType);
589: jp.setClassName(mimeJavaType);
590: }
591: } else if (JavaType.Style.OUT.equals(style)) {
592: JavaType jp = null;
593: if (!"void".equals(jm.getReturn().getType())
594: && mimeContent.getPart().equals(
595: jm.getReturn().getName())) {
596: jp = jm.getReturn();
597: jp.setClassName(mimeJavaType);
598: }
599:
600: if (jp == null) {
601: for (JavaParameter para : jm
602: .getParameters()) {
603: if (mimeContent.getPart().equals(
604: para.getPartName())) {
605: jp = para;
606: }
607: }
608: if (jp != null) {
609: ((JavaParameter) jp)
610: .setClassName(mimeJavaType);
611: }
612:
613: }
614:
615: if (jp == null) {
616: Message message = new Message(
617: "MIMEPART_CANNOT_MAP", LOG,
618: mimeContent.getPart());
619: throw new ToolException(message);
620: }
621: }
622: } else if (extElement instanceof SOAPHeader) {
623: processSoapHeader(jm, operation, extElement);
624: }
625: }
626: }
627: }
628:
629: private Map getSoapOperationProp(BindingOperationInfo bop) {
630: Map<String, Object> soapOPProp = new HashMap<String, Object>();
631: if (bop.getExtensor(ExtensibilityElement.class) != null) {
632: for (ExtensibilityElement ext : bop
633: .getExtensors(ExtensibilityElement.class)) {
634: if (SOAPBindingUtil.isSOAPOperation(ext)) {
635: SoapOperation soapOP = SOAPBindingUtil
636: .getSoapOperation(ext);
637: soapOPProp.put(this .soapOPAction, soapOP
638: .getSoapActionURI());
639: soapOPProp.put(this .soapOPStyle, soapOP.getStyle());
640: }
641: }
642: } else {
643: for (ExtensibilityElement ext : bop.getBinding()
644: .getExtensors(ExtensibilityElement.class)) {
645: if (SOAPBindingUtil.isSOAPOperation(ext)) {
646: SoapOperation soapOP = SOAPBindingUtil
647: .getSoapOperation(ext);
648: soapOPProp.put(this .soapOPAction, soapOP
649: .getSoapActionURI());
650: soapOPProp.put(this .soapOPStyle, soapOP.getStyle());
651: }
652: }
653:
654: }
655: return soapOPProp;
656: }
657:
658: private BindingType getBindingType(BindingInfo binding) {
659: for (ExtensibilityElement ext : binding
660: .getExtensors(ExtensibilityElement.class)) {
661: if (SOAPBindingUtil.isSOAPBinding(ext)) {
662: bindingObj = SOAPBindingUtil.getSoapBinding(ext);
663: return BindingType.SOAPBinding;
664: }
665: if (ext instanceof HTTPBinding) {
666: bindingObj = (HTTPBinding) ext;
667: return BindingType.HTTPBinding;
668: }
669: // TBD XMLBinding
670: return BindingType.XMLBinding;
671:
672: }
673: return null;
674: }
675:
676: private int isNonWrappable(BindingOperationInfo bop) {
677: QName operationName = bop.getName();
678: MessageInfo bodyMessage = null;
679: QName headerMessage = null;
680: SoapHeader header = null;
681: boolean containParts = false;
682: boolean isSameMessage = false;
683: boolean isNonWrappable = false;
684: boolean allPartsHeader = false;
685: int result = this .noHEADER;
686:
687: // begin process input
688: if (bop.getInput() != null
689: && bop.getInput().getExtensors(
690: ExtensibilityElement.class) != null) {
691: List<ExtensibilityElement> extensors = bop.getInput()
692: .getExtensors(ExtensibilityElement.class);
693: if (extensors != null) {
694: for (ExtensibilityElement ext : extensors) {
695: if (SOAPBindingUtil.isSOAPBody(ext)) {
696: bodyMessage = getMessage(operationName, true);
697: }
698: if (SOAPBindingUtil.isSOAPHeader(ext)) {
699: header = SOAPBindingUtil.getSoapHeader(ext);
700: headerMessage = header.getMessage();
701: if (header.getPart().length() > 0) {
702: containParts = true;
703: }
704: }
705: }
706: }
707:
708: if (headerMessage != null
709: && bodyMessage != null
710: && headerMessage.getNamespaceURI()
711: .equalsIgnoreCase(
712: bodyMessage.getName()
713: .getNamespaceURI())
714: && headerMessage.getLocalPart().equalsIgnoreCase(
715: bodyMessage.getName().getLocalPart())) {
716: isSameMessage = true;
717: }
718:
719: isNonWrappable = isSameMessage && containParts;
720: // if is nonwrapple then return
721: if (isNonWrappable) {
722: result = this .inHEADER;
723: }
724: }
725: isSameMessage = false;
726: containParts = false;
727:
728: // process output
729: if (bop.getOutput() != null
730: && bop.getOutput().getExtensors(
731: ExtensibilityElement.class) != null) {
732: List<ExtensibilityElement> extensors = bop.getOutput()
733: .getExtensors(ExtensibilityElement.class);
734: if (extensors != null) {
735: for (ExtensibilityElement ext : extensors) {
736: if (SOAPBindingUtil.isSOAPBody(ext)) {
737: bodyMessage = getMessage(operationName, false);
738: }
739: if (SOAPBindingUtil.isSOAPHeader(ext)) {
740: header = SOAPBindingUtil.getSoapHeader(ext);
741: headerMessage = header.getMessage();
742: if (header.getPart().length() > 0) {
743: containParts = true;
744: }
745: }
746: }
747: }
748: if (headerMessage != null
749: && bodyMessage != null
750: && headerMessage.getNamespaceURI()
751: .equalsIgnoreCase(
752: bodyMessage.getName()
753: .getNamespaceURI())
754: && headerMessage.getLocalPart().equalsIgnoreCase(
755: bodyMessage.getName().getLocalPart())) {
756: isSameMessage = true;
757: if (bodyMessage.getMessageParts().size() == 1) {
758: allPartsHeader = true;
759: }
760:
761: }
762: isNonWrappable = isSameMessage && containParts;
763: if (isNonWrappable && allPartsHeader) {
764: result = this .resultHeader;
765: }
766: if (isNonWrappable && !allPartsHeader) {
767: result = this .outHEADER;
768: }
769: }
770:
771: return result;
772: }
773:
774: private MessageInfo getMessage(QName operationName, boolean isIn) {
775: for (OperationInfo operation : service.getInterface()
776: .getOperations()) {
777: if (operationName.equals(operation.getName()) && isIn) {
778: return operation.getInput();
779: } else {
780: return operation.getOutput();
781: }
782: }
783: return null;
784: }
785:
786: public enum BindingType {
787: HTTPBinding, SOAPBinding, XMLBinding
788: }
789:
790: private boolean isSoapBinding() {
791: return bindingType != null
792: && "SOAPBinding".equals(bindingType.name());
793:
794: }
795: }
|