KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package xdoclet.modules.ejb.mdb;
6
7
8 import org.apache.commons.logging.Log;
9
10 import xjavadoc.XClass;
11
12 import xdoclet.XDocletException;
13 import xdoclet.XDocletMessages;
14 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask;
15 import xdoclet.modules.ejb.EjbTagsHandler;
16 import xdoclet.modules.ejb.XDocletModulesEjbMessages;
17 import xdoclet.tagshandler.PackageTagsHandler;
18 import xdoclet.util.LogUtil;
19
20 import xdoclet.util.Translator;
21
22 /**
23  * @author Jonathan Kovacs (jonk at globaliqx.com)
24  * @created Sept 15, 2003
25  * @ant.element display-name="Mdb Bean" name="mdb" parent="xdoclet.modules.ejb.EjbDocletTask"
26  * @version $Revision: 1.2 $
27  * @xdoclet.merge-file file="mdb-custom.xdt" relates-to="{0}Mdb.java" description="A text file containing custom
28  * template and/or java code to include in the EJB mdb class."
29  */

30 public class MdbSubTask extends AbstractEjbCodeGeneratorSubTask
31 {
32     public final static String JavaDoc DEFAULT_MESSAGE_DRIVEN_CLASS_PATTERN = "{0}Mdb";
33
34     protected final static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/mdb.xdt";
35
36     /**
37      * A configuration parameter for specifying the concrete mdb bean class name pattern. By default the value is used
38      * for deciding the concrete mdb bean class name. {0} in the value mean current class's symbolic name which for an
39      * EJBean is the EJB name.
40      *
41      * @see #getMessageDrivenClassPattern()
42      */

43     protected String JavaDoc mdbClassPattern;
44
45
46     /**
47      * Describe what the MdbSubTask constructor does
48      */

49     public MdbSubTask()
50     {
51         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
52         setDestinationFile(getMessageDrivenClassPattern() + ".java");
53         addOfType("javax.ejb.MessageDrivenBean");
54         setPackageSubstitutionInheritanceSupported(false);
55     }
56
57     /**
58      * Returns the configuration parameter for specifying the concrete mdb bean class name pattern. By default the value
59      * is used for deciding the concrete mdb bean class name. {0} in the value mean current class's symbolic name which
60      * for an EJBean is the EJB name. If nothing explicitly specified by user then "{0}Mdb" is used by default.
61      *
62      * @return The MdbClassPattern value
63      * @see #mdbClassPattern
64      */

65     public String JavaDoc getMessageDrivenClassPattern()
66     {
67         if (mdbClassPattern != null) {
68             return mdbClassPattern;
69         }
70         else {
71             return DEFAULT_MESSAGE_DRIVEN_CLASS_PATTERN;
72         }
73     }
74
75
76     /**
77      * Sets the Pattern attribute of the MdbSubTask object
78      *
79      * @param new_pattern The new Pattern value
80      */

81     public void setPattern(String JavaDoc new_pattern)
82     {
83         mdbClassPattern = new_pattern;
84     }
85
86
87     /**
88      * Called to validate configuration parameters.
89      *
90      * @exception XDocletException
91      */

92     public void validateOptions() throws XDocletException
93     {
94         super.validateOptions();
95
96         if (getMessageDrivenClassPattern() == null || getMessageDrivenClassPattern().trim().equals("")) {
97             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"pattern"}));
98         }
99
100         if (getMessageDrivenClassPattern().indexOf("{0}") == -1) {
101             throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER));
102         }
103     }
104
105
106     /**
107      * Gets the GeneratedFileName attribute of the MdbSubTask object
108      *
109      * @param clazz Describe what the parameter does
110      * @return The GeneratedFileName value
111      * @exception XDocletException
112      */

113     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
114     {
115         return PackageTagsHandler.packageNameAsPathFor(MdbTagsHandler.getMessageDrivenClassFor(getCurrentClass())) + ".java";
116     }
117
118
119     /**
120      * Describe what the method does
121      *
122      * @exception XDocletException
123      */

124     protected void engineStarted() throws XDocletException
125     {
126         System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_MDB_FOR,
127             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
128     }
129
130
131     /**
132      * Describe what the method does
133      *
134      * @param clazz Describe what the parameter does
135      * @return Describe the return value
136      * @exception XDocletException
137      */

138     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
139     {
140         Log log = LogUtil.getLog(MdbSubTask.class, "matchesGenerationRules");
141
142         if (super.matchesGenerationRules(clazz) == false) {
143             log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false.");
144             return false;
145         }
146
147         String JavaDoc generate = getCurrentClass().getDoc().getTagAttributeValue("ejb:bean", "generate", false);
148
149         if ((generate != null) && (generate.equals("false") || generate.equals("no"))) {
150             log.debug("Skip mdb class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
151             return false;
152         }
153
154         if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) {
155             return true;
156         }
157         else {
158             log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean.");
159             return false;
160         }
161     }
162
163 }
164
Popular Tags