1 5 package xdoclet.modules.ejb.dao; 6 7 import org.apache.commons.logging.Log; 8 9 import xjavadoc.XClass; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XDocletMessages; 13 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 14 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 15 import xdoclet.tagshandler.PackageTagsHandler; 16 import xdoclet.util.LogUtil; 17 import xdoclet.util.Translator; 18 19 27 public class DaoSubTask extends AbstractEjbCodeGeneratorSubTask 28 { 29 public final static String DEFAULT_DAO_CLASS_PATTERN = "{0}DAO"; 30 31 private static String DEFAULT_TEMPLATE_FILE = "resources/dao.xdt"; 32 33 39 private String daoClassPattern; 40 41 44 public DaoSubTask() 45 { 46 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 47 setDestinationFile(getDaoClassPattern() + ".java"); 48 addOfType("javax.ejb.EntityBean"); 49 addOfType("javax.ejb.SessionBean"); 50 setHavingClassTag("ejb.dao"); 51 setPackageSubstitutionInheritanceSupported(false); 52 } 53 54 61 public String getDaoClassPattern() 62 { 63 if (daoClassPattern != null) { 64 return daoClassPattern; 65 } 66 else { 67 return DEFAULT_DAO_CLASS_PATTERN; 68 } 69 } 70 71 76 public void setPattern(String new_pattern) 77 { 78 daoClassPattern = new_pattern; 79 } 80 81 86 public void validateOptions() throws XDocletException 87 { 88 super.validateOptions(); 89 90 if (getDaoClassPattern() == null || getDaoClassPattern().trim().equals("")) { 91 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 92 } 93 94 if (getDaoClassPattern().indexOf("{0}") == -1) { 95 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 96 } 97 } 98 99 106 protected String getGeneratedFileName(XClass clazz) throws XDocletException 107 { 108 return PackageTagsHandler.packageNameAsPathFor(DaoTagsHandler.getDaoClassFor(getCurrentClass())) + ".java"; 109 } 110 111 116 protected void engineStarted() throws XDocletException 117 { 118 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_DAO_FOR, 119 new String []{getCurrentClass().getQualifiedName()})); 120 } 121 122 129 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 130 { 131 Log log = LogUtil.getLog(DaoSubTask.class, "matchesGenerationRules"); 132 133 if (super.matchesGenerationRules(clazz) == false) { 134 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 135 return false; 136 } 137 138 String generate = clazz.getDoc().getTagAttributeValue("ejb.dao", "generate", false); 139 140 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 141 log.debug("Skip DAO class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 142 return false; 143 } 144 145 return true; 146 } 147 148 } 149 | Popular Tags |