KickJava   Java API By Example, From Geeks To Geeks.

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


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.modules.ejb.entity.FacadeTagsHandler;
17
18 import xdoclet.tagshandler.PackageTagsHandler;
19 import xdoclet.util.LogUtil;
20
21 import xdoclet.util.Translator;
22
23 /**
24  * this subtask is stage 2 of remote facade generation.
25  *
26  * @author Konstantin Pribluda (kpriblouda@yahoo.com)
27  * @created September 10, 2002
28  * @ant.element display-name="Facade" name="remotefacade" parent="xdoclet.modules.ejb.EjbDocletTask"
29  * @version $Revision: 1.4 $
30  */

31
32 public class RemoteFacadeSubTask extends AbstractEjbCodeGeneratorSubTask
33 {
34     public final static String JavaDoc DEFAULT_REMOTE_FACADE_CLASS_PATTERN = "{0}Remote";
35     protected final static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/remotefacade.xdt";
36
37     /**
38      * A configuration parameter for specifying the entity bean facade EJB class name pattern. By default the value is
39      * used for deciding the entity bean facade class name. {0} in the value mean current class's symbolic name which
40      * for an EJBean is the EJB name.
41      */

42     protected String JavaDoc remoteFacadeClassPattern;
43
44     /**
45      * a configuration parameter for specifying facade ejb names pattern {0} means ejb name
46      */

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

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

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

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

110     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
111     {
112         return PackageTagsHandler.packageNameAsPathFor(FacadeTagsHandler.getRemoteFacadeClassFor(getCurrentClass())) + ".java";
113     }
114
115     /**
116      * we accept session beans generated on first stage runs.
117      *
118      * @param clazz Describe what the parameter does
119      * @return Describe the return value
120      * @exception XDocletException
121      * @todo refactor/merge this method with matchesGenerationRules from EntityBmpSubTask
122      */

123     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
124     {
125         Log log = LogUtil.getLog(RemoteFacadeSubTask.class, "matchesGenerationRules");
126
127         System.out.println("remote facade tests: " + clazz.getQualifiedName());
128         if (super.matchesGenerationRules(clazz) == false) {
129             System.out.println("super failed");
130             log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false.");
131             return false;
132         }
133
134         if (SessionTagsHandler.isSession(getCurrentClass()) == false) {
135             System.out.println("session failed");
136
137             log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not session bean.");
138             return false;
139         }
140
141         String JavaDoc generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false);
142
143         if ((generate != null) && (generate.equals("false") || generate.equals("no"))) {
144             System.out.println("generate failed");
145             log.debug("Skip remote facade for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
146             return false;
147         }
148
149         if (!clazz.getDoc().hasTag("ejb.remote-facade")) {
150             System.out.println("remote-facade failed");
151             log.debug("Skip facade class for " + clazz.getQualifiedName() + " because ejb.remote-facade is absent");
152             return false;
153         }
154
155         String JavaDoc facade = clazz.getDoc().getTagAttributeValue("ejb.remote-facade", "generate", false);
156
157         if ((facade != null) && (facade.equals("false") || facade.equals("no"))) {
158             System.out.println("remote-facade generate failed");
159             log.debug("Skip facade class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
160             return false;
161         }
162
163         if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) {
164             return true;
165         }
166         else {
167             System.out.println("not concrete failed");
168             log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean.");
169             return false;
170         }
171     }
172
173     /**
174      * Describe what the method does
175      *
176      * @exception XDocletException
177      */

178     protected void engineStarted() throws XDocletException
179     {
180         System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_REMOTE_FACADE_FOR,
181             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
182     }
183
184 }
185
186
Popular Tags