01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.cxf;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: import javax.xml.ws.WebServiceException;
22: import javax.xml.ws.handler.Handler;
23: import javax.xml.ws.handler.HandlerResolver;
24: import javax.xml.ws.handler.PortInfo;
25:
26: import org.apache.cxf.jaxws.javaee.HandlerChainType;
27: import org.apache.cxf.jaxws.javaee.HandlerChainsType;
28: import org.apache.geronimo.jaxws.annotations.AnnotationException;
29: import org.apache.geronimo.jaxws.annotations.AnnotationProcessor;
30:
31: public class CXFHandlerResolver implements HandlerResolver {
32:
33: private HandlerChainsType handlerChains;
34:
35: private ClassLoader classLoader;
36:
37: private Class serviceClass;
38:
39: private AnnotationProcessor annotationProcessor;
40:
41: public CXFHandlerResolver(ClassLoader classLoader,
42: Class serviceClass, HandlerChainsType handlerChains,
43: AnnotationProcessor annotationProcessor) {
44: this .classLoader = classLoader;
45: this .serviceClass = serviceClass;
46: this .handlerChains = handlerChains;
47: this .annotationProcessor = annotationProcessor;
48: }
49:
50: public List<Handler> getHandlerChain(PortInfo portInfo) {
51:
52: GeronimoHandlerChainBuilder builder = new GeronimoHandlerChainBuilder(
53: this .classLoader, portInfo);
54:
55: List<Handler> handlers = null;
56: if (this .handlerChains == null) {
57: handlers = builder
58: .buildHandlerChainFromClass(this .serviceClass);
59: } else {
60: handlers = new ArrayList<Handler>();
61: for (HandlerChainType handlerChain : this .handlerChains
62: .getHandlerChain()) {
63: handlers
64: .addAll(builder
65: .buildHandlerChainFromConfiguration(handlerChain));
66: }
67: handlers = builder.sortHandlers(handlers);
68: }
69:
70: if (this .annotationProcessor != null) {
71: try {
72: for (Handler handler : handlers) {
73: this .annotationProcessor
74: .processAnnotations(handler);
75: this .annotationProcessor
76: .invokePostConstruct(handler);
77: }
78: } catch (AnnotationException e) {
79: throw new WebServiceException(
80: "Handler annotation failed", e);
81: }
82: }
83:
84: return handlers;
85: }
86:
87: }
|