KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > helper > bean > BusinessMethodResolver


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BusinessMethodResolver.java 451 2006-05-12 16:39:43Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.helper.bean;
27
28 import org.objectweb.easybeans.deployment.annotations.JMethod;
29 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
30 import org.objectweb.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata;
31 import org.objectweb.easybeans.log.JLog;
32 import org.objectweb.easybeans.log.JLogFactory;
33
34 /**
35  * This class resolves the business method for bean class by looking at the
36  * interfaces.
37  * @author Florent Benoit
38  */

39 public final class BusinessMethodResolver {
40
41     /**
42      * Name of the method used in constructor.
43      * This has to be ignored as this is never a business interface
44      */

45     private static final String JavaDoc CLASS_INIT = "<clinit>";
46
47     /**
48      * Ignore constructor "method" of interfaces.
49      * Not a business interface.
50      */

51     private static final String JavaDoc CONST_INIT = "<init>";
52
53     /**
54      * Logger.
55      */

56     private static JLog logger = JLogFactory.getLog(BusinessMethodResolver.class);
57
58     /**
59      * Helper class, no public constructor.
60      */

61     private BusinessMethodResolver() {
62
63     }
64
65     /**
66      * Found all business methods of a bean.<br>
67      * A business method is a method from one of the local or remote interfaces.
68      * @param classAnnotationMetadata class to analyze
69      */

70     public static void resolve(final ClassAnnotationMetadata classAnnotationMetadata) {
71         loop(classAnnotationMetadata, classAnnotationMetadata);
72     }
73
74     /**
75      * While there are super interfaces, loop on them.
76      * @param beanclassAnnotationMetadata the class that is analyzed
77      * @param visitingclassAnnotationMetadata classes from where we get
78      * interfaces
79      */

80     private static void loop(final ClassAnnotationMetadata beanclassAnnotationMetadata,
81             final ClassAnnotationMetadata visitingclassAnnotationMetadata) {
82         // first, need to analyze all methods of interfaces used by this class
83
// then, set them as business method
84

85         for (String JavaDoc itf : visitingclassAnnotationMetadata.getInterfaces()) {
86             if (itf.startsWith("javax/ejb/") || itf.startsWith("java/io/Serializable")
87                     || itf.startsWith("java/io/Externalizable")) {
88                 continue;
89             }
90
91             // get meta data of the interface
92
ClassAnnotationMetadata itfMetadata = visitingclassAnnotationMetadata.getEjbJarAnnotationMetadata()
93                     .getClassAnnotationMetadata(itf);
94
95             if (itfMetadata == null) {
96                 logger.warn("No class was found for interface {0}.", itf);
97                 continue;
98             }
99
100             // for each method of the interface, set the business method to true
101
// in bean
102
for (MethodAnnotationMetadata methodData : itfMetadata.getMethodAnnotationMetadataCollection()) {
103                 JMethod itfMethod = methodData.getJMethod();
104
105                 // Ignore class init method
106
if (itfMethod.getName().equals(CLASS_INIT) || itfMethod.getName().equals(CONST_INIT)) {
107                     continue;
108                 }
109
110                 // take the method from the bean class
111
MethodAnnotationMetadata beanMethod = beanclassAnnotationMetadata.getMethodAnnotationMetadata(itfMethod);
112                 if (beanMethod == null) {
113                     // TODO: I18n
114
throw new IllegalStateException JavaDoc("No method was found for method " + itfMethod + " in class "
115                             + beanclassAnnotationMetadata.getClassName());
116                 }
117                 beanMethod.setBusinessMethod(true);
118             }
119
120             // loop again
121
if (itfMetadata.getInterfaces() != null) {
122                 loop(beanclassAnnotationMetadata, itfMetadata);
123             }
124         }
125     }
126
127 }
128
Popular Tags