1 5 package xdoclet.modules.ejb.home; 6 7 import org.apache.commons.logging.Log; 8 9 import xjavadoc.XClass; 10 import xjavadoc.XTag; 11 12 import xdoclet.XDocletException; 13 import xdoclet.XDocletMessages; 14 15 import xdoclet.modules.ejb.AbstractEjbCodeGeneratorSubTask; 16 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 17 import xdoclet.modules.ejb.intf.InterfaceTagsHandler; 18 import xdoclet.tagshandler.PackageTagsHandler; 19 20 import xdoclet.util.LogUtil; 21 import xdoclet.util.Translator; 22 23 34 public class LocalHomeInterfaceSubTask extends AbstractEjbCodeGeneratorSubTask 35 { 36 public final static String DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN = "{0}LocalHome"; 37 38 protected final static String DEFAULT_TEMPLATE_FILE = "resources/home-local.xdt"; 39 40 47 protected String localHomeClassPattern; 48 49 52 public LocalHomeInterfaceSubTask() 53 { 54 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 55 setDestinationFile(getLocalHomeClassPattern() + ".java"); 56 addOfType("javax.ejb.EntityBean"); 57 addOfType("javax.ejb.SessionBean"); 58 } 59 60 69 public String getLocalHomeClassPattern() 70 { 71 if (localHomeClassPattern != null) { 72 return localHomeClassPattern; 73 } 74 else { 75 return DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN; 76 } 77 } 78 79 85 public void setPattern(String new_pattern) 86 { 87 localHomeClassPattern = new_pattern; 88 } 89 90 95 public void validateOptions() throws XDocletException 96 { 97 super.validateOptions(); 98 99 if (getLocalHomeClassPattern() == null || getLocalHomeClassPattern().trim().equals("")) { 100 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 101 } 102 103 if (getLocalHomeClassPattern().indexOf("{0}") == -1) { 104 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 105 } 106 } 107 108 115 protected String getGeneratedFileName(XClass clazz) throws XDocletException 116 { 117 return PackageTagsHandler.packageNameAsPathFor(HomeTagsHandler.getHomeInterface("local", getCurrentClass())) + ".java"; 118 } 119 120 127 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 128 { 129 if (super.matchesGenerationRules(clazz) == false) { 130 return false; 131 } 132 133 Log log = LogUtil.getLog(LocalHomeInterfaceSubTask.class, "matchesGenerationRules"); 134 135 if (!InterfaceTagsHandler.isLocalEjb(getCurrentClass())) { 136 log.debug("Reject file " + clazz.getQualifiedName() + " because of different view-type"); 137 return false; 138 } 139 140 XTag interfaceTag = getCurrentClass().getDoc().getTag("ejb:home"); 141 142 if (interfaceTag == null) { 143 return true; 144 } 145 146 String generate = interfaceTag.getAttributeValue("generate"); 147 148 if (generate != null && generate.indexOf("local") == -1) { 149 log.debug("Skip local home interface for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 150 return false; 151 } 152 153 return true; 154 } 155 156 161 protected void engineStarted() throws XDocletException 162 { 163 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_LOCALHOME_FOR, 164 new String []{getCurrentClass().getQualifiedName()})); 165 } 166 } 167 | Popular Tags |