1 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 22 public class BeanInfoSubTask extends TemplateSubTask 23 { 24 27 public static String GENERATED_BEANINFO_FILE_NAME = "{0}BeanInfo.java"; 28 31 public static String GENERATED_BEANINFO_CLASS_NAME = "{0}BeanInfo"; 32 35 private static String DEFAULT_BEANINFO_TEMPLATE_FILE = "resources/beaninfo.xdt"; 36 39 private static String DEFAULT_PROPERTIES_TEMPLATE_FILE = "resources/i18n.xdt"; 40 43 private static String GENERATED_PROPERTIES_FILE_NAME = "{0}BeanInfo.properties"; 44 47 protected boolean i18nGeneration = false; 48 49 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 64 public boolean isI18n() 65 { 66 return i18nGeneration; 67 } 68 69 74 public void setI18n(boolean value) 75 { 76 i18nGeneration = value; 77 } 78 79 84 public void validateOptions() throws XDocletException 85 { 86 } 90 91 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 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 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 []{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 []{getCurrentClass().getQualifiedName()})); 130 } 131 } 132 } 133 | Popular Tags |