1 5 package xdoclet.modules.ejb.entity; 6 7 import java.util.StringTokenizer ; 8 9 import xjavadoc.XClass; 10 import xjavadoc.XTag; 11 12 import xdoclet.XDocletException; 13 import xdoclet.XDocletMessages; 14 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 15 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 16 import xdoclet.tagshandler.PackageTagsHandler; 17 18 import xdoclet.util.Translator; 19 20 31 public class DataObjectSubTask extends AbstractEjbCodeGeneratorSubTask 32 { 33 public final static String DEFAULT_DATAOBJECT_CLASS_PATTERN = "{0}Data"; 34 35 protected final static String DEFAULT_TEMPLATE_FILE = "resources/dataobject.xdt"; 36 37 44 protected String dataObjectClassPattern; 45 46 47 50 public DataObjectSubTask() 51 { 52 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 53 setDestinationFile(getDataObjectClassPattern() + ".java"); 54 addOfType("javax.ejb.EntityBean"); 55 } 56 57 66 public String getDataObjectClassPattern() 67 { 68 if (dataObjectClassPattern != null) { 69 return dataObjectClassPattern; 70 } 71 else { 72 return DEFAULT_DATAOBJECT_CLASS_PATTERN; 73 } 74 } 75 76 82 public void setPattern(String new_pattern) 83 { 84 dataObjectClassPattern = new_pattern; 85 } 86 87 92 public void validateOptions() throws XDocletException 93 { 94 super.validateOptions(); 95 96 if (getDataObjectClassPattern() == null || getDataObjectClassPattern().trim().equals("")) { 97 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 98 } 99 100 if (getDataObjectClassPattern().indexOf("{0}") == -1) { 101 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 102 } 103 } 104 105 112 protected String getGeneratedFileName(XClass clazz) throws XDocletException 113 { 114 return PackageTagsHandler.packageNameAsPathFor(DataObjectTagsHandler.getDataObjectClassFor(getCurrentClass())) + ".java"; 115 } 116 117 124 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 125 { 126 if (super.matchesGenerationRules(clazz) == false) { 127 return false; 128 } 129 130 if (DataObjectTagsHandler.isGenerationNeeded(getCurrentClass())) { 131 return true; 132 } 133 else { 134 return false; 135 } 136 } 137 138 144 protected void generateForClass(XClass clazz) throws XDocletException 145 { 146 if (DataObjectTagsHandler.hasCustomBulkData(getCurrentClass())) { 147 149 XTag bdo = getCurrentClass().getDoc().getTag("ejb:bulk-data"); 150 StringTokenizer st = new StringTokenizer (bdo.getValue(), " "); 151 152 DataObjectTagsHandler.setCurrentDataObjectClassname(st.nextToken().trim()); 153 DataObjectTagsHandler.putDataObjectClassnames(getCurrentClass().getQualifiedName(), DataObjectTagsHandler.getCurrentDataObjectClassname()); 154 } 155 else { 156 DataObjectTagsHandler.setCurrentDataObjectClassname(DataObjectTagsHandler.generateDataObjectClass(clazz)); 157 DataObjectTagsHandler.putDataObjectClassnames(getCurrentClass().getQualifiedName(), DataObjectTagsHandler.getCurrentDataObjectClassname()); 158 } 159 160 super.generateForClass(clazz); 161 } 162 163 168 protected void engineStarted() throws XDocletException 169 { 170 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_DATAOBJECT_FOR, 171 new String []{getCurrentClass().getQualifiedName()})); 172 } 173 } 174 | Popular Tags |