01: package org.apache.myfaces.config.annotation;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import javax.naming.NamingException;
21: import javax.naming.Context;
22: import javax.annotation.Resource;
23: import javax.ejb.EJB;
24: import javax.persistence.PersistenceContext;
25: import javax.persistence.PersistenceUnit;
26:
27: import java.lang.reflect.Method;
28: import java.lang.reflect.InvocationTargetException;
29: import java.lang.reflect.Field;
30:
31: // TODO @EJBs
32: public class AllAnnotationLifecycleProvider extends
33: ResourceAnnotationLifecycleProvider {
34:
35: public AllAnnotationLifecycleProvider(Context context) {
36: super (context);
37: }
38:
39: protected void checkMethodAnnotation(Method method, Object instance)
40: throws NamingException, IllegalAccessException,
41: InvocationTargetException {
42: super .checkMethodAnnotation(method, instance);
43: if (method.isAnnotationPresent(Resource.class)) {
44: Resource annotation = method.getAnnotation(Resource.class);
45: lookupMethodResource(context, instance, method, annotation
46: .name());
47: }
48: if (method.isAnnotationPresent(EJB.class)) {
49: EJB annotation = method.getAnnotation(EJB.class);
50: lookupMethodResource(context, instance, method, annotation
51: .name());
52: }
53: // TODO where i find WebServiceRef?
54: /*if (method.isAnnotationPresent(WebServiceRef.class)) {
55: WebServiceRef annotation =
56: (WebServiceRef) method.getAnnotation(WebServiceRef.class);
57: lookupMethodResource(context, instance, methods, annotation.name());
58: }*/
59: if (method.isAnnotationPresent(PersistenceContext.class)) {
60: PersistenceContext annotation = method
61: .getAnnotation(PersistenceContext.class);
62: lookupMethodResource(context, instance, method, annotation
63: .name());
64: }
65: if (method.isAnnotationPresent(PersistenceUnit.class)) {
66: PersistenceUnit annotation = method
67: .getAnnotation(PersistenceUnit.class);
68: lookupMethodResource(context, instance, method, annotation
69: .name());
70: }
71: }
72:
73: protected void checkFieldAnnotation(Field field, Object instance)
74: throws NamingException, IllegalAccessException {
75: super .checkFieldAnnotation(field, instance);
76: if (field.isAnnotationPresent(EJB.class)) {
77: EJB annotation = field.getAnnotation(EJB.class);
78: lookupFieldResource(context, instance, field, annotation
79: .name());
80: }
81: /*if (field.isAnnotationPresent(WebServiceRef.class)) {
82: WebServiceRef annotation =
83: (WebServiceRef) field.getAnnotation(WebServiceRef.class);
84: lookupFieldResource(context, instance, field, annotation.name());
85: }*/
86: if (field.isAnnotationPresent(PersistenceContext.class)) {
87: PersistenceContext annotation = field
88: .getAnnotation(PersistenceContext.class);
89: lookupFieldResource(context, instance, field, annotation
90: .name());
91: }
92: if (field.isAnnotationPresent(PersistenceUnit.class)) {
93: PersistenceUnit annotation = field
94: .getAnnotation(PersistenceUnit.class);
95: lookupFieldResource(context, instance, field, annotation
96: .name());
97: }
98: }
99: }
|