KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > wsee > WsdlSubTask


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

5 package xdoclet.modules.wsee;
6
7 import java.io.File JavaDoc;
8
9 import java.text.MessageFormat JavaDoc;
10 import org.apache.commons.logging.Log;
11
12 import xjavadoc.XClass;
13 import xjavadoc.XPackage;
14
15 import xdoclet.ConfigParamIntrospector;
16 import xdoclet.XDocletException;
17 import xdoclet.XmlSubTask;
18 import xdoclet.tagshandler.PackageTagsHandler;
19 import xdoclet.util.LogUtil;
20 import xdoclet.util.Translator;
21
22 /**
23  * Subtask that generates a service.wsdl service descriptor.
24  *
25  * @author Christoph G. Jung (christoph.jung@infor.de)
26  * @author Jason Essington (jasone@greenrivercomputing.com)
27  * @created 23.12.03
28  * @ant.element display-name="service.wsdl" name="wsdl" parent="xdoclet.modules.wsee.WseeDocletTask"
29  * @version $Revision: 1.2 $
30  */

31 public class WsdlSubTask extends XmlSubTask
32 {
33     public final static String JavaDoc DEFAULT_WSDL_FILE_PATTERN = "wsdl/{0}.wsdl";
34     /**
35      * constants
36      */

37     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/wsdl.xdt";
38
39     private boolean prefixWithPackageStructure = false;
40
41     /**
42      * sets template
43      */

44     public WsdlSubTask()
45     {
46         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
47     }
48
49     /**
50      * Gets the PrefixWithPackageStructure attribute of the TemplateSubTask object
51      *
52      * @return The PrefixWithPackageStructure value
53      */

54     public boolean isPrefixWithPackageStructure()
55     {
56         return prefixWithPackageStructure;
57     }
58
59     /**
60      * Indicates whether or not to prefix with package structure.
61      *
62      * @param prefixWithPackageStructure The new PrefixWithPackageStructure value
63      * @ant.not-required No, default is "true"
64      */

65     public void setPrefixWithPackageStructure(boolean prefixWithPackageStructure)
66     {
67         this.prefixWithPackageStructure = prefixWithPackageStructure;
68     }
69
70     /**
71      * run subtask
72      *
73      * @exception XDocletException
74      */

75     public void execute() throws XDocletException
76     {
77         validateOptions();
78         startProcess();
79     }
80
81     /*
82      * validate wsdl file parameter
83      * @see xdoclet.SubTask#validateOptions()
84      */

85     public void validateOptions() throws XDocletException
86     {
87         Object JavaDoc wsdlFile = getContext().getConfigParam("wsdlFile");
88
89         if (wsdlFile == ConfigParamIntrospector.NULL || "".equals(wsdlFile)) {
90             wsdlFile = DEFAULT_WSDL_FILE_PATTERN;
91         }
92         setDestinationFile((String JavaDoc) wsdlFile);
93         super.validateOptions();
94     }
95
96     /**
97      * Returns class name for the generated file. {0} substituted by wsee.port-component name.
98      *
99      * @param clazz Description of Parameter
100      * @return The GeneratedClassName value
101      * @exception XDocletException Description of Exception
102      */

103     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
104     {
105         Log log = LogUtil.getLog(WsdlSubTask.class, "getGeneratedFileName");
106
107         XPackage pak = clazz.getContainingPackage();
108         String JavaDoc package_structure = null;
109
110         if (isPrefixWithPackageStructure() == true)
111             // This will do package substitution too
112
package_structure = PackageTagsHandler.packageNameAsPathFor(pak);
113         else
114             package_structure = null;
115
116         String JavaDoc packageName = isPackageSubstitutionInheritanceSupported() == true ? package_structure : null;
117
118         String JavaDoc serviceName = getCurrentClass().getDoc().getTagAttributeValue(WseeTagsHandler.PORT_COMPONENT, "name");
119         String JavaDoc file = new File JavaDoc(packageName, serviceName).toString();
120
121         String JavaDoc destinationFile = MessageFormat.format(getDestinationFile(), new Object JavaDoc[]{file});
122
123         if (log.isDebugEnabled()) {
124             log.debug("clazz.getName()=" + clazz.getName());
125             log.debug("clazz.getQualifiedName()=" + clazz.getQualifiedName());
126             log.debug("pak=" + pak);
127             log.debug("packageName=" + packageName);
128             log.debug("serviceName=" + serviceName);
129             log.debug("destinationFile=" + destinationFile);
130         }
131         return destinationFile;
132     }
133
134     /**
135      * notify start of task
136      *
137      * @exception XDocletException
138      */

139     protected void engineStarted() throws XDocletException
140     {
141         System.out.println(
142             Translator.getString(
143             XDocletModulesMessages.class,
144             XDocletModulesMessages.GENERATING_WSDL_DESCRIPTOR,
145             new String JavaDoc[]{getDestinationFile()}));
146     }
147
148     /**
149      * Describe what the method does
150      *
151      * @param clazz Describe what the parameter does
152      * @return Describe the return value
153      * @exception XDocletException
154      */

155     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
156     {
157         Log log = LogUtil.getLog(WsdlSubTask.class, "matchesGenerationRules");
158
159         if (super.matchesGenerationRules(clazz) == false) {
160             log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false.");
161             return false;
162         }
163
164         // TODO improve this check to make sure that our class is also a service-endpoint (SLSB or servlet)
165
boolean isPortComponent = getCurrentClass().getDoc().hasTag(WseeTagsHandler.PORT_COMPONENT, false);
166
167         return isPortComponent;
168     }
169
170 }
171
Popular Tags