1 5 package xdoclet.modules.apache.struts; 6 7 import java.util.Collection ; 8 import java.util.Iterator ; 9 import xjavadoc.XClass; 10 import xjavadoc.XTag; 11 12 import xdoclet.TemplateSubTask; 13 import xdoclet.XDocletException; 14 import xdoclet.XDocletMessages; 15 import xdoclet.modules.apache.struts.ejb.XDocletModulesApacheStrutsEjbMessages; 16 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 17 import xdoclet.tagshandler.PackageTagsHandler; 18 import xdoclet.util.Translator; 19 20 30 public class ActionFormSubTask extends TemplateSubTask 31 { 32 35 protected static String DEFAULT_TEMPLATE_FILE = "resources/struts_form.xdt"; 36 37 40 protected String formClassPattern; 41 42 45 protected XTag currentFormTag; 46 47 50 public ActionFormSubTask() 51 { 52 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 53 setDestinationFile(getActionFormClassPattern() + ".java"); 54 addOfType("java.lang.Object"); 55 } 56 57 62 public XTag getCurrentFormTag() 63 { 64 return currentFormTag; 65 } 66 67 72 public String getActionFormClassPattern() 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 (getActionFormClassPattern() == null || getActionFormClassPattern().trim().equals("")) { 112 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 113 } 114 115 if (getActionFormClassPattern().indexOf("{0}") == -1) { 116 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 117 } 118 if (getActionFormClassPattern().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(ActionFormTagsHandler.getActionFormClassFor(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 (ActionFormTagsHandler.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 []{ActionFormTagsHandler.getActionFormClassName(getCurrentClass())})); 183 } 184 } 185 | Popular Tags |