KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > home > LocalHomeInterfaceSubTask


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

5 package xdoclet.modules.ejb.home;
6
7 import org.apache.commons.logging.Log;
8
9 import xjavadoc.XClass;
10 import xjavadoc.XTag;
11
12 import xdoclet.XDocletException;
13 import xdoclet.XDocletMessages;
14
15 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask;
16 import xdoclet.modules.ejb.XDocletModulesEjbMessages;
17 import xdoclet.modules.ejb.intf.InterfaceTagsHandler;
18 import xdoclet.tagshandler.PackageTagsHandler;
19
20 import xdoclet.util.LogUtil;
21 import xdoclet.util.Translator;
22
23 /**
24  * Generates local home interfaces for EJBs.
25  *
26  * @author Ara Abrahamian (ara_e@email.com)
27  * @created Oct 15, 2001
28  * @ant.element display-name="Local Home Interface" name="localhomeinterface"
29  * parent="xdoclet.modules.ejb.EjbDocletTask"
30  * @version $Revision: 1.13 $
31  * @xdoclet.merge-file file="local-home-custom.xdt" relates-to="{0}LocalHome.java" description="A text file containing
32  * custom template and/or java code to include in the local home interface."
33  */

34 public class LocalHomeInterfaceSubTask extends AbstractEjbCodeGeneratorSubTask
35 {
36     public final static String JavaDoc DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN = "{0}LocalHome";
37
38     protected final static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/home-local.xdt";
39
40     /**
41      * A configuration parameter for specifying the local home interface name pattern. By default the value is used for
42      * deciding the local home interface name. The placeholder "{0}" in the value means the current class's symbolic
43      * name which for an EJBean is the EJB name.
44      *
45      * @see #getLocalHomeClassPattern()
46      */

47     protected String JavaDoc localHomeClassPattern;
48
49     /**
50      * Describe what the LocalHomeInterfaceSubTask constructor does
51      */

52     public LocalHomeInterfaceSubTask()
53     {
54         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
55         setDestinationFile(getLocalHomeClassPattern() + ".java");
56         addOfType("javax.ejb.EntityBean");
57         addOfType("javax.ejb.SessionBean");
58     }
59
60     /**
61      * Returns the configuration parameter for specifying the local home interface name pattern. By default the value is
62      * used for deciding the local home interface name. The placeholder "{0}" in the value means the current class's
63      * symbolic name which for an EJBean is the EJB name. If nothing explicitly specified by user then "{0}LocalHome" is
64      * used by default.
65      *
66      * @return The LocalHomeClassPattern value
67      * @see #localHomeClassPattern
68      */

69     public String JavaDoc getLocalHomeClassPattern()
70     {
71         if (localHomeClassPattern != null) {
72             return localHomeClassPattern;
73         }
74         else {
75             return DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN;
76         }
77     }
78
79     /**
80      * The pattern by which the local home interfaces are named. The placeholder "{0}" designates the EJB name.
81      *
82      * @param new_pattern The new Pattern value
83      * @ant.not-required No, defaults to {0}LocalHome
84      */

85     public void setPattern(String JavaDoc new_pattern)
86     {
87         localHomeClassPattern = new_pattern;
88     }
89
90     /**
91      * Called to validate configuration parameters.
92      *
93      * @exception XDocletException
94      */

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

115     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
116     {
117         return PackageTagsHandler.packageNameAsPathFor(HomeTagsHandler.getHomeInterface("local", getCurrentClass())) + ".java";
118     }
119
120     /**
121      * Describe what the method does
122      *
123      * @param clazz Describe what the parameter does
124      * @return Describe the return value
125      * @exception XDocletException
126      */

127     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
128     {
129         if (super.matchesGenerationRules(clazz) == false) {
130             return false;
131         }
132
133         Log log = LogUtil.getLog(LocalHomeInterfaceSubTask.class, "matchesGenerationRules");
134
135         if (!InterfaceTagsHandler.isLocalEjb(getCurrentClass())) {
136             log.debug("Reject file " + clazz.getQualifiedName() + " because of different view-type");
137             return false;
138         }
139
140         XTag interfaceTag = getCurrentClass().getDoc().getTag("ejb:home");
141
142         if (interfaceTag == null) {
143             return true;
144         }
145
146         String JavaDoc generate = interfaceTag.getAttributeValue("generate");
147
148         if (generate != null && generate.indexOf("local") == -1) {
149             log.debug("Skip local home interface for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag.");
150             return false;
151         }
152
153         return true;
154     }
155
156     /**
157      * Describe what the method does
158      *
159      * @exception XDocletException
160      */

161     protected void engineStarted() throws XDocletException
162     {
163         System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_LOCALHOME_FOR,
164             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
165     }
166 }
167
Popular Tags