KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package xdoclet.modules.ejb.entity;
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
18 import xdoclet.util.LogUtil;
19 import xdoclet.util.Translator;
20
21 /**
22  * Creates "entity bean classes" for BMP entity EJBs. The classes are derived from the abstract entity bean class. <br/>
23  * <b>Attention:</b> To give the developer more control over when the EJB becomes dirty (data changed) there is now a
24  * method called "makeDirty()" in the generated wrapper class. To use this please add to your EJB an abstract method
25  * called "makeDirty" and call it when you change data w/o using the setter methods. As example you could store the Data
26  * Object instead of storing all the attributes one by one (be aware that you have to clone the data object before
27  * storing to avoid side effects).
28  *
29  * @author Ara Abrahamian (ara_e@email.com)
30  * @created Oct 15, 2001
31  * @ant.element display-name="BMP" name="entitybmp" parent="xdoclet.modules.ejb.EjbDocletTask"
32  * @version $Revision: 1.11 $
33  * @xdoclet.merge-file file="entitybmp-custom.xdt" relates-to="{0}BMP.java" description="A text file containing custom
34  * template and/or java code to include in the EJB BMP class."
35  */

36 public class EntityBmpSubTask extends AbstractEjbCodeGeneratorSubTask
37 {
38     public final static String JavaDoc DEFAULT_ENTITYBMP_CLASS_PATTERN = "{0}BMP";
39
40     protected final static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/entitybmp.xdt";
41
42     /**
43      * A configuration parameter for specifying the concrete BMP entity bean class name pattern. By default the value is
44      * used for deciding the concrete BMP entity bean class name. The placeholder "{0}" in the value means the current
45      * class's symbolic name which for an EJBean is the EJB name.
46      *
47      * @see #getEntityBmpClassPattern()
48      */

49     protected String JavaDoc entityBmpClassPattern;
50
51
52     /**
53      * Describe what the EntityBmpSubTask constructor does
54      */

55     public EntityBmpSubTask()
56     {
57         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
58         setDestinationFile(getEntityBmpClassPattern() + ".java");
59         addOfType("javax.ejb.EntityBean");
60         setPackageSubstitutionInheritanceSupported(false);
61     }
62
63
64     /**
65      * Returns the configuration parameter for specifying the concrete BMP entity bean class name pattern. By default
66      * the value is used for deciding the concrete BMP entity bean class name. The placeholder "{0}" in the value means
67      * the current class's symbolic name which for an EJBean is the EJB name. If nothing explicitly specified by user
68      * then "{0}BMP" is used by default.
69      *
70      * @return The EntityBmpClassPattern value
71      * @see #entityBmpClassPattern
72      */

73     public String JavaDoc getEntityBmpClassPattern()
74     {
75         if (entityBmpClassPattern != null) {
76             return entityBmpClassPattern;
77         }
78         else {
79             return DEFAULT_ENTITYBMP_CLASS_PATTERN;
80         }
81     }
82
83
84     /**
85      * The pattern by which the BMP implementation classes are named. The placeholder "{0}" designates the EJB name.
86      *
87      * @param new_pattern The new Pattern value
88      * @ant.not-required No, defaults to {0}BMP
89      */

90     public void setPattern(String JavaDoc new_pattern)
91     {
92         entityBmpClassPattern = new_pattern;
93     }
94
95
96     /**
97      * Called to validate configuration parameters.
98      *
99      * @exception XDocletException
100      */

101     public void validateOptions() throws XDocletException
102     {
103         super.validateOptions();
104
105         if (getEntityBmpClassPattern() == null || getEntityBmpClassPattern().trim().equals("")) {
106             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"pattern"}));
107         }
108
109         if (getEntityBmpClassPattern().indexOf("{0}") == -1) {
110             throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER));
111         }
112     }
113
114
115     /**
116      * Gets the GeneratedFileName attribute of the EntityBmpSubTask object
117      *
118      * @param clazz Describe what the parameter does
119      * @return The GeneratedFileName value
120      * @exception XDocletException
121      */

122     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
123     {
124         return PackageTagsHandler.packageNameAsPathFor(BmpTagsHandler.getEntityBmpClassFor(getCurrentClass())) + ".java";
125     }
126
127
128     /**
129      * Describe what the method does
130      *
131      * @param clazz Describe what the parameter does
132      * @return Describe the return value
133      * @exception XDocletException
134      */

135     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
136     {
137         Log log = LogUtil.getLog(EntityBmpSubTask.class, "matchesGenerationRules");
138
139         if (super.matchesGenerationRules(clazz) == false) {
140             log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false.");
141             return false;
142         }
143
144         if (!BmpTagsHandler.isEntityBmp(getCurrentClass())) {
145             log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not BMP.");
146             return false;
147         }
148
149         String JavaDoc generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false);
150
151         if ((generate != null) && (generate.equals("false") || generate.equals("no"))) {
152             log.debug("Skip entity bmp class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
153             return false;
154         }
155
156         if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) {
157             return true;
158         }
159         else {
160             log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean.");
161             return false;
162         }
163     }
164
165
166     /**
167      * Describe what the method does
168      *
169      * @exception XDocletException
170      */

171     protected void engineStarted() throws XDocletException
172     {
173         System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_BMP_FOR,
174             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
175     }
176 }
177
Popular Tags