1 5 package xdoclet.modules.ejb.entity; 6 7 import java.util.*; 8 9 import xjavadoc.*; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XDocletMessages; 13 14 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 15 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 16 import xdoclet.tagshandler.PackageTagsHandler; 17 import xdoclet.util.Translator; 18 19 29 public class ValueObjectSubTask extends AbstractEjbCodeGeneratorSubTask 30 { 31 public final static String DEFAULT_DATAOBJECT_CLASS_PATTERN = "{0}Value"; 32 33 protected final static String DEFAULT_TEMPLATE_FILE = "resources/valueobject.xdt"; 34 35 private static String currentValueObjectClass; 36 37 private static String currentValueObjectName; 38 39 private static String currentValueObjectMatch; 40 private static String currentValueObjectImplements; 41 private static String currentValueObjectExtends; 42 43 50 protected String valueObjectClassPattern; 51 52 55 protected XTag currentDataObjectTag; 56 57 60 private boolean generatePKConstructor = false; 61 62 65 public ValueObjectSubTask() 66 { 67 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 68 setDestinationFile(getValueObjectClassPattern() + ".java"); 69 addOfType("javax.ejb.EntityBean"); 70 } 71 72 77 public static String getCurrentValueObjectClass() 78 { 79 return currentValueObjectClass; 80 } 81 82 public static String getCurrentValueObjectImplements() 83 { 84 return currentValueObjectImplements; 85 } 86 87 public static String getCurrentValueObjectExtends() 88 { 89 return currentValueObjectExtends; 90 } 91 92 97 public static String getCurrentValueObjectName() 98 { 99 return currentValueObjectName; 100 } 101 102 107 public static String getCurrentValueObjectMatch() 108 { 109 return currentValueObjectMatch; 110 } 111 112 121 public String getValueObjectClassPattern() 122 { 123 if (valueObjectClassPattern != null) { 124 return valueObjectClassPattern; 125 } 126 else { 127 return DEFAULT_DATAOBJECT_CLASS_PATTERN; 128 } 129 } 130 131 public boolean getGeneratePKConstructor() 132 { 133 return generatePKConstructor; 134 } 135 136 142 public void setPattern(String new_pattern) 143 { 144 valueObjectClassPattern = new_pattern; 145 } 146 147 153 public void setGeneratePKConstructor(String generatePKConstructor) 154 { 155 this.generatePKConstructor = generatePKConstructor.substring(0, 1).equalsIgnoreCase("t"); 156 } 157 158 163 public void validateOptions() throws XDocletException 164 { 165 super.validateOptions(); 166 167 if (getValueObjectClassPattern() == null || getValueObjectClassPattern().trim().equals("")) { 168 throw new XDocletException( 169 Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 170 } 171 172 if (getValueObjectClassPattern().indexOf("{0}") == -1) { 173 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 174 } 175 } 176 177 184 protected String getGeneratedFileName(XClass clazz) throws XDocletException 185 { 186 return PackageTagsHandler.packageNameAsPathFor(getCurrentValueObjectClass()) + ".java"; 187 } 188 189 196 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 197 { 198 if (super.matchesGenerationRules(clazz) == false) { 199 return false; 200 } 201 202 if (ValueObjectTagsHandler.isGenerationNeeded(getCurrentClass())) { 203 return true; 204 } 205 else { 206 return false; 207 } 208 } 209 210 216 protected void generateForClass(XClass clazz) throws XDocletException 217 { 218 219 Collection dos = getCurrentClass().getDoc().getTags("ejb:value-object"); 220 221 223 for (Iterator i = dos.iterator(); i.hasNext(); ) { 224 XTag tag = (XTag) i.next(); 225 226 currentValueObjectClass = ValueObjectTagsHandler.getCurrentValueObjectClass(getCurrentClass(), tag); 227 currentValueObjectName = ValueObjectTagsHandler.getCurrentValueObjectName(tag); 228 currentValueObjectMatch = ValueObjectTagsHandler.getCurrentValueObjectMatch(tag); 229 currentValueObjectImplements = ValueObjectTagsHandler.getCurrentValueObjectImplements(tag); 230 currentValueObjectExtends = ValueObjectTagsHandler.getCurrentValueObjectExtends(tag); 231 super.generateForClass(clazz); 232 } 233 } 234 235 240 protected void engineStarted() throws XDocletException 241 { 242 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_VALUEOBJECT_FOR, 243 new String []{getCurrentClass().getQualifiedName() + "--> " + getCurrentValueObjectClass()})); 244 } 245 246 } 247 | Popular Tags |