KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > entity > EntityTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.ejb.entity;
6
7 import java.lang.reflect.Modifier JavaDoc;
8
9 import java.util.Collection JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import xjavadoc.*;
13 import xdoclet.DocletSupport;
14 import xdoclet.XDocletException;
15 import xdoclet.modules.ejb.EjbDocletTask;
16 import xdoclet.modules.ejb.EjbTagsHandler;
17 import xdoclet.modules.ejb.entity.BmpTagsHandler;
18 import xdoclet.modules.ejb.entity.CmpTagsHandler;
19
20 /**
21  * @author Ara Abrahamian (ara_e@email.com)
22  * @created Oct 16, 2001
23  * @xdoclet.taghandler namespace="EjbEntity"
24  * @version $Revision: 1.12 $
25  */

26 public class EntityTagsHandler extends EjbTagsHandler
27 {
28     /**
29      * Returns true if clazz is an entity bean, false otherwise.
30      *
31      * @param clazz Description of Parameter
32      * @return The Entity value
33      */

34     public static boolean isEntity(XClass clazz)
35     {
36         return clazz.isA("javax.ejb.EntityBean");
37     }
38
39     public static boolean isEjbSelectMethod(XMethod method)
40     {
41         // if prefixed ejbSelect exactly
42
if (method.getName().startsWith("ejbSelect") == false)
43             return false;
44
45         // if ejbSelect<blabla>
46
if (method.getName().length() <= "ejbSelect".length())
47             return false;
48
49         // if is abstract and public
50
if ((method.getModifierSpecifier() & Modifier.ABSTRACT) == 0 || (method.getModifierSpecifier() & Modifier.PUBLIC) == 0)
51             return false;
52
53         // if has a return type of non-void
54
if (method.getReturnType().getType().getName().equals("void"))
55             return false;
56
57         // if throws FindException
58
//if (method.throwsException("javax.ejb.FinderException") == false)
59
// return false;
60

61         // if defines the ejbql (later we can make it optional and guess the ejbql from the method name and cmp field names)
62
//if (method.getDoc().hasTag("ejb:select") == false)
63
// return false;
64

65         return true;
66     }
67
68     /**
69      * Evaluate the body block if current class is of an entity type.
70      *
71      * @param template The body of the block tag
72      * @exception XDocletException
73      * @see #isEntity(xjavadoc.XClass)
74      * @doc.tag type="block"
75      */

76     public void ifEntity(String JavaDoc template) throws XDocletException
77     {
78         if (isEntity(getCurrentClass())) {
79             generate(template);
80         }
81     }
82
83
84     /**
85      * Returns the persistent type of current bean.
86      *
87      * @return "Container" or "Bean".
88      * @exception XDocletException
89      * @see xdoclet.modules.ejb.entity.CmpTagsHandler#isEntityCmp(xjavadoc.XClass)
90      * @see xdoclet.modules.ejb.entity.BmpTagsHandler#isEntityBmp(xjavadoc.XClass)
91      * @doc.tag type="content"
92      */

93     public String JavaDoc persistenceType() throws XDocletException
94     {
95         if (CmpTagsHandler.isEntityCmp(getCurrentClass()) &&
96             !BmpTagsHandler.isEntityBmp(getCurrentClass())) {
97             return "Container";
98         }
99         else {
100             return "Bean";
101         }
102     }
103
104
105     /**
106      * Evaluates the body block for each EJBean derived from EntityBean.
107      *
108      * @param template The body of the block tag
109      * @exception XDocletException
110      * @see #isEntity(xjavadoc.XClass)
111      * @doc.tag type="block"
112      */

113     public void forAllEntityBeans(String JavaDoc template) throws XDocletException
114     {
115         Collection JavaDoc classes = getXJavaDoc().getSourceClasses();
116
117         for (Iterator JavaDoc i = classes.iterator(); i.hasNext(); ) {
118             XClass clazz = (XClass) i.next();
119
120             setCurrentClass(clazz);
121
122             if (DocletSupport.isDocletGenerated(getCurrentClass())) {
123                 continue;
124             }
125
126             if (!hasHavingClassTag(getCurrentClass())) {
127                 continue;
128             }
129
130             if (isEntity(getCurrentClass())) {
131                 generate(template);
132             }
133         }
134     }
135
136
137     /**
138      * Returns True if ejb:bean reentrant is true, False otherwise. It does the case conversion trick from true to True
139      * and false to False.
140      *
141      * @return Description of the Returned Value
142      * @exception XDocletException
143      * @see #isEntity(xjavadoc.XClass)
144      * @doc.tag type="content"
145      */

146     public String JavaDoc reentrant() throws XDocletException
147     {
148         String JavaDoc value =
149             getTagValue(
150             FOR_CLASS,
151             "ejb:bean",
152             "reentrant",
153             null,
154             "false",
155             true,
156             false
157             );
158
159         String JavaDoc ejbSpec = EjbTagsHandler.getEjbSpec();
160
161         if (ejbSpec.equals(EjbDocletTask.EjbSpecVersion.EJB_1_1) ||
162             ejbSpec.equals(EjbDocletTask.EjbSpecVersion.EJB_2_0)) {
163             // ejb spec 1.1 and 2.0 require that the first character is upper case
164
return value.substring(0, 1).toUpperCase() + value.substring(1).toLowerCase();
165         }
166         else {
167             // ejb spec 2.1+ requires that all characters are lower case
168
return value.toLowerCase();
169         }
170     }
171
172     /**
173      * Evaluates the body block for each ejbSelect<blabla> method.
174      *
175      * @param template The body of the block tag
176      * @exception XDocletException
177      * @see #isEntity(xjavadoc.XClass)
178      * @doc.tag type="block"
179      */

180     public void forAllEjbSelectMethods(String JavaDoc template) throws XDocletException
181     {
182         XMethod old_cur_method = getCurrentMethod();
183
184         for (Iterator JavaDoc i = getCurrentClass().getMethods(true).iterator(); i.hasNext(); ) {
185             XMethod method = (XMethod) i.next();
186
187             if (isEjbSelectMethod(method)) {
188                 setCurrentMethod(method);
189                 generate(template);
190             }
191         }
192
193         setCurrentMethod(old_cur_method);
194     }
195 }
196
Popular Tags