1 5 package xdoclet.modules.apache.struts.ejb; 6 7 import java.util.*; 8 import xjavadoc.*; 9 10 import xdoclet.XDocletException; 11 import xdoclet.XDocletMessages; 12 import xdoclet.modules.apache.struts.StrutsFormTagsHandler; 13 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 14 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 15 import xdoclet.tagshandler.PackageTagsHandler; 16 17 import xdoclet.util.Translator; 18 19 29 public class StrutsFormSubTask extends AbstractEjbCodeGeneratorSubTask 30 { 31 34 protected final static String DEFAULT_TEMPLATE_FILE = "resources/struts_form.xdt"; 35 36 39 protected String formClassPattern; 40 41 44 protected XTag currentFormTag; 45 46 49 public StrutsFormSubTask() 50 { 51 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 52 setDestinationFile(getStrutsFormClassPattern() + ".java"); 53 addOfType("javax.ejb.EntityBean"); 54 addOfType("java.lang.Object"); 55 } 56 57 62 public XTag getCurrentFormTag() 63 { 64 return currentFormTag; 65 } 66 67 72 public String getStrutsFormClassPattern() 73 { 74 if (formClassPattern != null) { 75 return formClassPattern; 76 } 77 else { 78 return "{0}{1}Form"; 79 } 80 } 81 82 87 public void setCurrentFormTag(XTag t) 88 { 89 this.currentFormTag = t; 90 } 91 92 97 public void setPattern(String newPattern) 98 { 99 formClassPattern = newPattern; 100 } 101 102 107 public void validateOptions() throws XDocletException 108 { 109 super.validateOptions(); 110 111 if (getStrutsFormClassPattern() == null || getStrutsFormClassPattern().trim().equals("")) { 112 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 113 } 114 115 if (getStrutsFormClassPattern().indexOf("{0}") == -1) { 116 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 117 } 118 if (getStrutsFormClassPattern().indexOf("{1}") == -1) { 119 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesApacheStrutsEjbMessages.PATTERN_HAS_NO_FORM_PLACEHOLDER)); 120 } 121 } 122 123 130 protected String getGeneratedFileName(XClass clazz) throws XDocletException 131 { 132 return PackageTagsHandler.packageNameAsPathFor(StrutsFormTagsHandler.getStrutsFormClassFor(getCurrentClass())) + ".java"; 133 } 134 135 142 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 143 { 144 if (super.matchesGenerationRules(clazz) == false) { 145 return false; 146 } 147 148 if (StrutsFormTagsHandler.hasFormDefinition(getCurrentClass())) { 149 return true; 150 } 151 else { 152 return false; 153 } 154 } 155 156 162 protected void generateForClass(XClass clazz) throws XDocletException 163 { 164 Collection formTags = clazz.getDoc().getTags("struts.form"); 165 166 for (Iterator i = formTags.iterator(); i.hasNext(); ) { 167 XTag tag = (XTag) i.next(); 168 169 setCurrentFormTag(tag); 170 super.generateForClass(clazz); 171 } 172 } 173 174 179 protected void engineStarted() throws XDocletException 180 { 181 System.out.println(Translator.getString(XDocletModulesApacheStrutsEjbMessages.class, XDocletModulesApacheStrutsEjbMessages.GENERATING_FILE, 182 new String []{StrutsFormTagsHandler.getStrutsFormClassName(getCurrentClass())})); 183 } 184 } 185 | Popular Tags |