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 import xdoclet.util.LogUtil; 18 19 import xdoclet.util.Translator; 20 21 29 public class EntityCmpSubTask extends AbstractEjbCodeGeneratorSubTask 30 { 31 public final static String DEFAULT_ENTITYCMP_CLASS_PATTERN = "{0}CMP"; 32 33 protected final static String DEFAULT_TEMPLATE_FILE = "resources/entitycmp.xdt"; 34 35 42 protected String entityCmpClassPattern; 43 44 private String cmpspec = CmpSpecVersion.CMP_2_0; 45 46 49 public EntityCmpSubTask() 50 { 51 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 52 setDestinationFile(getEntityCmpClassPattern() + ".java"); 53 addOfType("javax.ejb.EntityBean"); 54 setPackageSubstitutionInheritanceSupported(false); 55 } 56 57 62 public String getCmpSpec() 63 { 64 return cmpspec; 65 } 66 67 76 public String getEntityCmpClassPattern() 77 { 78 if (entityCmpClassPattern != null) { 79 return entityCmpClassPattern; 80 } 81 else { 82 return DEFAULT_ENTITYCMP_CLASS_PATTERN; 83 } 84 } 85 86 91 public void setCmpSpec(CmpSpecVersion cmpspec) 92 { 93 this.cmpspec = cmpspec.getValue(); 94 } 95 96 101 public void setPattern(String new_pattern) 102 { 103 entityCmpClassPattern = new_pattern; 104 } 105 106 111 public void validateOptions() throws XDocletException 112 { 113 super.validateOptions(); 114 115 if (getEntityCmpClassPattern() == null || getEntityCmpClassPattern().trim().equals("")) { 116 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 117 } 118 119 if (getEntityCmpClassPattern().indexOf("{0}") == -1) { 120 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 121 } 122 } 123 124 131 protected String getGeneratedFileName(XClass clazz) throws XDocletException 132 { 133 return PackageTagsHandler.packageNameAsPathFor(CmpTagsHandler.getEntityCmpClassFor(getCurrentClass())) + ".java"; 134 } 135 136 137 143 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 144 { 145 Log log = LogUtil.getLog(EntityCmpSubTask.class, "matchesGenerationRules"); 146 147 if (super.matchesGenerationRules(clazz) == false) { 148 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 149 return false; 150 } 151 152 if (CmpTagsHandler.isEntityCmp(getCurrentClass()) == false) { 153 log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not BMP."); 154 return false; 155 } 156 157 String generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false); 158 159 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 160 log.debug("Skip entity cmp class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 161 return false; 162 } 163 164 if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) { 165 return true; 166 } 167 else { 168 log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean."); 169 return false; 170 } 171 } 172 173 178 protected void engineStarted() throws XDocletException 179 { 180 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_CMP_FOR, 181 new String []{getCurrentClass().getQualifiedName()})); 182 } 183 184 185 189 public static class CmpSpecVersion extends org.apache.tools.ant.types.EnumeratedAttribute 190 { 191 public final static String CMP_1_1 = "1.x"; 192 public final static String CMP_2_0 = "2.x"; 193 194 199 public final static String getVersions() 200 { 201 return CMP_1_1 + ',' + CMP_2_0; 202 } 203 204 209 public String [] getValues() 210 { 211 return (new String []{ 212 CMP_1_1, CMP_2_0 213 }); 214 } 215 } 216 } 217 | Popular Tags |