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 27 28 public class EntityFacadeSubTask extends AbstractEjbCodeGeneratorSubTask 29 { 30 public final static String DEFAULT_ENTITY_FACADE_CLASS_PATTERN = "{0}FacadeEJB"; 31 32 public final static String DEFAULT_FACADE_EJB_NAME_PATTERN = "{0}Facade"; 33 protected final static String DEFAULT_TEMPLATE_FILE = "resources/entityfacade.xdt"; 34 35 40 protected String entityFacadeClassPattern; 41 44 protected String entityFacadeEjbNamePattern; 45 46 public EntityFacadeSubTask() 47 { 48 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 49 setDestinationFile(getEntityFacadeClassPattern() + ".java"); 50 addOfType("javax.ejb.EntityBean"); 51 setPackageSubstitutionInheritanceSupported(false); 52 53 } 54 55 64 public String getEntityFacadeClassPattern() 65 { 66 if (entityFacadeClassPattern != null) { 67 return entityFacadeClassPattern; 68 } 69 else { 70 return DEFAULT_ENTITY_FACADE_CLASS_PATTERN; 71 } 72 } 73 74 75 public String getEntityFacadeEjbNamePattern() 76 { 77 if (entityFacadeEjbNamePattern != null) { 78 return entityFacadeEjbNamePattern; 79 } 80 else { 81 return DEFAULT_FACADE_EJB_NAME_PATTERN; 82 } 83 } 84 85 90 public void setPattern(String new_pattern) 91 { 92 entityFacadeClassPattern = new_pattern; 93 } 94 95 public void setEjbNamePattern(String new_pattern) 96 { 97 entityFacadeEjbNamePattern = new_pattern; 98 } 99 100 105 public void validateOptions() throws XDocletException 106 { 107 super.validateOptions(); 108 109 if (getEntityFacadeClassPattern() == null || getEntityFacadeClassPattern().trim().equals("")) { 110 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 111 } 112 113 if (getEntityFacadeClassPattern().indexOf("{0}") == -1) { 114 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 115 } 116 117 if (getEntityFacadeEjbNamePattern() == null || getEntityFacadeEjbNamePattern().trim().equals("")) { 118 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"ejbNamePattern"})); 119 } 120 if (getEntityFacadeEjbNamePattern().indexOf("{0}") == -1) { 121 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 122 } 123 } 124 125 132 protected String getGeneratedFileName(XClass clazz) throws XDocletException 133 { 134 return PackageTagsHandler.packageNameAsPathFor(FacadeTagsHandler.getEntityFacadeClassFor(getCurrentClass())) + ".java"; 135 } 136 137 138 144 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 145 { 146 Log log = LogUtil.getLog(EntityFacadeSubTask.class, "matchesGenerationRules"); 147 148 if (super.matchesGenerationRules(clazz) == false) { 149 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 150 return false; 151 } 152 153 if (EntityTagsHandler.isEntity(getCurrentClass()) == false) { 154 log.debug("Skip bean " + clazz.getQualifiedName() + " because of it's not entity."); 155 return false; 156 } 157 158 String generate = clazz.getDoc().getTagAttributeValue("ejb:bean", "generate", false); 159 160 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 161 log.debug("Skip entity class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 162 return false; 163 } 164 165 if (!clazz.getDoc().hasTag("ejb.facade")) { 166 log.debug("Skip facade class for " + clazz.getQualifiedName() + " because ejb.facade is absent"); 167 return false; 168 } 169 170 String facade = clazz.getDoc().getTagAttributeValue("ejb.facade", "generate", false); 171 172 if ((facade != null) && (facade.equals("false") || facade.equals("no"))) { 173 log.debug("Skip facade class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 174 return false; 175 } 176 177 if (EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) { 178 return true; 179 } 180 else { 181 log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean."); 182 return false; 183 } 184 } 185 186 187 192 protected void engineStarted() throws XDocletException 193 { 194 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_FACADE_FOR, 195 new String []{getCurrentClass().getQualifiedName()})); 196 } 197 198 } 199 200 | Popular Tags |