KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > doc > info > InfoTagsHandler


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

5 package xdoclet.modules.doc.info;
6
7 import java.util.*;
8
9 import xjavadoc.*;
10
11 import xdoclet.XDocletException;
12 import xdoclet.XDocletTagSupport;
13 import xdoclet.modules.doc.XDocletModulesDocMessages;
14 import xdoclet.tagshandler.*;
15 import xdoclet.template.TemplateException;
16 import xdoclet.util.Translator;
17
18 /**
19  * @author <a HREF="mailto:aslak.nospam@users.sf.net">Aslak Hellesøy</a>
20  * @created Oct 15, 2001
21  * @xdoclet.taghandler namespace="Info"
22  * @version $Revision: 1.9 $
23  */

24 public class InfoTagsHandler extends XDocletTagSupport
25 {
26     /**
27      * Describe what the method does
28      *
29      * @param template Describe what the parameter does
30      * @param properties Describe what the parameter does
31      * @exception XDocletException Describe the exception
32      */

33     public void ifTagCountNotZero(String JavaDoc template, Properties properties) throws XDocletException
34     {
35         String JavaDoc level = properties.getProperty("level");
36         int tagCount = tagCount_Impl(level);
37
38         if (tagCount != 0) {
39             generate(template);
40         }
41     }
42
43     /**
44      * Describe what the method does
45      *
46      * @param properties Describe what the parameter does
47      * @return Describe the return value
48      * @exception XDocletException Describe the exception
49      */

50     public String JavaDoc tagCount(Properties properties) throws XDocletException
51     {
52         String JavaDoc level = properties.getProperty("level");
53         int tagCount = tagCount_Impl(level);
54
55         return String.valueOf(tagCount);
56     }
57
58     /**
59      * Describe what the method does
60      *
61      * @return Describe the return value
62      * @exception XDocletException Describe the exception
63      */

64     public String JavaDoc classTagValue() throws XDocletException
65     {
66         return getClassTagsHandler().classTagValue(getProperties());
67     }
68
69     /**
70      * Describe what the method does
71      *
72      * @return Describe the return value
73      * @exception XDocletException Describe the exception
74      */

75     public String JavaDoc fieldTagValue() throws XDocletException
76     {
77         return getFieldTagsHandler().fieldTagValue(getProperties());
78     }
79
80     /**
81      * Describe what the method does
82      *
83      * @return Describe the return value
84      * @exception XDocletException Describe the exception
85      */

86     public String JavaDoc constructorTagValue() throws XDocletException
87     {
88         return getConstructorTagsHandler().constructorTagValue(getProperties());
89     }
90
91     /**
92      * Describe what the method does
93      *
94      * @return Describe the return value
95      * @exception XDocletException Describe the exception
96      */

97     public String JavaDoc methodTagValue() throws XDocletException
98     {
99         return getMethodTagsHandler().methodTagValue(getProperties());
100     }
101
102     /**
103      * Describe what the method does
104      *
105      * @param template Describe what the parameter does
106      * @exception XDocletException Describe the exception
107      */

108     public void forAllClassTags(String JavaDoc template) throws XDocletException
109     {
110         getClassTagsHandler().forAllClassTags(template, getProperties());
111     }
112
113     /**
114      * Describe what the method does
115      *
116      * @param template Describe what the parameter does
117      * @exception XDocletException Describe the exception
118      */

119     public void forAllConstructorTags(String JavaDoc template) throws XDocletException
120     {
121         getConstructorTagsHandler().forAllConstructorTags(template, getProperties());
122     }
123
124     /**
125      * Describe what the method does
126      *
127      * @param template Describe what the parameter does
128      * @exception XDocletException Describe the exception
129      */

130     public void forAllMethodTags(String JavaDoc template) throws XDocletException
131     {
132         getMethodTagsHandler().forAllMethodTags(template, getProperties());
133     }
134
135     /**
136      * Describe what the method does
137      *
138      * @param template Describe what the parameter does
139      * @exception XDocletException Describe the exception
140      */

141     public void forAllFieldTags(String JavaDoc template) throws XDocletException
142     {
143         getFieldTagsHandler().forAllFieldTags(template, getProperties());
144     }
145
146     /**
147      * Describe what the method does
148      *
149      * @return Describe the return value
150      * @exception XDocletException Describe the exception
151      */

152     public String JavaDoc projectname() throws XDocletException
153     {
154         InfoSubTask infoSubTask = (InfoSubTask) getDocletContext().getActiveSubTask();
155
156         return infoSubTask.getProjectname();
157     }
158
159     /**
160      * Describe what the method does
161      *
162      * @return Describe the return value
163      * @exception XDocletException Describe the exception
164      */

165     public String JavaDoc rootlink() throws XDocletException
166     {
167         String JavaDoc packageName = "";
168
169         if (getPackageTagsHandler().packageName() != null) {
170             packageName = getPackageTagsHandler().packageName();
171         }
172
173         StringTokenizer st = new StringTokenizer(packageName, ".");
174         int n = st.countTokens();
175         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
176
177         for (int i = 0; i < n; i++) {
178             sbuf.append("../");
179         }
180         return sbuf.toString();
181     }
182
183     /**
184      * Gets the Properties attribute of the InfoTagsHandler object
185      *
186      * @return The Properties value
187      */

188     private Properties getProperties()
189     {
190         Properties properties = ((InfoSubTask) getDocletContext().getActiveSubTask()).getProperties();
191
192         return properties;
193     }
194
195     /**
196      * Gets the MethodTagsHandler attribute of the InfoTagsHandler object
197      *
198      * @return The MethodTagsHandler value
199      * @exception XDocletException Describe the exception
200      */

201     private MethodTagsHandler getMethodTagsHandler() throws XDocletException
202     {
203         try {
204             return ((MethodTagsHandler) getEngine().getTagHandlerFor("Method"));
205         }
206         catch (TemplateException ex) {
207             throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String JavaDoc[]{"MethodTagsHandler", "Method"}));
208         }
209     }
210
211     /**
212      * Gets the FieldTagsHandler attribute of the InfoTagsHandler object
213      *
214      * @return The FieldTagsHandler value
215      * @exception XDocletException Describe the exception
216      */

217     private FieldTagsHandler getFieldTagsHandler() throws XDocletException
218     {
219         try {
220             return ((FieldTagsHandler) getEngine().getTagHandlerFor("Field"));
221         }
222         catch (TemplateException ex) {
223             throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String JavaDoc[]{"FieldTagsHandler", "Field"}));
224         }
225     }
226
227     /**
228      * Gets the ConstructorTagsHandler attribute of the InfoTagsHandler object
229      *
230      * @return The ConstructorTagsHandler value
231      * @exception XDocletException Describe the exception
232      */

233     private ConstructorTagsHandler getConstructorTagsHandler() throws XDocletException
234     {
235         try {
236             return ((ConstructorTagsHandler) getEngine().getTagHandlerFor("Constructor"));
237         }
238         catch (TemplateException ex) {
239             throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String JavaDoc[]{"ConstructorTagsHandler", "Constructor"}));
240         }
241     }
242
243     /**
244      * Gets the ClassTagsHandler attribute of the InfoTagsHandler object
245      *
246      * @return The ClassTagsHandler value
247      * @exception XDocletException Describe the exception
248      */

249     private ClassTagsHandler getClassTagsHandler() throws XDocletException
250     {
251         try {
252             return ((ClassTagsHandler) getEngine().getTagHandlerFor("Class"));
253         }
254         catch (TemplateException ex) {
255             throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String JavaDoc[]{"ClassTagsHandler", "Class"}));
256         }
257     }
258
259     /**
260      * Gets the PackageTagsHandler attribute of the InfoTagsHandler object
261      *
262      * @return The PackageTagsHandler value
263      * @exception XDocletException Describe the exception
264      */

265     private PackageTagsHandler getPackageTagsHandler() throws XDocletException
266     {
267         try {
268             return ((PackageTagsHandler) getEngine().getTagHandlerFor("Package"));
269         }
270         catch (TemplateException ex) {
271             throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String JavaDoc[]{"PackageTagsHandler", "Package"}));
272         }
273     }
274
275     /**
276      * Describe what the method does
277      *
278      * @param level Describe what the parameter does
279      * @return Describe the return value
280      * @exception XDocletException Describe the exception
281      */

282     private int tagCount_Impl(String JavaDoc level) throws XDocletException
283     {
284         int tagCount = 0;
285
286         if ("all".equals(level)) {
287             tagCount = tagCountInAll_Impl(getProperties());
288         }
289         else if ("package".equals(level)) {
290             tagCount = tagCountInPackage_Impl(getProperties(), getCurrentPackage());
291         }
292         else if ("whole-class".equals(level)) {
293             tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), true, true, true, true);
294         }
295         else if ("class".equals(level)) {
296             tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), true, false, false, false);
297         }
298         else if ("field".equals(level)) {
299             tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), false, true, false, false);
300         }
301         else if ("constructor".equals(level)) {
302             tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), false, false, true, false);
303         }
304         else if ("method".equals(level)) {
305             tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), false, false, false, true);
306         }
307         else {
308             throw new XDocletException(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.BAD_LEVEL, new String JavaDoc[]{level}));
309         }
310         return tagCount;
311     }
312
313     /**
314      * Describe what the method does
315      *
316      * @param attributes Describe what the parameter does
317      * @return Describe the return value
318      * @exception XDocletException Describe the exception
319      */

320     private int tagCountInAll_Impl(Properties attributes) throws XDocletException
321     {
322         int tagCount = 0;
323         Collection classes = getXJavaDoc().getSourceClasses();
324         SortedSet packages = new TreeSet();
325
326         for (Iterator i = classes.iterator(); i.hasNext(); ) {
327             packages.add(((XClass) i.next()).getContainingPackage());
328         }
329
330         for (Iterator packageIterator = packages.iterator(); packageIterator.hasNext(); ) {
331             XPackage cur_package = (XPackage) packageIterator.next();
332
333             tagCount += tagCountInPackage_Impl(attributes, cur_package);
334         }
335
336         return tagCount;
337     }
338
339     /**
340      * Describe what the method does
341      *
342      * @param attributes Describe what the parameter does
343      * @param pakkage Describe what the parameter does
344      * @return Describe the return value
345      */

346     private int tagCountInPackage_Impl(Properties attributes, XPackage pakkage)
347     {
348         int tagCount = 0;
349         Collection classes = pakkage.getClasses();
350
351         for (Iterator i = classes.iterator(); i.hasNext(); ) {
352             tagCount += tagCountInClass_Impl(attributes, (XClass) i.next(), true, true, true, true);
353         }
354         return tagCount;
355     }
356
357     /**
358      * Describe what the method does
359      *
360      * @param attributes Describe what the parameter does
361      * @param clazz Describe what the parameter does
362      * @param countClass Describe what the parameter does
363      * @param countFields Describe what the parameter does
364      * @param countConstructors Describe what the parameter does
365      * @param countMethods Describe what the parameter does
366      * @return Describe the return value
367      */

368     private int tagCountInClass_Impl(Properties attributes, XClass clazz, boolean countClass, boolean countFields, boolean countConstructors, boolean countMethods)
369     {
370         int tagCount = 0;
371         String JavaDoc tagName = attributes.getProperty("tagName");
372
373         if (countClass) {
374             tagCount += tagCount(clazz, tagName);
375         }
376         if (countConstructors) {
377             Collection constructors = clazz.getConstructors();
378
379             tagCount += tagCount(constructors, tagName);
380         }
381         if (countMethods) {
382             Collection methods = clazz.getMethods();
383
384             tagCount += tagCount(methods, tagName);
385         }
386         if (countFields) {
387             Collection fields = clazz.getFields();
388
389             tagCount += tagCount(fields, tagName);
390         }
391         return tagCount;
392     }
393
394     /**
395      * Describe what the method does
396      *
397      * @param programElement Describe what the parameter does
398      * @param tagName Describe what the parameter does
399      * @return Describe the return value
400      */

401     private int tagCount(XProgramElement programElement, String JavaDoc tagName)
402     {
403         return programElement.getDoc().getTags(tagName, false).size();
404     }
405
406     /**
407      * Describe what the method does
408      *
409      * @param programElements Describe what the parameter does
410      * @param tagName Describe what the parameter does
411      * @return Describe the return value
412      */

413     private int tagCount(Collection programElements, String JavaDoc tagName)
414     {
415         int count = 0;
416
417         for (Iterator i = programElements.iterator(); i.hasNext(); ) {
418             count += tagCount((XProgramElement) i.next(), tagName);
419         }
420         return count;
421     }
422 }
423
Popular Tags