KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > java > javabean > BeanInfoSubTask


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

5 package xdoclet.modules.java.javabean;
6
7
8 import xjavadoc.XClass;
9
10 import xdoclet.TemplateSubTask;
11 import xdoclet.XDocletException;
12 import xdoclet.tagshandler.PackageTagsHandler;
13 import xdoclet.util.Translator;
14 /**
15  * Generate the BeanInfo class for a given JavaBean class, and an optional messages properties bundle to go with it.
16  *
17  * @author Laurent Etiemble (letiemble@users.sourceforge.net)
18  * @created June 20, 2002
19  * @version $Revision: 1.6 $
20  * @ant.element name="beaninfo" display-name="BeanInfo Class" parent="xdoclet.DocletTask"
21  */

22 public class BeanInfoSubTask extends TemplateSubTask
23 {
24     /**
25      * Pattern for generation of BeanInfo files
26      */

27     public static String JavaDoc GENERATED_BEANINFO_FILE_NAME = "{0}BeanInfo.java";
28     /**
29      * Pattern for generation of BeanInfo files
30      */

31     public static String JavaDoc GENERATED_BEANINFO_CLASS_NAME = "{0}BeanInfo";
32     /**
33      * Default template to use for BeanInfo files
34      */

35     private static String JavaDoc DEFAULT_BEANINFO_TEMPLATE_FILE = "resources/beaninfo.xdt";
36     /**
37      * Default template to use for i18n properties files
38      */

39     private static String JavaDoc DEFAULT_PROPERTIES_TEMPLATE_FILE = "resources/i18n.xdt";
40     /**
41      * Pattern for generation of i18n properties files
42      */

43     private static String JavaDoc GENERATED_PROPERTIES_FILE_NAME = "{0}BeanInfo.properties";
44     /**
45      * Is the BeanInfo class built for I18N
46      */

47     protected boolean i18nGeneration = false;
48
49     /**
50      * Constructor for the BeanInfoSubTask object
51      */

52     public BeanInfoSubTask()
53     {
54         setHavingClassTag("javabean.class");
55         setTemplateURL(getClass().getResource(DEFAULT_BEANINFO_TEMPLATE_FILE));
56         setDestinationFile(GENERATED_BEANINFO_FILE_NAME);
57     }
58
59     /**
60      * Get whether or not a I18N resource bundle will be generated, and the BeanInfo classes will use it
61      *
62      * @return true if I18N is supported
63      */

64     public boolean isI18n()
65     {
66         return i18nGeneration;
67     }
68
69     /**
70      * Set whether or not a I18N resource bundle will be generated, and the BeanInfo classes will use it
71      *
72      * @param value true to support I18N
73      */

74     public void setI18n(boolean value)
75     {
76         i18nGeneration = value;
77     }
78
79     /**
80      * Called to validate configuration parameters.
81      *
82      * @exception XDocletException Description of Exception
83      */

84     public void validateOptions() throws XDocletException
85     {
86         // JavaBeans does not require a template url or a destination file
87
//
88
// super.validateOptions();
89
}
90
91     /**
92      * @exception XDocletException Description of Exception
93      */

94     public void execute() throws XDocletException
95     {
96         startProcess();
97
98         if (isI18n()) {
99             setTemplateURL(getClass().getResource(DEFAULT_PROPERTIES_TEMPLATE_FILE));
100             setDestinationFile(GENERATED_PROPERTIES_FILE_NAME);
101             startProcess();
102         }
103     }
104
105
106     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
107     {
108         if (getDestinationFile().equals(GENERATED_BEANINFO_FILE_NAME)) {
109             return PackageTagsHandler.packageNameAsPathFor(JavaBeanTagsHandler.getBeanInfoClassFor(clazz)) + ".java";
110         }
111         return super.getGeneratedFileName(clazz);
112     }
113
114     /**
115      * Called when the engine is started
116      *
117      * @exception XDocletException Thrown in case of problem
118      */

119     protected void engineStarted() throws XDocletException
120     {
121         if (getDestinationFile().equals(GENERATED_BEANINFO_FILE_NAME)) {
122             System.out.println(Translator.getString(XDocletModulesJavabeanMessages.class,
123                 XDocletModulesJavabeanMessages.GENERATING_BEANINFO_FOR,
124                 new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
125         }
126         else if (getDestinationFile().equals(GENERATED_PROPERTIES_FILE_NAME)) {
127             System.out.println(Translator.getString(XDocletModulesJavabeanMessages.class,
128                 XDocletModulesJavabeanMessages.GENERATING_PROPERTIES_FOR,
129                 new String JavaDoc[]{getCurrentClass().getQualifiedName()}));
130         }
131     }
132 }
133
Popular Tags