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.home.HomeTagsHandler; 18 import xdoclet.modules.ejb.intf.InterfaceTagsHandler; 19 import xdoclet.tagshandler.PackageTagsHandler; 20 21 import xdoclet.util.LogUtil; 22 import xdoclet.util.Translator; 23 24 34 public class HomeInterfaceSubTask extends AbstractEjbCodeGeneratorSubTask 35 { 36 public final static String DEFAULT_HOMEINTERFACE_CLASS_PATTERN = "{0}Home"; 37 38 protected final static String DEFAULT_TEMPLATE_FILE = "resources/home.xdt"; 39 40 47 protected String homeClassPattern; 48 49 52 public HomeInterfaceSubTask() 53 { 54 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 55 setDestinationFile(getHomeClassPattern() + ".java"); 56 addOfType("javax.ejb.EntityBean"); 57 addOfType("javax.ejb.SessionBean"); 58 } 59 60 61 69 public String getHomeClassPattern() 70 { 71 if (homeClassPattern != null) { 72 return homeClassPattern; 73 } 74 else { 75 return DEFAULT_HOMEINTERFACE_CLASS_PATTERN; 76 } 77 } 78 79 80 86 public void setPattern(String new_pattern) 87 { 88 Log log = LogUtil.getLog(HomeInterfaceSubTask.class, "setPattern"); 89 90 log.debug("Set pattern to " + new_pattern); 91 92 homeClassPattern = new_pattern; 93 } 94 95 96 101 public void validateOptions() throws XDocletException 102 { 103 super.validateOptions(); 104 105 if (getHomeClassPattern() == null || getHomeClassPattern().trim().equals("")) { 106 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 107 } 108 109 if (getHomeClassPattern().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(HomeTagsHandler.getHomeInterface("remote", getCurrentClass())) + ".java"; 125 } 126 127 128 135 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 136 { 137 if (super.matchesGenerationRules(clazz) == false) { 138 return false; 139 } 140 141 Log log = LogUtil.getLog(HomeInterfaceSubTask.class, "matchesGenerationRules"); 142 143 if (!InterfaceTagsHandler.isRemoteEjb(getCurrentClass())) { 144 log.debug("Reject file " + clazz.getQualifiedName() + " because of different view-type"); 145 return false; 146 } 147 148 XTag interfaceTag = getCurrentClass().getDoc().getTag("ejb:home", false); 149 150 if (interfaceTag == null) { 151 return true; 152 } 153 154 String generate = interfaceTag.getAttributeValue("generate"); 155 156 if ((generate != null) && (generate.indexOf("remote") == -1)) { 157 log.debug("Skip home interface for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 158 return false; 159 } 160 161 return true; 162 } 163 164 165 170 protected void engineStarted() throws XDocletException 171 { 172 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_HOME_FOR, 173 new String []{getCurrentClass().getQualifiedName()})); 174 } 175 176 } 177 | Popular Tags |