KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package xdoclet.modules.ejb.entity;
6
7 import java.text.MessageFormat JavaDoc;
8 import java.util.Collection JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 import xjavadoc.*;
12 import xdoclet.DocletContext;
13 import xdoclet.DocletSupport;
14
15 import xdoclet.DocletTask;
16 import xdoclet.XDocletException;
17 import xdoclet.XDocletTagSupport;
18 import xdoclet.modules.ejb.EjbTagsHandler;
19 import xdoclet.modules.ejb.entity.EntityBmpSubTask;
20
21 import xdoclet.util.TypeConversionUtil;
22
23 /**
24  * @author Ara Abrahamian (ara_e@email.com)
25  * @created Oct 16, 2001
26  * @xdoclet.taghandler namespace="EjbBmp"
27  * @version $Revision: 1.8 $
28  */

29 public class BmpTagsHandler extends EntityTagsHandler
30 {
31
32     /**
33      * Gets the EntityBmpClassFor attribute of the BmpTagsHandler class
34      *
35      * @param clazz Describe what the parameter does
36      * @return The EntityBmpClassFor value
37      * @exception XDocletException
38      */

39     public static String JavaDoc getEntityBmpClassFor(XClass clazz) throws XDocletException
40     {
41         String JavaDoc fileName = clazz.getContainingPackage().getName();
42         String JavaDoc entity_name = MessageFormat.format(getEntityBmpClassPattern(), new Object JavaDoc[]{EjbTagsHandler.getShortEjbNameFor(clazz)});
43
44         // Fix package name
45
fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(EntityBmpSubTask.class));
46         if (fileName.length() > 0) {
47             fileName += ".";
48         }
49
50         fileName += entity_name;
51
52         return fileName;
53     }
54
55
56     /**
57      * Returns true if clazz is an BMP entity bean, false otherwise. Entity type is determined by looking at the
58      * ejb:bean's type parameter.
59      *
60      * @param clazz Description of Parameter
61      * @return The EntityBmp value
62      * @exception XDocletException
63      */

64     public static boolean isEntityBmp(XClass clazz) throws XDocletException
65     {
66         if (isEntity(clazz) == false) {
67             return false;
68         }
69
70         XTag beanTag = clazz.getDoc().getTag("ejb:bean");
71
72         //assume CMP if not specified
73
if (beanTag == null) {
74             return false;
75         }
76
77         String JavaDoc value = beanTag.getAttributeValue("type");
78
79         //assume CMP if not specified
80
if (value == null) {
81             return false;
82         }
83
84         if (value.equals("BMP")) {
85             return true;
86         }
87         else {
88             return false;
89         }
90     }
91
92
93     /**
94      * Returns true if clazz has ejb:use-soft-locking tag, false otherwise.
95      *
96      * @param clazz Description of Parameter
97      * @return Description of the Returned Value
98      */

99     public static boolean useSoftLocking(XClass clazz)
100     {
101         String JavaDoc soft_locking_str = clazz.getDoc().getTagAttributeValue("ejb:bean", "use-soft-locking", false);
102         boolean soft_locking = TypeConversionUtil.stringToBoolean(soft_locking_str, false);
103
104         return soft_locking;
105     }
106
107
108     /**
109      * Gets the EntityBmpClassPattern attribute of the BmpTagsHandler class
110      *
111      * @return The EntityBmpClassPattern value
112      */

113     protected static String JavaDoc getEntityBmpClassPattern()
114     {
115         EntityBmpSubTask entitybmp_subtask = ((EntityBmpSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(EntityBmpSubTask.class)));
116
117         if (entitybmp_subtask != null) {
118             return entitybmp_subtask.getEntityBmpClassPattern();
119         }
120         else {
121             return EntityBmpSubTask.DEFAULT_ENTITYBMP_CLASS_PATTERN;
122         }
123     }
124
125     /**
126      * Returns the name of generated BMP class.
127      *
128      * @return The name of generated BMP class.
129      * @exception XDocletException
130      * @doc.tag type="content"
131      */

132     public String JavaDoc entityBmpClass() throws XDocletException
133     {
134         return getEntityBmpClassFor(XDocletTagSupport.getCurrentClass());
135     }
136
137
138     /**
139      * Evaluates the body block if current class is an BMP entity bean.
140      *
141      * @param template The body of the block tag
142      * @exception XDocletException
143      * @doc.tag type="block"
144      */

145     public void ifEntityIsBmp(String JavaDoc template) throws XDocletException
146     {
147         if (isEntityBmp(XDocletTagSupport.getCurrentClass())) {
148             generate(template);
149         }
150     }
151
152
153     /**
154      * Evaluates the body block for each EJBean derived from EntityBean which is BMP.
155      *
156      * @param template The body of the block tag
157      * @exception XDocletException
158      * @see #isEntityBmp(xjavadoc.XClass)
159      * @doc.tag type="block"
160      */

161     public void forAllBmpEntityBeans(String JavaDoc template) throws XDocletException
162     {
163         Collection JavaDoc classes = getXJavaDoc().getSourceClasses();
164
165         for (Iterator JavaDoc i = classes.iterator(); i.hasNext(); ) {
166             XClass clazz = (XClass) i.next();
167
168             XDocletTagSupport.setCurrentClass(clazz);
169
170             if (DocletSupport.isDocletGenerated(XDocletTagSupport.getCurrentClass())) {
171                 continue;
172             }
173
174             if (!hasHavingClassTag(getCurrentClass())) {
175                 continue;
176             }
177
178             if (isEntityBmp(XDocletTagSupport.getCurrentClass())) {
179                 generate(template);
180             }
181         }
182     }
183
184
185     /**
186      * Evaluates the body block if ejb:use-soft-locking is set for current class.
187      *
188      * @param template The body of the block tag
189      * @exception XDocletException
190      * @see #useSoftLocking(xjavadoc.XClass)
191      * @doc.tag type="block"
192      */

193     public void ifUseSoftLocking(String JavaDoc template) throws XDocletException
194     {
195         if (useSoftLocking(XDocletTagSupport.getCurrentClass())) {
196             generate(template);
197         }
198     }
199 }
200
Popular Tags