src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLModelImpl.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.model.wsdl;
    28 import com.sun.istack.internal.NotNull;
    29 import com.sun.xml.internal.ws.api.model.ParameterBinding;
    30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
    31 import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage;
    32 import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel;
    33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
    34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType;
    36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
    37 import com.sun.xml.internal.ws.policy.PolicyMap;
    39 import javax.jws.WebParam.Mode;
    40 import javax.xml.namespace.QName;
    41 import java.net.URL;
    42 import java.util.Collections;
    43 import java.util.HashMap;
    44 import java.util.Iterator;
    45 import java.util.LinkedHashMap;
    46 import java.util.Map;
    48 /**
    49  * Implementation of {@link WSDLModel}
    50  *
    51  * @author Vivek Pandey
    52  */
    53 public final class WSDLModelImpl extends AbstractExtensibleImpl implements WSDLModel {
    54     private final Map<QName, WSDLMessageImpl> messages = new HashMap<QName, WSDLMessageImpl>();
    55     private final Map<QName, WSDLPortTypeImpl> portTypes = new HashMap<QName, WSDLPortTypeImpl>();
    56     private final Map<QName, WSDLBoundPortTypeImpl> bindings = new HashMap<QName, WSDLBoundPortTypeImpl>();
    57     private final Map<QName, WSDLServiceImpl> services = new LinkedHashMap<QName, WSDLServiceImpl>();
    59     private PolicyMap policyMap;
    60     private final Map<QName,WSDLBoundPortType> unmBindings
    61         = Collections.<QName,WSDLBoundPortType>unmodifiableMap(bindings);
    64     public WSDLModelImpl(@NotNull String systemId) {
    65         super(systemId,-1);
    66     }
    68     /**
    69      * To create {@link WSDLModelImpl} from WSDL that doesn't have a system ID.
    70      */
    71     public WSDLModelImpl() {
    72         super(null,-1);
    73     }
    75     public void addMessage(WSDLMessageImpl msg){
    76         messages.put(msg.getName(), msg);
    77     }
    79     public WSDLMessageImpl getMessage(QName name){
    80         return messages.get(name);
    81     }
    83     public void addPortType(WSDLPortTypeImpl pt){
    84         portTypes.put(pt.getName(), pt);
    85     }
    87     public WSDLPortTypeImpl getPortType(QName name){
    88         return portTypes.get(name);
    89     }
    91     public void addBinding(WSDLBoundPortTypeImpl boundPortType){
    92         assert !bindings.containsValue(boundPortType);
    93         bindings.put(boundPortType.getName(), boundPortType);
    94     }
    96     public WSDLBoundPortTypeImpl getBinding(QName name){
    97         return bindings.get(name);
    98     }
   100     public void addService(WSDLServiceImpl svc){
   101         services.put(svc.getName(), svc);
   102     }
   104     public WSDLServiceImpl getService(QName name){
   105         return services.get(name);
   106     }
   108     public Map<QName, WSDLMessageImpl> getMessages() {
   109         return messages;
   110     }
   112     public @NotNull Map<QName, WSDLPortTypeImpl> getPortTypes() {
   113         return portTypes;
   114     }
   116     public @NotNull Map<QName, WSDLBoundPortType> getBindings() {
   117         return unmBindings;
   118     }
   120     public @NotNull Map<QName, WSDLServiceImpl> getServices(){
   121         return services;
   122     }
   124     /**
   125      * Returns the first service QName from insertion order
   126      */
   127     public QName getFirstServiceName(){
   128         if(services.isEmpty())
   129             return null;
   130         return services.values().iterator().next().getName();
   131     }
   133     /**
   134      * Returns first port QName from first service as per the insertion order
   135      */
   136     public QName getFirstPortName(){
   137         WSDLPort fp = getFirstPort();
   138         if(fp==null)
   139             return null;
   140         else
   141             return fp.getName();
   142     }
   144     private WSDLPort getFirstPort(){
   145         if(services.isEmpty())
   146             return null;
   147         WSDLService service = services.values().iterator().next();
   148         Iterator<? extends WSDLPort> iter = service.getPorts().iterator();
   149         WSDLPort port = iter.hasNext()?iter.next():null;
   150         return port;
   151     }
   153     /**
   154     * gets the first port in the wsdl which matches the serviceName and portType
   155     */
   156     public WSDLPortImpl getMatchingPort(QName serviceName, QName portType){
   157         return getService(serviceName).getMatchingPort(portType);
   158     }
   160     /**
   161      *
   162      * @param serviceName non-null service QName
   163      * @param portName    non-null port QName
   164      * @return
   165      *          WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null
   166      */
   167     public WSDLBoundPortTypeImpl getBinding(QName serviceName, QName portName){
   168         WSDLServiceImpl service = services.get(serviceName);
   169         if(service != null){
   170             WSDLPortImpl port = service.get(portName);
   171             if(port != null)
   172                 return port.getBinding();
   173         }
   174         return null;
   175     }
   177     void finalizeRpcLitBinding(WSDLBoundPortTypeImpl boundPortType){
   178         assert(boundPortType != null);
   179         QName portTypeName = boundPortType.getPortTypeName();
   180         if(portTypeName == null)
   181             return;
   182         WSDLPortType pt = portTypes.get(portTypeName);
   183         if(pt == null)
   184             return;
   185         for (WSDLBoundOperationImpl bop : boundPortType.getBindingOperations()) {
   186             WSDLOperation pto = pt.get(bop.getName().getLocalPart());
   187             WSDLMessage inMsgName = pto.getInput().getMessage();
   188             if(inMsgName == null)
   189                 continue;
   190             WSDLMessageImpl inMsg = messages.get(inMsgName.getName());
   191             int bodyindex = 0;
   192             if(inMsg != null){
   193                 for(WSDLPartImpl part:inMsg.parts()){
   194                     String name = part.getName();
   195                     ParameterBinding pb = bop.getInputBinding(name);
   196                     if(pb.isBody()){
   197                         part.setIndex(bodyindex++);
   198                         part.setBinding(pb);
   199                         bop.addPart(part, Mode.IN);
   200                     }
   201                 }
   202             }
   203             bodyindex=0;
   204             if(pto.isOneWay())
   205                 continue;
   206             WSDLMessage outMsgName = pto.getOutput().getMessage();
   207             if(outMsgName == null)
   208                 continue;
   209             WSDLMessageImpl outMsg = messages.get(outMsgName.getName());
   210             if(outMsg!= null){
   211                 for(WSDLPartImpl part:outMsg.parts()){
   212                     String name = part.getName();
   213                     ParameterBinding pb = bop.getOutputBinding(name);
   214                     if(pb.isBody()){
   215                         part.setIndex(bodyindex++);
   216                         part.setBinding(pb);
   217                         bop.addPart(part, Mode.OUT);
   218                     }
   219                 }
   220             }
   221         }
   222     }
   224     /**
   225      * Gives the PolicyMap associated with the WSDLModel
   226      *
   227      * @return PolicyMap
   228      */
   229     public PolicyMap getPolicyMap() {
   230         return policyMap;
   231     }
   233     /**
   234      * Set PolicyMap for the WSDLModel.
   235      * @param policyMap
   236      */
   237     public void setPolicyMap(PolicyMap policyMap) {
   238         this.policyMap = policyMap;
   239     }
   241     /**
   242      * Invoked at the end of the model construction to fix up references, etc.
   243      */
   244     public void freeze() {
   245         for (WSDLServiceImpl service : services.values()) {
   246             service.freeze(this);
   247         }
   248         for (WSDLBoundPortTypeImpl bp : bindings.values()) {
   249             bp.freeze();
   250         }
   251         // Enforce freeze all the portTypes referenced by this endpoints, see Bug8966673 for detail
   252         for (WSDLPortTypeImpl pt : portTypes.values()) {
   253             pt.freeze();
   254         }
   255     }
   256 }

mercurial