1 5 package xdoclet.modules.ejb.lookup; 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 31 public class LookupObjectSubTask extends AbstractEjbCodeGeneratorSubTask 32 { 33 public final static String DEFAULT_UTIL_CLASS_PATTERN = "{0}Util"; 34 35 private static String DEFAULT_TEMPLATE_FILE = "resources/lookup.xdt"; 36 37 44 private String utilClassPattern; 45 46 49 private boolean includeGUID = false; 50 51 54 private boolean cacheHomes = false; 55 56 59 private String kind = LookupKind.LOGICAL; 60 61 64 private boolean localProxies = false; 65 66 69 public LookupObjectSubTask() 70 { 71 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 72 setDestinationFile(getUtilClassPattern() + ".java"); 73 addOfType("javax.ejb.EntityBean"); 74 addOfType("javax.ejb.SessionBean"); 75 addOfType("javax.ejb.MessageDrivenBean"); 76 } 77 78 83 public boolean getLocalProxies() 84 { 85 return localProxies; 86 } 87 88 93 public String getKind() 94 { 95 return kind; 96 } 97 98 103 public boolean getIncludeGUID() 104 { 105 return includeGUID; 106 } 107 108 113 public boolean getCacheHomes() 114 { 115 return cacheHomes; 116 } 117 118 125 public String getUtilClassPattern() 126 { 127 if (utilClassPattern != null) { 128 return utilClassPattern; 129 } 130 else { 131 return DEFAULT_UTIL_CLASS_PATTERN; 132 } 133 } 134 135 141 public void setLocalProxies(boolean localProxies) 142 { 143 this.localProxies = localProxies; 144 } 145 146 151 public void setKind(LookupKind kind) 152 { 153 this.kind = kind.getValue(); 154 } 155 156 161 public void setPattern(String new_pattern) 162 { 163 utilClassPattern = new_pattern; 164 } 165 166 171 public void setIncludeGUID(boolean includeGUID) 172 { 173 this.includeGUID = includeGUID; 174 } 175 176 181 public void setCacheHomes(boolean cacheHomes) 182 { 183 this.cacheHomes = cacheHomes; 184 } 185 186 191 public void validateOptions() throws XDocletException 192 { 193 super.validateOptions(); 194 195 if (getUtilClassPattern() == null || getUtilClassPattern().trim().equals("")) { 196 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 197 } 198 199 if (getUtilClassPattern().indexOf("{0}") == -1) { 200 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 201 } 202 } 203 204 211 protected String getGeneratedFileName(XClass clazz) throws XDocletException 212 { 213 return PackageTagsHandler.packageNameAsPathFor(LookupUtilTagsHandler.getUtilClassFor(getCurrentClass())) + ".java"; 214 } 215 216 221 protected void engineStarted() throws XDocletException 222 { 223 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_UTIL_FOR, 224 new String []{getCurrentClass().getQualifiedName()})); 225 } 226 227 234 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 235 { 236 Log log = LogUtil.getLog(LookupObjectSubTask.class, "matchesGenerationRules"); 237 238 if (super.matchesGenerationRules(clazz) == false) { 239 log.debug("Skip bean " + clazz.getQualifiedName() + " because super.matchesGenerationRules() returned false."); 240 return false; 241 } 242 243 if (!EjbTagsHandler.isAConcreteEJBean(getCurrentClass())) { 244 log.debug("Skip bean " + clazz.getQualifiedName() + " because it's not a concrete bean."); 245 return false; 246 } 247 248 String generate = getCurrentClass().getDoc().getTagAttributeValue("ejb:util", "generate", true); 249 250 if ((generate != null) && (generate.equals("false") || generate.equals("no"))) { 251 log.debug("Skip util class for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 252 return false; 253 } 254 255 return true; 256 } 257 258 262 public static class LookupKind extends org.apache.tools.ant.types.EnumeratedAttribute 263 { 264 public final static String PHYSICAL = "physical"; 265 266 public final static String LOGICAL = "logical"; 267 268 273 public String [] getValues() 274 { 275 return (new String []{ 276 PHYSICAL, LOGICAL 277 }); 278 } 279 } 280 } 281 | Popular Tags |