KickJava   Java API By Example, From Geeks To Geeks.

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


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 import xdoclet.util.LogUtil;
18
19 import xdoclet.util.Translator;
20
21 /**
22  * @author Konstantin Pribluda (kpriblouda@yahoo.com)
23  * @created September 8, 2002
24  * @ant.element display-name="Facade" name="entityfacade" parent="xdoclet.modules.ejb.EjbDocletTask"
25  * @version $Revision: 1.3 $
26  */

27
28 public class EntityFacadeSubTask extends AbstractEjbCodeGeneratorSubTask
29 {
30     public final static String JavaDoc DEFAULT_ENTITY_FACADE_CLASS_PATTERN = "{0}FacadeEJB";
31
32     public final static String JavaDoc DEFAULT_FACADE_EJB_NAME_PATTERN = "{0}Facade";
33     protected final static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/entityfacade.xdt";
34
35     /**
36      * A configuration parameter for specifying the entity bean facade EJB class name pattern. By default the value is
37      * used for deciding the entity bean facade class name. {0} in the value mean current class's symbolic name which
38      * for an EJBean is the EJB name.
39      */

40     protected String JavaDoc entityFacadeClassPattern;
41     /**
42      * a configuration parameter for specifying facade ejb names pattern {0} means ejb name
43      */

44     protected String JavaDoc entityFacadeEjbNamePattern;
45
46     public EntityFacadeSubTask()
47     {
48         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
49         setDestinationFile(getEntityFacadeClassPattern() + ".java");
50         addOfType("javax.ejb.EntityBean");
51         setPackageSubstitutionInheritanceSupported(false);
52
53     }
54
55     /**
56      * Returns the configuration parameter for specifying the entity bean facade class name pattern. By default the
57      * value is used for deciding the concrete CMP entity bean class name. {0} in the value mean current class's
58      * symbolic name which for an EJBean is the EJB name. If nothing explicitly specified by user then "{0}FacadeEJB" is
59      * used by default.
60      *
61      * @return The EntityCmpClassPattern value
62      * @see #entityCmpFacadePattern
63      */

64     public String JavaDoc getEntityFacadeClassPattern()
65     {
66         if (entityFacadeClassPattern != null) {
67             return entityFacadeClassPattern;
68         }
69         else {
70             return DEFAULT_ENTITY_FACADE_CLASS_PATTERN;
71         }
72     }
73
74
75     public String JavaDoc getEntityFacadeEjbNamePattern()
76     {
77         if (entityFacadeEjbNamePattern != null) {
78             return entityFacadeEjbNamePattern;
79         }
80         else {
81             return DEFAULT_FACADE_EJB_NAME_PATTERN;
82         }
83     }
84
85     /**
86      * Sets the Pattern attribute of the EntityFacadeSubTask object
87      *
88      * @param new_pattern The new Pattern value
89      */

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

105     public void validateOptions() throws XDocletException
106     {
107         super.validateOptions();
108
109         if (getEntityFacadeClassPattern() == null || getEntityFacadeClassPattern().trim().equals("")) {
110             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"pattern"}));
111         }
112
113         if (getEntityFacadeClassPattern().indexOf("{0}") == -1) {
114             throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER));
115         }
116
117         if (getEntityFacadeEjbNamePattern() == null || getEntityFacadeEjbNamePattern().trim().equals("")) {
118             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"ejbNamePattern"}));
119         }
120         if (getEntityFacadeEjbNamePattern().indexOf("{0}") == -1) {
121             throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER));
122         }
123     }
124
125     /**
126      * Gets the GeneratedFileName attribute of the EntityCmpSubTask object
127      *
128      * @param clazz Describe what the parameter does
129      * @return The GeneratedFileName value
130      * @exception XDocletException
131      */

132     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
133     {
134         return PackageTagsHandler.packageNameAsPathFor(FacadeTagsHandler.getEntityFacadeClassFor(getCurrentClass())) + ".java";
135     }
136
137
138     /**
139      * @param clazz Describe what the parameter does
140      * @return Describe the return value
141      * @exception XDocletException
142      * @todo refactor/merge this method with matchesGenerationRules from EntityBmpSubTask
143      */

144     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
145     {
146         Log log = LogUtil.getLog(EntityFacadeSubTask.class, "matchesGenerationRules");
147
148         if (super.matchesGenerationRules(clazz) == false) {
149             log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false.");
150             return false;
151         }
152
153         if (EntityTagsHandler.isEntity(getCurrentClass()) == false) {
154             log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not entity.");
155             return false;
156         }
157
158         String JavaDoc generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false);
159
160         if ((generate != null) && (generate.equals("false") || generate.equals("no"))) {
161             log.debug("Skip entity class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
162             return false;
163         }
164
165         if (!clazz.getDoc().hasTag("ejb.facade")) {
166             log.debug("Skip facade class for " + clazz.getQualifiedName() + " because ejb.facade is absent");
167             return false;
168         }
169
170         String JavaDoc facade = clazz.getDoc().getTagAttributeValue("ejb.facade", "generate", false);
171
172         if ((facade != null) && (facade.equals("false") || facade.equals("no"))) {
173             log.debug("Skip facade class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
174             return false;
175         }
176
177         if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) {
178             return true;
179         }
180         else {
181             log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean.");
182             return false;
183         }
184     }
185
186
187     /**
188      * Describe what the method does
189      *
190      * @exception XDocletException
191      */

192     protected void engineStarted() throws XDocletException
193     {
194         System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_FACADE_FOR,
195             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
196     }
197
198 }
199
200
Popular Tags