KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > mdb > MdbTagsHandler


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

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

25 public class MdbTagsHandler extends EjbTagsHandler
26 {
27
28     private XTag currentDestination;
29
30     /**
31      * Gets the MdbClassFor attribute of the MdbTagsHandler class
32      *
33      * @param clazz Describe what the parameter does
34      * @return The MessageDrivenClassFor value
35      */

36     public static String JavaDoc getMessageDrivenClassFor(XClass clazz)
37     {
38         String JavaDoc fileName = clazz.getContainingPackage().getName();
39         String JavaDoc mdbName = MessageFormat.format(getMessageDrivenClassPattern(), new Object JavaDoc[]{getShortEjbNameFor(clazz)});
40
41         // Fix package name
42
fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(MdbSubTask.class));
43         if (fileName.length() > 0) {
44             fileName += ".";
45         }
46
47         fileName += mdbName;
48
49         return fileName;
50     }
51
52     /**
53      * Returns true if clazz is a message-driven bean, false otherwise.
54      *
55      * @param clazz Description of Parameter
56      * @return The MessageDriven value
57      */

58     public static boolean isMessageDriven(XClass clazz)
59     {
60         return clazz.isA("javax.ejb.MessageDrivenBean");
61     }
62
63     /**
64      * Gets the MdbClassPattern attribute of the MdbTagsHandler class
65      *
66      * @return The MdbClassPattern value
67      */

68     protected static String JavaDoc getMessageDrivenClassPattern()
69     {
70         MdbSubTask mdbSubtask = ((MdbSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(MdbSubTask.class)));
71
72         if (mdbSubtask != null) {
73             return mdbSubtask.getMessageDrivenClassPattern();
74         }
75         else {
76             return MdbSubTask.DEFAULT_MESSAGE_DRIVEN_CLASS_PATTERN;
77         }
78     }
79
80     /**
81      * Evaluates the body block for each EJBean derived from MessageDrivenBean.
82      *
83      * @param template The body of the block tag
84      * @exception XDocletException
85      * @see #isMessageDriven(xjavadoc.XClass)
86      * @doc.tag type="block"
87      */

88     public void forAllMDBeans(String JavaDoc template) throws XDocletException
89     {
90         Collection classes = getXJavaDoc().getSourceClasses();
91
92         for (Iterator i = classes.iterator(); i.hasNext(); ) {
93             XClass clazz = (XClass) i.next();
94
95             setCurrentClass(clazz);
96
97             if (DocletSupport.isDocletGenerated(getCurrentClass())) {
98                 continue;
99             }
100
101             if (!hasHavingClassTag(getCurrentClass())) {
102                 continue;
103             }
104
105             if (isMessageDriven(getCurrentClass())) {
106                 generate(template);
107             }
108         }
109     }
110
111     /**
112      * Evaluate the body block if current class is of a message driven bean type.
113      *
114      * @param template The body of the block tag
115      * @exception XDocletException
116      * @doc.tag type="block"
117      */

118     public void ifMessageDriven(String JavaDoc template) throws XDocletException
119     {
120         if (isMessageDriven(getCurrentClass())) {
121             generate(template);
122         }
123     }
124
125     /**
126      * Evaluate the body block if current class is not of a message driven bean type.
127      *
128      * @param template The body of the block tag
129      * @exception XDocletException
130      * @doc.tag type="block"
131      */

132     public void ifNotMessageDriven(String JavaDoc template) throws XDocletException
133     {
134         if (!isMessageDriven(getCurrentClass())) {
135             generate(template);
136         }
137     }
138
139     /**
140      * Returns the name of message-driven bean class.
141      *
142      * @return The name of generated message-driven bean class.
143      * @exception XDocletException
144      * @doc.tag type="content"
145      */

146     public String JavaDoc messageDrivenClass() throws XDocletException
147     {
148         return getMessageDrivenClassFor(getCurrentClass());
149     }
150
151     /**
152      * Returns the name of message-driven bean class.
153      *
154      * @return The name of generated message-driven bean class.
155      * @exception XDocletException
156      * @doc.tag type="content"
157      */

158     public String JavaDoc mdbClass() throws XDocletException
159     {
160         return getMessageDrivenClassFor(getCurrentClass());
161     }
162
163
164     /**
165      * Evaluate the body block if the current class has a activation config
166      *
167      * @param template The body of the block tag
168      * @param attributes
169      * @exception XDocletException
170      * @doc.tag type="block"
171      */

172     public void ifHasActivationConfig(String JavaDoc template, Properties attributes) throws XDocletException
173     {
174         if (hasActivationConfig()) {
175             generate(template);
176         }
177     }
178
179     /**
180      * Evaluates the body block for each ejb:message-destination defined in class level
181      *
182      * @param template The body of the block tag
183      * @exception XDocletException
184      * @see #destinationName()
185      * @see #destinationDescription()
186      * @see #destinationDisplayName()
187      * @doc.tag type="block"
188      */

189     public void forAllDestinations(String JavaDoc template) throws XDocletException
190     {
191         Collection classes = getXJavaDoc().getSourceClasses();
192
193         Map dests = new HashMap();
194
195         for (Iterator i = classes.iterator(); i.hasNext(); ) {
196             XClass clazz = (XClass) i.next();
197
198             setCurrentClass(clazz);
199
200             if (getCurrentClass().getDoc().hasTag("ejb.message-destination")) {
201                 XTag tag = getCurrentClass().getDoc().getTag("ejb.message-destination");
202                 String JavaDoc destName = tag.getAttributeValue("name");
203
204                 if (destName != null) {
205                     dests.put(destName, tag);
206                 }
207             }
208         }
209
210         // Output set of destinations
211
for (Iterator it = dests.values().iterator(); it.hasNext(); ) {
212             currentDestination = (XTag) it.next();
213
214             generate(template);
215         }
216     }
217
218     /**
219      * Returns the name of the current message destination
220      *
221      * @return Current message destination's name
222      * @exception XDocletException
223      * @see #forAllDestinations(java.lang.String)
224      * @doc.tag type="content"
225      */

226     public String JavaDoc destinationName() throws XDocletException
227     {
228         return currentDestination.getAttributeValue("name");
229     }
230
231     /**
232      * Returns the display-name of the current message destination
233      *
234      * @return Current message destination's display-name
235      * @exception XDocletException
236      * @see #forAllDestinations(java.lang.String)
237      * @doc.tag type="content"
238      */

239     public String JavaDoc destinationDisplayName() throws XDocletException
240     {
241         return currentDestination.getAttributeValue("display-name");
242     }
243
244     /**
245      * Evaluate the body block if the current message destination has a display-name
246      *
247      * @param template The body of the block tag
248      * @exception XDocletException
249      * @doc.tag type="block"
250      */

251     public void ifDestinationHasDisplayName(String JavaDoc template) throws XDocletException
252     {
253         if (destinationDisplayName() != null) {
254             generate(template);
255         }
256     }
257
258     /**
259      * Returns the jndi-name of the current message destination
260      *
261      * @return Current message destination's jndi-name
262      * @exception XDocletException
263      * @see #forAllDestinations(java.lang.String)
264      * @doc.tag type="content"
265      */

266     public String JavaDoc destinationJndiName() throws XDocletException
267     {
268         return currentDestination.getAttributeValue("jndi-name");
269     }
270
271     /**
272      * Evaluate the body block if the current message destination has a jndi-name
273      *
274      * @param template The body of the block tag
275      * @exception XDocletException
276      * @doc.tag type="block"
277      */

278     public void ifDestinationHasJndiName(String JavaDoc template) throws XDocletException
279     {
280         if (destinationJndiName() != null) {
281             generate(template);
282         }
283     }
284
285     /**
286      * Returns the description of the current message destination
287      *
288      * @return Current message destination's description
289      * @exception XDocletException
290      * @see #forAllDestinations(java.lang.String)
291      * @doc.tag type="content"
292      */

293     public String JavaDoc destinationDescription() throws XDocletException
294     {
295         return currentDestination.getAttributeValue("description");
296     }
297
298     /**
299      * Evaluate the body block if the current message destination has a descrition
300      *
301      * @param template The body of the block tag
302      * @exception XDocletException
303      * @doc.tag type="block"
304      */

305     public void ifDestinationHasDescription(String JavaDoc template) throws XDocletException
306     {
307         if (destinationDescription() != null) {
308             generate(template);
309         }
310     }
311
312     /**
313      * Returns true if the current class has a activation config
314      *
315      * @return <code>true</code> if the current class has a activation config
316      * @exception XDocletException
317      */

318     private boolean hasActivationConfig() throws XDocletException
319     {
320         Properties props = new Properties();
321
322         props.setProperty("tagName", "ejb.bean");
323         props.setProperty("paramName", "destination-type");
324         if (hasTag(props, FOR_CLASS)) {
325             return true;
326         }
327
328         props.setProperty("paramName", "acknowledge-mode");
329         if (hasTag(props, FOR_CLASS)) {
330             return true;
331         }
332
333         props.setProperty("paramName", "subscription-durability");
334         if (hasTag(props, FOR_CLASS)) {
335             return true;
336         }
337
338         props.setProperty("paramName", "message-selector");
339         if (hasTag(props, FOR_CLASS)) {
340             return true;
341         }
342
343         props.setProperty("tagName", "ejb.activation-config-property");
344         props.setProperty("paramName", "");
345         return hasTag(props, FOR_CLASS);
346     }
347
348 }
349
350
Popular Tags