1 5 package xdoclet.modules.ejb.entity; 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 17 import xdoclet.util.LogUtil; 18 import xdoclet.util.Translator; 19 20 30 public class EntityPkSubTask extends AbstractEjbCodeGeneratorSubTask 31 { 32 public final static String DEFAULT_ENTITY_PK_CLASS_PATTERN = "{0}PK"; 33 34 protected final static String DEFAULT_TEMPLATE_FILE = "resources/entitypk.xdt"; 35 36 43 protected String entityPkClassPattern; 44 45 48 public EntityPkSubTask() 49 { 50 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 51 setDestinationFile(getEntityPkClassPattern() + ".java"); 52 addOfType("javax.ejb.EntityBean"); 53 } 54 55 64 public String getEntityPkClassPattern() 65 { 66 if (entityPkClassPattern != null) { 67 return entityPkClassPattern; 68 } 69 else { 70 return DEFAULT_ENTITY_PK_CLASS_PATTERN; 71 } 72 } 73 74 80 public void setPattern(String new_pattern) 81 { 82 entityPkClassPattern = new_pattern; 83 } 84 85 90 public void validateOptions() throws XDocletException 91 { 92 super.validateOptions(); 93 94 if (getEntityPkClassPattern() == null || getEntityPkClassPattern().trim().equals("")) { 95 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 96 } 97 98 if (getEntityPkClassPattern().indexOf("{0}") == -1) { 99 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 100 } 101 } 102 103 110 protected String getGeneratedFileName(XClass clazz) throws XDocletException 111 { 112 return PackageTagsHandler.packageNameAsPathFor(PkTagsHandler.getPkClassFor(getCurrentClass())) + ".java"; 113 } 114 115 122 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 123 { 124 if (super.matchesGenerationRules(clazz) == false) { 125 return false; 126 } 127 128 Log log = LogUtil.getLog(EntityPkSubTask.class, "matchesGenerationRules"); 129 130 if (log.isDebugEnabled()) { 131 log.debug("clazz=" + clazz); 132 } 133 134 if ("false".equalsIgnoreCase(clazz.getDoc().getTagAttributeValue("ejb:pk", "generate", false))) { 135 log.debug("Skip primary key for " + clazz.getQualifiedName() + " because of false generate flag"); 136 return false; 137 } 138 139 if (PkTagsHandler.classHasPrimkeyField(clazz)) { 140 log.debug("Skip primary key for " + clazz.getQualifiedName() + " because it has a PK Field."); 141 return false; 142 } 143 144 return true; 145 } 146 147 152 protected void engineStarted() throws XDocletException 153 { 154 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_PK_FOR, 155 new String []{getCurrentClass().getQualifiedName()})); 156 } 157 158 } 159 | Popular Tags |