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.jaxws;
17:
18: import org.apache.geronimo.jaxws.annotations.AnnotationProcessor;
19: import org.apache.geronimo.jaxws.annotations.EJBAnnotationHandler;
20: import org.apache.geronimo.jaxws.annotations.InjectionException;
21: import org.apache.geronimo.jaxws.annotations.ResourceAnnotationHandler;
22: import org.apache.geronimo.jaxws.annotations.WebServiceRefAnnotationHandler;
23:
24: import javax.naming.NamingException;
25: import javax.xml.ws.WebServiceContext;
26: import java.lang.annotation.Annotation;
27:
28: public class JAXWSAnnotationProcessor extends AnnotationProcessor {
29:
30: private JNDIResolver jndiResolver;
31: private WebServiceContext context;
32:
33: public JAXWSAnnotationProcessor(JNDIResolver jndiResolver,
34: WebServiceContext context) {
35: this .jndiResolver = jndiResolver;
36: this .context = context;
37:
38: // register @Resource annotation handler
39: registerHandler(new JAXWSResourceAnnotationHandler());
40: // register @EJB annotation handler
41: registerHandler(new JAXWSEJBAnnotationHandler());
42: // register @WebServiceRef annotation handler
43: registerHandler(new JAXWSWebServiceRefAnnotationHandler());
44: }
45:
46: private Object lookupJNDI(String name, Class<?> type)
47: throws InjectionException {
48: try {
49: return jndiResolver.resolve(name, type);
50: } catch (NamingException e) {
51: throw new InjectionException(
52: "JNDI injection failed for resource '" + name + "'",
53: e);
54: }
55: }
56:
57: private class JAXWSResourceAnnotationHandler extends
58: ResourceAnnotationHandler {
59: public Object getAnnotationValue(Annotation annotation,
60: String name, Class<?> type) throws InjectionException {
61: if (WebServiceContext.class.isAssignableFrom(type)) {
62: return type.cast(context);
63: } else {
64: return lookupJNDI(name, type);
65: }
66: }
67: }
68:
69: private class JAXWSEJBAnnotationHandler extends
70: EJBAnnotationHandler {
71: public Object getAnnotationValue(Annotation annotation,
72: String name, Class<?> type) throws InjectionException {
73: return lookupJNDI(name, type);
74: }
75: }
76:
77: private class JAXWSWebServiceRefAnnotationHandler extends
78: WebServiceRefAnnotationHandler {
79: public Object getAnnotationValue(Annotation annotation,
80: String name, Class<?> type) throws InjectionException {
81: return lookupJNDI(name, type);
82: }
83: }
84: }
|