Package org.servicemix.components.wsif

Source Code of org.servicemix.components.wsif.WSIFOperationMap

/**
*
* Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.servicemix.components.wsif;

import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFService;
import org.servicemix.jbi.NoSuchOperationException;

import javax.wsdl.Binding;
import javax.wsdl.BindingOperation;
import javax.wsdl.Operation;
import javax.xml.namespace.QName;
import javax.jbi.messaging.MessageExchange;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* Maintains a Map of the available operations for the binding.
*
* @version $Revision: 228 $
*/
public class WSIFOperationMap {

    private WSIFService service;
    private Map operationMap = new HashMap();
    private WSIFOperationInfo defaultOperation;

    public WSIFOperationMap(WSIFService service) {
        this.service = service;
    }

    /**
     * Returns the operation information for the current message exchange.
     *
     * @param exchange the current message exchange
     * @return the operation information
     * @throws NoSuchOperationException if the operation is not available
     */
    public WSIFOperationInfo getOperationForExchange(MessageExchange exchange) throws NoSuchOperationException {
        QName operationName = exchange.getOperation();
        WSIFOperationInfo operationInfo = getOperation(operationName);
        if (operationInfo == null) {
            throw new NoSuchOperationException(operationName);
        }
        return operationInfo;
    }

    /**
     * Returns the operation information for the given QName
     *
     * @param operationName is the name of the operation
     * @return the operation information or null if it is not available
     */
    public WSIFOperationInfo getOperation(QName operationName) {
        if (operationName == null) {
            // lets try a default operation
            return defaultOperation;
        }
        return (WSIFOperationInfo) operationMap.get(operationName);
    }

    public int getOperationCount() {
        return operationMap.values().size();
    }

    /**
     * Returns the operation for the given name
     *
     * @param operationName is the name of the operation
     * @return the operation instance or null if it is not available
     */
    public WSIFOperationInfo getOperation(String operationName) {
        return (WSIFOperationInfo) operationMap.get(operationName);
    }

    public void addBinding(Binding binding) throws WSIFException {
        List list = binding.getBindingOperations();
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            BindingOperation bindingOperation = (BindingOperation) iter.next();
            addBindingOperation(binding, bindingOperation);
        }
    }

    protected void addBindingOperation(Binding binding, BindingOperation bindingOperation) throws WSIFException {
        Operation operation = bindingOperation.getOperation();
        String name = operation.getName();
        WSIFOperation wsifOperation = service.getPort().createOperation(name);

        WSIFOperationInfo info = new WSIFOperationInfo(wsifOperation, bindingOperation);

        operationMap.put(name, info);
        operationMap.put(new QName(name), info);
        if (defaultOperation == null) {
            defaultOperation = info;
        }
    }

}
TOP

Related Classes of org.servicemix.components.wsif.WSIFOperationMap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.