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.EjbTagsHandler; 15 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 16 import xdoclet.tagshandler.PackageTagsHandler; 17 18 import xdoclet.util.LogUtil; 19 import xdoclet.util.Translator; 20 21 36 public class EntityBmpSubTask extends AbstractEjbCodeGeneratorSubTask 37 { 38 public final static String DEFAULT_ENTITYBMP_CLASS_PATTERN = "{0}BMP"; 39 40 protected final static String DEFAULT_TEMPLATE_FILE = "resources/entitybmp.xdt"; 41 42 49 protected String entityBmpClassPattern; 50 51 52 55 public EntityBmpSubTask() 56 { 57 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 58 setDestinationFile(getEntityBmpClassPattern() + ".java"); 59 addOfType("javax.ejb.EntityBean"); 60 setPackageSubstitutionInheritanceSupported(false); 61 } 62 63 64 73 public String getEntityBmpClassPattern() 74 { 75 if (entityBmpClassPattern != null) { 76 return entityBmpClassPattern; 77 } 78 else { 79 return DEFAULT_ENTITYBMP_CLASS_PATTERN; 80 } 81 } 82 83 84 90 public void setPattern(String new_pattern) 91 { 92 entityBmpClassPattern = new_pattern; 93 } 94 95 96 101 public void validateOptions() throws XDocletException 102 { 103 super.validateOptions(); 104 105 if (getEntityBmpClassPattern() == null || getEntityBmpClassPattern().trim().equals("")) { 106 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 107 } 108 109 if (getEntityBmpClassPattern().indexOf("{0}") == -1) { 110 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 111 } 112 } 113 114 115 122 protected String getGeneratedFileName(XClass clazz) throws XDocletException 123 { 124 return PackageTagsHandler.packageNameAsPathFor(BmpTagsHandler.getEntityBmpClassFor(getCurrentClass())) + ".java"; 125 } 126 127 128 135 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 136 { 137 Log log = LogUtil.getLog(EntityBmpSubTask.class, "matchesGenerationRules"); 138 139 if (super.matchesGenerationRules(clazz) == false) { 140 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 141 return false; 142 } 143 144 if (!BmpTagsHandler.isEntityBmp(getCurrentClass())) { 145 log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not BMP."); 146 return false; 147 } 148 149 String generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false); 150 151 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 152 log.debug("Skip entity bmp class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 153 return false; 154 } 155 156 if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) { 157 return true; 158 } 159 else { 160 log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean."); 161 return false; 162 } 163 } 164 165 166 171 protected void engineStarted() throws XDocletException 172 { 173 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_BMP_FOR, 174 new String []{getCurrentClass().getQualifiedName()})); 175 } 176 } 177 | Popular Tags |