KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > wsif > WSIFOperationMap


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.wsif;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.jbi.messaging.MessageExchange;
25 import javax.wsdl.Binding;
26 import javax.wsdl.BindingOperation;
27 import javax.wsdl.Operation;
28 import javax.xml.namespace.QName JavaDoc;
29
30 import org.apache.servicemix.jbi.NoSuchOperationException;
31 import org.apache.wsif.WSIFException;
32 import org.apache.wsif.WSIFService;
33
34 /**
35  * Maintains a Map of the available operations for the binding.
36  *
37  * @version $Revision: 426415 $
38  */

39 public class WSIFOperationMap {
40
41     private WSIFService service;
42     private Map JavaDoc operationMap = new HashMap JavaDoc();
43     private WSIFOperationInfo defaultOperation;
44
45     public WSIFOperationMap(WSIFService service) {
46         this.service = service;
47     }
48
49     /**
50      * Returns the operation information for the current message exchange.
51      *
52      * @param exchange the current message exchange
53      * @return the operation information
54      * @throws NoSuchOperationException if the operation is not available
55      */

56     public WSIFOperationInfo getOperationForExchange(MessageExchange exchange) throws NoSuchOperationException {
57         QName JavaDoc operationName = exchange.getOperation();
58         WSIFOperationInfo operationInfo = getOperation(operationName);
59         if (operationInfo == null) {
60             throw new NoSuchOperationException(operationName);
61         }
62         return operationInfo;
63     }
64
65     /**
66      * Returns the operation information for the given QName
67      *
68      * @param operationName is the name of the operation
69      * @return the operation information or null if it is not available
70      */

71     public WSIFOperationInfo getOperation(QName JavaDoc operationName) {
72         if (operationName == null) {
73             // lets try a default operation
74
return defaultOperation;
75         }
76         return (WSIFOperationInfo) operationMap.get(operationName);
77     }
78
79     public int getOperationCount() {
80         return operationMap.values().size();
81     }
82
83     /**
84      * Returns the operation for the given name
85      *
86      * @param operationName is the name of the operation
87      * @return the operation instance or null if it is not available
88      */

89     public WSIFOperationInfo getOperation(String JavaDoc operationName) {
90         return (WSIFOperationInfo) operationMap.get(operationName);
91     }
92
93     public void addBinding(Binding binding) throws WSIFException {
94         List JavaDoc list = binding.getBindingOperations();
95         for (Iterator JavaDoc iter = list.iterator(); iter.hasNext();) {
96             BindingOperation bindingOperation = (BindingOperation) iter.next();
97             addBindingOperation(binding, bindingOperation);
98         }
99     }
100
101     protected void addBindingOperation(Binding binding, BindingOperation bindingOperation) throws WSIFException {
102         Operation operation = bindingOperation.getOperation();
103         String JavaDoc name = operation.getName();
104         WSIFOperationInfo info = new WSIFOperationInfo(service.getPort(), name);
105         operationMap.put(name, info);
106         operationMap.put(new QName JavaDoc(name), info);
107         if (defaultOperation == null) {
108             defaultOperation = info;
109         }
110     }
111
112 }
113
Popular Tags