KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > session > SessionSubTask


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

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

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

42     protected String JavaDoc sessionClassPattern;
43
44
45     /**
46      * Describe what the SessionSubTask constructor does
47      */

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

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

81     public void setPattern(String JavaDoc new_pattern)
82     {
83         sessionClassPattern = 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 (getSessionClassPattern() == null || getSessionClassPattern().trim().equals("")) {
97             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"pattern"}));
98         }
99
100         if (getSessionClassPattern().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 SessionSubTask 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(SessionTagsHandler.getSessionClassFor(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_SESSION_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(SessionSubTask.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 session 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