KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > intf > RemoteInterfaceSubTask


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

5 package xdoclet.modules.ejb.intf;
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 remote interfaces for EJBs.
25  *
26  * @author Ara Abrahamian (ara_e@email.com)
27  * @created Oct 15, 2001
28  * @ant.element display-name="Remote Interface" name="remoteinterface"
29  * parent="xdoclet.modules.ejb.EjbDocletTask"
30  * @version $Revision: 1.12 $
31  * @xdoclet.merge-file file="remote-custom.xdt" relates-to="{0}.java" description="A text file containing custom
32  * template and/or java code to include in the remote interface."
33  */

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

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

52     public RemoteInterfaceSubTask()
53     {
54         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
55         setDestinationFile(getRemoteClassPattern() + ".java");
56         addOfType("javax.ejb.EntityBean");
57         addOfType("javax.ejb.SessionBean");
58     }
59
60     /**
61      * Returns the configuration parameter for specifying the remote interface name pattern. By default the value is
62      * used for deciding the remote 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}" is used by
64      * default.
65      *
66      * @return The RemoteClassPattern value
67      * @see #remoteClassPattern
68      */

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

85     public void setPattern(String JavaDoc newPattern)
86     {
87         remoteClassPattern = newPattern;
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 (getRemoteClassPattern() == null || getRemoteClassPattern().trim().equals("")) {
100             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"pattern"}));
101         }
102
103         if (getRemoteClassPattern().indexOf("{0}") == -1) {
104             throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER));
105         }
106     }
107
108
109     /**
110      * Gets the GeneratedFileName attribute of the RemoteInterfaceSubTask object
111      *
112      * @param clazz Describe what the parameter does
113      * @return The GeneratedFileName value
114      * @exception XDocletException
115      */

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

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

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