325N/A/*
325N/A * Copyright (c) 2007, 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.wsdl;
325N/A
325N/Aimport com.sun.istack.internal.Nullable;
325N/Aimport com.sun.xml.internal.ws.api.WSBinding;
325N/Aimport com.sun.xml.internal.ws.api.model.JavaMethod;
325N/Aimport com.sun.xml.internal.ws.api.model.SEIModel;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
325N/Aimport com.sun.xml.internal.ws.api.message.Packet;
325N/Aimport com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
325N/Aimport com.sun.xml.internal.ws.model.JavaMethodImpl;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport java.util.HashMap;
325N/Aimport java.util.Map;
325N/A
325N/A/**
325N/A * An {@link WSDLOperationFinder} that uses SOAPAction as the key for dispatching.
325N/A * <p/>
325N/A * A map of all SOAPAction on the port and the corresponding WSDL operation QName
325N/A * is initialized in the constructor. The SOAPAction from the
325N/A * request {@link com.sun.xml.internal.ws.api.message.Packet} is used as the key to identify the associated wsdl operation.
325N/A *
325N/A * @author Jitendra Kotamraju
325N/A */
325N/Afinal class SOAPActionBasedOperationFinder extends WSDLOperationFinder {
325N/A private final Map<String, QName> methodHandlers;
325N/A
325N/A public SOAPActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) {
325N/A super(wsdlModel,binding,seiModel);
325N/A methodHandlers = new HashMap<String, QName>();
325N/A
325N/A // Find if any SOAPAction repeat for operations
325N/A Map<String, Integer> unique = new HashMap<String, Integer>();
325N/A if (seiModel != null) {
325N/A for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
325N/A String soapAction = m.getOperation().getSOAPAction();
325N/A Integer count = unique.get(soapAction);
325N/A if (count == null) {
325N/A unique.put(soapAction, 1);
325N/A } else {
325N/A unique.put(soapAction, ++count);
325N/A }
325N/A }
325N/A
325N/A for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
325N/A String soapAction = m.getOperation().getSOAPAction();
325N/A // Set up method handlers only for unique SOAPAction values so
325N/A // that dispatching happens consistently for a method
325N/A if (unique.get(soapAction) == 1) {
325N/A methodHandlers.put('"' + soapAction + '"', m.getOperation().getName());
325N/A }
325N/A }
325N/A } else {
325N/A for(WSDLBoundOperation wsdlOp: wsdlModel.getBinding().getBindingOperations()) {
325N/A methodHandlers.put(wsdlOp.getSOAPAction(),wsdlOp.getName());
325N/A }
325N/A }
325N/A
325N/A }
325N/A
325N/A public QName getWSDLOperationQName(Packet request) {
325N/A return request.soapAction == null ? null : methodHandlers.get(request.soapAction);
325N/A }
325N/A}