Source Code Cross Referenced for WSDLModeler.java in  » 6.0-JDK-Modules-com.sun » tools » com » sun » tools » internal » ws » processor » modeler » wsdl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » tools » com.sun.tools.internal.ws.processor.modeler.wsdl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Portions Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
0003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004:         *
0005:         * This code is free software; you can redistribute it and/or modify it
0006:         * under the terms of the GNU General Public License version 2 only, as
0007:         * published by the Free Software Foundation.  Sun designates this
0008:         * particular file as subject to the "Classpath" exception as provided
0009:         * by Sun in the LICENSE file that accompanied this code.
0010:         *
0011:         * This code is distributed in the hope that it will be useful, but WITHOUT
0012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0014:         * version 2 for more details (a copy is included in the LICENSE file that
0015:         * accompanied this code).
0016:         *
0017:         * You should have received a copy of the GNU General Public License version
0018:         * 2 along with this work; if not, write to the Free Software Foundation,
0019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020:         *
0021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022:         * CA 95054 USA or visit www.sun.com if you need additional information or
0023:         * have any questions.
0024:         */
0025:        package com.sun.tools.internal.ws.processor.modeler.wsdl;
0026:
0027:        import com.sun.codemodel.internal.JCodeModel;
0028:        import com.sun.codemodel.internal.JType;
0029:        import com.sun.tools.internal.ws.processor.ProcessorOptions;
0030:        import com.sun.tools.internal.ws.processor.config.WSDLModelInfo;
0031:        import com.sun.tools.internal.ws.processor.generator.GeneratorConstants;
0032:        import com.sun.tools.internal.ws.processor.model.AsyncOperation;
0033:        import com.sun.tools.internal.ws.processor.model.AsyncOperationType;
0034:        import com.sun.tools.internal.ws.processor.model.Block;
0035:        import com.sun.tools.internal.ws.processor.model.Fault;
0036:        import com.sun.tools.internal.ws.processor.model.Model;
0037:        import com.sun.tools.internal.ws.processor.model.ModelException;
0038:        import com.sun.tools.internal.ws.processor.model.ModelObject;
0039:        import com.sun.tools.internal.ws.processor.model.ModelProperties;
0040:        import com.sun.tools.internal.ws.processor.model.Operation;
0041:        import com.sun.tools.internal.ws.processor.model.Parameter;
0042:        import com.sun.tools.internal.ws.processor.model.Port;
0043:        import com.sun.tools.internal.ws.processor.model.Request;
0044:        import com.sun.tools.internal.ws.processor.model.Response;
0045:        import com.sun.tools.internal.ws.processor.model.Service;
0046:        import com.sun.tools.internal.ws.processor.model.java.JavaException;
0047:        import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
0048:        import com.sun.tools.internal.ws.processor.model.java.JavaMethod;
0049:        import com.sun.tools.internal.ws.processor.model.java.JavaParameter;
0050:        import com.sun.tools.internal.ws.processor.model.java.JavaSimpleType;
0051:        import com.sun.tools.internal.ws.processor.model.java.JavaStructureMember;
0052:        import com.sun.tools.internal.ws.processor.model.java.JavaType;
0053:        import com.sun.tools.internal.ws.processor.model.jaxb.JAXBElementMember;
0054:        import com.sun.tools.internal.ws.processor.model.jaxb.JAXBProperty;
0055:        import com.sun.tools.internal.ws.processor.model.jaxb.JAXBStructuredType;
0056:        import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType;
0057:        import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
0058:        import com.sun.tools.internal.ws.processor.model.jaxb.RpcLitMember;
0059:        import com.sun.tools.internal.ws.processor.model.jaxb.RpcLitStructure;
0060:        import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
0061:        import com.sun.tools.internal.ws.processor.modeler.ModelerException;
0062:        import com.sun.tools.internal.ws.processor.modeler.ModelerUtils;
0063:        import com.sun.tools.internal.ws.processor.util.ClassNameCollector;
0064:        import com.sun.tools.internal.ws.processor.util.ProcessorEnvironment;
0065:        import com.sun.tools.internal.ws.wsdl.document.Binding;
0066:        import com.sun.tools.internal.ws.wsdl.document.BindingFault;
0067:        import com.sun.tools.internal.ws.wsdl.document.BindingOperation;
0068:        import com.sun.tools.internal.ws.wsdl.document.Documentation;
0069:        import com.sun.tools.internal.ws.wsdl.document.Kinds;
0070:        import com.sun.tools.internal.ws.wsdl.document.Message;
0071:        import com.sun.tools.internal.ws.wsdl.document.MessagePart;
0072:        import com.sun.tools.internal.ws.wsdl.document.OperationStyle;
0073:        import com.sun.tools.internal.ws.wsdl.document.PortType;
0074:        import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
0075:        import com.sun.tools.internal.ws.wsdl.document.WSDLDocument;
0076:        import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName;
0077:        import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
0078:        import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
0079:        import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
0080:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Binding;
0081:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Constants;
0082:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPAddress;
0083:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
0084:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBody;
0085:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPConstants;
0086:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPFault;
0087:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPHeader;
0088:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPOperation;
0089:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
0090:        import com.sun.tools.internal.ws.wsdl.document.soap.SOAPUse;
0091:        import com.sun.tools.internal.ws.wsdl.framework.Entity;
0092:        import com.sun.tools.internal.ws.wsdl.framework.Extensible;
0093:        import com.sun.tools.internal.ws.wsdl.framework.NoSuchEntityException;
0094:        import com.sun.tools.internal.ws.wsdl.framework.ParseException;
0095:        import com.sun.tools.internal.ws.wsdl.framework.ParserListener;
0096:        import com.sun.tools.internal.ws.wsdl.framework.ValidationException;
0097:        import com.sun.tools.internal.ws.wsdl.parser.SOAPEntityReferenceValidator;
0098:        import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
0099:        import com.sun.tools.internal.xjc.api.S2JJAXBModel;
0100:        import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
0101:        import com.sun.tools.internal.xjc.api.XJC;
0102:        import com.sun.xml.internal.bind.api.JAXBRIContext;
0103:        import com.sun.xml.internal.ws.model.Mode;
0104:        import com.sun.xml.internal.ws.util.xml.XmlUtil;
0105:        import org.xml.sax.InputSource;
0106:
0107:        import javax.xml.namespace.QName;
0108:        import java.util.ArrayList;
0109:        import java.util.HashMap;
0110:        import java.util.HashSet;
0111:        import java.util.Iterator;
0112:        import java.util.List;
0113:        import java.util.Map;
0114:        import java.util.Properties;
0115:        import java.util.Set;
0116:        import java.util.StringTokenizer;
0117:
0118:        /**
0119:         * The WSDLModeler processes a WSDL to create a Model.
0120:         *
0121:         * @author WS Development Team
0122:         */
0123:        public class WSDLModeler extends WSDLModelerBase {
0124:
0125:            //map of wsdl:operation QName to <soapenv:Body> child, as per BP it must be unique in a port
0126:            private final Map<QName, QName> uniqueBodyBlocks = new HashMap<QName, QName>();
0127:            private final QName VOID_BODYBLOCK = new QName("");
0128:            private ClassNameCollector classNameCollector;
0129:            private boolean extensions = false;
0130:
0131:            protected enum StyleAndUse {
0132:                RPC_LITERAL, DOC_LITERAL
0133:            };
0134:
0135:            private ModelerUtils modelerUtils;
0136:            private JAXBModelBuilder jaxbModelBuilder;
0137:
0138:            /**
0139:             * @param modelInfo
0140:             * @param options
0141:             */
0142:            public WSDLModeler(WSDLModelInfo modelInfo, Properties options) {
0143:                super (modelInfo, options);
0144:                classNameCollector = new ClassNameCollector();
0145:            }
0146:
0147:            public Model buildModel() {
0148:                try {
0149:
0150:                    parser = new WSDLParser(_modelInfo);
0151:                    parser.addParserListener(new ParserListener() {
0152:                        public void ignoringExtension(QName name, QName parent) {
0153:                            if (parent.equals(WSDLConstants.QNAME_TYPES)) {
0154:                                // check for a schema element with the wrong namespace URI
0155:                                if (name.getLocalPart().equals("schema")
0156:                                        && !name.getNamespaceURI().equals("")) {
0157:                                    warn(
0158:                                            "wsdlmodeler.warning.ignoringUnrecognizedSchemaExtension",
0159:                                            name.getNamespaceURI());
0160:                                }
0161:                            }
0162:                        }
0163:
0164:                        public void doneParsingEntity(QName element,
0165:                                Entity entity) {
0166:                        }
0167:                    });
0168:                    hSet = parser.getUse();
0169:
0170:                    extensions = Boolean.valueOf(_options
0171:                            .getProperty(ProcessorOptions.EXTENSION));
0172:
0173:                    useWSIBasicProfile = !extensions;
0174:                    document = parser.parse();
0175:                    document.validateLocally();
0176:
0177:                    boolean validateWSDL = Boolean
0178:                            .valueOf(
0179:                                    _options
0180:                                            .getProperty(ProcessorOptions.VALIDATE_WSDL_PROPERTY))
0181:                            .booleanValue();
0182:                    if (validateWSDL) {
0183:                        document.validate(new SOAPEntityReferenceValidator());
0184:                    }
0185:
0186:                    Model model = internalBuildModel(document);
0187:                    //ClassNameCollector classNameCollector = new ClassNameCollector();
0188:                    classNameCollector.process(model);
0189:                    if (classNameCollector.getConflictingClassNames().isEmpty()) {
0190:                        return model;
0191:                    }
0192:                    // do another pass, this time with conflict resolution enabled
0193:                    model = internalBuildModel(document);
0194:                    classNameCollector.process(model);
0195:                    if (classNameCollector.getConflictingClassNames().isEmpty()) {
0196:                        // we're done
0197:                        return model;
0198:                    }
0199:                    // give up
0200:                    StringBuffer conflictList = new StringBuffer();
0201:                    boolean first = true;
0202:                    for (Iterator iter = classNameCollector
0203:                            .getConflictingClassNames().iterator(); iter
0204:                            .hasNext();) {
0205:                        if (!first) {
0206:                            conflictList.append(", ");
0207:                        } else {
0208:                            first = false;
0209:                        }
0210:                        conflictList.append((String) iter.next());
0211:                    }
0212:                    throw new ModelerException(
0213:                            "wsdlmodeler.unsolvableNamingConflicts",
0214:                            conflictList.toString());
0215:
0216:                } catch (ModelException e) {
0217:                    throw new ModelerException((Exception) e);
0218:                } catch (ParseException e) {
0219:                    throw new ModelerException((Exception) e);
0220:                } catch (ValidationException e) {
0221:                    throw new ModelerException((Exception) e);
0222:                }
0223:            }
0224:
0225:            private Model internalBuildModel(WSDLDocument document) {
0226:
0227:                //build the jaxbModel to be used latter
0228:                buildJAXBModel(document, _modelInfo, classNameCollector);
0229:
0230:                QName modelName = new QName(document.getDefinitions()
0231:                        .getTargetNamespaceURI(), document.getDefinitions()
0232:                        .getName() == null ? "model" : document
0233:                        .getDefinitions().getName());
0234:                Model model = new Model(modelName);
0235:                model.setJAXBModel(getJAXBModelBuilder().getJAXBModel());
0236:
0237:                // This fails with the changed classname (WSDLModeler to WSDLModeler11 etc.)
0238:                // with this source comaptibility change the WSDL Modeler class name is changed. Right now hardcoding the
0239:                // modeler class name to the same one being checked in WSDLGenerator.
0240:
0241:                model.setProperty(ModelProperties.PROPERTY_MODELER_NAME,
0242:                        ModelProperties.WSDL_MODELER_NAME);
0243:
0244:                _javaTypes = new JavaSimpleTypeCreator();
0245:                _javaExceptions = new HashMap();
0246:                _bindingNameToPortMap = new HashMap();
0247:
0248:                // grab target namespace
0249:                model.setTargetNamespaceURI(document.getDefinitions()
0250:                        .getTargetNamespaceURI());
0251:
0252:                setDocumentationIfPresent(model, document.getDefinitions()
0253:                        .getDocumentation());
0254:
0255:                boolean hasServices = document.getDefinitions().services()
0256:                        .hasNext();
0257:                if (hasServices) {
0258:                    for (Iterator iter = document.getDefinitions().services(); iter
0259:                            .hasNext();) {
0260:                        processService(
0261:                                (com.sun.tools.internal.ws.wsdl.document.Service) iter
0262:                                        .next(), model, document);
0263:                        hasServices = true;
0264:                    }
0265:                } else {
0266:                    // emit a warning if there are no service definitions
0267:                    warn("wsdlmodeler.warning.noServiceDefinitionsFound");
0268:                }
0269:
0270:                return model;
0271:            }
0272:
0273:            /* (non-Javadoc)
0274:             * @see WSDLModelerBase#processService(Service, Model, WSDLDocument)
0275:             */
0276:            protected void processService(
0277:                    com.sun.tools.internal.ws.wsdl.document.Service wsdlService,
0278:                    Model model, WSDLDocument document) {
0279:                String serviceInterface = "";
0280:                QName serviceQName = getQNameOf(wsdlService);
0281:                serviceInterface = getServiceInterfaceName(serviceQName,
0282:                        wsdlService);
0283:                if (isConflictingServiceClassName(serviceInterface)) {
0284:                    serviceInterface += "_Service";
0285:                }
0286:                Service service = new Service(serviceQName, new JavaInterface(
0287:                        serviceInterface, serviceInterface + "Impl"));
0288:
0289:                setDocumentationIfPresent(service, wsdlService
0290:                        .getDocumentation());
0291:                boolean hasPorts = false;
0292:                for (Iterator iter = wsdlService.ports(); iter.hasNext();) {
0293:                    boolean processed = processPort(
0294:                            (com.sun.tools.internal.ws.wsdl.document.Port) iter
0295:                                    .next(), service, document);
0296:                    hasPorts = hasPorts || processed;
0297:                }
0298:                if (!hasPorts) {
0299:                    // emit a warning if there are no ports
0300:                    warn("wsdlmodeler.warning.noPortsInService", wsdlService
0301:                            .getName());
0302:                } else {
0303:                    model.addService(service);
0304:                }
0305:            }
0306:
0307:            /* (non-Javadoc)
0308:             * @see WSDLModelerBase#processPort(Port, Service, WSDLDocument)
0309:             */
0310:            protected boolean processPort(
0311:                    com.sun.tools.internal.ws.wsdl.document.Port wsdlPort,
0312:                    Service service, WSDLDocument document) {
0313:                try {
0314:
0315:                    //clear the  unique block map
0316:                    uniqueBodyBlocks.clear();
0317:
0318:                    QName portQName = getQNameOf(wsdlPort);
0319:                    Port port = new Port(portQName);
0320:
0321:                    setDocumentationIfPresent(port, wsdlPort.getDocumentation());
0322:
0323:                    SOAPAddress soapAddress = (SOAPAddress) getExtensionOfType(
0324:                            wsdlPort, SOAPAddress.class);
0325:                    if (soapAddress == null) {
0326:                        // not a SOAP port, ignore it
0327:                        warn(
0328:                                "wsdlmodeler.warning.ignoringNonSOAPPort.noAddress",
0329:                                wsdlPort.getName());
0330:                        return false;
0331:                    }
0332:
0333:                    port.setAddress(soapAddress.getLocation());
0334:                    Binding binding = wsdlPort.resolveBinding(document);
0335:                    QName bindingName = getQNameOf(binding);
0336:                    PortType portType = binding.resolvePortType(document);
0337:
0338:                    port.setProperty(ModelProperties.PROPERTY_WSDL_PORT_NAME,
0339:                            getQNameOf(wsdlPort));
0340:                    port.setProperty(
0341:                            ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME,
0342:                            getQNameOf(portType));
0343:                    port.setProperty(
0344:                            ModelProperties.PROPERTY_WSDL_BINDING_NAME,
0345:                            bindingName);
0346:
0347:                    boolean isProvider = isProvider(wsdlPort);
0348:                    if (_bindingNameToPortMap.containsKey(bindingName)
0349:                            && !isProvider) {
0350:                        // this binding has been processed before
0351:                        Port existingPort = _bindingNameToPortMap
0352:                                .get(bindingName);
0353:                        port.setOperations(existingPort.getOperations());
0354:                        port.setJavaInterface(existingPort.getJavaInterface());
0355:                        port.setStyle(existingPort.getStyle());
0356:                        port.setWrapped(existingPort.isWrapped());
0357:                    } else {
0358:                        // find out the SOAP binding extension, if any
0359:                        SOAPBinding soapBinding = (SOAPBinding) getExtensionOfType(
0360:                                binding, SOAPBinding.class);
0361:
0362:                        if (soapBinding == null) {
0363:                            soapBinding = (SOAPBinding) getExtensionOfType(
0364:                                    binding, SOAP12Binding.class);
0365:                            if (soapBinding == null) {
0366:                                // cannot deal with non-SOAP ports
0367:                                warn("wsdlmodeler.warning.ignoringNonSOAPPort",
0368:                                        wsdlPort.getName());
0369:                                return false;
0370:                            }
0371:                            // we can only do soap1.2 if extensions are on
0372:                            if (extensions) {
0373:                                warn("wsdlmodeler.warning.port.SOAPBinding12",
0374:                                        wsdlPort.getName());
0375:                            } else {
0376:                                warn(
0377:                                        "wsdlmodeler.warning.ignoringSOAPBinding12",
0378:                                        wsdlPort.getName());
0379:                                return false;
0380:                            }
0381:                        }
0382:
0383:                        if (soapBinding.getTransport() == null
0384:                                || (!soapBinding.getTransport().equals(
0385:                                        SOAPConstants.URI_SOAP_TRANSPORT_HTTP) && !soapBinding
0386:                                        .getTransport()
0387:                                        .equals(
0388:                                                SOAP12Constants.URI_SOAP_TRANSPORT_HTTP))) {
0389:                            // cannot deal with non-HTTP ports
0390:                            warn(
0391:                                    "wsdlmodeler.warning.ignoringSOAPBinding.nonHTTPTransport",
0392:                                    wsdlPort.getName());
0393:                            return false;
0394:                        }
0395:
0396:                        /**
0397:                         * validate wsdl:binding uniqueness in style, e.g. rpclit or doclit
0398:                         * ref: WSI BP 1.1 R 2705
0399:                         */
0400:                        if (!validateWSDLBindingStyle(binding)) {
0401:                            if (extensions) {
0402:                                warn(
0403:                                        "wsdlmodeler.warning.port.SOAPBinding.mixedStyle",
0404:                                        wsdlPort.getName());
0405:                            } else {
0406:                                fail(
0407:                                        "wsdlmodeler.warning.ignoringSOAPBinding.mixedStyle",
0408:                                        wsdlPort.getName());
0409:                                return false;
0410:                            }
0411:                        }
0412:
0413:                        port.setStyle(soapBinding.getStyle());
0414:                        boolean hasOverloadedOperations = false;
0415:                        Set<String> operationNames = new HashSet<String>();
0416:                        for (Iterator iter = portType.operations(); iter
0417:                                .hasNext();) {
0418:                            com.sun.tools.internal.ws.wsdl.document.Operation operation = (com.sun.tools.internal.ws.wsdl.document.Operation) iter
0419:                                    .next();
0420:
0421:                            if (operationNames.contains(operation.getName())) {
0422:                                hasOverloadedOperations = true;
0423:                                break;
0424:                            }
0425:                            operationNames.add(operation.getName());
0426:
0427:                            for (Iterator itr = binding.operations(); iter
0428:                                    .hasNext();) {
0429:                                BindingOperation bindingOperation = (BindingOperation) itr
0430:                                        .next();
0431:                                if (operation.getName().equals(
0432:                                        bindingOperation.getName())) {
0433:                                    break;
0434:                                } else if (!itr.hasNext()) {
0435:                                    throw new ModelerException(
0436:                                            "wsdlmodeler.invalid.bindingOperation.notFound",
0437:                                            new Object[] { operation.getName(),
0438:                                                    binding.getName() });
0439:                                }
0440:                            }
0441:                        }
0442:
0443:                        Map headers = new HashMap();
0444:                        boolean hasOperations = false;
0445:                        for (Iterator iter = binding.operations(); iter
0446:                                .hasNext();) {
0447:                            BindingOperation bindingOperation = (BindingOperation) iter
0448:                                    .next();
0449:
0450:                            com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation = null;
0451:                            Set operations = portType
0452:                                    .getOperationsNamed(bindingOperation
0453:                                            .getName());
0454:                            if (operations.size() == 0) {
0455:                                // the WSDL document is invalid
0456:                                throw new ModelerException(
0457:                                        "wsdlmodeler.invalid.bindingOperation.notInPortType",
0458:                                        new Object[] {
0459:                                                bindingOperation.getName(),
0460:                                                binding.getName() });
0461:                            } else if (operations.size() == 1) {
0462:                                portTypeOperation = (com.sun.tools.internal.ws.wsdl.document.Operation) operations
0463:                                        .iterator().next();
0464:                            } else {
0465:                                boolean found = false;
0466:                                String expectedInputName = bindingOperation
0467:                                        .getInput().getName();
0468:                                String expectedOutputName = bindingOperation
0469:                                        .getOutput().getName();
0470:
0471:                                for (Iterator iter2 = operations.iterator(); iter2
0472:                                        .hasNext();) {
0473:                                    com.sun.tools.internal.ws.wsdl.document.Operation candidateOperation = (com.sun.tools.internal.ws.wsdl.document.Operation) iter2
0474:                                            .next();
0475:
0476:                                    if (expectedInputName == null) {
0477:                                        // the WSDL document is invalid
0478:                                        throw new ModelerException(
0479:                                                "wsdlmodeler.invalid.bindingOperation.missingInputName",
0480:                                                new Object[] {
0481:                                                        bindingOperation
0482:                                                                .getName(),
0483:                                                        binding.getName() });
0484:                                    }
0485:                                    if (expectedOutputName == null) {
0486:                                        // the WSDL document is invalid
0487:                                        throw new ModelerException(
0488:                                                "wsdlmodeler.invalid.bindingOperation.missingOutputName",
0489:                                                new Object[] {
0490:                                                        bindingOperation
0491:                                                                .getName(),
0492:                                                        binding.getName() });
0493:                                    }
0494:                                    if (expectedInputName
0495:                                            .equals(candidateOperation
0496:                                                    .getInput().getName())
0497:                                            && expectedOutputName
0498:                                                    .equals(candidateOperation
0499:                                                            .getOutput()
0500:                                                            .getName())) {
0501:                                        if (found) {
0502:                                            // the WSDL document is invalid
0503:                                            throw new ModelerException(
0504:                                                    "wsdlmodeler.invalid.bindingOperation.multipleMatchingOperations",
0505:                                                    new Object[] {
0506:                                                            bindingOperation
0507:                                                                    .getName(),
0508:                                                            binding.getName() });
0509:                                        }
0510:                                        // got it!
0511:                                        found = true;
0512:                                        portTypeOperation = candidateOperation;
0513:                                    }
0514:                                }
0515:                                if (!found) {
0516:                                    // the WSDL document is invalid
0517:                                    throw new ModelerException(
0518:                                            "wsdlmodeler.invalid.bindingOperation.notFound",
0519:                                            new Object[] {
0520:                                                    bindingOperation.getName(),
0521:                                                    binding.getName() });
0522:                                }
0523:                            }
0524:                            if (!isProvider) {
0525:                                this .info = new ProcessSOAPOperationInfo(port,
0526:                                        wsdlPort, portTypeOperation,
0527:                                        bindingOperation, soapBinding,
0528:                                        document, hasOverloadedOperations,
0529:                                        headers);
0530:
0531:                                Operation operation = processSOAPOperation();
0532:                                if (operation != null) {
0533:                                    port.addOperation(operation);
0534:                                    hasOperations = true;
0535:                                }
0536:                            }
0537:                        }
0538:                        if (!isProvider && !hasOperations) {
0539:                            // emit a warning if there are no operations, except when its a provider port
0540:                            warn("wsdlmodeler.warning.noOperationsInPort",
0541:                                    wsdlPort.getName());
0542:                            return false;
0543:                        }
0544:                        createJavaInterfaceForPort(port, isProvider);
0545:                        PortType pt = binding.resolvePortType(document);
0546:                        String jd = (pt.getDocumentation() != null) ? pt
0547:                                .getDocumentation().getContent() : null;
0548:                        port.getJavaInterface().setJavaDoc(jd);
0549:                        _bindingNameToPortMap.put(bindingName, port);
0550:                    }
0551:
0552:                    // now deal with the configured handlers
0553:                    port.setClientHandlerChainInfo(_modelInfo
0554:                            .getClientHandlerChainInfo());
0555:                    port.setServerHandlerChainInfo(_modelInfo
0556:                            .getServerHandlerChainInfo());
0557:
0558:                    service.addPort(port);
0559:                    applyPortMethodCustomization(port, wsdlPort);
0560:                    applyWrapperStyleCustomization(port, binding
0561:                            .resolvePortType(document));
0562:
0563:                    return true;
0564:
0565:                } catch (NoSuchEntityException e) {
0566:                    warn(e);
0567:                    // should not happen
0568:                    return false;
0569:                }
0570:            }
0571:
0572:            /* (non-Javadoc)
0573:             * @see WSDLModelerBase#processSOAPOperation()
0574:             */
0575:            protected Operation processSOAPOperation() {
0576:                Operation operation = new Operation(new QName(null,
0577:                        info.bindingOperation.getName()));
0578:
0579:                setDocumentationIfPresent(operation, info.portTypeOperation
0580:                        .getDocumentation());
0581:
0582:                if (info.portTypeOperation.getStyle() != OperationStyle.REQUEST_RESPONSE
0583:                        && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
0584:                    if (extensions) {
0585:                        warn(
0586:                                "wsdlmodeler.warning.ignoringOperation.notSupportedStyle",
0587:                                info.portTypeOperation.getName());
0588:                        return null;
0589:                    }
0590:                    fail("wsdlmodeler.invalid.operation.notSupportedStyle",
0591:                            new Object[] {
0592:                                    info.portTypeOperation.getName(),
0593:                                    info.port.resolveBinding(document)
0594:                                            .resolvePortType(document)
0595:                                            .getName() });
0596:                }
0597:
0598:                SOAPStyle soapStyle = info.soapBinding.getStyle();
0599:
0600:                // find out the SOAP operation extension, if any
0601:                SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
0602:                        info.bindingOperation, SOAPOperation.class);
0603:
0604:                if (soapOperation != null) {
0605:                    if (soapOperation.getStyle() != null) {
0606:                        soapStyle = soapOperation.getStyle();
0607:                    }
0608:                    if (soapOperation.getSOAPAction() != null) {
0609:                        operation.setSOAPAction(soapOperation.getSOAPAction());
0610:                    }
0611:                }
0612:
0613:                operation.setStyle(soapStyle);
0614:
0615:                String uniqueOperationName = getUniqueName(
0616:                        info.portTypeOperation, info.hasOverloadedOperations);
0617:                if (info.hasOverloadedOperations) {
0618:                    operation.setUniqueName(uniqueOperationName);
0619:                }
0620:
0621:                info.operation = operation;
0622:                info.uniqueOperationName = uniqueOperationName;
0623:
0624:                //attachment
0625:                SOAPBody soapRequestBody = getSOAPRequestBody();
0626:                if (soapRequestBody == null) {
0627:                    // the WSDL document is invalid
0628:                    throw new ModelerException(
0629:                            "wsdlmodeler.invalid.bindingOperation.inputMissingSoapBody",
0630:                            new Object[] { info.bindingOperation.getName() });
0631:                }
0632:
0633:                if (soapStyle == SOAPStyle.RPC) {
0634:                    if (soapRequestBody.isEncoded()) {
0635:                        throw new ModelerException(
0636:                                "wsdlmodeler20.rpcenc.not.supported");
0637:                    }
0638:                    return processLiteralSOAPOperation(StyleAndUse.RPC_LITERAL);
0639:                }
0640:                // document style
0641:                return processLiteralSOAPOperation(StyleAndUse.DOC_LITERAL);
0642:            }
0643:
0644:            protected Operation processLiteralSOAPOperation(
0645:                    StyleAndUse styleAndUse) {
0646:                //returns false if the operation name is not acceptable
0647:                if (!applyOperationNameCustomization())
0648:                    return null;
0649:
0650:                boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
0651:                Request request = new Request();
0652:                Response response = new Response();
0653:                info.operation.setUse(SOAPUse.LITERAL);
0654:                SOAPBody soapRequestBody = getSOAPRequestBody();
0655:                if ((StyleAndUse.DOC_LITERAL == styleAndUse)
0656:                        && (soapRequestBody.getNamespace() != null)) {
0657:                    warn("wsdlmodeler.warning.r2716", new Object[] {
0658:                            "soapbind:body", info.bindingOperation.getName() });
0659:                }
0660:
0661:                Message inputMessage = getInputMessage();
0662:
0663:                SOAPBody soapResponseBody = null;
0664:                Message outputMessage = null;
0665:                if (isRequestResponse) {
0666:                    soapResponseBody = getSOAPResponseBody();
0667:                    if (isOperationDocumentLiteral(styleAndUse)
0668:                            && (soapResponseBody.getNamespace() != null)) {
0669:                        warn("wsdlmodeler.warning.r2716", new Object[] {
0670:                                "soapbind:body",
0671:                                info.bindingOperation.getName() });
0672:                    }
0673:                    outputMessage = getOutputMessage();
0674:                }
0675:
0676:                //ignore operation if there are more than one root part
0677:                if (!validateMimeParts(getMimeParts(info.bindingOperation
0678:                        .getInput()))
0679:                        || !validateMimeParts(getMimeParts(info.bindingOperation
0680:                                .getOutput())))
0681:                    return null;
0682:
0683:                if (!validateBodyParts(info.bindingOperation)) {
0684:                    // BP 1.1
0685:                    // R2204   A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s),
0686:                    // only to wsdl:part element(s) that have been defined using the element attribute.
0687:
0688:                    // R2203   An rpc-literal binding in a DESCRIPTION MUST refer, in its soapbind:body element(s),
0689:                    // only to wsdNl:part element(s) that have been defined using the type attribute.
0690:                    if (isOperationDocumentLiteral(styleAndUse))
0691:                        if (extensions)
0692:                            warn(
0693:                                    "wsdlmodeler.warning.ignoringOperation.cannotHandleTypeMessagePart",
0694:                                    info.portTypeOperation.getName());
0695:                        else
0696:                            fail("wsdlmodeler.invalid.doclitoperation",
0697:                                    info.portTypeOperation.getName());
0698:                    else if (isOperationRpcLiteral(styleAndUse)) {
0699:                        if (extensions)
0700:                            warn(
0701:                                    "wsdlmodeler.warning.ignoringOperation.cannotHandleElementMessagePart",
0702:                                    info.portTypeOperation.getName());
0703:                        else
0704:                            fail("wsdlmodeler.invalid.rpclitoperation",
0705:                                    info.portTypeOperation.getName());
0706:                    }
0707:                    return null;
0708:                }
0709:
0710:                // Process parameterOrder and get the parameterList
0711:                List<MessagePart> parameterList = getParameterOrder();
0712:
0713:                //binding is invalid in the wsdl, ignore the operation.
0714:                if (!setMessagePartsBinding(styleAndUse))
0715:                    return null;
0716:
0717:                List<Parameter> params = null;
0718:                boolean unwrappable = isUnwrappable();
0719:                info.operation.setWrapped(unwrappable);
0720:                if (isOperationDocumentLiteral(styleAndUse)) {
0721:                    params = getDoclitParameters(request, response,
0722:                            parameterList);
0723:                } else if (isOperationRpcLiteral(styleAndUse)) {
0724:                    String operationName = info.bindingOperation.getName();
0725:                    Block reqBlock = null;
0726:                    if (inputMessage != null) {
0727:                        QName name = new QName(
0728:                                getRequestNamespaceURI(soapRequestBody),
0729:                                operationName);
0730:                        RpcLitStructure rpcStruct = new RpcLitStructure(name,
0731:                                getJAXBModelBuilder().getJAXBModel());
0732:                        rpcStruct
0733:                                .setJavaType(new JavaSimpleType(
0734:                                        "com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload",
0735:                                        null));
0736:                        reqBlock = new Block(name, rpcStruct);
0737:                        request.addBodyBlock(reqBlock);
0738:                    }
0739:
0740:                    Block resBlock = null;
0741:                    if (isRequestResponse && outputMessage != null) {
0742:                        QName name = new QName(
0743:                                getResponseNamespaceURI(soapResponseBody),
0744:                                operationName + "Response");
0745:                        RpcLitStructure rpcStruct = new RpcLitStructure(name,
0746:                                getJAXBModelBuilder().getJAXBModel());
0747:                        rpcStruct
0748:                                .setJavaType(new JavaSimpleType(
0749:                                        "com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload",
0750:                                        null));
0751:                        resBlock = new Block(name, rpcStruct);
0752:                        response.addBodyBlock(resBlock);
0753:                    }
0754:                    params = getRpcLitParameters(request, response, reqBlock,
0755:                            resBlock, parameterList);
0756:                }
0757:
0758:                if (!validateParameterName(params)) {
0759:                    return null;
0760:                }
0761:
0762:                // create a definitive list of parameters to match what we'd like to get
0763:                // in the java interface (which is generated much later), parameterOrder
0764:                List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
0765:                for (Parameter param : params) {
0766:                    if (param.isReturn()) {
0767:                        info.operation
0768:                                .setProperty(WSDL_RESULT_PARAMETER, param);
0769:                        response.addParameter(param);
0770:                        continue;
0771:                    }
0772:                    if (param.isIN()) {
0773:                        request.addParameter(param);
0774:                    } else if (param.isOUT()) {
0775:                        response.addParameter(param);
0776:                    } else if (param.isINOUT()) {
0777:                        request.addParameter(param);
0778:                        response.addParameter(param);
0779:                    }
0780:                    definitiveParameterList.add(param);
0781:                }
0782:
0783:                info.operation.setRequest(request);
0784:
0785:                if (isRequestResponse) {
0786:                    info.operation.setResponse(response);
0787:                }
0788:
0789:                Iterator<Block> bb = request.getBodyBlocks();
0790:                QName body = VOID_BODYBLOCK;
0791:                QName opName = null;
0792:
0793:                if (bb.hasNext()) {
0794:                    body = bb.next().getName();
0795:                    opName = uniqueBodyBlocks.get(body);
0796:                } else {
0797:                    //there is no body block
0798:                    body = VOID_BODYBLOCK;
0799:                    opName = uniqueBodyBlocks.get(VOID_BODYBLOCK);
0800:                }
0801:                if (opName != null) {
0802:                    fail("wsdlmodeler.nonUnique.body", new Object[] {
0803:                            info.port.getName(), info.operation.getName(),
0804:                            opName, body });
0805:                } else {
0806:                    uniqueBodyBlocks.put(body, info.operation.getName());
0807:                }
0808:
0809:                // faults with duplicate names
0810:                Set duplicateNames = getDuplicateFaultNames();
0811:
0812:                // handle soap:fault
0813:                handleLiteralSOAPFault(response, duplicateNames);
0814:                info.operation.setProperty(WSDL_PARAMETER_ORDER,
0815:                        definitiveParameterList);
0816:
0817:                //set Async property
0818:                Binding binding = info.port.resolveBinding(document);
0819:                PortType portType = binding.resolvePortType(document);
0820:                if (isAsync(portType, info.portTypeOperation)) {
0821:                    addAsyncOperations(info.operation, styleAndUse);
0822:                }
0823:
0824:                return info.operation;
0825:            }
0826:
0827:            /**
0828:             *
0829:             * @param params
0830:             * @return
0831:             */
0832:            private boolean validateParameterName(List<Parameter> params) {
0833:                Message msg = getInputMessage();
0834:                for (Parameter param : params) {
0835:                    if (param.isOUT())
0836:                        continue;
0837:                    if (param.getCustomName() != null) {
0838:                        if (getEnvironment().getNames().isJavaReservedWord(
0839:                                param.getCustomName())) {
0840:                            if (extensions)
0841:                                warn(
0842:                                        "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.customName",
0843:                                        new Object[] {
0844:                                                info.operation.getName(),
0845:                                                param.getCustomName() });
0846:                            else
0847:                                fail(
0848:                                        "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.customName",
0849:                                        new Object[] {
0850:                                                info.operation.getName(),
0851:                                                param.getCustomName() });
0852:                            return false;
0853:                        }
0854:                        return true;
0855:                    }
0856:                    //process doclit wrapper style
0857:                    if (param.isEmbedded()
0858:                            && !(param.getBlock().getType() instanceof  RpcLitStructure)) {
0859:                        if (getEnvironment().getNames().isJavaReservedWord(
0860:                                param.getName())) {
0861:                            if (extensions)
0862:                                warn(
0863:                                        "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.wrapperStyle",
0864:                                        new Object[] {
0865:                                                info.operation.getName(),
0866:                                                param.getName(),
0867:                                                param.getBlock().getName() });
0868:                            else
0869:                                fail(
0870:                                        "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.wrapperStyle",
0871:                                        new Object[] {
0872:                                                info.operation.getName(),
0873:                                                param.getName(),
0874:                                                param.getBlock().getName() });
0875:                            return false;
0876:                        }
0877:                    } else {
0878:                        //non-wrapper style and rpclit
0879:                        if (getEnvironment().getNames().isJavaReservedWord(
0880:                                param.getName())) {
0881:                            if (extensions)
0882:                                warn(
0883:                                        "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.nonWrapperStyle",
0884:                                        new Object[] {
0885:                                                info.operation.getName(),
0886:                                                msg.getName(), param.getName() });
0887:                            else
0888:                                fail(
0889:                                        "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.nonWrapperStyle",
0890:                                        new Object[] {
0891:                                                info.operation.getName(),
0892:                                                msg.getName(), param.getName() });
0893:                            return false;
0894:                        }
0895:                    }
0896:                }
0897:
0898:                boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
0899:                if (isRequestResponse) {
0900:                    msg = getOutputMessage();
0901:                    for (Parameter param : params) {
0902:                        if (param.isIN())
0903:                            continue;
0904:                        if (param.getCustomName() != null) {
0905:                            if (getEnvironment().getNames().isJavaReservedWord(
0906:                                    param.getCustomName())) {
0907:                                if (extensions)
0908:                                    warn(
0909:                                            "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.customName",
0910:                                            new Object[] {
0911:                                                    info.operation.getName(),
0912:                                                    param.getCustomName() });
0913:                                else
0914:                                    fail(
0915:                                            "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.customName",
0916:                                            new Object[] {
0917:                                                    info.operation.getName(),
0918:                                                    param.getCustomName() });
0919:                                return false;
0920:                            }
0921:                            return true;
0922:                        }
0923:                        //process doclit wrapper style
0924:                        if (param.isEmbedded()
0925:                                && !(param.getBlock().getType() instanceof  RpcLitStructure)) {
0926:                            if (param.isReturn())
0927:                                continue;
0928:                            if (!param.getName().equals("return")
0929:                                    && getEnvironment()
0930:                                            .getNames()
0931:                                            .isJavaReservedWord(param.getName())) {
0932:                                if (extensions)
0933:                                    warn(
0934:                                            "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.wrapperStyle",
0935:                                            new Object[] {
0936:                                                    info.operation.getName(),
0937:                                                    param.getName(),
0938:                                                    param.getBlock().getName() });
0939:                                else
0940:                                    fail(
0941:                                            "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.wrapperStyle",
0942:                                            new Object[] {
0943:                                                    info.operation.getName(),
0944:                                                    param.getName(),
0945:                                                    param.getBlock().getName() });
0946:                                return false;
0947:                            }
0948:                        } else {
0949:                            if (param.isReturn())
0950:                                continue;
0951:
0952:                            //non-wrapper style and rpclit
0953:                            if (getEnvironment().getNames().isJavaReservedWord(
0954:                                    param.getName())) {
0955:                                if (extensions)
0956:                                    warn(
0957:                                            "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.nonWrapperStyle",
0958:                                            new Object[] {
0959:                                                    info.operation.getName(),
0960:                                                    msg.getName(),
0961:                                                    param.getName() });
0962:                                else
0963:                                    fail(
0964:                                            "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.nonWrapperStyle",
0965:                                            new Object[] {
0966:                                                    info.operation.getName(),
0967:                                                    msg.getName(),
0968:                                                    param.getName() });
0969:                                return false;
0970:                            }
0971:                        }
0972:                    }
0973:                }
0974:
0975:                return true;
0976:            }
0977:
0978:            /**
0979:             * @return
0980:             */
0981:            private boolean enableMimeContent() {
0982:                //first we look at binding operation
0983:                JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
0984:                        info.bindingOperation, JAXWSBinding.class);
0985:                Boolean mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization
0986:                        .isEnableMimeContentMapping()
0987:                        : null;
0988:                if (mimeContentMapping != null)
0989:                    return mimeContentMapping;
0990:
0991:                //then in wsdl:binding
0992:                Binding binding = info.port.resolveBinding(info.document);
0993:                jaxwsCustomization = (JAXWSBinding) getExtensionOfType(binding,
0994:                        JAXWSBinding.class);
0995:                mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization
0996:                        .isEnableMimeContentMapping()
0997:                        : null;
0998:                if (mimeContentMapping != null)
0999:                    return mimeContentMapping;
1000:
1001:                //at last look in wsdl:definitions
1002:                jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1003:                        info.document.getDefinitions(), JAXWSBinding.class);
1004:                mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization
1005:                        .isEnableMimeContentMapping()
1006:                        : null;
1007:                if (mimeContentMapping != null)
1008:                    return mimeContentMapping;
1009:                return false;
1010:            }
1011:
1012:            /**
1013:             *
1014:             */
1015:            private boolean applyOperationNameCustomization() {
1016:                JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1017:                        info.portTypeOperation, JAXWSBinding.class);
1018:                String operationName = (jaxwsCustomization != null) ? ((jaxwsCustomization
1019:                        .getMethodName() != null) ? jaxwsCustomization
1020:                        .getMethodName().getName() : null)
1021:                        : null;
1022:                if (operationName != null) {
1023:                    if (getEnvironment().getNames().isJavaReservedWord(
1024:                            operationName)) {
1025:                        if (extensions)
1026:                            warn(
1027:                                    "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.customizedOperationName",
1028:                                    new Object[] { info.operation.getName(),
1029:                                            operationName });
1030:                        else
1031:                            fail(
1032:                                    "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.customizedOperationName",
1033:                                    new Object[] { info.operation.getName(),
1034:                                            operationName });
1035:                        return false;
1036:                    }
1037:
1038:                    info.operation.setCustomizedName(operationName);
1039:                }
1040:
1041:                if (getEnvironment().getNames().isJavaReservedWord(
1042:                        info.operation.getJavaMethodName())) {
1043:                    if (extensions)
1044:                        warn(
1045:                                "wsdlmodeler.warning.ignoringOperation.javaReservedWordNotAllowed.operationName",
1046:                                new Object[] { info.operation.getName() });
1047:                    else
1048:                        fail(
1049:                                "wsdlmodeler.invalid.operation.javaReservedWordNotAllowed.operationName",
1050:                                new Object[] { info.operation.getName() });
1051:                    return false;
1052:                }
1053:                return true;
1054:            }
1055:
1056:            protected String getAsyncOperationName(Operation operation) {
1057:                String name = operation.getCustomizedName();
1058:                if (name == null)
1059:                    name = operation.getUniqueName();
1060:                return name;
1061:            }
1062:
1063:            /**
1064:             * @param styleAndUse
1065:             */
1066:            private void addAsyncOperations(Operation syncOperation,
1067:                    StyleAndUse styleAndUse) {
1068:                Operation operation = createAsyncOperation(syncOperation,
1069:                        styleAndUse, AsyncOperationType.POLLING);
1070:                if (operation != null)
1071:                    info.modelPort.addOperation(operation);
1072:
1073:                operation = createAsyncOperation(syncOperation, styleAndUse,
1074:                        AsyncOperationType.CALLBACK);
1075:                if (operation != null)
1076:                    info.modelPort.addOperation(operation);
1077:            }
1078:
1079:            /**
1080:             *
1081:             * @param syncOperation
1082:             * @param styleAndUse
1083:             * @param asyncType
1084:             * @return
1085:             */
1086:            private Operation createAsyncOperation(Operation syncOperation,
1087:                    StyleAndUse styleAndUse, AsyncOperationType asyncType) {
1088:                boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
1089:                if (!isRequestResponse)
1090:                    return null;
1091:                Request request = new Request();
1092:                Response response = new Response();
1093:
1094:                //create async operations
1095:                AsyncOperation operation = new AsyncOperation(info.operation);
1096:
1097:                //creation the async operation name: operationName+Async or customized name
1098:                //operation.setName(new QName(operation.getName().getNamespaceURI(), getAsyncOperationName(info.portTypeOperation, operation)));
1099:                if (asyncType.equals(AsyncOperationType.CALLBACK))
1100:                    operation.setUniqueName(info.operation.getUniqueName()
1101:                            + "_async_callback");
1102:                else if (asyncType.equals(AsyncOperationType.POLLING))
1103:                    operation.setUniqueName(info.operation.getUniqueName()
1104:                            + "_async_polling");
1105:
1106:                setDocumentationIfPresent(operation, info.portTypeOperation
1107:                        .getDocumentation());
1108:
1109:                operation.setAsyncType(asyncType);
1110:                operation.setSOAPAction(info.operation.getSOAPAction());
1111:                boolean unwrappable = info.operation.isWrapped();
1112:                operation.setWrapped(unwrappable);
1113:                SOAPBody soapRequestBody = getSOAPRequestBody();
1114:
1115:                Message inputMessage = getInputMessage();
1116:
1117:                SOAPBody soapResponseBody = null;
1118:                Message outputMessage = null;
1119:                if (isRequestResponse) {
1120:                    soapResponseBody = getSOAPResponseBody();
1121:                    outputMessage = getOutputMessage();
1122:                }
1123:
1124:                // Process parameterOrder and get the parameterList
1125:                java.util.List<String> parameterList = getAsynParameterOrder();
1126:
1127:                List<Parameter> inParameters = null;
1128:                if (isOperationDocumentLiteral(styleAndUse)) {
1129:                    inParameters = getRequestParameters(request, parameterList);
1130:                    // outParameters = getResponseParameters(response);
1131:                    // re-create parameterList with unwrapped parameters
1132:                    if (unwrappable) {
1133:                        List<String> unwrappedParameterList = new ArrayList<String>();
1134:                        if (inputMessage != null) {
1135:                            Iterator<MessagePart> parts = inputMessage.parts();
1136:                            if (parts.hasNext()) {
1137:                                MessagePart part = parts.next();
1138:                                JAXBType jaxbType = getJAXBType(part
1139:                                        .getDescriptor());
1140:                                List<JAXBProperty> memberList = jaxbType
1141:                                        .getWrapperChildren();
1142:                                Iterator<JAXBProperty> props = memberList
1143:                                        .iterator();
1144:                                while (props.hasNext()) {
1145:                                    JAXBProperty prop = props.next();
1146:                                    unwrappedParameterList.add(prop
1147:                                            .getElementName().getLocalPart());
1148:                                }
1149:                            }
1150:                        }
1151:
1152:                        parameterList.clear();
1153:                        parameterList.addAll(unwrappedParameterList);
1154:                    }
1155:                } else if (isOperationRpcLiteral(styleAndUse)) {
1156:                    String operationName = info.bindingOperation.getName();
1157:                    Block reqBlock = null;
1158:                    if (inputMessage != null) {
1159:                        QName name = new QName(
1160:                                getRequestNamespaceURI(soapRequestBody),
1161:                                operationName);
1162:                        RpcLitStructure rpcStruct = new RpcLitStructure(name,
1163:                                getJAXBModelBuilder().getJAXBModel());
1164:                        rpcStruct
1165:                                .setJavaType(new JavaSimpleType(
1166:                                        "com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload",
1167:                                        null));
1168:                        reqBlock = new Block(name, rpcStruct);
1169:                        request.addBodyBlock(reqBlock);
1170:                    }
1171:                    inParameters = createRpcLitRequestParameters(request,
1172:                            parameterList, reqBlock);
1173:                }
1174:
1175:                // add response blocks, we dont need to create respnse parameters, just blocks will be fine, lets
1176:                // copy them from sync optraions
1177:                //copy the response blocks from the sync operation
1178:                Iterator<Block> blocks = info.operation.getResponse()
1179:                        .getBodyBlocks();
1180:
1181:                while (blocks.hasNext()) {
1182:                    response.addBodyBlock(blocks.next());
1183:                }
1184:
1185:                blocks = info.operation.getResponse().getHeaderBlocks();
1186:                while (blocks.hasNext()) {
1187:                    response.addHeaderBlock(blocks.next());
1188:                }
1189:
1190:                blocks = info.operation.getResponse().getAttachmentBlocks();
1191:                while (blocks.hasNext()) {
1192:                    response.addAttachmentBlock(blocks.next());
1193:                }
1194:
1195:                List<MessagePart> outputParts = outputMessage.getParts();
1196:
1197:                // handle headers
1198:                int numOfOutMsgParts = outputParts.size();
1199:
1200:                if (isRequestResponse) {
1201:                    if (numOfOutMsgParts == 1) {
1202:                        MessagePart part = outputParts.get(0);
1203:                        if (isOperationDocumentLiteral(styleAndUse)) {
1204:                            JAXBType type = getJAXBType(part.getDescriptor());
1205:                            operation.setResponseBean(type);
1206:                        } else if (isOperationRpcLiteral(styleAndUse)) {
1207:                            String operationName = info.bindingOperation
1208:                                    .getName();
1209:                            Block resBlock = null;
1210:                            if (isRequestResponse && outputMessage != null) {
1211:                                resBlock = info.operation
1212:                                        .getResponse()
1213:                                        .getBodyBlocksMap()
1214:                                        .get(
1215:                                                new QName(
1216:                                                        getResponseNamespaceURI(soapResponseBody),
1217:                                                        operationName
1218:                                                                + "Response"));
1219:                            }
1220:                            RpcLitStructure resBean = (resBlock == null) ? null
1221:                                    : (RpcLitStructure) resBlock.getType();
1222:                            List<RpcLitMember> members = resBean
1223:                                    .getRpcLitMembers();
1224:
1225:                            operation.setResponseBean(members.get(0));
1226:                        }
1227:                    } else {
1228:                        //create response bean
1229:                        String nspace = "";
1230:                        QName responseBeanName = new QName(nspace,
1231:                                getAsyncOperationName(info.operation)
1232:                                        + "Response");
1233:                        JAXBType responseBeanType = getJAXBType(responseBeanName);
1234:                        operation.setResponseBean(responseBeanType);
1235:                    }
1236:                }
1237:                QName respBeanName = new QName(soapResponseBody.getNamespace(),
1238:                        getAsyncOperationName(info.operation) + "Response");
1239:                Block block = new Block(respBeanName, operation
1240:                        .getResponseBeanType());
1241:                JavaType respJavaType = operation.getResponseBeanJavaType();
1242:                JAXBType respType = new JAXBType(respBeanName, respJavaType);
1243:                Parameter respParam = ModelerUtils.createParameter(
1244:                        info.operation.getName() + "Response", respType, block);
1245:                respParam.setParameterIndex(-1);
1246:                response.addParameter(respParam);
1247:                operation.setProperty(WSDL_RESULT_PARAMETER, respParam
1248:                        .getName());
1249:
1250:                List<String> definitiveParameterList = new ArrayList<String>();
1251:                int parameterOrderPosition = 0;
1252:                for (String name : parameterList) {
1253:                    Parameter inParameter = null;
1254:
1255:                    inParameter = ModelerUtils.getParameter(name, inParameters);
1256:                    if (inParameter == null) {
1257:                        if (extensions)
1258:                            warn(
1259:                                    "wsdlmodeler.warning.ignoringOperation.partNotFound",
1260:                                    new Object[] {
1261:                                            info.operation.getName()
1262:                                                    .getLocalPart(), name });
1263:                        else
1264:                            fail("wsdlmodeler.error.partNotFound",
1265:                                    new Object[] {
1266:                                            info.operation.getName()
1267:                                                    .getLocalPart(), name });
1268:                        return null;
1269:                    }
1270:                    request.addParameter(inParameter);
1271:                    inParameter.setParameterIndex(parameterOrderPosition);
1272:                    definitiveParameterList.add(name);
1273:                    parameterOrderPosition++;
1274:                }
1275:
1276:                if (isRequestResponse) {
1277:                    operation.setResponse(response);
1278:                }
1279:
1280:                //  add callback handlerb Parameter to request
1281:                if (operation.getAsyncType()
1282:                        .equals(AsyncOperationType.CALLBACK)) {
1283:                    JavaType cbJavaType = operation.getCallBackType();
1284:                    JAXBType callbackType = new JAXBType(respBeanName,
1285:                            cbJavaType);
1286:                    Parameter cbParam = ModelerUtils.createParameter(
1287:                            "asyncHandler", callbackType, block);
1288:                    request.addParameter(cbParam);
1289:                }
1290:
1291:                operation.setRequest(request);
1292:
1293:                return operation;
1294:            }
1295:
1296:            protected boolean isAsync(
1297:                    com.sun.tools.internal.ws.wsdl.document.PortType portType,
1298:                    com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation) {
1299:                //First look into wsdl:operation
1300:                JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1301:                        wsdlOperation, JAXWSBinding.class);
1302:                Boolean isAsync = (jaxwsCustomization != null) ? jaxwsCustomization
1303:                        .isEnableAsyncMapping()
1304:                        : null;
1305:
1306:                if (isAsync != null)
1307:                    return isAsync;
1308:
1309:                // then into wsdl:portType
1310:                QName portTypeName = new QName(portType.getDefining()
1311:                        .getTargetNamespaceURI(), portType.getName());
1312:                if (portTypeName != null) {
1313:                    jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
1314:                            portType, JAXWSBinding.class);
1315:                    isAsync = (jaxwsCustomization != null) ? jaxwsCustomization
1316:                            .isEnableAsyncMapping() : null;
1317:                    if (isAsync != null)
1318:                        return isAsync;
1319:                }
1320:
1321:                //then wsdl:definitions
1322:                jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document
1323:                        .getDefinitions(), JAXWSBinding.class);
1324:                isAsync = (jaxwsCustomization != null) ? jaxwsCustomization
1325:                        .isEnableAsyncMapping() : null;
1326:                if (isAsync != null)
1327:                    return isAsync;
1328:                return false;
1329:            }
1330:
1331:            protected void handleLiteralSOAPHeaders(Request request,
1332:                    Response response, Iterator headerParts,
1333:                    Set duplicateNames, List definitiveParameterList,
1334:                    boolean processRequest) {
1335:                QName headerName = null;
1336:                Block headerBlock = null;
1337:                JAXBType jaxbType = null;
1338:                int parameterOrderPosition = definitiveParameterList.size();
1339:                while (headerParts.hasNext()) {
1340:                    MessagePart part = (MessagePart) headerParts.next();
1341:                    headerName = part.getDescriptor();
1342:                    jaxbType = getJAXBType(headerName);
1343:                    headerBlock = new Block(headerName, jaxbType);
1344:                    Extensible ext;
1345:                    if (processRequest) {
1346:                        ext = info.bindingOperation.getInput();
1347:                    } else {
1348:                        ext = info.bindingOperation.getOutput();
1349:                    }
1350:                    Message headerMessage = getHeaderMessage(part, ext);
1351:
1352:                    if (processRequest) {
1353:                        request.addHeaderBlock(headerBlock);
1354:                    } else {
1355:                        response.addHeaderBlock(headerBlock);
1356:                    }
1357:
1358:                    Parameter parameter = ModelerUtils.createParameter(part
1359:                            .getName(), jaxbType, headerBlock);
1360:                    parameter.setParameterIndex(parameterOrderPosition);
1361:                    setCustomizedParameterName(info.bindingOperation,
1362:                            headerMessage, part, parameter, false);
1363:                    if (processRequest && definitiveParameterList != null) {
1364:                        request.addParameter(parameter);
1365:                        definitiveParameterList.add(parameter.getName());
1366:                    } else {
1367:                        if (definitiveParameterList != null) {
1368:                            for (Iterator iterInParams = definitiveParameterList
1369:                                    .iterator(); iterInParams.hasNext();) {
1370:                                String inParamName = (String) iterInParams
1371:                                        .next();
1372:                                if (inParamName.equals(parameter.getName())) {
1373:                                    Parameter inParam = request
1374:                                            .getParameterByName(inParamName);
1375:                                    parameter.setLinkedParameter(inParam);
1376:                                    inParam.setLinkedParameter(parameter);
1377:                                    //its in/out parameter, input and output parameter have the same order position.
1378:                                    parameter.setParameterIndex(inParam
1379:                                            .getParameterIndex());
1380:                                }
1381:                            }
1382:                            if (!definitiveParameterList.contains(parameter
1383:                                    .getName())) {
1384:                                definitiveParameterList
1385:                                        .add(parameter.getName());
1386:                            }
1387:                        }
1388:                        response.addParameter(parameter);
1389:                    }
1390:                    parameterOrderPosition++;
1391:                }
1392:
1393:            }
1394:
1395:            protected void handleLiteralSOAPFault(Response response,
1396:                    Set duplicateNames) {
1397:                for (Iterator iter = info.bindingOperation.faults(); iter
1398:                        .hasNext();) {
1399:                    BindingFault bindingFault = (BindingFault) iter.next();
1400:                    com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
1401:                    for (Iterator iter2 = info.portTypeOperation.faults(); iter2
1402:                            .hasNext();) {
1403:                        com.sun.tools.internal.ws.wsdl.document.Fault aFault = (com.sun.tools.internal.ws.wsdl.document.Fault) iter2
1404:                                .next();
1405:                        if (aFault.getName().equals(bindingFault.getName())) {
1406:                            if (portTypeFault != null) {
1407:                                // the WSDL document is invalid, a wsld:fault in a wsdl:operation of a portType can be bound only once
1408:                                throw new ModelerException(
1409:                                        "wsdlmodeler.invalid.bindingFault.notUnique",
1410:                                        new Object[] { bindingFault.getName(),
1411:                                                info.bindingOperation.getName() });
1412:                            }
1413:                            portTypeFault = aFault;
1414:                        }
1415:                    }
1416:
1417:                    // The WSDL document is invalid, the wsdl:fault in abstract operation is does not have any binding
1418:                    if (portTypeFault == null) {
1419:                        throw new ModelerException(
1420:                                "wsdlmodeler.invalid.bindingFault.notFound",
1421:                                new Object[] { bindingFault.getName(),
1422:                                        info.bindingOperation.getName() });
1423:
1424:                    }
1425:
1426:                    // wsdl:fault message name is used to create the java exception name later on
1427:                    String faultName = getFaultClassName(portTypeFault);
1428:                    Fault fault = new Fault(faultName);
1429:                    setDocumentationIfPresent(fault, portTypeFault
1430:                            .getDocumentation());
1431:
1432:                    //get the soapbind:fault from wsdl:fault in the binding
1433:                    SOAPFault soapFault = (SOAPFault) getExtensionOfType(
1434:                            bindingFault, SOAPFault.class);
1435:
1436:                    // The WSDL document is invalid, can't have wsdl:fault without soapbind:fault
1437:                    if (soapFault == null) {
1438:                        throw new ModelerException(
1439:                                "wsdlmodeler.invalid.bindingFault.outputMissingSoapFault",
1440:                                new Object[] { bindingFault.getName(),
1441:                                        info.bindingOperation.getName() });
1442:                    }
1443:
1444:                    //the soapbind:fault must have use="literal" or no use attribute, in that case its assumed "literal"
1445:                    if (!soapFault.isLiteral()) {
1446:                        if (extensions)
1447:                            warn(
1448:                                    "wsdlmodeler.warning.ignoringFault.notLiteral",
1449:                                    new Object[] { bindingFault.getName(),
1450:                                            info.bindingOperation.getName() });
1451:                        else
1452:                            fail(
1453:                                    "wsdlmodeler.invalid.operation.fault.notLiteral",
1454:                                    new Object[] { bindingFault.getName(),
1455:                                            info.bindingOperation.getName() });
1456:                        continue;
1457:                    }
1458:
1459:                    // the soapFault name must be present
1460:                    if (soapFault.getName() == null) {
1461:                        warn(
1462:                                "wsdlmodeler.invalid.bindingFault.noSoapFaultName",
1463:                                new Object[] { bindingFault.getName(),
1464:                                        info.bindingOperation.getName() });
1465:                    } else if (!soapFault.getName().equals(
1466:                            bindingFault.getName())) {
1467:                        // the soapFault name must match bindingFault name
1468:                        warn(
1469:                                "wsdlmodeler.invalid.bindingFault.wrongSoapFaultName",
1470:                                new Object[] { soapFault.getName(),
1471:                                        bindingFault.getName(),
1472:                                        info.bindingOperation.getName() });
1473:                    } else if (soapFault.getNamespace() != null) {
1474:                        // bug fix: 4852729
1475:                        warn("wsdlmodeler.warning.r2716r2726", new Object[] {
1476:                                "soapbind:fault", soapFault.getName() });
1477:                    }
1478:
1479:                    String faultNamespaceURI = soapFault.getNamespace();
1480:                    if (faultNamespaceURI == null) {
1481:                        faultNamespaceURI = portTypeFault.getMessage()
1482:                                .getNamespaceURI();
1483:                    }
1484:
1485:                    com.sun.tools.internal.ws.wsdl.document.Message faultMessage = portTypeFault
1486:                            .resolveMessage(info.document);
1487:                    Iterator iter2 = faultMessage.parts();
1488:                    if (!iter2.hasNext()) {
1489:                        // the WSDL document is invalid
1490:                        throw new ModelerException(
1491:                                "wsdlmodeler.invalid.bindingFault.emptyMessage",
1492:                                new Object[] { bindingFault.getName(),
1493:                                        faultMessage.getName() });
1494:                    }
1495:                    MessagePart faultPart = (MessagePart) iter2.next();
1496:                    QName faultQName = faultPart.getDescriptor();
1497:
1498:                    // Don't include fault messages with non-unique soap:fault names
1499:                    if (duplicateNames.contains(faultQName)) {
1500:                        warn("wsdlmodeler.duplicate.fault.soap.name",
1501:                                new Object[] { bindingFault.getName(),
1502:                                        info.portTypeOperation.getName(),
1503:                                        faultPart.getName() });
1504:                        continue;
1505:                    }
1506:
1507:                    if (iter2.hasNext()) {
1508:                        // the WSDL document is invalid
1509:                        throw new ModelerException(
1510:                                "wsdlmodeler.invalid.bindingFault.messageHasMoreThanOnePart",
1511:                                new Object[] { bindingFault.getName(),
1512:                                        faultMessage.getName() });
1513:                    }
1514:
1515:                    if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1516:                        throw new ModelerException(
1517:                                "wsdlmodeler.invalid.message.partMustHaveElementDescriptor",
1518:                                new Object[] { faultMessage.getName(),
1519:                                        faultPart.getName() });
1520:                    }
1521:
1522:                    JAXBType jaxbType = getJAXBType(faultPart.getDescriptor());
1523:
1524:                    fault.setElementName(faultPart.getDescriptor());
1525:                    fault.setJavaMemberName(getEnvironment().getNames()
1526:                            .getExceptionClassMemberName());
1527:
1528:                    Block faultBlock = new Block(faultQName, jaxbType);
1529:                    fault.setBlock(faultBlock);
1530:                    createParentFault(fault);
1531:                    createSubfaults(fault);
1532:                    if (!response.getFaultBlocksMap().containsKey(
1533:                            faultBlock.getName()))
1534:                        response.addFaultBlock(faultBlock);
1535:                    info.operation.addFault(fault);
1536:                }
1537:            }
1538:
1539:            /**
1540:             * @param portTypeFault
1541:             * @return
1542:             */
1543:            private String getFaultClassName(
1544:                    com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault) {
1545:                JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
1546:                        portTypeFault, JAXWSBinding.class);
1547:                if (jaxwsBinding != null) {
1548:                    CustomName className = jaxwsBinding.getClassName();
1549:                    if (className != null) {
1550:                        return className.getName();
1551:                    }
1552:                }
1553:                return portTypeFault.getMessage().getLocalPart();
1554:            }
1555:
1556:            protected boolean setMessagePartsBinding(StyleAndUse styleAndUse) {
1557:                SOAPBody inBody = getSOAPRequestBody();
1558:                Message inMessage = getInputMessage();
1559:                if (!setMessagePartsBinding(inBody, inMessage, styleAndUse,
1560:                        true))
1561:                    return false;
1562:
1563:                if (isRequestResponse()) {
1564:                    SOAPBody outBody = getSOAPResponseBody();
1565:                    Message outMessage = getOutputMessage();
1566:                    if (!setMessagePartsBinding(outBody, outMessage,
1567:                            styleAndUse, false))
1568:                        return false;
1569:                }
1570:                return true;
1571:            }
1572:
1573:            //returns false if the wsdl is invalid and operation should be ignored
1574:            protected boolean setMessagePartsBinding(SOAPBody body,
1575:                    Message message, StyleAndUse styleAndUse, boolean isInput) {
1576:                List<MessagePart> parts = new ArrayList<MessagePart>();
1577:
1578:                //get Mime parts
1579:                List<MessagePart> mimeParts = null;
1580:                List<MessagePart> headerParts = null;
1581:                List<MessagePart> bodyParts = getBodyParts(body, message);
1582:
1583:                if (isInput) {
1584:                    headerParts = getHeaderPartsFromMessage(message, isInput);
1585:                    mimeParts = getMimeContentParts(message,
1586:                            info.bindingOperation.getInput());
1587:                } else {
1588:                    headerParts = getHeaderPartsFromMessage(message, isInput);
1589:                    mimeParts = getMimeContentParts(message,
1590:                            info.bindingOperation.getOutput());
1591:                }
1592:
1593:                //As of now WSDL MIME binding is not supported, so throw the exception when such binding is encounterd
1594:                //        if(mimeParts.size() > 0){
1595:                //            fail("wsdlmodeler.unsupportedBinding.mime", new Object[]{});
1596:                //        }
1597:
1598:                //if soap:body parts attribute not there, then all unbounded message parts will
1599:                // belong to the soap body
1600:                if (bodyParts == null) {
1601:                    bodyParts = new ArrayList<MessagePart>();
1602:                    for (Iterator<MessagePart> iter = message.parts(); iter
1603:                            .hasNext();) {
1604:                        MessagePart mPart = iter.next();
1605:                        //Its a safe assumption that the parts in the message not belonging to header or mime will
1606:                        // belong to the body?
1607:                        if (mimeParts.contains(mPart)
1608:                                || headerParts.contains(mPart)
1609:                                || boundToFault(mPart.getName())) {
1610:                            //throw error that a part cant be bound multiple times, not ignoring operation, if there
1611:                            //is conflict it will fail latter
1612:                            if (extensions)
1613:                                warn(
1614:                                        "wsdlmodeler.warning.bindingOperation.multiplePartBinding",
1615:                                        new Object[] {
1616:                                                info.bindingOperation.getName(),
1617:                                                mPart.getName() });
1618:                            else
1619:                                fail(
1620:                                        "wsdlmodeler.invalid.bindingOperation.multiplePartBinding",
1621:                                        new Object[] {
1622:                                                info.bindingOperation.getName(),
1623:                                                mPart.getName() });
1624:                        }
1625:                        bodyParts.add(mPart);
1626:                    }
1627:                }
1628:
1629:                //now build the final parts list with header, mime parts and body parts
1630:                for (Iterator iter = message.parts(); iter.hasNext();) {
1631:                    MessagePart mPart = (MessagePart) iter.next();
1632:                    if (mimeParts.contains(mPart)) {
1633:                        mPart
1634:                                .setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
1635:                        parts.add(mPart);
1636:                    } else if (headerParts.contains(mPart)) {
1637:                        mPart
1638:                                .setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1639:                        parts.add(mPart);
1640:                    } else if (bodyParts.contains(mPart)) {
1641:                        mPart
1642:                                .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1643:                        parts.add(mPart);
1644:                    } else {
1645:                        mPart
1646:                                .setBindingExtensibilityElementKind(MessagePart.PART_NOT_BOUNDED);
1647:                    }
1648:                }
1649:
1650:                if (isOperationDocumentLiteral(styleAndUse)
1651:                        && bodyParts.size() > 1) {
1652:                    if (extensions)
1653:                        warn(
1654:                                "wsdlmodeler.warning.operation.MoreThanOnePartInMessage",
1655:                                info.portTypeOperation.getName());
1656:                    else
1657:                        fail(
1658:                                "wsdlmodeler.invalid.operation.MoreThanOnePartInMessage",
1659:                                info.portTypeOperation.getName());
1660:                    return false;
1661:                }
1662:                return true;
1663:            }
1664:
1665:            private boolean boundToFault(String partName) {
1666:                for (Iterator iter = info.bindingOperation.faults(); iter
1667:                        .hasNext();) {
1668:                    BindingFault bindingFault = (BindingFault) iter.next();
1669:                    if (partName.equals(bindingFault.getName()))
1670:                        return true;
1671:                }
1672:                return false;
1673:            }
1674:
1675:            //get MessagePart(s) referenced by parts attribute of soap:body element
1676:            private List<MessagePart> getBodyParts(SOAPBody body,
1677:                    Message message) {
1678:                String bodyParts = body.getParts();
1679:                if (bodyParts != null) {
1680:                    List<MessagePart> partsList = new ArrayList<MessagePart>();
1681:                    StringTokenizer in = new StringTokenizer(bodyParts.trim(),
1682:                            " ");
1683:                    while (in.hasMoreTokens()) {
1684:                        String part = in.nextToken();
1685:                        MessagePart mPart = message.getPart(part);
1686:                        if (null == mPart) {
1687:                            throw new ModelerException(
1688:                                    "wsdlmodeler.error.partsNotFound",
1689:                                    new Object[] { part, message.getName() });
1690:                        }
1691:                        mPart
1692:                                .setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1693:                        partsList.add(mPart);
1694:                    }
1695:                    return partsList;
1696:                }
1697:                return null;
1698:            }
1699:
1700:            private List<MessagePart> getHeaderPartsFromMessage(
1701:                    Message message, boolean isInput) {
1702:                List<MessagePart> headerParts = new ArrayList<MessagePart>();
1703:                Iterator<MessagePart> parts = message.parts();
1704:                List<MessagePart> headers = getHeaderParts(isInput);
1705:                while (parts.hasNext()) {
1706:                    MessagePart part = parts.next();
1707:                    if (headers.contains(part)) {
1708:                        headerParts.add(part);
1709:                    }
1710:                }
1711:                return headerParts;
1712:            }
1713:
1714:            private Message getHeaderMessage(MessagePart part, Extensible ext) {
1715:                Iterator<SOAPHeader> headers = getHeaderExtensions(ext)
1716:                        .iterator();
1717:                while (headers.hasNext()) {
1718:                    SOAPHeader header = headers.next();
1719:                    if (!header.isLiteral())
1720:                        continue;
1721:                    com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(
1722:                            header.getMessage(), info);
1723:                    if (headerMessage == null)
1724:                        continue;
1725:
1726:                    MessagePart headerPart = headerMessage.getPart(header
1727:                            .getPart());
1728:                    if (headerPart == part)
1729:                        return headerMessage;
1730:                }
1731:                return null;
1732:            }
1733:
1734:            private List<MessagePart> getHeaderPartsNotFromMessage(
1735:                    Message message, boolean isInput) {
1736:                List<MessagePart> headerParts = new ArrayList<MessagePart>();
1737:                List<MessagePart> parts = message.getParts();
1738:                Iterator<MessagePart> headers = getHeaderParts(isInput)
1739:                        .iterator();
1740:                while (headers.hasNext()) {
1741:                    MessagePart part = headers.next();
1742:                    if (!parts.contains(part)) {
1743:                        headerParts.add(part);
1744:                    }
1745:                }
1746:                return headerParts;
1747:            }
1748:
1749:            private List<MessagePart> getHeaderParts(boolean isInput) {
1750:                Extensible ext;
1751:                if (isInput) {
1752:                    ext = info.bindingOperation.getInput();
1753:                } else {
1754:                    ext = info.bindingOperation.getOutput();
1755:                }
1756:
1757:                List<MessagePart> parts = new ArrayList<MessagePart>();
1758:                Iterator<SOAPHeader> headers = getHeaderExtensions(ext)
1759:                        .iterator();
1760:                while (headers.hasNext()) {
1761:                    SOAPHeader header = headers.next();
1762:                    if (!header.isLiteral()) {
1763:                        fail("wsdlmodeler.invalid.header.notLiteral",
1764:                                new Object[] { header.getPart(),
1765:                                        info.bindingOperation.getName() });
1766:                    }
1767:
1768:                    if (header.getNamespace() != null) {
1769:                        warn("wsdlmodeler.warning.r2716r2726", new Object[] {
1770:                                "soapbind:header",
1771:                                info.bindingOperation.getName() });
1772:                    }
1773:                    com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(
1774:                            header.getMessage(), info);
1775:                    if (headerMessage == null) {
1776:                        fail("wsdlmodeler.invalid.header.cant.resolve.message",
1777:                                new Object[] { header.getMessage(),
1778:                                        info.bindingOperation.getName() });
1779:                    }
1780:
1781:                    MessagePart part = headerMessage.getPart(header.getPart());
1782:                    if (part == null) {
1783:                        fail("wsdlmodeler.invalid.header.notFound",
1784:                                new Object[] { header.getPart(),
1785:                                        info.bindingOperation.getName() });
1786:                    }
1787:                    if (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1788:                        fail(
1789:                                "wsdlmodeler.invalid.header.message.partMustHaveElementDescriptor",
1790:                                new Object[] { part.getName(),
1791:                                        info.bindingOperation.getName() });
1792:                    }
1793:                    part
1794:                            .setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1795:                    parts.add(part);
1796:                }
1797:                return parts;
1798:            }
1799:
1800:            private boolean isOperationDocumentLiteral(StyleAndUse styleAndUse) {
1801:                return StyleAndUse.DOC_LITERAL == styleAndUse;
1802:            }
1803:
1804:            private boolean isOperationRpcLiteral(StyleAndUse styleAndUse) {
1805:                return StyleAndUse.RPC_LITERAL == styleAndUse;
1806:            }
1807:
1808:            /**
1809:             * @param part
1810:             * @return Returns a JAXBType object
1811:             */
1812:            private JAXBType getJAXBType(MessagePart part) {
1813:                JAXBType type = null;
1814:                QName name = part.getDescriptor();
1815:                if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
1816:                    type = getJAXBType(name);
1817:                } else {
1818:                    S2JJAXBModel jaxbModel = getJAXBModelBuilder()
1819:                            .getJAXBModel().getS2JJAXBModel();
1820:                    TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
1821:                    if (typeAnno == null) {
1822:                        fail("wsdlmodeler.jaxb.javatype.notfound",
1823:                                new Object[] { name, part.getName() });
1824:                    }
1825:                    JavaType javaType = new JavaSimpleType(
1826:                            new JAXBTypeAndAnnotation(typeAnno));
1827:                    type = new JAXBType(new QName("", part.getName()), javaType);
1828:                }
1829:                return type;
1830:            }
1831:
1832:            private List<Parameter> getDoclitParameters(Request req,
1833:                    Response res, List<MessagePart> parameterList) {
1834:                if (parameterList.size() == 0)
1835:                    return new ArrayList<Parameter>();
1836:                List<Parameter> params = null;
1837:                Message inMsg = getInputMessage();
1838:                Message outMsg = getOutputMessage();
1839:                boolean unwrappable = isUnwrappable();
1840:                List<Parameter> outParams = null;
1841:                int pIndex = 0;
1842:                for (MessagePart part : parameterList) {
1843:                    QName reqBodyName = part.getDescriptor();
1844:                    JAXBType jaxbType = getJAXBType(part);
1845:                    Block block = new Block(reqBodyName, jaxbType);
1846:                    if (unwrappable) {
1847:                        //So build body and header blocks and set to request and response
1848:                        JAXBStructuredType jaxbStructType = ModelerUtils
1849:                                .createJAXBStructureType(jaxbType);
1850:                        block = new Block(reqBodyName, jaxbStructType);
1851:                        if (ModelerUtils.isBoundToSOAPBody(part)) {
1852:                            if (part.isIN()) {
1853:                                req.addBodyBlock(block);
1854:                            } else if (part.isOUT()) {
1855:                                res.addBodyBlock(block);
1856:                            } else if (part.isINOUT()) {
1857:                                req.addBodyBlock(block);
1858:                                res.addBodyBlock(block);
1859:                            }
1860:                        } else if (ModelerUtils.isUnbound(part)) {
1861:                            if (part.isIN())
1862:                                req.addUnboundBlock(block);
1863:                            else if (part.isOUT())
1864:                                res.addUnboundBlock(block);
1865:                            else if (part.isINOUT()) {
1866:                                req.addUnboundBlock(block);
1867:                                res.addUnboundBlock(block);
1868:                            }
1869:
1870:                        }
1871:                        if (part.isIN() || part.isINOUT()) {
1872:                            params = ModelerUtils.createUnwrappedParameters(
1873:                                    jaxbStructType, block);
1874:                            int index = 0;
1875:                            Mode mode = (part.isINOUT()) ? Mode.INOUT : Mode.IN;
1876:                            for (Parameter param : params) {
1877:                                param.setParameterIndex(index++);
1878:                                param.setMode(mode);
1879:                                setCustomizedParameterName(
1880:                                        info.portTypeOperation, inMsg, part,
1881:                                        param, unwrappable);
1882:                            }
1883:                        } else if (part.isOUT()) {
1884:                            outParams = ModelerUtils.createUnwrappedParameters(
1885:                                    jaxbStructType, block);
1886:                            for (Parameter param : outParams) {
1887:                                param.setMode(Mode.OUT);
1888:                                setCustomizedParameterName(
1889:                                        info.portTypeOperation, outMsg, part,
1890:                                        param, unwrappable);
1891:                            }
1892:                        }
1893:                    } else {
1894:                        if (ModelerUtils.isBoundToSOAPBody(part)) {
1895:                            if (part.isIN()) {
1896:                                req.addBodyBlock(block);
1897:                            } else if (part.isOUT()) {
1898:                                res.addBodyBlock(block);
1899:                            } else if (part.isINOUT()) {
1900:                                req.addBodyBlock(block);
1901:                                res.addBodyBlock(block);
1902:                            }
1903:                        } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1904:                            if (part.isIN()) {
1905:                                req.addHeaderBlock(block);
1906:                            } else if (part.isOUT()) {
1907:                                res.addHeaderBlock(block);
1908:                            } else if (part.isINOUT()) {
1909:                                req.addHeaderBlock(block);
1910:                                res.addHeaderBlock(block);
1911:                            }
1912:                        } else if (ModelerUtils.isBoundToMimeContent(part)) {
1913:                            List<MIMEContent> mimeContents = null;
1914:
1915:                            if (part.isIN()) {
1916:                                mimeContents = getMimeContents(
1917:                                        info.bindingOperation.getInput(),
1918:                                        getInputMessage(), part.getName());
1919:                                jaxbType = getAttachmentType(mimeContents, part);
1920:                                block = new Block(jaxbType.getName(), jaxbType);
1921:                                req.addAttachmentBlock(block);
1922:                            } else if (part.isOUT()) {
1923:                                mimeContents = getMimeContents(
1924:                                        info.bindingOperation.getOutput(),
1925:                                        getOutputMessage(), part.getName());
1926:                                jaxbType = getAttachmentType(mimeContents, part);
1927:                                block = new Block(jaxbType.getName(), jaxbType);
1928:                                res.addAttachmentBlock(block);
1929:                            } else if (part.isINOUT()) {
1930:                                mimeContents = getMimeContents(
1931:                                        info.bindingOperation.getInput(),
1932:                                        getInputMessage(), part.getName());
1933:                                jaxbType = getAttachmentType(mimeContents, part);
1934:                                block = new Block(jaxbType.getName(), jaxbType);
1935:                                req.addAttachmentBlock(block);
1936:                                res.addAttachmentBlock(block);
1937:
1938:                                mimeContents = getMimeContents(
1939:                                        info.bindingOperation.getOutput(),
1940:                                        getOutputMessage(), part.getName());
1941:                                JAXBType outJaxbType = getAttachmentType(
1942:                                        mimeContents, part);
1943:
1944:                                String inType = jaxbType.getJavaType()
1945:                                        .getType().getName();
1946:                                String outType = outJaxbType.getJavaType()
1947:                                        .getType().getName();
1948:
1949:                                TypeAndAnnotation inTa = jaxbType.getJavaType()
1950:                                        .getType().getTypeAnn();
1951:                                TypeAndAnnotation outTa = outJaxbType
1952:                                        .getJavaType().getType().getTypeAnn();
1953:                                if ((((inTa != null) && (outTa != null) && inTa
1954:                                        .equals(outTa)))
1955:                                        && !inType.equals(outType)) {
1956:                                    String javaType = "javax.activation.DataHandler";
1957:
1958:                                    S2JJAXBModel jaxbModel = getJAXBModelBuilder()
1959:                                            .getJAXBModel().getS2JJAXBModel();
1960:                                    JCodeModel cm = jaxbModel.generateCode(
1961:                                            null, new ConsoleErrorReporter(
1962:                                                    getEnvironment(), false));
1963:                                    JType jt = null;
1964:                                    jt = cm.ref(javaType);
1965:                                    JAXBTypeAndAnnotation jaxbTa = jaxbType
1966:                                            .getJavaType().getType();
1967:                                    jaxbTa.setType(jt);
1968:                                }
1969:                            }
1970:                        } else if (ModelerUtils.isUnbound(part)) {
1971:                            if (part.isIN()) {
1972:                                req.addUnboundBlock(block);
1973:                            } else if (part.isOUT()) {
1974:                                res.addUnboundBlock(block);
1975:                            } else if (part.isINOUT()) {
1976:                                req.addUnboundBlock(block);
1977:                                res.addUnboundBlock(block);
1978:                            }
1979:                        }
1980:                        if (params == null)
1981:                            params = new ArrayList<Parameter>();
1982:                        Parameter param = ModelerUtils.createParameter(part
1983:                                .getName(), jaxbType, block);
1984:                        param.setMode(part.getMode());
1985:                        if (part.isReturn()) {
1986:                            param.setParameterIndex(-1);
1987:                        } else {
1988:                            param.setParameterIndex(pIndex++);
1989:                        }
1990:
1991:                        if (part.isIN())
1992:                            setCustomizedParameterName(info.portTypeOperation,
1993:                                    inMsg, part, param, false);
1994:                        else if (outMsg != null)
1995:                            setCustomizedParameterName(info.portTypeOperation,
1996:                                    outMsg, part, param, false);
1997:
1998:                        params.add(param);
1999:                    }
2000:                }
2001:                if (unwrappable && (outParams != null)) {
2002:                    int index = params.size();
2003:                    for (Parameter param : outParams) {
2004:                        if (param.getName().equals("return")) {
2005:                            param.setParameterIndex(-1);
2006:                        } else {
2007:                            Parameter inParam = ModelerUtils.getParameter(param
2008:                                    .getName(), params);
2009:                            if ((inParam != null) && inParam.isIN()) {
2010:                                QName inElementName = ((JAXBType) inParam
2011:                                        .getType()).getName();
2012:                                QName outElementName = ((JAXBType) param
2013:                                        .getType()).getName();
2014:                                String inJavaType = inParam.getTypeName();
2015:                                String outJavaType = param.getTypeName();
2016:                                TypeAndAnnotation inTa = inParam.getType()
2017:                                        .getJavaType().getType().getTypeAnn();
2018:                                TypeAndAnnotation outTa = param.getType()
2019:                                        .getJavaType().getType().getTypeAnn();
2020:                                if (inElementName.getLocalPart().equals(
2021:                                        outElementName.getLocalPart())
2022:                                        && inJavaType.equals(outJavaType)
2023:                                        && ((inTa == null || outTa == null) || ((inTa != null)
2024:                                                && (outTa != null) && inTa
2025:                                                .equals(outTa)))) {
2026:                                    inParam.setMode(Mode.INOUT);
2027:                                    continue;
2028:                                }
2029:                            } else if (outParams.size() == 1) {
2030:                                param.setParameterIndex(-1);
2031:                            } else {
2032:                                param.setParameterIndex(index++);
2033:                            }
2034:                        }
2035:                        params.add(param);
2036:                    }
2037:                }
2038:                return params;
2039:            }
2040:
2041:            private List<Parameter> getRpcLitParameters(Request req,
2042:                    Response res, Block reqBlock, Block resBlock,
2043:                    List<MessagePart> paramList) {
2044:                List<Parameter> params = new ArrayList<Parameter>();
2045:                Message inMsg = getInputMessage();
2046:                Message outMsg = getOutputMessage();
2047:                S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType())
2048:                        .getJaxbModel().getS2JJAXBModel();
2049:                List<Parameter> inParams = ModelerUtils.createRpcLitParameters(
2050:                        inMsg, reqBlock, jaxbModel);
2051:                List<Parameter> outParams = null;
2052:                if (outMsg != null)
2053:                    outParams = ModelerUtils.createRpcLitParameters(outMsg,
2054:                            resBlock, jaxbModel);
2055:
2056:                //create parameters for header and mime parts
2057:                int index = 0;
2058:                for (MessagePart part : paramList) {
2059:                    Parameter param = null;
2060:                    if (ModelerUtils.isBoundToSOAPBody(part)) {
2061:                        if (part.isIN()) {
2062:                            param = ModelerUtils.getParameter(part.getName(),
2063:                                    inParams);
2064:                        } else if (outParams != null) {
2065:                            param = ModelerUtils.getParameter(part.getName(),
2066:                                    outParams);
2067:                        }
2068:                    } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
2069:                        QName headerName = part.getDescriptor();
2070:                        JAXBType jaxbType = getJAXBType(headerName);
2071:                        Block headerBlock = new Block(headerName, jaxbType);
2072:                        param = ModelerUtils.createParameter(part.getName(),
2073:                                jaxbType, headerBlock);
2074:                        if (part.isIN()) {
2075:                            req.addHeaderBlock(headerBlock);
2076:                        } else if (part.isOUT()) {
2077:                            res.addHeaderBlock(headerBlock);
2078:                        } else if (part.isINOUT()) {
2079:                            req.addHeaderBlock(headerBlock);
2080:                            res.addHeaderBlock(headerBlock);
2081:                        }
2082:                    } else if (ModelerUtils.isBoundToMimeContent(part)) {
2083:                        List<MIMEContent> mimeContents = null;
2084:                        if (part.isIN() || part.isINOUT())
2085:                            mimeContents = getMimeContents(
2086:                                    info.bindingOperation.getInput(),
2087:                                    getInputMessage(), part.getName());
2088:                        else
2089:                            mimeContents = getMimeContents(
2090:                                    info.bindingOperation.getOutput(),
2091:                                    getOutputMessage(), part.getName());
2092:
2093:                        JAXBType type = getAttachmentType(mimeContents, part);
2094:                        //create Parameters in request or response
2095:                        //Block mimeBlock = new Block(new QName(part.getName()), type);
2096:                        Block mimeBlock = new Block(type.getName(), type);
2097:                        param = ModelerUtils.createParameter(part.getName(),
2098:                                type, mimeBlock);
2099:                        if (part.isIN()) {
2100:                            req.addAttachmentBlock(mimeBlock);
2101:                        } else if (part.isOUT()) {
2102:                            res.addAttachmentBlock(mimeBlock);
2103:                        } else if (part.isINOUT()) {
2104:                            mimeContents = getMimeContents(
2105:                                    info.bindingOperation.getOutput(),
2106:                                    getOutputMessage(), part.getName());
2107:                            JAXBType outJaxbType = getAttachmentType(
2108:                                    mimeContents, part);
2109:
2110:                            String inType = type.getJavaType().getType()
2111:                                    .getName();
2112:                            String outType = outJaxbType.getJavaType()
2113:                                    .getType().getName();
2114:                            if (!inType.equals(outType)) {
2115:                                String javaType = "javax.activation.DataHandler";
2116:                                JCodeModel cm = jaxbModel.generateCode(null,
2117:                                        new ConsoleErrorReporter(
2118:                                                getEnvironment(), false));
2119:                                JType jt = null;
2120:                                jt = cm.ref(javaType);
2121:                                JAXBTypeAndAnnotation jaxbTa = type
2122:                                        .getJavaType().getType();
2123:                                jaxbTa.setType(jt);
2124:                            }
2125:                            req.addAttachmentBlock(mimeBlock);
2126:                            res.addAttachmentBlock(mimeBlock);
2127:                        }
2128:                    } else if (ModelerUtils.isUnbound(part)) {
2129:                        QName name = part.getDescriptor();
2130:                        JAXBType type = getJAXBType(part);
2131:                        Block unboundBlock = new Block(name, type);
2132:                        if (part.isIN()) {
2133:                            req.addUnboundBlock(unboundBlock);
2134:                        } else if (part.isOUT()) {
2135:                            res.addUnboundBlock(unboundBlock);
2136:                        } else if (part.isINOUT()) {
2137:                            req.addUnboundBlock(unboundBlock);
2138:                            res.addUnboundBlock(unboundBlock);
2139:                        }
2140:                        param = ModelerUtils.createParameter(part.getName(),
2141:                                type, unboundBlock);
2142:                    }
2143:                    if (param != null) {
2144:                        if (part.isReturn()) {
2145:                            param.setParameterIndex(-1);
2146:                        } else {
2147:                            param.setParameterIndex(index++);
2148:                        }
2149:                        param.setMode(part.getMode());
2150:                        params.add(param);
2151:                    }
2152:                }
2153:                for (Parameter param : params) {
2154:                    if (param.isIN())
2155:                        setCustomizedParameterName(info.portTypeOperation,
2156:                                inMsg, inMsg.getPart(param.getName()), param,
2157:                                false);
2158:                    else if (outMsg != null)
2159:                        setCustomizedParameterName(info.portTypeOperation,
2160:                                outMsg, outMsg.getPart(param.getName()), param,
2161:                                false);
2162:                }
2163:                return params;
2164:            }
2165:
2166:            private List<Parameter> getRequestParameters(Request request,
2167:                    List<String> parameterList) {
2168:                Message inputMessage = getInputMessage();
2169:                //there is no input message, return zero parameters
2170:                if (inputMessage != null && !inputMessage.parts().hasNext())
2171:                    return new ArrayList<Parameter>();
2172:
2173:                List<Parameter> inParameters = null;
2174:                QName reqBodyName = null;
2175:                Block reqBlock = null;
2176:                JAXBType jaxbReqType = null;
2177:                boolean unwrappable = isUnwrappable();
2178:                boolean doneSOAPBody = false;
2179:                //setup request parameters
2180:                for (String inParamName : parameterList) {
2181:                    MessagePart part = inputMessage.getPart(inParamName);
2182:                    if (part == null)
2183:                        continue;
2184:                    reqBodyName = part.getDescriptor();
2185:                    jaxbReqType = getJAXBType(part);
2186:                    if (unwrappable) {
2187:                        //So build body and header blocks and set to request and response
2188:                        JAXBStructuredType jaxbRequestType = ModelerUtils
2189:                                .createJAXBStructureType(jaxbReqType);
2190:                        reqBlock = new Block(reqBodyName, jaxbRequestType);
2191:                        if (ModelerUtils.isBoundToSOAPBody(part)) {
2192:                            request.addBodyBlock(reqBlock);
2193:                        } else if (ModelerUtils.isUnbound(part)) {
2194:                            request.addUnboundBlock(reqBlock);
2195:                        }
2196:                        inParameters = ModelerUtils.createUnwrappedParameters(
2197:                                jaxbRequestType, reqBlock);
2198:                        for (Parameter param : inParameters) {
2199:                            setCustomizedParameterName(info.portTypeOperation,
2200:                                    inputMessage, part, param, unwrappable);
2201:                        }
2202:                    } else {
2203:                        reqBlock = new Block(reqBodyName, jaxbReqType);
2204:                        if (ModelerUtils.isBoundToSOAPBody(part)
2205:                                && !doneSOAPBody) {
2206:                            doneSOAPBody = true;
2207:                            request.addBodyBlock(reqBlock);
2208:                        } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
2209:                            request.addHeaderBlock(reqBlock);
2210:                        } else if (ModelerUtils.isBoundToMimeContent(part)) {
2211:                            List<MIMEContent> mimeContents = getMimeContents(
2212:                                    info.bindingOperation.getInput(),
2213:                                    getInputMessage(), part.getName());
2214:                            jaxbReqType = getAttachmentType(mimeContents, part);
2215:                            //reqBlock = new Block(new QName(part.getName()), jaxbReqType);
2216:                            reqBlock = new Block(jaxbReqType.getName(),
2217:                                    jaxbReqType);
2218:                            request.addAttachmentBlock(reqBlock);
2219:                        } else if (ModelerUtils.isUnbound(part)) {
2220:                            request.addUnboundBlock(reqBlock);
2221:                        }
2222:                        if (inParameters == null)
2223:                            inParameters = new ArrayList<Parameter>();
2224:                        Parameter param = ModelerUtils.createParameter(part
2225:                                .getName(), jaxbReqType, reqBlock);
2226:                        setCustomizedParameterName(info.portTypeOperation,
2227:                                inputMessage, part, param, false);
2228:                        inParameters.add(param);
2229:                    }
2230:                }
2231:                return inParameters;
2232:            }
2233:
2234:            /**
2235:             * @param part
2236:             * @param param
2237:             * @param wrapperStyle TODO
2238:             */
2239:            private void setCustomizedParameterName(Extensible extension,
2240:                    Message msg, MessagePart part, Parameter param,
2241:                    boolean wrapperStyle) {
2242:                JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
2243:                        extension, JAXWSBinding.class);
2244:                if (jaxwsBinding == null)
2245:                    return;
2246:                String paramName = part.getName();
2247:                QName elementName = part.getDescriptor();
2248:                if (wrapperStyle)
2249:                    elementName = param.getType().getName();
2250:                String customName = jaxwsBinding.getParameterName(
2251:                        msg.getName(), paramName, elementName, wrapperStyle);
2252:                if (customName != null && !customName.equals("")) {
2253:                    param.setCustomName(customName);
2254:                }
2255:            }
2256:
2257:            /**
2258:             * @param name
2259:             * @return
2260:             */
2261:            private JAXBType getJAXBType(QName name) {
2262:                return jaxbModelBuilder.getJAXBType(name);
2263:            }
2264:
2265:            protected boolean isConflictingPortClassName(String name) {
2266:                return false;
2267:            }
2268:
2269:            /* (non-Javadoc)
2270:             * @see WSDLModelerBase#getJAXBSchemaAnalyzerInstnace(WSDLModelInfo, Properties, org.w3c.dom.Element)
2271:             */
2272:            protected JAXBModelBuilder getJAXBSchemaAnalyzerInstnace(
2273:                    WSDLModelInfo info, Properties options,
2274:                    ClassNameCollector classNameCollector, List elements) {
2275:                return new JAXBModelBuilder(info, options, classNameCollector,
2276:                        elements);
2277:            }
2278:
2279:            /* (non-Javadoc)
2280:             * @see WSDLModelerBase#isUnwrappable()
2281:             */
2282:            protected boolean isUnwrappable() {
2283:                if (!getWrapperStyleCustomization())
2284:                    return false;
2285:
2286:                com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
2287:                com.sun.tools.internal.ws.wsdl.document.Message outputMessage = getOutputMessage();
2288:
2289:                // Wrapper style if the operation's input and output messages each contain
2290:                // only a single part
2291:                if ((inputMessage != null && inputMessage.numParts() != 1)
2292:                        || (outputMessage != null && outputMessage.numParts() != 1)) {
2293:                    return false;
2294:                }
2295:
2296:                MessagePart inputPart = inputMessage != null ? (MessagePart) inputMessage
2297:                        .parts().next()
2298:                        : null;
2299:                MessagePart outputPart = outputMessage != null ? (MessagePart) outputMessage
2300:                        .parts().next()
2301:                        : null;
2302:                String operationName = info.portTypeOperation.getName();
2303:
2304:                // Wrapper style if the input message part refers to a global element declaration whose localname
2305:                // is equal to the operation name
2306:                // Wrapper style if the output message part refers to a global element declaration
2307:                if ((inputPart != null && !inputPart.getDescriptor()
2308:                        .getLocalPart().equals(operationName))
2309:                        || (outputPart != null && outputPart
2310:                                .getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
2311:                    return false;
2312:
2313:                //check to see if either input or output message part not bound to soapbing:body
2314:                //in that case the operation is not wrapper style
2315:                if (((inputPart != null) && (inputPart
2316:                        .getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING))
2317:                        || ((outputPart != null) && (outputPart
2318:                                .getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)))
2319:                    return false;
2320:
2321:                // Wrapper style if the elements referred to by the input and output message parts
2322:                // (henceforth referred to as wrapper elements) are both complex types defined
2323:                // using the xsd:sequence compositor
2324:                // Wrapper style if the wrapper elements only contain child elements, they must not
2325:                // contain other structures such as xsd:choice, substitution groups1 or attributes
2326:                //These checkins are done by jaxb, we just check if jaxb has wrapper children. If there
2327:                // are then its wrapper style
2328:                //if(inputPart != null && outputPart != null){
2329:                if (inputPart != null) {
2330:                    boolean inputWrappable = false;
2331:                    JAXBType inputType = getJAXBType(inputPart.getDescriptor());
2332:                    if (inputType != null) {
2333:                        inputWrappable = inputType.isUnwrappable();
2334:                    }
2335:                    //if there are no output part (oneway), the operation can still be wrapper style
2336:                    if (outputPart == null) {
2337:                        return inputWrappable;
2338:                    }
2339:                    JAXBType outputType = getJAXBType(outputPart
2340:                            .getDescriptor());
2341:                    if ((inputType != null) && (outputType != null))
2342:                        return inputType.isUnwrappable()
2343:                                && outputType.isUnwrappable();
2344:                }
2345:
2346:                return false;
2347:            }
2348:
2349:            /**
2350:             * @return
2351:             */
2352:            private boolean getWrapperStyleCustomization() {
2353:                //first we look into wsdl:portType/wsdl:operation
2354:                com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation = info.portTypeOperation;
2355:                JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
2356:                        portTypeOperation, JAXWSBinding.class);
2357:                if (jaxwsBinding != null) {
2358:                    Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2359:                    if (isWrappable != null)
2360:                        return isWrappable;
2361:                }
2362:
2363:                //then into wsdl:portType        
2364:                PortType portType = info.port.resolveBinding(document)
2365:                        .resolvePortType(document);
2366:                jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType,
2367:                        JAXWSBinding.class);
2368:                if (jaxwsBinding != null) {
2369:                    Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2370:                    if (isWrappable != null)
2371:                        return isWrappable;
2372:                }
2373:
2374:                //then wsdl:definitions
2375:                jaxwsBinding = (JAXWSBinding) getExtensionOfType(document
2376:                        .getDefinitions(), JAXWSBinding.class);
2377:                if (jaxwsBinding != null) {
2378:                    Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2379:                    if (isWrappable != null)
2380:                        return isWrappable;
2381:                }
2382:                return true;
2383:            }
2384:
2385:            /* (non-Javadoc)
2386:             * @see WSDLModelerBase#isSingleInOutPart(Set, MessagePart)
2387:             */
2388:            protected boolean isSingleInOutPart(Set inputParameterNames,
2389:                    MessagePart outputPart) {
2390:                // As of now, we dont have support for in/out in doc-lit. So return false.
2391:                SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
2392:                        info.bindingOperation, SOAPOperation.class);
2393:                if ((soapOperation != null)
2394:                        && (soapOperation.isDocument() || info.soapBinding
2395:                                .isDocument())) {
2396:                    Iterator iter = getInputMessage().parts();
2397:                    while (iter.hasNext()) {
2398:                        MessagePart part = (MessagePart) iter.next();
2399:                        if (outputPart.getName().equals(part.getName())
2400:                                && outputPart.getDescriptor().equals(
2401:                                        part.getDescriptor()))
2402:                            return true;
2403:                    }
2404:                } else if (soapOperation != null && soapOperation.isRPC()
2405:                        || info.soapBinding.isRPC()) {
2406:                    com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
2407:                    if (inputParameterNames.contains(outputPart.getName())) {
2408:                        if (inputMessage.getPart(outputPart.getName())
2409:                                .getDescriptor().equals(
2410:                                        outputPart.getDescriptor())) {
2411:                            return true;
2412:                        }
2413:                    }
2414:                }
2415:                return false;
2416:            }
2417:
2418:            private List<Parameter> createRpcLitRequestParameters(
2419:                    Request request, List<String> parameterList, Block block) {
2420:                Message message = getInputMessage();
2421:                S2JJAXBModel jaxbModel = ((RpcLitStructure) block.getType())
2422:                        .getJaxbModel().getS2JJAXBModel();
2423:                List<Parameter> parameters = ModelerUtils
2424:                        .createRpcLitParameters(message, block, jaxbModel);
2425:
2426:                //create parameters for header and mime parts
2427:                for (String paramName : parameterList) {
2428:                    MessagePart part = message.getPart(paramName);
2429:                    if (part == null)
2430:                        continue;
2431:                    if (ModelerUtils.isBoundToSOAPHeader(part)) {
2432:                        if (parameters == null)
2433:                            parameters = new ArrayList<Parameter>();
2434:                        QName headerName = part.getDescriptor();
2435:                        JAXBType jaxbType = getJAXBType(headerName);
2436:                        Block headerBlock = new Block(headerName, jaxbType);
2437:                        request.addHeaderBlock(headerBlock);
2438:                        Parameter param = ModelerUtils.createParameter(part
2439:                                .getName(), jaxbType, headerBlock);
2440:                        if (param != null) {
2441:                            parameters.add(param);
2442:                        }
2443:                    } else if (ModelerUtils.isBoundToMimeContent(part)) {
2444:                        if (parameters == null)
2445:                            parameters = new ArrayList<Parameter>();
2446:                        List<MIMEContent> mimeContents = getMimeContents(
2447:                                info.bindingOperation.getInput(),
2448:                                getInputMessage(), paramName);
2449:
2450:                        JAXBType type = getAttachmentType(mimeContents, part);
2451:                        //create Parameters in request or response
2452:                        //Block mimeBlock = new Block(new QName(part.getName()), type);
2453:                        Block mimeBlock = new Block(type.getName(), type);
2454:                        request.addAttachmentBlock(mimeBlock);
2455:                        Parameter param = ModelerUtils.createParameter(part
2456:                                .getName(), type, mimeBlock);
2457:                        if (param != null) {
2458:                            parameters.add(param);
2459:                        }
2460:                    } else if (ModelerUtils.isUnbound(part)) {
2461:                        if (parameters == null)
2462:                            parameters = new ArrayList<Parameter>();
2463:                        QName name = part.getDescriptor();
2464:                        JAXBType type = getJAXBType(part);
2465:                        Block unboundBlock = new Block(name, type);
2466:                        request.addUnboundBlock(unboundBlock);
2467:                        Parameter param = ModelerUtils.createParameter(part
2468:                                .getName(), type, unboundBlock);
2469:                        if (param != null) {
2470:                            parameters.add(param);
2471:                        }
2472:                    }
2473:                }
2474:                for (Parameter param : parameters) {
2475:                    setCustomizedParameterName(info.portTypeOperation, message,
2476:                            message.getPart(param.getName()), param, false);
2477:                }
2478:                return parameters;
2479:            }
2480:
2481:            private String getJavaTypeForMimeType(String mimeType) {
2482:                if (mimeType.equals("image/jpeg")
2483:                        || mimeType.equals("image/gif")) {
2484:                    return "java.awt.Image";
2485:                } else if (mimeType.equals("text/xml")
2486:                        || mimeType.equals("application/xml")) {
2487:                    return "javax.xml.transform.Source";
2488:                }
2489:                return "javax.activation.DataHandler";
2490:            }
2491:
2492:            /**
2493:             * @param mimeContents
2494:             * @return
2495:             */
2496:            private JAXBType getAttachmentType(List<MIMEContent> mimeContents,
2497:                    MessagePart part) {
2498:                if (!enableMimeContent()) {
2499:                    return getJAXBType(part);
2500:                }
2501:                String javaType = null;
2502:                List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
2503:                if (mimeTypes.size() > 1) {
2504:                    javaType = "javax.activation.DataHandler";
2505:                } else {
2506:                    javaType = getJavaTypeForMimeType(mimeTypes.get(0));
2507:                }
2508:
2509:                S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel()
2510:                        .getS2JJAXBModel();
2511:                JCodeModel cm = jaxbModel.generateCode(null,
2512:                        new ConsoleErrorReporter(getEnvironment(), false));
2513:                JType jt = null;
2514:                jt = cm.ref(javaType);
2515:                QName desc = part.getDescriptor();
2516:                TypeAndAnnotation typeAnno = null;
2517:
2518:                if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
2519:                    typeAnno = jaxbModel.getJavaType(desc);
2520:                    desc = new QName("", part.getName());
2521:                } else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
2522:                    typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
2523:                    for (Iterator mimeTypeIter = mimeTypes.iterator(); mimeTypeIter
2524:                            .hasNext();) {
2525:                        String mimeType = (String) mimeTypeIter.next();
2526:                        if ((!mimeType.equals("text/xml") && !mimeType
2527:                                .equals("application/xml"))) {
2528:                            //According to AP 1.0,
2529:                            //RZZZZ: In a DESCRIPTION, if a wsdl:part element refers to a
2530:                            //global element declaration (via the element attribute of the wsdl:part
2531:                            //element) then the value of the type attribute of a mime:content element
2532:                            //that binds that part MUST be a content type suitable for carrying an
2533:                            //XML serialization.
2534:                            //should we throw warning?
2535:                            //type = MimeHelper.javaType.DATA_HANDLER_JAVATYPE;
2536:                            warn(
2537:                                    "mimemodeler.elementPart.invalidElementMimeType",
2538:                                    new Object[] { part.getName(), mimeType });
2539:                        }
2540:                    }
2541:                }
2542:                if (typeAnno == null) {
2543:                    fail("wsdlmodeler.jaxb.javatype.notfound", new Object[] {
2544:                            desc, part.getName() });
2545:                }
2546:                return new JAXBType(desc, new JavaSimpleType(
2547:                        new JAXBTypeAndAnnotation(typeAnno, jt)), null,
2548:                        getJAXBModelBuilder().getJAXBModel());
2549:            }
2550:
2551:            protected void buildJAXBModel(WSDLDocument wsdlDocument,
2552:                    WSDLModelInfo modelInfo,
2553:                    ClassNameCollector classNameCollector) {
2554:                JAXBModelBuilder jaxbModelBuilder = new JAXBModelBuilder(
2555:                        getWSDLModelInfo(), _options, classNameCollector,
2556:                        parser.getSchemaElements());
2557:                //set the java package where wsdl artifacts will be generated
2558:                //if user provided package name  using -p switch (or package property on wsimport ant task)
2559:                //ignore the package customization in the wsdl and schema bidnings
2560:                if (getWSDLModelInfo().getDefaultJavaPackage() != null) {
2561:                    getWSDLModelInfo().setJavaPackageName(
2562:                            getWSDLModelInfo().getDefaultJavaPackage());
2563:                    jaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(
2564:                            getWSDLModelInfo().getJavaPackageName());
2565:                } else {
2566:                    String jaxwsPackage = getJavaPackage();
2567:                    getWSDLModelInfo().setJavaPackageName(jaxwsPackage);
2568:                }
2569:
2570:                //create pseudo schema for async operations(if any) response bean
2571:                List<InputSource> schemas = PseudoSchemaBuilder.build(this ,
2572:                        _modelInfo);
2573:                for (InputSource schema : schemas) {
2574:                    jaxbModelBuilder.getJAXBSchemaCompiler()
2575:                            .parseSchema(schema);
2576:                }
2577:                jaxbModelBuilder.bind();
2578:                this .jaxbModelBuilder = jaxbModelBuilder;
2579:            }
2580:
2581:            protected String getJavaPackage() {
2582:                String jaxwsPackage = null;
2583:                JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(
2584:                        document.getDefinitions(), JAXWSBinding.class);
2585:                if (jaxwsCustomization != null
2586:                        && jaxwsCustomization.getJaxwsPackage() != null) {
2587:                    jaxwsPackage = jaxwsCustomization.getJaxwsPackage()
2588:                            .getName();
2589:                }
2590:                if (jaxwsPackage != null) {
2591:                    return jaxwsPackage;
2592:                }
2593:                String wsdlUri = document.getDefinitions()
2594:                        .getTargetNamespaceURI();
2595:                return XJC.getDefaultPackageName(wsdlUri);
2596:
2597:            }
2598:
2599:            protected void createJavaInterfaceForProviderPort(Port port) {
2600:                String interfaceName = "javax.xml.ws.Provider";
2601:                JavaInterface intf = new JavaInterface(interfaceName);
2602:                port.setJavaInterface(intf);
2603:            }
2604:
2605:            protected void createJavaInterfaceForPort(Port port,
2606:                    boolean isProvider) {
2607:                if (isProvider) {
2608:                    createJavaInterfaceForProviderPort(port);
2609:                    return;
2610:                }
2611:                String interfaceName = getJavaNameOfSEI(port);
2612:
2613:                if (isConflictingPortClassName(interfaceName)) {
2614:                    interfaceName += "_PortType";
2615:                }
2616:
2617:                JavaInterface intf = new JavaInterface(interfaceName);
2618:                for (Operation operation : port.getOperations()) {
2619:                    createJavaMethodForOperation(port, operation, intf);
2620:
2621:                    for (JavaParameter jParam : operation.getJavaMethod()
2622:                            .getParametersList()) {
2623:                        Parameter param = jParam.getParameter();
2624:                        if (param.getCustomName() != null)
2625:                            jParam.setName(param.getCustomName());
2626:                    }
2627:                }
2628:
2629:                port.setJavaInterface(intf);
2630:            }
2631:
2632:            protected String getServiceInterfaceName(QName serviceQName,
2633:                    com.sun.tools.internal.ws.wsdl.document.Service wsdlService) {
2634:                String serviceName = wsdlService.getName();
2635:                JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(
2636:                        wsdlService, JAXWSBinding.class);
2637:                if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2638:                    CustomName name = jaxwsCust.getClassName();
2639:                    if (name != null && !name.equals(""))
2640:                        serviceName = name.getName();
2641:                }
2642:                String serviceInterface = "";
2643:                String javaPackageName = null;
2644:                if (_modelInfo.getJavaPackageName() != null
2645:                        && !_modelInfo.getJavaPackageName().equals("")) {
2646:                    javaPackageName = _modelInfo.getJavaPackageName();
2647:                }
2648:                if (javaPackageName != null) {
2649:                    serviceInterface = javaPackageName + ".";
2650:                }
2651:                serviceInterface += getEnvironment().getNames()
2652:                        .validJavaClassName(serviceName);
2653:                return serviceInterface;
2654:            }
2655:
2656:            protected String getJavaNameOfSEI(Port port) {
2657:                QName portTypeName = (QName) port
2658:                        .getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
2659:                PortType pt = (PortType) document.find(Kinds.PORT_TYPE,
2660:                        portTypeName);
2661:                JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(pt,
2662:                        JAXWSBinding.class);
2663:                if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2664:                    CustomName name = jaxwsCust.getClassName();
2665:                    if (name != null && !name.equals("")) {
2666:                        return makePackageQualified(name.getName(),
2667:                                portTypeName, false);
2668:                    }
2669:                }
2670:
2671:                String interfaceName = null;
2672:                if (portTypeName != null) {
2673:                    // got portType information from WSDL, use it to name the interface
2674:                    interfaceName = makePackageQualified(
2675:                            JAXBRIContext.mangleNameToClassName(portTypeName
2676:                                    .getLocalPart()), portTypeName, false);
2677:                } else {
2678:                    // somehow we only got the port name, so we use that
2679:                    interfaceName = makePackageQualified(JAXBRIContext
2680:                            .mangleNameToClassName(port.getName()
2681:                                    .getLocalPart()), port.getName(), false);
2682:                }
2683:                return interfaceName;
2684:            }
2685:
2686:            private void createJavaMethodForAsyncOperation(Port port,
2687:                    Operation operation, JavaInterface intf) {
2688:                String candidateName = getJavaNameForOperation(operation);
2689:                JavaMethod method = new JavaMethod(candidateName);
2690:                method.setThrowsRemoteException(false);
2691:                Request request = operation.getRequest();
2692:                Iterator requestBodyBlocks = request.getBodyBlocks();
2693:                Block requestBlock = (requestBodyBlocks.hasNext() ? (Block) request
2694:                        .getBodyBlocks().next()
2695:                        : null);
2696:
2697:                Response response = operation.getResponse();
2698:                Iterator responseBodyBlocks = null;
2699:                Block responseBlock = null;
2700:                if (response != null) {
2701:                    responseBodyBlocks = response.getBodyBlocks();
2702:                    responseBlock = responseBodyBlocks.hasNext() ? (Block) response
2703:                            .getBodyBlocks().next()
2704:                            : null;
2705:                }
2706:
2707:                // build a signature of the form "opName%arg1type%arg2type%...%argntype so that we
2708:                // detect overloading conflicts in the generated java interface/classes
2709:                String signature = candidateName;
2710:                for (Iterator iter = request.getParameters(); iter.hasNext();) {
2711:                    Parameter parameter = (Parameter) iter.next();
2712:
2713:                    if (parameter.getJavaParameter() != null) {
2714:                        throw new ModelerException(
2715:                                "wsdlmodeler.invalidOperation", operation
2716:                                        .getName().getLocalPart());
2717:                    }
2718:
2719:                    JavaType parameterType = parameter.getType().getJavaType();
2720:                    JavaParameter javaParameter = new JavaParameter(
2721:                            JAXBRIContext.mangleNameToVariableName(parameter
2722:                                    .getName()), parameterType, parameter,
2723:                            parameter.getLinkedParameter() != null);
2724:                    if (javaParameter.isHolder()) {
2725:                        javaParameter.setHolderName(javax.xml.ws.Holder.class
2726:                                .getName());
2727:                    }
2728:                    method.addParameter(javaParameter);
2729:                    parameter.setJavaParameter(javaParameter);
2730:
2731:                    signature += "%" + parameterType.getName();
2732:                }
2733:
2734:                if (response != null) {
2735:                    String resultParameterName = (String) operation
2736:                            .getProperty(WSDL_RESULT_PARAMETER);
2737:                    Parameter resultParameter = response
2738:                            .getParameterByName(resultParameterName);
2739:                    JavaType returnType = resultParameter.getType()
2740:                            .getJavaType();
2741:                    method.setReturnType(returnType);
2742:
2743:                }
2744:                operation.setJavaMethod(method);
2745:                intf.addMethod(method);
2746:            }
2747:
2748:            /* (non-Javadoc)
2749:             * @see WSDLModelerBase#createJavaMethodForOperation(Port, Operation, JavaInterface, Set, Set)
2750:             */
2751:            protected void createJavaMethodForOperation(Port port,
2752:                    Operation operation, JavaInterface intf) {
2753:                if ((operation instanceof  AsyncOperation)) {
2754:                    createJavaMethodForAsyncOperation(port, operation, intf);
2755:                    return;
2756:                }
2757:                String candidateName = getJavaNameForOperation(operation);
2758:                JavaMethod method = new JavaMethod(candidateName);
2759:                Request request = operation.getRequest();
2760:                Parameter returnParam = (Parameter) operation
2761:                        .getProperty(WSDL_RESULT_PARAMETER);
2762:                if (returnParam != null) {
2763:                    JavaType parameterType = returnParam.getType()
2764:                            .getJavaType();
2765:                    method.setReturnType(parameterType);
2766:                } else {
2767:                    JavaType ret = new JavaSimpleTypeCreator().VOID_JAVATYPE;
2768:                    method.setReturnType(ret);
2769:                }
2770:                List<Parameter> parameterOrder = (List<Parameter>) operation
2771:                        .getProperty(WSDL_PARAMETER_ORDER);
2772:                for (Parameter param : parameterOrder) {
2773:                    JavaType parameterType = param.getType().getJavaType();
2774:                    String name = (param.getCustomName() != null) ? param
2775:                            .getCustomName() : param.getName();
2776:                    JavaParameter javaParameter = new JavaParameter(
2777:                            JAXBRIContext.mangleNameToVariableName(name),
2778:                            parameterType, param, param.isINOUT()
2779:                                    || param.isOUT());
2780:                    if (javaParameter.isHolder()) {
2781:                        javaParameter.setHolderName(javax.xml.ws.Holder.class
2782:                                .getName());
2783:                    }
2784:                    method.addParameter(javaParameter);
2785:                    param.setJavaParameter(javaParameter);
2786:                }
2787:                operation.setJavaMethod(method);
2788:                intf.addMethod(method);
2789:
2790:                String opName = JAXBRIContext
2791:                        .mangleNameToVariableName(operation.getName()
2792:                                .getLocalPart());
2793:                for (Iterator iter = operation.getFaults(); iter != null
2794:                        && iter.hasNext();) {
2795:                    Fault fault = (Fault) iter.next();
2796:                    createJavaExceptionFromLiteralType(fault, port, opName);
2797:                }
2798:                JavaException javaException;
2799:                Fault fault;
2800:                for (Iterator iter = operation.getFaults(); iter.hasNext();) {
2801:                    fault = (Fault) iter.next();
2802:                    javaException = fault.getJavaException();
2803:                    method.addException(javaException.getName());
2804:                }
2805:
2806:            }
2807:
2808:            protected boolean createJavaExceptionFromLiteralType(Fault fault,
2809:                    com.sun.tools.internal.ws.processor.model.Port port,
2810:                    String operationName) {
2811:                ProcessorEnvironment _env = getProcessorEnvironment();
2812:
2813:                JAXBType faultType = (JAXBType) fault.getBlock().getType();
2814:
2815:                String exceptionName = makePackageQualified(_env.getNames()
2816:                        .validJavaClassName(fault.getName()), port.getName());
2817:
2818:                // use fault namespace attribute
2819:                JAXBStructuredType jaxbStruct = new JAXBStructuredType(
2820:                        new QName(fault.getBlock().getName().getNamespaceURI(),
2821:                                fault.getName()));
2822:
2823:                QName memberName = fault.getElementName();
2824:                JAXBElementMember jaxbMember = new JAXBElementMember(
2825:                        memberName, faultType);
2826:                //jaxbMember.setNillable(faultType.isNillable());
2827:
2828:                String javaMemberName = getLiteralJavaMemberName(fault);
2829:                JavaStructureMember javaMember = new JavaStructureMember(
2830:                        javaMemberName, faultType.getJavaType(), jaxbMember);
2831:                jaxbMember.setJavaStructureMember(javaMember);
2832:                javaMember.setReadMethod(_env.getNames()
2833:                        .getJavaMemberReadMethod(javaMember));
2834:                javaMember.setInherited(false);
2835:                jaxbMember.setJavaStructureMember(javaMember);
2836:                jaxbStruct.add(jaxbMember);
2837:
2838:                if (isConflictingExceptionClassName(exceptionName)) {
2839:                    exceptionName += "_Exception";
2840:                }
2841:
2842:                JavaException existingJavaException = (JavaException) _javaExceptions
2843:                        .get(exceptionName);
2844:                if (existingJavaException != null) {
2845:                    if (existingJavaException.getName().equals(exceptionName)) {
2846:                        if (((JAXBType) existingJavaException.getOwner())
2847:                                .getName().equals(jaxbStruct.getName())
2848:                                || ModelerUtils
2849:                                        .isEquivalentLiteralStructures(
2850:                                                jaxbStruct,
2851:                                                (JAXBStructuredType) existingJavaException
2852:                                                        .getOwner())) {
2853:                            // we have mapped this fault already
2854:                            if (faultType instanceof  JAXBStructuredType) {
2855:                                fault.getBlock().setType(
2856:                                        (JAXBType) existingJavaException
2857:                                                .getOwner());
2858:                            }
2859:                            fault.setJavaException(existingJavaException);
2860:                            return false;
2861:                        }
2862:                    }
2863:                }
2864:
2865:                JavaException javaException = new JavaException(exceptionName,
2866:                        false, jaxbStruct);
2867:                javaException.add(javaMember);
2868:                jaxbStruct.setJavaType(javaException);
2869:
2870:                _javaExceptions.put(javaException.getName(), javaException);
2871:
2872:                fault.setJavaException(javaException);
2873:                return true;
2874:            }
2875:
2876:            protected boolean isRequestResponse() {
2877:                return info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
2878:            }
2879:
2880:            protected java.util.List<String> getAsynParameterOrder() {
2881:                //for async operation ignore the parameterOrder
2882:                java.util.List<String> parameterList = new ArrayList<String>();
2883:                Message inputMessage = getInputMessage();
2884:                List<MessagePart> inputParts = inputMessage.getParts();
2885:                for (MessagePart part : inputParts) {
2886:                    parameterList.add(part.getName());
2887:                }
2888:                return parameterList;
2889:            }
2890:
2891:            protected List<MessagePart> getParameterOrder() {
2892:                List<MessagePart> params = new ArrayList<MessagePart>();
2893:                String parameterOrder = info.portTypeOperation
2894:                        .getParameterOrder();
2895:                java.util.List<String> parameterList = new ArrayList<String>();
2896:                boolean parameterOrderPresent = false;
2897:                if ((parameterOrder != null)
2898:                        && !(parameterOrder.trim().equals(""))) {
2899:                    parameterList = XmlUtil.parseTokenList(parameterOrder);
2900:                    parameterOrderPresent = true;
2901:                } else {
2902:                    parameterList = new ArrayList<String>();
2903:                }
2904:                Message inputMessage = getInputMessage();
2905:                Message outputMessage = getOutputMessage();
2906:                List<MessagePart> outputParts = null;
2907:                List<MessagePart> inputParts = inputMessage.getParts();
2908:                //reset the mode and ret flag, as MEssagePArts aer shared across ports
2909:                for (MessagePart part : inputParts) {
2910:                    part.setMode(Mode.IN);
2911:                    part.setReturn(false);
2912:                }
2913:                if (isRequestResponse()) {
2914:                    outputParts = outputMessage.getParts();
2915:                    for (MessagePart part : outputParts) {
2916:                        part.setMode(Mode.OUT);
2917:                        part.setReturn(false);
2918:                    }
2919:                }
2920:
2921:                if (parameterOrderPresent) {
2922:                    boolean validParameterOrder = true;
2923:                    Iterator<String> paramOrders = parameterList.iterator();
2924:                    // If any part in the parameterOrder is not present in the request or
2925:                    // response message, we completely ignore the parameterOrder hint
2926:                    while (paramOrders.hasNext()) {
2927:                        String param = paramOrders.next();
2928:                        boolean partFound = false;
2929:                        for (MessagePart part : inputParts) {
2930:                            if (param.equals(part.getName())) {
2931:                                partFound = true;
2932:                                break;
2933:                            }
2934:                        }
2935:                        // if not found, check in output parts
2936:                        if (!partFound) {
2937:                            for (MessagePart part : outputParts) {
2938:                                if (param.equals(part.getName())) {
2939:                                    partFound = true;
2940:                                    break;
2941:                                }
2942:                            }
2943:                        }
2944:                        if (!partFound) {
2945:                            warn(
2946:                                    "wsdlmodeler.invalid.parameterorder.parameter",
2947:                                    new Object[] {
2948:                                            param,
2949:                                            info.operation.getName()
2950:                                                    .getLocalPart() });
2951:                            validParameterOrder = false;
2952:                        }
2953:                    }
2954:
2955:                    List<MessagePart> inputUnlistedParts = new ArrayList<MessagePart>();
2956:                    List<MessagePart> outputUnlistedParts = new ArrayList<MessagePart>();
2957:
2958:                    //gather input Parts
2959:                    if (validParameterOrder) {
2960:                        for (String param : parameterList) {
2961:                            MessagePart part = inputMessage.getPart(param);
2962:                            if (part != null) {
2963:                                params.add(part);
2964:                                continue;
2965:                            }
2966:                            if (isRequestResponse()) {
2967:                                MessagePart outPart = outputMessage
2968:                                        .getPart(param);
2969:                                if (outPart != null) {
2970:                                    params.add(outPart);
2971:                                    continue;
2972:                                }
2973:                            }
2974:                        }
2975:
2976:                        for (MessagePart part : inputParts) {
2977:                            if (!parameterList.contains(part.getName())) {
2978:                                inputUnlistedParts.add(part);
2979:                            }
2980:                        }
2981:
2982:                        if (isRequestResponse()) {
2983:                            // at most one output part should be unlisted
2984:                            for (MessagePart part : outputParts) {
2985:                                if (!parameterList.contains(part.getName())) {
2986:                                    MessagePart inPart = inputMessage
2987:                                            .getPart(part.getName());
2988:                                    //dont add inout as unlisted part
2989:                                    if ((inPart != null)
2990:                                            && inPart.getDescriptor().equals(
2991:                                                    part.getDescriptor())) {
2992:                                        inPart.setMode(Mode.INOUT);
2993:                                    } else {
2994:                                        outputUnlistedParts.add(part);
2995:                                    }
2996:                                } else {
2997:                                    //param list may contain it, check if its INOUT
2998:                                    MessagePart inPart = inputMessage
2999:                                            .getPart(part.getName());
3000:                                    //dont add inout as unlisted part
3001:                                    if ((inPart != null)
3002:                                            && inPart.getDescriptor().equals(
3003:                                                    part.getDescriptor())) {
3004:                                        inPart.setMode(Mode.INOUT);
3005:                                    } else if (!params.contains(part)) {
3006:                                        params.add(part);
3007:                                    }
3008:                                }
3009:                            }
3010:                            if (outputUnlistedParts.size() == 1) {
3011:                                MessagePart resultPart = outputUnlistedParts
3012:                                        .get(0);
3013:                                resultPart.setReturn(true);
3014:                                params.add(resultPart);
3015:                                outputUnlistedParts.clear();
3016:                            }
3017:                        }
3018:
3019:                        //add the input and output unlisted parts
3020:                        for (MessagePart part : inputUnlistedParts) {
3021:                            params.add(part);
3022:                        }
3023:
3024:                        for (MessagePart part : outputUnlistedParts) {
3025:                            params.add(part);
3026:                        }
3027:                        return params;
3028:
3029:                    }
3030:                    //parameterOrder attribute is not valid, we ignore it
3031:                    warn(
3032:                            "wsdlmodeler.invalid.parameterOrder.invalidParameterOrder",
3033:                            new Object[] { info.operation.getName()
3034:                                    .getLocalPart() });
3035:                    parameterOrderPresent = false;
3036:                    parameterList.clear();
3037:                }
3038:
3039:                List<MessagePart> outParts = new ArrayList<MessagePart>();
3040:
3041:                //construct input parameter list with the same order as in input message
3042:                for (MessagePart part : inputParts) {
3043:                    params.add(part);
3044:                }
3045:
3046:                if (isRequestResponse()) {
3047:                    for (MessagePart part : outputParts) {
3048:                        MessagePart inPart = inputMessage.getPart(part
3049:                                .getName());
3050:                        if (inPart != null
3051:                                && part.getDescriptorKind() == inPart
3052:                                        .getDescriptorKind()
3053:                                && part.getDescriptor().equals(
3054:                                        inPart.getDescriptor())) {
3055:                            inPart.setMode(Mode.INOUT);
3056:                            continue;
3057:                        }
3058:                        outParts.add(part);
3059:                    }
3060:
3061:                    //append the out parts to the parameterList
3062:                    for (MessagePart part : outParts) {
3063:                        if (outParts.size() == 1)
3064:                            part.setReturn(true);
3065:                        params.add(part);
3066:                    }
3067:                }
3068:                return params;
3069:            }
3070:
3071:            /**
3072:             *
3073:             * @param port
3074:             * @param suffix
3075:             * @return the Java ClassName for a port
3076:             */
3077:            protected String getClassName(Port port, String suffix) {
3078:                String name = "";
3079:                String javaPackageName = "";
3080:                if (_modelInfo.getJavaPackageName() != null
3081:                        && !_modelInfo.getJavaPackageName().equals("")) {
3082:                    javaPackageName = _modelInfo.getJavaPackageName();
3083:                }
3084:                String prefix = getEnvironment().getNames().validJavaClassName(
3085:                        port.getName().getLocalPart());
3086:                name = javaPackageName + "." + prefix + suffix;
3087:                return name;
3088:            }
3089:
3090:            protected boolean isConflictingServiceClassName(String name) {
3091:                if (conflictsWithSEIClass(name) || conflictsWithJAXBClass(name)
3092:                        || conflictsWithExceptionClass(name)) {
3093:                    return true;
3094:                }
3095:                return false;
3096:            }
3097:
3098:            private boolean conflictsWithSEIClass(String name) {
3099:                Set<String> seiNames = classNameCollector.getSeiClassNames();
3100:                if (seiNames != null && seiNames.contains(name))
3101:                    return true;
3102:                return false;
3103:            }
3104:
3105:            private boolean conflictsWithJAXBClass(String name) {
3106:                Set<String> jaxbNames = classNameCollector
3107:                        .getJaxbGeneratedClassNames();
3108:                if (jaxbNames != null && jaxbNames.contains(name))
3109:                    return true;
3110:                return false;
3111:            }
3112:
3113:            private boolean conflictsWithExceptionClass(String name) {
3114:                Set<String> exceptionNames = classNameCollector
3115:                        .getExceptionClassNames();
3116:                if (exceptionNames != null && exceptionNames.contains(name))
3117:                    return true;
3118:                return false;
3119:            }
3120:
3121:            protected boolean isConflictingExceptionClassName(String name) {
3122:                if (conflictsWithSEIClass(name) || conflictsWithJAXBClass(name)) {
3123:                    return true;
3124:                }
3125:                return false;
3126:            }
3127:
3128:            protected JAXBModelBuilder getJAXBModelBuilder() {
3129:                return jaxbModelBuilder;
3130:            }
3131:
3132:            protected boolean validateWSDLBindingStyle(Binding binding) {
3133:                boolean mixedStyle = false;
3134:                SOAPBinding soapBinding = (SOAPBinding) getExtensionOfType(
3135:                        binding, SOAPBinding.class);
3136:
3137:                //dont process the binding
3138:                if (soapBinding == null)
3139:                    soapBinding = (SOAPBinding) getExtensionOfType(binding,
3140:                            SOAP12Binding.class);
3141:                if (soapBinding == null)
3142:                    return false;
3143:
3144:                //if soapbind:binding has no style attribute, the default is DOCUMENT
3145:                if (soapBinding.getStyle() == null)
3146:                    soapBinding.setStyle(SOAPStyle.DOCUMENT);
3147:
3148:                SOAPStyle opStyle = soapBinding.getStyle();
3149:                for (Iterator iter = binding.operations(); iter.hasNext();) {
3150:                    BindingOperation bindingOperation = (BindingOperation) iter
3151:                            .next();
3152:                    SOAPOperation soapOperation = (SOAPOperation) getExtensionOfType(
3153:                            bindingOperation, SOAPOperation.class);
3154:                    if (soapOperation != null) {
3155:                        SOAPStyle currOpStyle = (soapOperation.getStyle() != null) ? soapOperation
3156:                                .getStyle()
3157:                                : soapBinding.getStyle();
3158:                        //dont check for the first operation
3159:                        if (!currOpStyle.equals(opStyle))
3160:                            return false;
3161:                    }
3162:                }
3163:                return true;
3164:            }
3165:
3166:            /**
3167:             * @param port
3168:             */
3169:            private void applyWrapperStyleCustomization(Port port,
3170:                    PortType portType) {
3171:                JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(
3172:                        portType, JAXWSBinding.class);
3173:                Boolean wrapperStyle = (jaxwsBinding != null) ? jaxwsBinding
3174:                        .isEnableWrapperStyle() : null;
3175:                if (wrapperStyle != null) {
3176:                    port.setWrapped(wrapperStyle);
3177:                }
3178:            }
3179:
3180:            protected static void setDocumentationIfPresent(ModelObject obj,
3181:                    Documentation documentation) {
3182:                if (documentation != null && documentation.getContent() != null) {
3183:                    obj.setJavaDoc(documentation.getContent());
3184:                }
3185:            }
3186:
3187:            protected String getJavaNameForOperation(Operation operation) {
3188:                String name = operation.getJavaMethodName();
3189:                if (getEnvironment().getNames().isJavaReservedWord(name)) {
3190:                    name = "_" + name;
3191:                }
3192:                return name;
3193:            }
3194:
3195:            protected void fail(String key, String arg) {
3196:                throw new ModelerException(key, arg);
3197:            }
3198:
3199:            protected void fail(String key, Object[] args) {
3200:                throw new ModelerException(key, args);
3201:            }
3202:        }
ww___w.___j_a___v__a_2__s___.___c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.