325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.model.wsdl;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.xml.internal.ws.api.model.ParameterBinding;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLModel;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
325N/Aimport com.sun.xml.internal.ws.policy.PolicyMap;
325N/A
325N/Aimport javax.jws.WebParam.Mode;
325N/Aimport javax.xml.namespace.QName;
325N/Aimport java.net.URL;
325N/Aimport java.util.Collections;
325N/Aimport java.util.HashMap;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.LinkedHashMap;
325N/Aimport java.util.Map;
325N/A
325N/A/**
325N/A * Implementation of {@link WSDLModel}
325N/A *
325N/A * @author Vivek Pandey
325N/A */
325N/Apublic final class WSDLModelImpl extends AbstractExtensibleImpl implements WSDLModel {
325N/A private final Map<QName, WSDLMessageImpl> messages = new HashMap<QName, WSDLMessageImpl>();
325N/A private final Map<QName, WSDLPortTypeImpl> portTypes = new HashMap<QName, WSDLPortTypeImpl>();
325N/A private final Map<QName, WSDLBoundPortTypeImpl> bindings = new HashMap<QName, WSDLBoundPortTypeImpl>();
325N/A private final Map<QName, WSDLServiceImpl> services = new LinkedHashMap<QName, WSDLServiceImpl>();
325N/A
325N/A private PolicyMap policyMap;
325N/A private final Map<QName,WSDLBoundPortType> unmBindings
325N/A = Collections.<QName,WSDLBoundPortType>unmodifiableMap(bindings);
325N/A
325N/A
325N/A public WSDLModelImpl(@NotNull String systemId) {
325N/A super(systemId,-1);
325N/A }
325N/A
325N/A /**
325N/A * To create {@link WSDLModelImpl} from WSDL that doesn't have a system ID.
325N/A */
325N/A public WSDLModelImpl() {
325N/A super(null,-1);
325N/A }
325N/A
325N/A public void addMessage(WSDLMessageImpl msg){
325N/A messages.put(msg.getName(), msg);
325N/A }
325N/A
325N/A public WSDLMessageImpl getMessage(QName name){
325N/A return messages.get(name);
325N/A }
325N/A
325N/A public void addPortType(WSDLPortTypeImpl pt){
325N/A portTypes.put(pt.getName(), pt);
325N/A }
325N/A
325N/A public WSDLPortTypeImpl getPortType(QName name){
325N/A return portTypes.get(name);
325N/A }
325N/A
325N/A public void addBinding(WSDLBoundPortTypeImpl boundPortType){
325N/A assert !bindings.containsValue(boundPortType);
325N/A bindings.put(boundPortType.getName(), boundPortType);
325N/A }
325N/A
325N/A public WSDLBoundPortTypeImpl getBinding(QName name){
325N/A return bindings.get(name);
325N/A }
325N/A
325N/A public void addService(WSDLServiceImpl svc){
325N/A services.put(svc.getName(), svc);
325N/A }
325N/A
325N/A public WSDLServiceImpl getService(QName name){
325N/A return services.get(name);
325N/A }
325N/A
325N/A public Map<QName, WSDLMessageImpl> getMessages() {
325N/A return messages;
325N/A }
325N/A
325N/A public @NotNull Map<QName, WSDLPortTypeImpl> getPortTypes() {
325N/A return portTypes;
325N/A }
325N/A
325N/A public @NotNull Map<QName, WSDLBoundPortType> getBindings() {
325N/A return unmBindings;
325N/A }
325N/A
325N/A public @NotNull Map<QName, WSDLServiceImpl> getServices(){
325N/A return services;
325N/A }
325N/A
325N/A /**
325N/A * Returns the first service QName from insertion order
325N/A */
325N/A public QName getFirstServiceName(){
325N/A if(services.isEmpty())
325N/A return null;
325N/A return services.values().iterator().next().getName();
325N/A }
325N/A
325N/A /**
325N/A * Returns first port QName from first service as per the insertion order
325N/A */
325N/A public QName getFirstPortName(){
325N/A WSDLPort fp = getFirstPort();
325N/A if(fp==null)
325N/A return null;
325N/A else
325N/A return fp.getName();
325N/A }
325N/A
325N/A private WSDLPort getFirstPort(){
325N/A if(services.isEmpty())
325N/A return null;
325N/A WSDLService service = services.values().iterator().next();
325N/A Iterator<? extends WSDLPort> iter = service.getPorts().iterator();
325N/A WSDLPort port = iter.hasNext()?iter.next():null;
325N/A return port;
325N/A }
325N/A
325N/A /**
325N/A * gets the first port in the wsdl which matches the serviceName and portType
325N/A */
325N/A public WSDLPortImpl getMatchingPort(QName serviceName, QName portType){
325N/A return getService(serviceName).getMatchingPort(portType);
325N/A }
325N/A
325N/A /**
325N/A *
325N/A * @param serviceName non-null service QName
325N/A * @param portName non-null port QName
325N/A * @return
325N/A * WSDLBoundOperation on success otherwise null. throws NPE if any of the parameters null
325N/A */
325N/A public WSDLBoundPortTypeImpl getBinding(QName serviceName, QName portName){
325N/A WSDLServiceImpl service = services.get(serviceName);
325N/A if(service != null){
325N/A WSDLPortImpl port = service.get(portName);
325N/A if(port != null)
325N/A return port.getBinding();
325N/A }
325N/A return null;
325N/A }
325N/A
325N/A void finalizeRpcLitBinding(WSDLBoundPortTypeImpl boundPortType){
325N/A assert(boundPortType != null);
325N/A QName portTypeName = boundPortType.getPortTypeName();
325N/A if(portTypeName == null)
325N/A return;
325N/A WSDLPortType pt = portTypes.get(portTypeName);
325N/A if(pt == null)
325N/A return;
325N/A for (WSDLBoundOperationImpl bop : boundPortType.getBindingOperations()) {
325N/A WSDLOperation pto = pt.get(bop.getName().getLocalPart());
325N/A WSDLMessage inMsgName = pto.getInput().getMessage();
325N/A if(inMsgName == null)
325N/A continue;
325N/A WSDLMessageImpl inMsg = messages.get(inMsgName.getName());
325N/A int bodyindex = 0;
325N/A if(inMsg != null){
325N/A for(WSDLPartImpl part:inMsg.parts()){
325N/A String name = part.getName();
325N/A ParameterBinding pb = bop.getInputBinding(name);
325N/A if(pb.isBody()){
325N/A part.setIndex(bodyindex++);
325N/A part.setBinding(pb);
325N/A bop.addPart(part, Mode.IN);
325N/A }
325N/A }
325N/A }
325N/A bodyindex=0;
325N/A if(pto.isOneWay())
325N/A continue;
325N/A WSDLMessage outMsgName = pto.getOutput().getMessage();
325N/A if(outMsgName == null)
325N/A continue;
325N/A WSDLMessageImpl outMsg = messages.get(outMsgName.getName());
325N/A if(outMsg!= null){
325N/A for(WSDLPartImpl part:outMsg.parts()){
325N/A String name = part.getName();
325N/A ParameterBinding pb = bop.getOutputBinding(name);
325N/A if(pb.isBody()){
325N/A part.setIndex(bodyindex++);
325N/A part.setBinding(pb);
325N/A bop.addPart(part, Mode.OUT);
325N/A }
325N/A }
325N/A }
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Gives the PolicyMap associated with the WSDLModel
325N/A *
325N/A * @return PolicyMap
325N/A */
325N/A public PolicyMap getPolicyMap() {
325N/A return policyMap;
325N/A }
325N/A
325N/A /**
325N/A * Set PolicyMap for the WSDLModel.
325N/A * @param policyMap
325N/A */
325N/A public void setPolicyMap(PolicyMap policyMap) {
325N/A this.policyMap = policyMap;
325N/A }
325N/A
325N/A /**
325N/A * Invoked at the end of the model construction to fix up references, etc.
325N/A */
325N/A public void freeze() {
325N/A for (WSDLServiceImpl service : services.values()) {
325N/A service.freeze(this);
325N/A }
325N/A for (WSDLBoundPortTypeImpl bp : bindings.values()) {
325N/A bp.freeze();
325N/A }
325N/A }
325N/A}