KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > tagshandler > ClassTagsHandler


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

5 package xdoclet.tagshandler;
6
7 import java.text.DateFormat JavaDoc;
8 import java.util.Calendar JavaDoc;
9
10 import java.util.Collection JavaDoc;
11 import java.util.HashSet JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Properties JavaDoc;
14 import java.util.Set JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 import org.apache.commons.logging.Log;
18
19 import xjavadoc.*;
20
21 import xdoclet.*;
22 import xdoclet.template.*;
23 import xdoclet.util.LogUtil;
24 import xdoclet.util.Translator;
25 import xdoclet.util.TypeConversionUtil;
26
27 /**
28  * Tags relating to classes being processed and class-level attributes.
29  *
30  * @author Ara Abrahamian (ara_e_w@yahoo.com)
31  * @created Oct 14, 2001
32  * @xdoclet.taghandler namespace="Class"
33  * @version $Revision: 1.25 $
34  */

35 public class ClassTagsHandler extends AbstractProgramElementTagsHandler
36 {
37     /**
38      * Used for setting the timestamp for xdoclet-generated marker in generated files.
39      */

40     protected final static DateFormat JavaDoc dateFormatter = DateFormat.getDateTimeInstance();
41
42     protected final static Calendar JavaDoc now = Calendar.getInstance();
43
44     /**
45      * Returns the not-full-qualified name of the specified class without the package name.
46      *
47      * @param clazz Description of Parameter
48      * @return Description of the Returned Value
49      * @todo duplicate in AbstractProgramElementTagsHandler
50      * @deprecated use XClass.name()
51      */

52     public static String JavaDoc getClassNameFor(XClass clazz)
53     {
54         return clazz.getName();
55     }
56
57     /**
58      * Returns the full-qualified name of the specified class with the package name.
59      *
60      * @param clazz Description of Parameter
61      * @return Description of the Returned Value
62      * @deprecated use XClass.qualifiedName()
63      */

64     public static String JavaDoc getFullClassNameFor(XClass clazz)
65     {
66         if (clazz.getContainingClass() != null) {
67             return clazz.getContainingClass().getQualifiedName();
68         }
69         return clazz.getQualifiedName();
70     }
71
72     /**
73      * Iterates over all tags named according to tagName in a non-duplicated manner. The paramName parameter should be
74      * the tag parameter that should be unique during the iteration. Duplicated tags will generate a warning message.
75      * Please note that this tag already processes all classes. There is no need to wrap it inside a
76      * <XDtClass:forAllClasses> tag or any other tag that processes a group of classes.
77      *
78      * @param engine
79      * @param template The body of the block tag
80      * @param tagName The tag to iterate
81      * @param paramName The tag parameter that should be used as identifier.
82      * @throws XDocletException if something goes wrong
83      */

84     public static void forAllDistinctClassTags(TemplateEngine engine, String JavaDoc template, String JavaDoc tagName, String JavaDoc paramName) throws XDocletException
85     {
86         // A set to store already processed references
87
Set JavaDoc tagKeys = new HashSet JavaDoc();
88         Log log = LogUtil.getLog(ClassTagsHandler.class, "forAllDistinctClassTags");
89
90         try {
91
92             for (Iterator JavaDoc i = getXJavaDoc().getSourceClasses().iterator(); i.hasNext(); ) {
93                 XClass clazz = (XClass) i.next();
94
95                 setCurrentClass(clazz);
96
97                 Collection JavaDoc tags = clazz.getDoc().getTags(tagName);
98
99                 if (tags == null)
100                     continue;
101
102                 for (Iterator JavaDoc j = tags.iterator(); j.hasNext(); ) {
103                     XTag tag = (XTag) j.next();
104
105                     setCurrentClassTag(tag);
106                     if (!tagKeys.contains(tag.getAttributeValue(paramName))) {
107                         tagKeys.add(tag.getAttributeValue(paramName));
108                         engine.generate(template);
109                     }
110                     else {
111                         log.warn(Translator.getString(XDocletMessages.class, XDocletMessages.DUPLICATED_TAG,
112                             new String JavaDoc[]{tagName, paramName, tag.getAttributeValue(paramName)}));
113                     }
114                 }
115             }
116         }
117         catch (TemplateException e) {
118             if (e instanceof XDocletException) {
119                 throw (XDocletException) e;
120             }
121             else {
122                 throw new XDocletException(e, Translator.getString(XDocletMessages.class, XDocletMessages.RUNNING_FAILED));
123             }
124         }
125     }
126
127     /**
128      * Iterates over all tags named according to tagName in a non-duplicated manner. The paramName parameter specifies
129      * the tag parameter that should be unique during the iteration. Duplicated tags will generate a warning message.
130      * Please note that this tag already processes all classes. There is no need to wrap it inside a
131      * <XDtClass:forAllClasses> tag or any other tag that processes a group of classes.
132      *
133      * @param template The body of the block tag
134      * @param attributes The attributes of the template tag
135      * @throws XDocletException if something goes wrong
136      * @doc.tag type="block"
137      * @doc.param name="tagName" optional="false" description="The tag to iterate."
138      * @doc.param name="tagKey" optional="false" description="The tag parameter that should be used as
139      * identifier."
140      */

141     public void forAllDistinctClassTags(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
142     {
143         String JavaDoc tagName = attributes.getProperty("tagName");
144         String JavaDoc paramName = attributes.getProperty("paramName");
145
146         forAllDistinctClassTags(getEngine(), template, tagName, paramName);
147     }
148
149     /**
150      * Returns the not-fully-qualified name of the current class without the package name.
151      *
152      * @return the name of the current class
153      * @exception XDocletException if something goes wrong
154      * @doc.tag type="content"
155      */

156     public String JavaDoc className() throws XDocletException
157     {
158         return getCurrentClass().getName();
159     }
160
161     /**
162      * Returns the full-qualified name of the current class.
163      *
164      * @return the name of the current class
165      * @exception XDocletException if something goes wrong
166      * @doc.tag type="content"
167      */

168     public String JavaDoc fullClassName() throws XDocletException
169     {
170         return getCurrentClass().getQualifiedName();
171     }
172
173     /**
174      * Returns the transformed name of the current class with package name.
175      *
176      * @return the name of the current class
177      * @exception XDocletException if something goes wrong
178      * @doc.tag type="content"
179      */

180     public String JavaDoc transformedClassName() throws XDocletException
181     {
182         return getCurrentClass().getTransformedName();
183     }
184
185     /**
186      * Returns the fully-qualified transformed name of the current class with package name.
187      *
188      * @return the name of the current class
189      * @exception XDocletException if something goes wrong
190      * @doc.tag type="content"
191      */

192     public String JavaDoc fullTransformedClassName() throws XDocletException
193     {
194         return getCurrentClass().getTransformedQualifiedName();
195     }
196
197     /**
198      * Returns the full-qualified name of the superclass of the current class.
199      *
200      * @return the name of the superclass of the current class
201      * @exception XDocletException if something goes wrong
202      * @doc.tag type="content"
203      */

204     public String JavaDoc fullSuperclassName() throws XDocletException
205     {
206         return getFullSuperclassNameFor(getCurrentClass());
207     }
208
209     /**
210      * Returns the not-full-qualified name of the full-qualified class name specified in the body of this tag.
211      *
212      * @param template The body of the block tag
213      * @exception XDocletException if something goes wrong
214      * @doc.tag type="block"
215      */

216     public void classOf(String JavaDoc template) throws XDocletException
217     {
218         try {
219             String JavaDoc fullClassName = getEngine().outputOf(template);
220
221             String JavaDoc result = fullClassName;
222             int pos = fullClassName.lastIndexOf('.');
223
224             if (pos >= 0) {
225                 result = fullClassName.substring(pos + 1);
226             }
227
228             getEngine().print(result);
229             // use out.print because it's a block tag and can't return a String
230
}
231         catch (TemplateException ex) {
232             throw new XDocletException(ex, Translator.getString(XDocletMessages.class, XDocletMessages.METHOD_FAILED, new String JavaDoc[]{"ClassTagsHandler.classOf"}));
233         }
234     }
235
236     /**
237      * Evaluate the body block if current class is abstract.
238      *
239      * @param template The body of the block tag
240      * @exception XDocletException Description of Exception
241      * @see #ifIsClassNotAbstract(java.lang.String)
242      * @doc.tag type="block"
243      */

244     public void ifIsClassAbstract(String JavaDoc template) throws XDocletException
245     {
246         if (getCurrentClass().isAbstract()) {
247             generate(template);
248         }
249     }
250
251     /**
252      * Evaluate the body block if current class is not abstract.
253      *
254      * @param template The body of the block tag
255      * @exception XDocletException Description of Exception
256      * @see #ifIsClassAbstract(java.lang.String)
257      * @doc.tag type="block"
258      */

259     public void ifIsClassNotAbstract(String JavaDoc template) throws XDocletException
260     {
261         if (!getCurrentClass().isAbstract()) {
262             generate(template);
263         }
264     }
265
266     /**
267      * Pushes the class specified by value parameter to top of stack making it the current class.
268      *
269      * @param attributes The attributes of the template tag
270      * @param template The body of the block tag
271      * @exception XDocletException Description of Exception
272      * @doc.tag type="block"
273      * @doc.param name="value" optional="false" values="return-type,whatever class name"
274      * description="If return-type specified then push current method return type, else find the XClass for the
275      * class name and push it."
276      */

277     public void pushClass(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
278     {
279         String JavaDoc value = attributes.getProperty("value", null);
280         XClass currentClass = null;
281
282         if (value == null) {
283             try {
284                 value = getEngine().outputOf(template);
285             }
286             catch (TemplateException ex) {
287                 throw new XDocletException(ex, Translator.getString(XDocletMessages.class, XDocletMessages.METHOD_FAILED, new String JavaDoc[]{"pushClass"}));
288             }
289         }
290
291         currentClass = getXJavaDoc().getXClass(value.replace('$', '.'));
292
293         if (currentClass == null) {
294             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.JAVADOC_COULDNT_LOAD_CLASS, new String JavaDoc[]{value}));
295         }
296
297         XMethod oldMethod = getCurrentMethod();
298
299         pushCurrentClass(currentClass);
300         setCurrentMethod(null);
301         generate(template);
302         popCurrentClass();
303         setCurrentMethod(oldMethod);
304     }
305
306     /**
307      * Iterates over all classes loaded by xjavadoc and evaluates the body of the tag for each class. It discards
308      * classes that have a xdoclet-generated class tag defined.
309      *
310      * @param template The body of the block tag
311      * @param attributes The attributes of the template tag
312      * @exception XDocletException Description of Exception
313      * @doc.tag type="block"
314      * @doc.param name="abstract" optional="true" values="true,false" description="If true then accept
315      * abstract classes also; otherwise don't."
316      * @doc.param name="type" optional="true" description="For all classes by the type."
317      * @doc.param name="extent" optional="true" values="concrete-type,superclass,hierarchy"
318      * description="Specifies the extent of the type search. If concrete-type then only check the concrete type, if
319      * superclass then check also superclass, if hierarchy then search the whole hierarchy and find if the class is
320      * of the specified type. Default is hierarchy."
321      */

322     public void forAllClasses(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
323     {
324         Log log = LogUtil.getLog(ClassTagsHandler.class, "forAllClasses");
325
326         String JavaDoc abstractStr = attributes.getProperty("abstract");
327         boolean acceptAbstractClasses = TypeConversionUtil.stringToBoolean(abstractStr, true);
328         String JavaDoc typeName = attributes.getProperty("type");
329         String JavaDoc extentStr = attributes.getProperty("extent");
330         int extent = TypeTagsHandler.extractExtentType(extentStr);
331
332         if (log.isDebugEnabled()) {
333             log.debug("acceptAbstractClasses=" + acceptAbstractClasses);
334             log.debug("typeName=" + typeName);
335             log.debug("extentStr=" + extentStr);
336             log.debug("extent=" + extent);
337         }
338
339         for (Iterator JavaDoc i = getAllClasses().iterator(); i.hasNext(); ) {
340             XClass currentClass = (XClass) i.next();
341
342             setCurrentClass(currentClass);
343             log.debug("currentClass=" + currentClass);
344
345             if (DocletSupport.isDocletGenerated(getCurrentClass()) || (getCurrentClass().isAbstract() && acceptAbstractClasses == false)) {
346                 log.debug("isDocletGenerated or isAbstract");
347                 continue;
348             }
349
350             if (typeName != null) {
351                 if (TypeTagsHandler.isOfType(currentClass, typeName, extent)) {
352                     log.debug("isOfType true, generate().");
353                     generate(template);
354                 }
355                 else {
356                     log.debug("isOfType false");
357                 }
358             }
359             else {
360                 log.debug("typeName=null, generate().");
361                 generate(template);
362             }
363         }
364     }
365
366     /**
367      * The current class' modifiers.
368      *
369      * @return modifiers
370      * @exception XDocletException Describe the exception
371      * @doc.tag type="content"
372      */

373     public String JavaDoc modifiers() throws XDocletException
374     {
375         return modifiers(FOR_CLASS);
376     }
377
378     /**
379      * Returns the symbolic name of the current class. For a java bean it's the same as the class name.
380      *
381      * @return The symbolic name of the current class
382      * @exception XDocletException Description of Exception
383      * @doc.tag type="content"
384      */

385     public String JavaDoc symbolicClassName() throws XDocletException
386     {
387         // (Aslak) not sure if this is correct
388
return getCurrentClass().getName();
389     }
390
391     /**
392      * Evaluates the body if current class doesn't have at least one tag with the specified name.
393      *
394      * @param template The body of the block tag
395      * @param attributes The attributes of the template tag
396      * @exception XDocletException Description of Exception
397      * @doc.tag type="block"
398      * @doc.param name="tagName" optional="false" description="The tag name."
399      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
400      * content of the tag is returned."
401      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
402      * used the space-separated format for specifying parameters."
403      * @doc.param name="superclasses" values="true,false" description="If true then traverse
404      * superclasses also, otherwise look up the tag in current concrete class only."
405      * @doc.param name="error" description="Show this error message if no tag found."
406      */

407     public void ifDoesntHaveClassTag(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
408     {
409         if (!hasTag(attributes, FOR_CLASS)) {
410             generate(template);
411         }
412         else {
413             String JavaDoc error = attributes.getProperty("error");
414
415             if (error != null) {
416                 getEngine().print(error);
417             }
418         }
419     }
420
421     /**
422      * Evaluates the body if current class has at least one tag with the specified name.
423      *
424      * @param template The body of the block tag
425      * @param attributes The attributes of the template tag
426      * @exception XDocletException Description of Exception
427      * @doc.tag type="block"
428      * @doc.param name="tagName" optional="false" description="The tag name."
429      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
430      * content of the tag is returned."
431      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
432      * used the space-separated format for specifying parameters."
433      * @doc.param name="superclasses" values="true,false" description="If true then traverse
434      * superclasses also, otherwise look up the tag in current concrete class only."
435      * @doc.param name="error" description="Show this error message if no tag found."
436      */

437     public void ifHasClassTag(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
438     {
439         if (hasTag(attributes, FOR_CLASS)) {
440             generate(template);
441         }
442         else {
443             String JavaDoc error = attributes.getProperty("error");
444
445             if (error != null) {
446                 getEngine().print(error);
447             }
448         }
449     }
450
451     /**
452      * Evaluate the body if the match variable equals with the value of the specified tag/parameter.
453      *
454      * @param template The body of the block tag
455      * @param attributes The attributes of the template tag
456      * @exception XDocletException Description of Exception
457      * @todo (Aslak) It appears that this method does the same job as ifClassTagValueEquals. It
458      * also appears that no templates are using it. Candidate for removal?
459      * @doc.tag type="block"
460      * @doc.param name="values" description="The valid values for the parameter, comma separated. An
461      * error message is printed if the parameter value is not one of the values."
462      * @doc.param name="default" description="The default value is returned if parameter not specified
463      * by user for the tag."
464      * @doc.param name="superclasses" values="true,false" description="If true then traverse
465      * superclasses also, otherwise look up the tag in current concrete class only."
466      */

467     public void ifClassTagValueMatches(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
468     {
469         String JavaDoc wantedTagValue = getTagValue(attributes, FOR_CLASS);
470
471         if (wantedTagValue.equals(matchPattern)) {
472             generate(template);
473         }
474     }
475
476     /**
477      * Evaluates the body if value for the class tag equals the specified value.
478      *
479      * @param template The body of the block tag
480      * @param attributes The attributes of the template tag
481      * @exception XDocletException Description of Exception
482      * @doc.tag type="block"
483      * @doc.param name="tagName" optional="false" description="The tag name."
484      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
485      * content of the tag is returned."
486      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
487      * used the space-separated format for specifying parameters."
488      * @doc.param name="value" optional="false" description="The desired value."
489      */

490     public void ifClassTagValueEquals(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
491     {
492         if (isTagValueEqual(attributes, FOR_CLASS)) {
493             generate(template);
494         }
495     }
496
497     /**
498      * Evaluates the body if value for the class tag not equals the specified value.
499      *
500      * @param template The body of the block tag
501      * @param attributes The attributes of the template tag
502      * @exception XDocletException Description of Exception
503      * @doc.tag type="block"
504      * @doc.param name="tagName" optional="false" description="The tag name."
505      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
506      * content of the tag is returned."
507      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
508      * used the space-separated format for specifying parameters."
509      * @doc.param name="value" optional="false" description="The desired value."
510      */

511     public void ifClassTagValueNotEquals(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
512     {
513         if (!isTagValueEqual(attributes, FOR_CLASS)) {
514             generate(template);
515         }
516     }
517
518     /**
519      * Iterates over all class tags with the specified tagName and evaluates the body of the tag for each class tag.
520      *
521      * @param attributes The attributes of the template tag
522      * @return Description of the Returned Value
523      * @exception XDocletException Description of Exception
524      * @doc.tag type="content"
525      * @doc.param name="tagName" optional="false" description="The tag name."
526      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
527      * content of the tag is returned."
528      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
529      * used the space-separated format for specifying parameters."
530      * @doc.param name="values" description="The valid values for the parameter, comma separated. An
531      * error message is printed if the parameter value is not one of the values."
532      * @doc.param name="default" description="The default value is returned if parameter not specified
533      * by user for the tag."
534      * @doc.param name="superclasses" values="true,false" description="If true then traverse
535      * superclasses also, otherwise look up the tag in current concrete class only."
536      * @doc.param name="mandatory" values="true,false" description="Generate an error if parameter not
537      * specified by user for the tag."
538      */

539     public String JavaDoc classTagValue(Properties JavaDoc attributes) throws XDocletException
540     {
541         return getExpandedDelimitedTagValue(attributes, FOR_CLASS);
542     }
543
544     /**
545      * Sets the value of match variable. Match variable serves as a variable for templates, you set it somewhere in
546      * template and look it up somewhere else in temaplte. This tag does not return any content, it just sets the match
547      * variable.
548      *
549      * @param attributes The attributes of the template tag
550      * @return Description of the Returned Value
551      * @exception XDocletException Description of Exception
552      * @doc.tag type="content"
553      * @doc.param name="tagName" optional="false" description="The tag name."
554      * @doc.param name="paramName" description="The parameter name. If not specified, then the raw
555      * content of the tag is returned."
556      * @doc.param name="paramNum" description="The zero-based parameter number. It's used if the user
557      * used the space-separated format for specifying parameters."
558      */

559     public String JavaDoc classTagValueMatch(Properties JavaDoc attributes) throws XDocletException
560     {
561         matchPattern = getTagValue(attributes, FOR_CLASS);
562         return "";
563     }
564
565     /**
566      * Iterates over all tags of current class with the name tagName and evaluates the body of the tag for each method.
567      *
568      * @param template The body of the block tag
569      * @param attributes The attributes of the template tag
570      * @exception XDocletException Description of Exception
571      * @doc.tag type="block"
572      * @doc.param name="tagName" optional="false" description="The tag name."
573      * @doc.param name="superclasses" values="true,false" description="If true then traverse
574      * superclasses also, otherwise look up the tag in current concrete class only."
575      * @doc.param name="tagKey" description="A tag property that will be used as a unique key. This is
576      * used to avoid duplicate code due to similar tags in superclasses."
577      */

578     public void forAllClassTags(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
579     {
580         boolean superclasses = TypeConversionUtil.stringToBoolean(attributes.getProperty("superclasses"), true);
581         Collection JavaDoc tags = getCurrentClass().getDoc().getTags(attributes.getProperty("tagName"), superclasses);
582         Set JavaDoc done = new HashSet JavaDoc();
583
584         matchPattern = null;
585
586         String JavaDoc tagKey = attributes.getProperty("tagKey");
587
588         for (Iterator JavaDoc i = tags.iterator(); i.hasNext(); ) {
589             XTag tag = (XTag) i.next();
590
591             if (tagKey != null) {
592                 String JavaDoc key = tag.getAttributeValue(tagKey);
593
594                 if (!done.add(key)) {
595                     // no change to set, therefore we must have already done this tag
596
continue;
597                 }
598             }
599
600             setCurrentClassTag(tag);
601
602             generate(template);
603         }
604         setCurrentClassTag(null);
605         matchPattern = null;
606     }
607
608     /**
609      * Iterates over all tokens in specified class tag with the name tagName and evaluates the body for every token.
610      *
611      * @param template The body of the block tag
612      * @param attributes The attributes of the template tag
613      * @exception XDocletException Description of Exception
614      * @doc.tag type="block"
615      * @doc.param name="tagName" optional="false" description="The name of the tag to look in."
616      * @doc.param name="paramName" optional="false" description="The parameter of the tag whose value
617      * is to be tokenized."
618      * @doc.param name="superclasses" values="true,false" description="If true then traverse
619      * superclasses also, otherwise look up the tag in current concrete class only."
620      * @doc.param name="delimiter" description="delimiter for the StringTokenizer. consult javadoc for
621      * java.util.StringTokenizer default is ','"
622      * @doc.param name="skip" description="how many tokens to skip on start"
623      */

624     public void forAllClassTagTokens(String JavaDoc template, Properties JavaDoc attributes) throws XDocletException
625     {
626         forAllMemberTagTokens(template, attributes, FOR_CLASS);
627     }
628
629     /**
630      * The comment for the current class.
631      *
632      * @param attributes The attributes of the template tag
633      * @return javadoc comment
634      * @exception XDocletException Description of Exception
635      * @see MethodTagsHandler#methodComment(java.util.Properties)
636      * @see #classCommentText(java.util.Properties)
637      * @see #classCommentTags(java.util.Properties)
638      * @doc.tag type="content"
639      * @doc.param name="no-comment-signs" optional="true" values="true,false" description="If true
640      * then don't decorate the comment with comment signs. Default is false."
641      * @doc.param name="indent" optional="true" description="Number of spaces to indent the comment.
642      * Default is 0."
643      */

644     public String JavaDoc classComment(Properties JavaDoc attributes) throws XDocletException
645     {
646         // Leave out the tags if no comment delimiters; I can't think of a reason you'd
647
// still want them, since they won't do anything outside of javadoc comments
648
boolean noCommentSigns = TypeConversionUtil.stringToBoolean(attributes.getProperty("no-comment-signs"), false);
649
650         if (noCommentSigns) {
651             return getCurrentClass().getDoc().getCommentText();
652         }
653
654         char[] spaces = getIndentChars(attributes);
655         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
656
657         sbuf.append(spaces).append("/**").append(PrettyPrintWriter.LINE_SEPARATOR);
658         sbuf.append(classCommentText(attributes));
659         sbuf.append(classCommentTags(attributes));
660         sbuf.append(spaces).append(" */");
661
662         return sbuf.toString();
663     }
664
665     /**
666      * The text of the javadoc comment for the current class.
667      *
668      * @param attributes The attributes of the template tag
669      * @return comment text
670      * @exception XDocletException Description of Exception
671      * @see MethodTagsHandler#methodComment(java.util.Properties)
672      * @see #classComment(java.util.Properties)
673      * @doc.tag type="content"
674      * @doc.param name="no-comment-signs" optional="true" values="true,false" description="If true
675      * then don't decorate the comment with comment signs. Default is false."
676      * @doc.param name="indent" optional="true" description="Number of spaces to indent the comment.
677      * Default is 0."
678      * @todo handle inline link tags in comment text
679      */

680     public String JavaDoc classCommentText(Properties JavaDoc attributes) throws XDocletException
681     {
682         boolean noCommentSigns = TypeConversionUtil.stringToBoolean(attributes.getProperty("no-comment-signs"), false);
683
684         if (noCommentSigns) {
685             return getCurrentClass().getDoc().getCommentText();
686         }
687
688         char[] spaces = getIndentChars(attributes);
689         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
690
691         sbuf.append(spaces).append(" * ").append(getCurrentClass().getDoc().getCommentText()).append(PrettyPrintWriter.LINE_SEPARATOR);
692
693         return sbuf.toString();
694     }
695
696     /**
697      * The javadoc comment tags for the current class (plus xdoclet-generated).
698      *
699      * @param attributes The attributes of the template tag
700      * @return The class-level tags
701      * @exception XDocletException Description of Exception
702      * @see MethodTagsHandler#methodComment(java.util.Properties)
703      * @see #classComment(java.util.Properties)
704      * @doc.tag type="content"
705      * @doc.param name="indent" optional="true" description="Number of spaces to indent the tags.
706      * Default is 0."
707      */

708     public String JavaDoc classCommentTags(Properties JavaDoc attributes) throws XDocletException
709     {
710         char[] spaces = getIndentChars(attributes);
711         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
712         Collection JavaDoc classTags = getCurrentClass().getDoc().getTags();
713
714         for (Iterator JavaDoc i = classTags.iterator(); i.hasNext(); ) {
715             XTag tag = (XTag) i.next();
716
717             String JavaDoc classTag = tag.getName();
718
719             // omit ejbdoclet-specific tags, which all have a ":" or "."
720
if (classTag.indexOf(':') == -1 && classTag.indexOf('.') == -1) {
721                 // omit excluded tags
722
if (getDocletContext().getExcludedTags().indexOf(classTag) == -1) {
723                     sbuf.append(spaces).append(" * @").append(classTag).append(' ');
724                     sbuf.append(tag.getValue()).append(PrettyPrintWriter.LINE_SEPARATOR);
725                 }
726             }
727         }
728
729         if (getDocletContext().getAddedTags() != null) {
730             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(getDocletContext().getAddedTags(), ",");
731
732             while (st.hasMoreTokens()) {
733                 sbuf.append(spaces).append(" * ").append(st.nextToken()).append(PrettyPrintWriter.LINE_SEPARATOR);
734             }
735         }
736
737         return sbuf.toString();
738     }
739
740     /**
741      * Return first sentence of standard javadoc of current class.
742      *
743      * @param attributes The attributes of the template tag
744      * @return class comment's first sentence
745      * @exception XDocletException Description of Exception
746      * @doc.tag type="content"
747      * @doc.param name="no-description-if-lacking" optional="true" description="Returns 'No
748      * Description' if comment is lacking."
749      */

750     public String JavaDoc firstSentenceDescription(Properties JavaDoc attributes) throws XDocletException
751     {
752         String JavaDoc desc = getCurrentClass().getDoc().getFirstSentence();
753
754         if (desc == null) {
755             String JavaDoc noDescriptionIfLackingStr = attributes.getProperty("no-description-if-lacking");
756             boolean noDescriptionIfLacking = TypeConversionUtil.stringToBoolean(noDescriptionIfLackingStr, true);
757
758             if (noDescriptionIfLacking) {
759                 desc = Translator.getString(XDocletMessages.class, XDocletMessages.NO_DESCRIPTION);
760             }
761             else {
762                 desc = "";
763             }
764         }
765
766         // Check if there is a \n and replace it by a space
767
return checkForWrap(desc.trim());
768     }
769
770     /**
771      * Iterates over all imported classes and packages imported in the current class and returns the list. The composed
772      * string has 'import ' in front of each import statement, and each import is in a separate line.
773      *
774      * @param attributes The attributes of the template tag
775      * @return import statements
776      * @exception XDocletException Description of Exception
777      * @deprecated Make sure the template file uses full qualified class names everywhere instead.
778      * @doc.tag type="content"
779      * @doc.param name="currentClass" optional="false" description="???"
780      */

781     public String JavaDoc importedList(Properties JavaDoc attributes) throws XDocletException
782     {
783         String JavaDoc currentClass = attributes.getProperty("currentClass");
784
785         if (currentClass == null) {
786             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.TAG_MUST_INCLUDE_A_PROPERTY, new String JavaDoc[]{"importList", "currentClass"}));
787         }
788
789         String JavaDoc currentPackage = PackageTagsHandler.getPackageNameFor(currentClass);
790
791         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
792
793         Collection JavaDoc packages = getCurrentClass().getImportedPackages();
794
795         for (Iterator JavaDoc i = packages.iterator(); i.hasNext(); ) {
796             XPackage pakkage = (XPackage) i.next();
797
798             if (!pakkage.getName().equals(currentPackage)) {
799                 sbuf.append("import ").append(pakkage.getName()).append(".*;").append(PrettyPrintWriter.LINE_SEPARATOR);
800             }
801         }
802
803         for (Iterator JavaDoc j = getCurrentClass().getImportedClasses().iterator(); j.hasNext(); ) {
804             XClass clazz = (XClass) j.next();
805
806             if (!PackageTagsHandler.getPackageNameFor(clazz.toString()).equals(currentPackage)) {
807                 sbuf.append("import ").append(clazz.toString()).append(';').append(PrettyPrintWriter.LINE_SEPARATOR);
808             }
809         }
810
811         return sbuf.toString();
812     }
813 }
814
Popular Tags