View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
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   */
19  package org.apache.myfaces.config.annotation;
20  
21  import javax.naming.NamingException;
22  import javax.naming.Context;
23  import jakarta.annotation.Resource;
24  import jakarta.ejb.EJB;
25  import jakarta.persistence.PersistenceContext;
26  import jakarta.persistence.PersistenceUnit;
27  
28  import java.lang.reflect.Method;
29  import java.lang.reflect.InvocationTargetException;
30  import java.lang.reflect.Field;
31  
32  // TODO @EJBs
33  public class AllAnnotationLifecycleProvider extends ResourceAnnotationLifecycleProvider
34  {
35  
36      public AllAnnotationLifecycleProvider(Context context)
37      {
38          super(context);
39      }
40  
41      @Override
42      protected void checkMethodAnnotation(Method method, Object instance)
43              throws NamingException, IllegalAccessException, InvocationTargetException
44      {
45          super.checkMethodAnnotation(method, instance);
46          if (method.isAnnotationPresent(Resource.class))
47          {
48              Resource annotation =  method.getAnnotation(Resource.class);
49              lookupMethodResource(context, instance, method, annotation.name());
50          }
51          if (method.isAnnotationPresent(EJB.class))
52          {
53              EJB annotation =  method.getAnnotation(EJB.class);
54              lookupMethodResource(context, instance, method, annotation.name());
55          }
56          // TODO where i find WebServiceRef?
57          /*if (method.isAnnotationPresent(WebServiceRef.class)) {
58              WebServiceRef annotation =
59                  (WebServiceRef) method.getAnnotation(WebServiceRef.class);
60              lookupMethodResource(context, instance, methods, annotation.name());
61          }*/
62          if (method.isAnnotationPresent(PersistenceContext.class))
63          {
64              PersistenceContext annotation = method.getAnnotation(PersistenceContext.class);
65              lookupMethodResource(context, instance, method, annotation.name());
66          }
67          if (method.isAnnotationPresent(PersistenceUnit.class))
68          {
69              PersistenceUnit annotation = method.getAnnotation(PersistenceUnit.class);
70              lookupMethodResource(context, instance, method, annotation.name());
71          }
72      }
73  
74      @Override
75      protected void checkFieldAnnotation(Field field, Object instance)
76              throws NamingException, IllegalAccessException
77      {
78          super.checkFieldAnnotation(field, instance);
79          if (field.isAnnotationPresent(EJB.class))
80          {
81              EJB annotation = field.getAnnotation(EJB.class);
82              lookupFieldResource(context, instance, field, annotation.name());
83          }
84          /*if (field.isAnnotationPresent(WebServiceRef.class)) {
85              WebServiceRef annotation =
86                  (WebServiceRef) field.getAnnotation(WebServiceRef.class);
87              lookupFieldResource(context, instance, field, annotation.name());
88          }*/
89          if (field.isAnnotationPresent(PersistenceContext.class))
90          {
91              PersistenceContext annotation = field.getAnnotation(PersistenceContext.class);
92              lookupFieldResource(context, instance, field, annotation.name());
93          }
94          if (field.isAnnotationPresent(PersistenceUnit.class))
95          {
96              PersistenceUnit annotation = field.getAnnotation(PersistenceUnit.class);
97              lookupFieldResource(context, instance, field, annotation.name());
98          }
99      }
100 }