KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > web > ServiceEndpointSubTask


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

5 package xdoclet.modules.web;
6
7 import org.apache.commons.logging.Log;
8
9 import xjavadoc.XClass;
10 import xjavadoc.XTag;
11
12 import xdoclet.TemplateSubTask;
13 import xdoclet.XDocletException;
14 import xdoclet.XDocletMessages;
15
16 import xdoclet.tagshandler.PackageTagsHandler;
17
18 import xdoclet.util.LogUtil;
19 import xdoclet.util.Translator;
20
21 /**
22  * Generates service endpoint interfaces for JAXPRC beans.
23  *
24  * @author Christoph G. Jung (christoph.jung@infor.de)
25  * @created 22.12.03
26  * @ant.element display-name="Service-Endpoint Interface" name="service-endpoint"
27  * parent="xdoclet.modules.web.WebDocletTask"
28  * @version $Revision: 1.3 $
29  * @xdoclet.merge-file file="service-endpoint-custom.xdt" relates-to="{0}.java" description="A text file containing
30  * custom template and/or java code to include in the service-endpoint interface."
31  */

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

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

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

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

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

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

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

126     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
127     {
128         if (super.matchesGenerationRules(clazz) == false) {
129             return false;
130         }
131
132         XTag interfaceTag = clazz.getDoc().getTag(WEB_SERVLET);
133
134         Log log = LogUtil.getLog(ServiceEndpointSubTask.class, "matchesGenerationRules");
135
136         if (interfaceTag == null) {
137             log.debug("Reject file " + clazz.getQualifiedName() + " because of not being a servlet");
138             return false;
139         }
140
141         return true;
142     }
143
144     /**
145      * Describe what the method does
146      *
147      * @exception XDocletException
148      */

149     protected void engineStarted() throws XDocletException
150     {
151         System.out.println(Translator.getString(XDocletModulesWebMessages.class, XDocletModulesWebMessages.GENERATING_SERVICE_ENDPOINT_FOR,
152             new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
153     }
154 }
155
Popular Tags