KickJava   Java API By Example, From Geeks To Geeks.

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


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.tagshandler.PackageTagsHandler;
18
19 import xdoclet.util.LogUtil;
20 import xdoclet.util.Translator;
21
22 /**
23  * Generates service endpoint interfaces for JAXPRC beans.
24  *
25  * @author Christoph G. Jung (christoph.jung@infor.de)
26  * @created 24. Februar 2004
27  * @since 22.12.03
28  * @version $Revision: 1.2 $
29  * @ant.element display-name="Service-Endpoint Interface" name="service-endpoint"
30  * parent="xdoclet.modules.ejb.EjbDocletTask"
31  * @xdoclet.merge-file file="service-endpoint-custom.xdt" relates-to="{0}.java" description="A text file containing
32  * custom template and/or java code to include in the service-endpoint interface."
33  */

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

48     protected String JavaDoc serviceEndpointClassPattern;
49
50     /**
51      * Describe what the ServiceEndpointSubTask constructor does
52      */

53     public ServiceEndpointSubTask()
54     {
55         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
56         setDestinationFile(getServiceEndpointClassPattern() + ".java");
57         addOfType("javax.ejb.SessionBean");
58     }
59
60     /**
61      * Returns the configuration parameter for specifying the service-endpoint interface name pattern. By default the
62      * value is used for deciding the service-endpoint interface name. {0} in the value mean current class's symbolic
63      * name which for an EJBean is the EJB name. If nothing explicitly specified by user then "{0}" is used by default.
64      *
65      * @return The ServiceEndpointClassPattern value
66      * @see #remoteClassPattern
67      */

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

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

94     public void validateOptions() throws XDocletException
95     {
96         super.validateOptions();
97
98         if (getServiceEndpointClassPattern() == null || getServiceEndpointClassPattern().trim().equals("")) {
99             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"pattern"}));
100         }
101
102         if (getServiceEndpointClassPattern().indexOf("{0}") == -1) {
103             throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER));
104         }
105     }
106
107
108     /**
109      * Gets the GeneratedFileName attribute of the ServiceEndpointInterfaceSubTask 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(InterfaceTagsHandler.getComponentInterface(InterfaceTagsHandler.SERVICE_ENDPOINT, 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(ServiceEndpointSubTask.class, "matchesGenerationRules");
134
135         if (!InterfaceTagsHandler.isServiceEndpointEjb(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:interface");
141
142         if (interfaceTag == null) {
143             return true;
144         }
145
146         String JavaDoc generate = interfaceTag.getAttributeValue("generate");
147
148         if ((generate != null) && (generate.indexOf(InterfaceTagsHandler.SERVICE_ENDPOINT) == -1)) {
149             log.debug("Skip service-endpoint 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_SERVICE_ENDPOINT_FOR,
164             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
165     }
166 }
167
Popular Tags