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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/model/wsdl/WSDLModelImpl.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,256 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.model.wsdl;
    1.30 +
    1.31 +import com.sun.istack.internal.NotNull;
    1.32 +import com.sun.xml.internal.ws.api.model.ParameterBinding;
    1.33 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
    1.34 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage;
    1.35 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel;
    1.36 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
    1.37 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.38 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType;
    1.39 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
    1.40 +import com.sun.xml.internal.ws.policy.PolicyMap;
    1.41 +
    1.42 +import javax.jws.WebParam.Mode;
    1.43 +import javax.xml.namespace.QName;
    1.44 +import java.net.URL;
    1.45 +import java.util.Collections;
    1.46 +import java.util.HashMap;
    1.47 +import java.util.Iterator;
    1.48 +import java.util.LinkedHashMap;
    1.49 +import java.util.Map;
    1.50 +
    1.51 +/**
    1.52 + * Implementation of {@link WSDLModel}
    1.53 + *
    1.54 + * @author Vivek Pandey
    1.55 + */
    1.56 +public final class WSDLModelImpl extends AbstractExtensibleImpl implements WSDLModel {
    1.57 +    private final Map<QName, WSDLMessageImpl> messages = new HashMap<QName, WSDLMessageImpl>();
    1.58 +    private final Map<QName, WSDLPortTypeImpl> portTypes = new HashMap<QName, WSDLPortTypeImpl>();
    1.59 +    private final Map<QName, WSDLBoundPortTypeImpl> bindings = new HashMap<QName, WSDLBoundPortTypeImpl>();
    1.60 +    private final Map<QName, WSDLServiceImpl> services = new LinkedHashMap<QName, WSDLServiceImpl>();
    1.61 +
    1.62 +    private PolicyMap policyMap;
    1.63 +    private final Map<QName,WSDLBoundPortType> unmBindings
    1.64 +        = Collections.<QName,WSDLBoundPortType>unmodifiableMap(bindings);
    1.65 +
    1.66 +
    1.67 +    public WSDLModelImpl(@NotNull String systemId) {
    1.68 +        super(systemId,-1);
    1.69 +    }
    1.70 +
    1.71 +    /**
    1.72 +     * To create {@link WSDLModelImpl} from WSDL that doesn't have a system ID.
    1.73 +     */
    1.74 +    public WSDLModelImpl() {
    1.75 +        super(null,-1);
    1.76 +    }
    1.77 +
    1.78 +    public void addMessage(WSDLMessageImpl msg){
    1.79 +        messages.put(msg.getName(), msg);
    1.80 +    }
    1.81 +
    1.82 +    public WSDLMessageImpl getMessage(QName name){
    1.83 +        return messages.get(name);
    1.84 +    }
    1.85 +
    1.86 +    public void addPortType(WSDLPortTypeImpl pt){
    1.87 +        portTypes.put(pt.getName(), pt);
    1.88 +    }
    1.89 +
    1.90 +    public WSDLPortTypeImpl getPortType(QName name){
    1.91 +        return portTypes.get(name);
    1.92 +    }
    1.93 +
    1.94 +    public void addBinding(WSDLBoundPortTypeImpl boundPortType){
    1.95 +        assert !bindings.containsValue(boundPortType);
    1.96 +        bindings.put(boundPortType.getName(), boundPortType);
    1.97 +    }
    1.98 +
    1.99 +    public WSDLBoundPortTypeImpl getBinding(QName name){
   1.100 +        return bindings.get(name);
   1.101 +    }
   1.102 +
   1.103 +    public void addService(WSDLServiceImpl svc){
   1.104 +        services.put(svc.getName(), svc);
   1.105 +    }
   1.106 +
   1.107 +    public WSDLServiceImpl getService(QName name){
   1.108 +        return services.get(name);
   1.109 +    }
   1.110 +
   1.111 +    public Map<QName, WSDLMessageImpl> getMessages() {
   1.112 +        return messages;
   1.113 +    }
   1.114 +
   1.115 +    public @NotNull Map<QName, WSDLPortTypeImpl> getPortTypes() {
   1.116 +        return portTypes;
   1.117 +    }
   1.118 +
   1.119 +    public @NotNull Map<QName, WSDLBoundPortType> getBindings() {
   1.120 +        return unmBindings;
   1.121 +    }
   1.122 +
   1.123 +    public @NotNull Map<QName, WSDLServiceImpl> getServices(){
   1.124 +        return services;
   1.125 +    }
   1.126 +
   1.127 +    /**
   1.128 +     * Returns the first service QName from insertion order
   1.129 +     */
   1.130 +    public QName getFirstServiceName(){
   1.131 +        if(services.isEmpty())
   1.132 +            return null;
   1.133 +        return services.values().iterator().next().getName();
   1.134 +    }
   1.135 +
   1.136 +    /**
   1.137 +     * Returns first port QName from first service as per the insertion order
   1.138 +     */
   1.139 +    public QName getFirstPortName(){
   1.140 +        WSDLPort fp = getFirstPort();
   1.141 +        if(fp==null)
   1.142 +            return null;
   1.143 +        else
   1.144 +            return fp.getName();
   1.145 +    }
   1.146 +
   1.147 +    private WSDLPort getFirstPort(){
   1.148 +        if(services.isEmpty())
   1.149 +            return null;
   1.150 +        WSDLService service = services.values().iterator().next();
   1.151 +        Iterator<? extends WSDLPort> iter = service.getPorts().iterator();
   1.152 +        WSDLPort port = iter.hasNext()?iter.next():null;
   1.153 +        return port;
   1.154 +    }
   1.155 +
   1.156 +    /**
   1.157 +    * gets the first port in the wsdl which matches the serviceName and portType
   1.158 +    */
   1.159 +    public WSDLPortImpl getMatchingPort(QName serviceName, QName portType){
   1.160 +        return getService(serviceName).getMatchingPort(portType);
   1.161 +    }
   1.162 +
   1.163 +    /**
   1.164 +     *
   1.165 +     * @param serviceName non-null service QName
   1.166 +     * @param portName    non-null port QName
   1.167 +     * @return
   1.168 +     *          WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null
   1.169 +     */
   1.170 +    public WSDLBoundPortTypeImpl getBinding(QName serviceName, QName portName){
   1.171 +        WSDLServiceImpl service = services.get(serviceName);
   1.172 +        if(service != null){
   1.173 +            WSDLPortImpl port = service.get(portName);
   1.174 +            if(port != null)
   1.175 +                return port.getBinding();
   1.176 +        }
   1.177 +        return null;
   1.178 +    }
   1.179 +
   1.180 +    void finalizeRpcLitBinding(WSDLBoundPortTypeImpl boundPortType){
   1.181 +        assert(boundPortType != null);
   1.182 +        QName portTypeName = boundPortType.getPortTypeName();
   1.183 +        if(portTypeName == null)
   1.184 +            return;
   1.185 +        WSDLPortType pt = portTypes.get(portTypeName);
   1.186 +        if(pt == null)
   1.187 +            return;
   1.188 +        for (WSDLBoundOperationImpl bop : boundPortType.getBindingOperations()) {
   1.189 +            WSDLOperation pto = pt.get(bop.getName().getLocalPart());
   1.190 +            WSDLMessage inMsgName = pto.getInput().getMessage();
   1.191 +            if(inMsgName == null)
   1.192 +                continue;
   1.193 +            WSDLMessageImpl inMsg = messages.get(inMsgName.getName());
   1.194 +            int bodyindex = 0;
   1.195 +            if(inMsg != null){
   1.196 +                for(WSDLPartImpl part:inMsg.parts()){
   1.197 +                    String name = part.getName();
   1.198 +                    ParameterBinding pb = bop.getInputBinding(name);
   1.199 +                    if(pb.isBody()){
   1.200 +                        part.setIndex(bodyindex++);
   1.201 +                        part.setBinding(pb);
   1.202 +                        bop.addPart(part, Mode.IN);
   1.203 +                    }
   1.204 +                }
   1.205 +            }
   1.206 +            bodyindex=0;
   1.207 +            if(pto.isOneWay())
   1.208 +                continue;
   1.209 +            WSDLMessage outMsgName = pto.getOutput().getMessage();
   1.210 +            if(outMsgName == null)
   1.211 +                continue;
   1.212 +            WSDLMessageImpl outMsg = messages.get(outMsgName.getName());
   1.213 +            if(outMsg!= null){
   1.214 +                for(WSDLPartImpl part:outMsg.parts()){
   1.215 +                    String name = part.getName();
   1.216 +                    ParameterBinding pb = bop.getOutputBinding(name);
   1.217 +                    if(pb.isBody()){
   1.218 +                        part.setIndex(bodyindex++);
   1.219 +                        part.setBinding(pb);
   1.220 +                        bop.addPart(part, Mode.OUT);
   1.221 +                    }
   1.222 +                }
   1.223 +            }
   1.224 +        }
   1.225 +    }
   1.226 +
   1.227 +    /**
   1.228 +     * Gives the PolicyMap associated with the WSDLModel
   1.229 +     *
   1.230 +     * @return PolicyMap
   1.231 +     */
   1.232 +    public PolicyMap getPolicyMap() {
   1.233 +        return policyMap;
   1.234 +    }
   1.235 +
   1.236 +    /**
   1.237 +     * Set PolicyMap for the WSDLModel.
   1.238 +     * @param policyMap
   1.239 +     */
   1.240 +    public void setPolicyMap(PolicyMap policyMap) {
   1.241 +        this.policyMap = policyMap;
   1.242 +    }
   1.243 +
   1.244 +    /**
   1.245 +     * Invoked at the end of the model construction to fix up references, etc.
   1.246 +     */
   1.247 +    public void freeze() {
   1.248 +        for (WSDLServiceImpl service : services.values()) {
   1.249 +            service.freeze(this);
   1.250 +        }
   1.251 +        for (WSDLBoundPortTypeImpl bp : bindings.values()) {
   1.252 +            bp.freeze();
   1.253 +        }
   1.254 +        // Enforce freeze all the portTypes referenced by this endpoints, see Bug8966673 for detail
   1.255 +        for (WSDLPortTypeImpl pt : portTypes.values()) {
   1.256 +            pt.freeze();
   1.257 +        }
   1.258 +    }
   1.259 +}

mercurial