01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.frontend;
19:
20: import java.lang.reflect.Method;
21: import java.util.HashMap;
22: import java.util.Map;
23: import java.util.concurrent.ConcurrentHashMap;
24:
25: import org.apache.cxf.endpoint.Endpoint;
26: import org.apache.cxf.service.model.BindingInfo;
27: import org.apache.cxf.service.model.BindingOperationInfo;
28: import org.apache.cxf.service.model.OperationInfo;
29:
30: public class SimpleMethodDispatcher implements MethodDispatcher {
31:
32: private Map<Method, Map<BindingInfo, BindingOperationInfo>> infoMap = new ConcurrentHashMap<Method, Map<BindingInfo, BindingOperationInfo>>();
33: private Map<OperationInfo, Method> opToMethod = new ConcurrentHashMap<OperationInfo, Method>();
34: private Map<Method, OperationInfo> methodToOp = new ConcurrentHashMap<Method, OperationInfo>();
35:
36: public void bind(OperationInfo o, Method... methods) {
37: Method primary = methods[0];
38: for (Method m : methods) {
39: methodToOp.put(m, o);
40:
41: Map<BindingInfo, BindingOperationInfo> biToBop = new HashMap<BindingInfo, BindingOperationInfo>();
42: infoMap.put(m, biToBop);
43: }
44:
45: opToMethod.put(o, primary);
46:
47: if (o.isUnwrappedCapable()) {
48: opToMethod.put(o.getUnwrappedOperation(), primary);
49: }
50: }
51:
52: public BindingOperationInfo getBindingOperation(Method method,
53: Endpoint endpoint) {
54: Map<BindingInfo, BindingOperationInfo> bops = infoMap
55: .get(method);
56: if (bops == null) {
57: return null;
58: }
59:
60: BindingOperationInfo bop = bops.get(endpoint.getEndpointInfo()
61: .getBinding());
62: if (bop == null) {
63: OperationInfo o = methodToOp.get(method);
64: if (o == null) {
65: return null;
66: }
67:
68: BindingInfo b = endpoint.getEndpointInfo().getBinding();
69: for (BindingOperationInfo bop2 : b.getOperations()) {
70: if (bop2.getOperationInfo().equals(o)) {
71: bop2 = getRealOperation(o, bop2);
72:
73: bops.put(b, bop2);
74: return bop2;
75: }
76: }
77: }
78: return bop;
79: }
80:
81: private BindingOperationInfo getRealOperation(OperationInfo o,
82: BindingOperationInfo bop) {
83: BindingOperationInfo unwrappedOp = bop.getUnwrappedOperation();
84: if (unwrappedOp != null
85: && unwrappedOp.getOperationInfo().equals(
86: o.getUnwrappedOperation())) {
87: bop = unwrappedOp;
88: }
89: return bop;
90: }
91:
92: public Method getMethod(BindingOperationInfo op) {
93: return opToMethod.get(op.getOperationInfo());
94: }
95:
96: public Method getPrimaryMethod(OperationInfo op) {
97: return opToMethod.get(op);
98: }
99: }
|