KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > TemplateSubTask


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

5 package xdoclet;
6
7 import java.io.File JavaDoc;
8 import java.net.MalformedURLException JavaDoc;
9 import java.net.URL JavaDoc;
10 import java.text.MessageFormat JavaDoc;
11 import java.util.*;
12
13 import org.apache.commons.logging.Log;
14
15 import xjavadoc.*;
16
17 import xdoclet.tagshandler.PackageTagsHandler;
18 import xdoclet.tagshandler.TypeTagsHandler;
19 import xdoclet.template.TemplateEngine;
20 import xdoclet.template.TemplateException;
21 import xdoclet.template.XDocletTemplateMessages;
22 import xdoclet.util.LogUtil;
23 import xdoclet.util.Translator;
24
25 /**
26  * Generic subtask for processing a user-supplied template. The template is specified in the <code>templateFile</code>
27  * configuration parameter. It operates in two modes: per class and single output.
28  *
29  * @author Ara Abrahamian (ara_e@email.com)
30  * @created Sep 25, 2001
31  * @ant.element name="template" parent="xdoclet.DocletTask" display-name="Standard Subtask"
32  * @version $Revision: 1.79 $
33  * @ant.attribute name="destinationFile" description="The destination file name. If a {0} is found it's assumed that a
34  * per class output generation is needed, so {0} is substituted with class name; otherwise a single file is
35  * generated with the specified name." required="Yes"
36  * @ant.attribute name="extent" description="You can control the extent in which the type search occurs. Valid values
37  * are: <i>concrete-type</i> , <i> superclass</i> and <i>hierarchy</i> ." required="No. Default is \"hierarchy\""
38  */

39 public class TemplateSubTask extends SubTask
40 {
41     private final static String JavaDoc SUBTASK_NAME = "template";
42
43     private URL JavaDoc templateURL = null;
44
45     private transient TemplateEngine engine = null;
46
47     private boolean prefixWithPackageStructure = true;
48
49     private boolean acceptInterfaces = true;
50     private boolean acceptAbstractClasses = true;
51     private String JavaDoc docEncoding = null;
52
53     /**
54      * @see #setDestinationFile(java.lang.String)
55      * @see #getDestinationFile()
56      */

57     private String JavaDoc destinationFile = null;
58
59     /**
60      * Applicable only to per class output generation. Specify full qualified class name from which classes should be
61      * derived. Output generation is performed only for classes of one of the types defined in this list. You can
62      * control the extent in which the type search occures by using 'extent' property.
63      *
64      * @see #addOfType(java.lang.String)
65      * @see #getOfType()
66      * @see #setExtent(TemplateSubTask.ExtentTypes)
67      * @see #getExtent()
68      */

69     private List ofType = new ArrayList();
70
71     /**
72      * You can control the extent in which the type search occurs. Valid values are: <i>concrete-type</i> , <i>
73      * superclass</i> and <i>hierarchy</i> which is the default.
74      *
75      * @see #setExtent(TemplateSubTask.ExtentTypes)
76      * @see #getExtent()
77      * @see #addOfType(java.lang.String)
78      * @see #getOfType()
79      */

80     private String JavaDoc extent = "hierarchy";
81
82     /**
83      * A class should have the class tag defined in this property in order to be processed and output generated for.
84      *
85      * @see #setHavingClassTag(java.lang.String)
86      * @see #getHavingClassTag()
87      */

88     private String JavaDoc havingClassTag = null;
89
90     /**
91      * The subtask class.
92      */

93     private String JavaDoc subTaskClassName = null;
94
95     private ArrayList packageSubstitutions = new ArrayList();
96
97     private boolean packageSubstitutionInheritanceSupported = true;
98
99     private GenerationManager generationManager;
100
101     public TemplateSubTask()
102     {
103         super();
104         DocletTask.registerSubTaskName(this, SUBTASK_NAME);
105     }
106
107     /**
108      * Converts the fully qualified class name to a valid path with File.separator characters instead of "." characters
109      * and class name postfixed by a ".java".
110      *
111      * @param className class name
112      * @return file path
113      */

114     protected static String JavaDoc javaFile(String JavaDoc className)
115     {
116         return className.replace('.', '/') + ".java";
117     }
118
119     public boolean getAcceptInterfaces()
120     {
121         return acceptInterfaces;
122     }
123
124     public boolean getAcceptAbstractClasses()
125     {
126         return acceptAbstractClasses;
127     }
128
129     public GenerationManager getGenerationManager()
130     {
131         return generationManager;
132     }
133
134     /**
135      * Gets the PackageSubstitutions attribute of the TemplateSubTask object
136      *
137      * @return The PackageSubstitutions value
138      */

139     public ArrayList getPackageSubstitutions()
140     {
141         return packageSubstitutions;
142     }
143
144     /**
145      * By default supports, but some subtasks may not support because global packageSubstitution is for public
146      * interfaces/classes, not good for impl classes.
147      *
148      * @return true
149      */

150     public boolean isPackageSubstitutionInheritanceSupported()
151     {
152         return packageSubstitutionInheritanceSupported;
153     }
154
155     /**
156      * Gets the SubTaskClassName attribute of the TemplateSubTask object
157      *
158      * @return The SubTaskClassName value
159      */

160     public String JavaDoc getSubTaskClassName()
161     {
162         return subTaskClassName;
163     }
164
165     /**
166      * Gets the Engine attribute of the TemplateSubTask object
167      *
168      * @return The Engine value
169      */

170     public TemplateEngine getEngine()
171     {
172         if (engine == null) {
173             throw new IllegalStateException JavaDoc("Engine is null?!");
174         }
175         return engine;
176     }
177
178     /**
179      * Gets the TemplateURL attribute of the TemplateSubTask object
180      *
181      * @return The TemplateURL value
182      */

183     public URL JavaDoc getTemplateURL()
184     {
185         return templateURL;
186     }
187
188     /**
189      * Gets the DestinationFile attribute of the TemplateSubTask object
190      *
191      * @return The DestinationFile value
192      */

193     public String JavaDoc getDestinationFile()
194     {
195         return destinationFile;
196     }
197
198     /**
199      * Gets the OfType attribute of the TemplateSubTask object
200      *
201      * @return The OfType value
202      */

203     public String JavaDoc[] getOfType()
204     {
205         String JavaDoc[] result = new String JavaDoc[ofType.size()];
206
207         for (int i = 0; i < ofType.size(); i++) {
208             result[i] = ((OfType) ofType.get(i)).getType();
209         }
210
211         return result;
212     }
213
214     /**
215      * Gets the Extent attribute of the TemplateSubTask object
216      *
217      * @return The Extent value
218      */

219     public String JavaDoc getExtent()
220     {
221         return extent;
222     }
223
224     /**
225      * Gets the HavingClassTag attribute of the TemplateSubTask object
226      *
227      * @return The HavingClassTag value
228      */

229     public String JavaDoc getHavingClassTag()
230     {
231         return havingClassTag;
232     }
233
234     /**
235      * Gets the PrefixWithPackageStructure attribute of the TemplateSubTask object
236      *
237      * @return The PrefixWithPackageStructure value
238      */

239     public boolean isPrefixWithPackageStructure()
240     {
241         return prefixWithPackageStructure;
242     }
243
244     /**
245      * Indicates whether or not to generate for interfaces.
246      *
247      * @param acceptInterfaces
248      * @ant.not-required No, default is "true"
249      */

250     public void setAcceptInterfaces(boolean acceptInterfaces)
251     {
252         this.acceptInterfaces = acceptInterfaces;
253     }
254
255     /**
256      * Indicates whether or not to generate for abstract classes.
257      *
258      * @param acceptAbstractClasses
259      * @ant.not-required No, default is "true"
260      */

261     public void setAcceptAbstractClasses(boolean acceptAbstractClasses)
262     {
263         this.acceptAbstractClasses = acceptAbstractClasses;
264     }
265
266     /**
267      * Sets the PackageSubstitutions attribute of the TemplateSubTask object
268      *
269      * @param packageSubstitutions The new PackageSubstitutions value
270      */

271     public void setPackageSubstitutions(ArrayList packageSubstitutions)
272     {
273         this.packageSubstitutions = packageSubstitutions;
274     }
275
276     /**
277      * Indicates whether or not package substitution should be inherited
278      *
279      * @param packageSubstitutionInheritanceSupported The new PackageSubstitutionInheritanceSupported value
280      * @ant.not-required No, default is "true"
281      */

282     public void setPackageSubstitutionInheritanceSupported(boolean packageSubstitutionInheritanceSupported)
283     {
284         this.packageSubstitutionInheritanceSupported = packageSubstitutionInheritanceSupported;
285     }
286
287     /**
288      * Sets the SubTaskClassName attribute of the TemplateSubTask object
289      *
290      * @param subTaskClassName The new SubTaskClassName value
291      * @ant.ignore
292      */

293     public void setSubTaskClassName(String JavaDoc subTaskClassName)
294     {
295         this.subTaskClassName = subTaskClassName;
296     }
297
298     /**
299      * Indicates whether or not to prefix with package structure.
300      *
301      * @param prefixWithPackageStructure The new PrefixWithPackageStructure value
302      * @ant.not-required No, default is "true"
303      */

304     public void setPrefixWithPackageStructure(boolean prefixWithPackageStructure)
305     {
306         this.prefixWithPackageStructure = prefixWithPackageStructure;
307     }
308
309     /**
310      * Sets the Engine attribute of the TemplateSubTask object
311      *
312      * @param engine The new Engine value
313      * @ant.ignore
314      */

315     public void setEngine(TemplateEngine engine)
316     {
317         this.engine = engine;
318     }
319
320     /**
321      * The destination file name. If a {0} is found it's assumed that a per class output generation is needed, so {0} is
322      * substituted with class name; otherwise a single file is generated with the specified name.
323      *
324      * @param destinationFile The new DestinationFile value
325      * @ant.not-required No, default is determined by this task.
326      */

327     public void setDestinationFile(String JavaDoc destinationFile)
328     {
329         this.destinationFile = destinationFile;
330     }
331
332     /**
333      * This method should be called to set a template file programmatically. The URL is typically obtained with a
334      * getClass().getResource( templateName )
335      *
336      * @param templateURL
337      * @ant.ignore
338      */

339     public void setTemplateURL(URL JavaDoc templateURL)
340     {
341         this.templateURL = templateURL;
342     }
343
344     /**
345      * Sets the name of the template file to use for generation
346      *
347      * @param templateFile the file name (real file!) of the template
348      * @exception XDocletException
349      * @ant.not-required No, default is determined by this task.
350      */

351     public void setTemplateFile(File JavaDoc templateFile) throws XDocletException
352     {
353         if (templateFile.exists()) {
354             try {
355                 setTemplateURL(templateFile.toURL());
356             }
357             catch (MalformedURLException JavaDoc e) {
358                 throw new XDocletException(e.getMessage());
359             }
360         }
361         else {
362             throw new XDocletException("Couldn't find template: " + templateFile.getAbsolutePath());
363         }
364     }
365
366     /**
367      * You can control the extent in which the type search occurs. Valid values are:
368      * <ul>
369      * <li> "concrete-type": the class is itself one of the classes listed in ofType attribute. </li>
370      * <li> "superclass": the class is itself one of the classes listed in ofType attribute or its superclass is one
371      * of the listed ones </li>
372      * <li> "hierarchy" which is the default: anywhere in its hierarchy it derives from one of the listed classes.
373      * </li>
374      * </ul>
375      * There's no distinction between a class and an interface.
376      *
377      * @param extent The new Extent value
378      * @ant.ignore
379      */

380     public void setExtent(ExtentTypes extent)
381     {
382         this.extent = extent.getValue();
383     }
384
385     /**
386      * Sets the HavingClassTag attribute of the TemplateSubTask object
387      *
388      * @param havingClassTag The new HavingClassTag value
389      */

390     public void setHavingClassTag(String JavaDoc havingClassTag)
391     {
392         this.havingClassTag = havingClassTag;
393     }
394
395     public void setOfType(String JavaDoc ofType)
396     {
397         StringTokenizer st = new StringTokenizer(ofType, ",");
398
399         while (st.hasMoreTokens()) {
400             String JavaDoc type = st.nextToken();
401
402             OfType new_oftype = new OfType();
403
404             new_oftype.setType(type);
405             addOfType(new_oftype);
406         }
407     }
408
409     public void addOfType(OfType ofType)
410     {
411         this.ofType.add(ofType);
412     }
413
414     /**
415      * Substitutes the package of the generated files.
416      *
417      * @param ps The feature to be added to the Fileset attribute
418      */

419     public void addPackageSubstitution(xdoclet.tagshandler.PackageTagsHandler.PackageSubstitution ps)
420     {
421         packageSubstitutions.add(ps);
422     }
423
424     /**
425      * Describe what the method does
426      *
427      * @param src Describe what the parameter does
428      */

429     public void copyAttributesFrom(TemplateSubTask src)
430     {
431         setTemplateURL(src.getTemplateURL());
432         setPrefixWithPackageStructure(src.isPrefixWithPackageStructure());
433         setAcceptInterfaces(src.getAcceptInterfaces());
434         setAcceptAbstractClasses(src.getAcceptAbstractClasses());
435         setDestinationFile(src.getDestinationFile());
436         for (int i = 0; i < src.ofType.size(); i++) {
437             addOfType((OfType) src.ofType.get(i));
438         }
439         setExtentValue(src.getExtent());
440         setHavingClassTag(src.getHavingClassTag());
441         setSubTaskClassName(src.getSubTaskClassName());
442         for (int i = 0; i < src.packageSubstitutions.size(); i++) {
443             addPackageSubstitution((PackageTagsHandler.PackageSubstitution) src.packageSubstitutions.get(i));
444         }
445         setPackageSubstitutionInheritanceSupported(src.isPackageSubstitutionInheritanceSupported());
446         setGenerationManager(src.getGenerationManager());
447     }
448
449     /**
450      * Describe what the method does
451      *
452      * @param xJavaDoc
453      * @exception XDocletException Describe the exception
454      */

455     public void init(XJavaDoc xJavaDoc) throws XDocletException
456     {
457         super.init(xJavaDoc);
458         TemplateEngine.getEngineInstance().setXJavaDoc(getXJavaDoc());
459         setEngine(TemplateEngine.getEngineInstance());
460     }
461
462     /**
463      * Called to validate configuration parameters.
464      *
465      * @exception XDocletException Description of Exception
466      */

467     public void validateOptions() throws XDocletException
468     {
469         super.validateOptions();
470
471         if (getTemplateURL() == null) {
472             throw new XDocletException(Translator.getString(XDocletTemplateMessages.class, XDocletTemplateMessages.TEMPLATE_PARAMETER_MISSING, new String JavaDoc[]{"templateFile"}));
473         }
474
475         if (getDestinationFile() == null) {
476             throw new XDocletException(Translator.getString(XDocletTemplateMessages.class, XDocletTemplateMessages.TEMPLATE_PARAMETER_MISSING, new String JavaDoc[]{"destinationFile"}));
477         }
478     }
479
480     /**
481      * Describe what the method does
482      *
483      * @exception XDocletException Describe the exception
484      */

485     public void execute() throws XDocletException
486     {
487         startProcess();
488     }
489
490     /**
491      * Returns the filename of the generated file for a class. If the string "{0}" is present in the pattern, it will be
492      * substituted with the transformed class name.
493      *
494      * @param clazz the class being processed
495      * @return the corresponding filename
496      * @exception XDocletException Description of Exception
497      */

498     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
499     {
500         Log log = LogUtil.getLog(TemplateSubTask.class, "getGeneratedFileName");
501
502         XPackage pak = clazz.getContainingPackage();
503         String JavaDoc package_structure = null;
504
505         if (isPrefixWithPackageStructure() == true)
506             // This will do package substitution too
507
package_structure = PackageTagsHandler.packageNameAsPathFor(pak);
508         else
509             package_structure = null;
510
511         String JavaDoc packageName = isPackageSubstitutionInheritanceSupported() == true ? package_structure : null;
512
513         String JavaDoc name = clazz.getTransformedName();
514
515         String JavaDoc destinationFile = MessageFormat.format(getDestinationFile(), new Object JavaDoc[]{name});
516
517         if (log.isDebugEnabled()) {
518             log.debug("clazz.getName()=" + clazz.getName());
519             log.debug("clazz.getQualifiedName()=" + clazz.getQualifiedName());
520             log.debug("pak=" + pak);
521             log.debug("packageName=" + packageName);
522             log.debug("destinationFile=" + destinationFile);
523         }
524
525         return new File JavaDoc(packageName, destinationFile).toString();
526     }
527
528     /**
529      * Sets the GenerationManager attribute of the TemplateSubTask object
530      *
531      * @param gM The new GenerationManager value
532      */

533     protected void setGenerationManager(GenerationManager gM)
534     {
535         this.generationManager = gM;
536     }
537
538     /**
539      * Sets the ExtentValue attribute of the TemplateSubTask object
540      *
541      * @param extent The new ExtentValue value
542      */

543     protected void setExtentValue(String JavaDoc extent)
544     {
545         this.extent = extent;
546     }
547
548     /**
549      * Describe what the method does
550      *
551      * @param templateURL Describe what the parameter does
552      * @param outputFile Describe what the parameter does
553      * @exception TemplateException Describe the exception
554      */

555     protected final void startEngine(URL JavaDoc templateURL, File JavaDoc outputFile) throws TemplateException
556     {
557         engineStarted();
558
559         getEngine().setOutput(outputFile);
560         getEngine().setTemplateURL(templateURL);
561
562         getEngine().start();
563
564         engineFinished();
565     }
566
567     protected void addOfType(String JavaDoc ofType)
568     {
569         OfType new_oftype = new OfType();
570
571         new_oftype.setType(ofType);
572
573         this.ofType.add(new_oftype);
574     }
575
576     /**
577      * Describe what the method does
578      *
579      * @exception XDocletException Describe the exception
580      */

581     protected void startProcess() throws XDocletException
582     {
583         Log log = LogUtil.getLog(TemplateSubTask.class, "startProcess");
584
585         if (log.isDebugEnabled()) {
586             log.debug("docEncoding=" + docEncoding);
587             log.debug("destDir.toString()=" + getDestDir());
588             log.debug("getTemplateURL()=" + getTemplateURL());
589             log.debug("getDestinationfile()=" + getDestinationFile());
590             log.debug("getOfType()=" + getOfType());
591             log.debug("getExtent()=" + getExtent());
592             log.debug("getHavingClassTag()=" + getHavingClassTag());
593         }
594
595         if (isGenerationPerClass()) {
596             startProcessPerClass();
597         }
598         else {
599             startProcessForAll();
600         }
601     }
602
603     protected void startProcessForAll() throws XDocletException
604     {
605         Log log = LogUtil.getLog(TemplateSubTask.class, "startProcessForAll");
606
607         if (log.isDebugEnabled()) {
608             log.debug("Not per class.");
609         }
610
611         getEngine().setTemplateURL(getTemplateURL());
612
613         File JavaDoc outputFile = new File JavaDoc(getDestDir(), getDestinationFile());
614
615         try {
616             setGenerationManager(new GenerationManager(getXJavaDoc(), this));
617             if (generationManager.isGenerationNeeded(outputFile)) {
618                 startEngine(getTemplateURL(), outputFile);
619             }
620         }
621         catch (TemplateException e) {
622             if (e instanceof XDocletException) {
623                 throw (XDocletException) e;
624             }
625             else {
626                 if (log.isDebugEnabled()) {
627                     log.debug("startProcess()");
628                 }
629                 throw new XDocletException(e, Translator.getString(XDocletMessages.class, XDocletMessages.RUNNING_FAILED));
630             }
631         }
632     }
633
634     /**
635      * Subclasses should override this method and return true if they want startProcessPerClass() to process inner
636      * classes too.
637      *
638      * @return
639      */

640     protected boolean processInnerClasses()
641     {
642         return false;
643     }
644
645     protected void startProcessPerClass() throws XDocletException
646     {
647         Log log = LogUtil.getLog(TemplateSubTask.class, "startProcessPerClass");
648
649         if (log.isDebugEnabled()) {
650             log.debug("Per class.");
651         }
652
653         /*
654          * loop over all classes. false->use readonly classes. subtask decides whether inner classes
655          * should be processed too.
656          * ideally, getSourceClasses should always return inner classes too (with no optional inner argument),
657          * but we have to think about bwc too.
658          */

659         Collection classes;
660         XJavaDoc xjavadoc = getXJavaDoc();
661
662         xjavadoc.setUseNodeParser(false);
663         // currently the default value, but let's make sure since we don't need it
664
if (processInnerClasses()) {
665             classes = xjavadoc.getSourceClasses();
666         }
667         else {
668             classes = xjavadoc.getSourceClasses(new XJavaDoc.NoInnerClassesPredicate());
669         }
670
671         for (Iterator i = classes.iterator(); i.hasNext(); ) {
672             XClass clazz = (XClass) i.next();
673
674             setCurrentClass(clazz);
675             if (matchesGenerationRules(clazz)) {
676                 if (log.isDebugEnabled()) {
677                     log.debug("Working on " + clazz);
678                 }
679                 generateForClass(clazz);
680             }
681         }
682     }
683
684     /**
685      * Returns true if output not already generated for clazz, and is of the specified type and has the specified class
686      * tag; false otherwise. If returned false, no output file is generated for clazz.
687      *
688      * @param clazz Description of Parameter
689      * @return Description of the Returned Value
690      * @exception XDocletException Description of Exception
691      */

692     protected boolean matchesGenerationRules(XClass clazz) throws XDocletException
693     {
694         Log log = LogUtil.getLog(TemplateSubTask.class, "matchesGenerationRules");
695
696         // skip inner classes
697
if (clazz.getContainingClass() != null && !processInnerClasses()) {
698             return false;
699         }
700
701         // skip automatically generated classes
702
if (isDocletGenerated(clazz)) {
703             if (log.isDebugEnabled()) {
704                 log.debug("Reject file '" + clazz.getQualifiedName() + "' because it is a doclet generated one.");
705             }
706             return false;
707         }
708
709         if (acceptInterfaces == false && clazz.isInterface()) {
710             if (log.isDebugEnabled()) {
711                 log.debug("Reject file '" + clazz.getQualifiedName() + "' because it is an interface and acceptInterfaces=false.");
712             }
713             return false;
714         }
715
716         if (acceptAbstractClasses == false && clazz.isAbstract()) {
717             if (log.isDebugEnabled()) {
718                 log.debug("Reject file '" + clazz.getQualifiedName() + "' because it is an abstract class and acceptAbstractClasses=false.");
719             }
720             return false;
721         }
722
723         if (ofType.size() > 0 && classIsntOfOneOfTheTypes(clazz, log))
724             return false;
725
726         if (getHavingClassTag() != null) {
727             if (!clazz.getDoc().hasTag(getHavingClassTag(), false)) {
728                 if (log.isDebugEnabled()) {
729                     log.debug("Reject class '" + clazz.getQualifiedName() + "' because it doesn't have class tag '" + getHavingClassTag() + "'.");
730                 }
731                 return false;
732             }
733             else {
734                 if (log.isDebugEnabled()) {
735                     log.debug("Accept class '" + clazz.getQualifiedName() + "' because it has class tag '" + getHavingClassTag() + "'.");
736                 }
737             }
738         }
739
740         return true;
741     }
742
743     /**
744      * Processed template for clazz and generates output file for clazz.
745      *
746      * @param clazz Description of Parameter
747      * @exception XDocletException Description of Exception
748      */

749     protected void generateForClass(XClass clazz) throws XDocletException
750     {
751         Log log = LogUtil.getLog(TemplateSubTask.class, "generateForClass");
752
753         File JavaDoc file = new File JavaDoc(getDestDir().toString(), getGeneratedFileName(clazz));
754
755         if (log.isDebugEnabled()) {
756             log.debug("destDir.toString()=" + getDestDir().toString());
757             log.debug("getGeneratedFileName()=" + getGeneratedFileName(clazz));
758             log.debug("file=" + file);
759         }
760
761         if (file.exists()) {
762             log.debug("File exists.");
763
764             // Check modification timestamps
765
setGenerationManager(new GenerationManager(getXJavaDoc(), this));
766
767             boolean isGenerationNeeded = generationManager.isGenerationNeeded(clazz, file, true);
768
769             if (!isGenerationNeeded) {
770                 return;
771             }
772         }
773
774         file.getParentFile().mkdirs();
775
776         try {
777             setCurrentPackage(clazz.getContainingPackage());
778             setCurrentClass(clazz);
779             startEngine(getTemplateURL(), new File JavaDoc(getDestDir(), getGeneratedFileName(clazz)));
780         }
781         catch (TemplateException e) {
782             if (e instanceof XDocletException) {
783                 throw (XDocletException) e;
784             }
785             else {
786                 log.debug("generateForClass()");
787                 e.printStackTrace();
788                 throw new XDocletException(e, Translator.getString(XDocletMessages.class, XDocletMessages.RUNNING_FAILED));
789             }
790         }
791     }
792
793     /**
794      * Describe what the method does
795      *
796      * @exception XDocletException Describe the exception
797      */

798     protected void engineStarted() throws XDocletException
799     {
800         Log log = LogUtil.getLog(TemplateSubTask.class, "engineStarted");
801
802         if (isGenerationPerClass()) {
803             log.info(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_TEMPLATE_OUTPUT_PER_CLASS, new String JavaDoc[]{getCurrentClass().getQualifiedName(), getTemplateURL().toString()}));
804         }
805         else {
806             log.info(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_TEMPLATE_OUTPUT_SINGLE_FILE, new String JavaDoc[]{getDestinationFile(), getTemplateURL().toString()}));
807         }
808
809         if (log.isDebugEnabled()) {
810             log.debug("getCurrentClass()=" + getCurrentClass());
811             log.debug("isGenerationPerClass()=" + isGenerationPerClass());
812         }
813     }
814
815     /**
816      * Describe what the method does
817      *
818      * @exception TemplateException Describe the exception
819      */

820     protected void engineFinished() throws TemplateException
821     {
822     }
823
824     /**
825      * Gets the GenerationPerClass attribute of the TemplateSubTask object
826      *
827      * @return The GenerationPerClass value
828      */

829     private boolean isGenerationPerClass()
830     {
831         return getDestinationFile().indexOf("{0}") != -1;
832     }
833
834     private boolean classIsntOfOneOfTheTypes(XClass clazz, Log log)
835     {
836         boolean match = false;
837         String JavaDoc type = null;
838         int extent_value = TypeTagsHandler.extractExtentType(getExtent());
839
840         for (Iterator it = ofType.iterator(); it.hasNext(); ) {
841             type = ((OfType) it.next()).getType();
842
843             if (TypeTagsHandler.isOfType(clazz, type, extent_value) == true) {
844
845                 match = true;
846                 break;
847             }
848         }
849
850         if (!match) {
851             if (log.isDebugEnabled()) {
852                 log.debug("Reject class '" + clazz.getQualifiedName() + "' because it is not of the specified types according to extent='" + getExtent() + "'.");
853             }
854
855             return true;
856         }
857         else {
858             if (log.isDebugEnabled()) {
859                 log.debug("Accept class '" + clazz.getQualifiedName() + "' because it is of type '" + type + "'.");
860             }
861
862             return false;
863         }
864     }
865
866     /**
867      * @author Ara Abrahamian (ara_e@email.com)
868      * @created July 19, 2001
869      */

870     public final static class ExtentTypes extends org.apache.tools.ant.types.EnumeratedAttribute
871     {
872         public final static String JavaDoc EXTENT_TYPE_CONCRETE_TYPE = "concrete-type";
873         public final static String JavaDoc EXTENT_TYPE_SUPERCLASS = "superclass";
874         public final static String JavaDoc EXTENT_TYPE_HIERARCHY = "hierarchy";
875
876         public java.lang.String JavaDoc[] getValues()
877         {
878             return (new java.lang.String JavaDoc[]{EXTENT_TYPE_CONCRETE_TYPE, EXTENT_TYPE_SUPERCLASS, EXTENT_TYPE_HIERARCHY});
879         }
880     }
881
882     /**
883      * Applicable only to per class output generation. Specify full qualified class name from which classes should be
884      * derived. Output generation is performed only for classes of one of the types defined in this property, it's a
885      * comma-separated list. You can control the extent in which the type search occurs by using 'extent' property.
886      *
887      * @created 10. september 2002
888      */

889     public final static class OfType
890     {
891         private String JavaDoc type;
892
893         public String JavaDoc getType()
894         {
895             return type;
896         }
897
898         public void setType(String JavaDoc type)
899         {
900             this.type = type;
901         }
902     }
903 }
904
Popular Tags