1 5 package xdoclet.modules.ejb.intf; 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 RemoteInterfaceSubTask extends AbstractEjbCodeGeneratorSubTask 35 { 36 public final static String DEFAULT_REMOTE_CLASS_PATTERN = "{0}"; 37 38 protected final static String DEFAULT_TEMPLATE_FILE = "resources/remote.xdt"; 39 40 47 protected String remoteClassPattern; 48 49 52 public RemoteInterfaceSubTask() 53 { 54 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 55 setDestinationFile(getRemoteClassPattern() + ".java"); 56 addOfType("javax.ejb.EntityBean"); 57 addOfType("javax.ejb.SessionBean"); 58 } 59 60 69 public String getRemoteClassPattern() 70 { 71 if (remoteClassPattern != null) { 72 return remoteClassPattern; 73 } 74 else { 75 return DEFAULT_REMOTE_CLASS_PATTERN; 76 } 77 } 78 79 85 public void setPattern(String newPattern) 86 { 87 remoteClassPattern = newPattern; 88 } 89 90 95 public void validateOptions() throws XDocletException 96 { 97 super.validateOptions(); 98 99 if (getRemoteClassPattern() == null || getRemoteClassPattern().trim().equals("")) { 100 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 101 } 102 103 if (getRemoteClassPattern().indexOf("{0}") == -1) { 104 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 105 } 106 } 107 108 109 116 protected String getGeneratedFileName(XClass clazz) throws XDocletException 117 { 118 return PackageTagsHandler.packageNameAsPathFor(InterfaceTagsHandler.getComponentInterface("remote", getCurrentClass())) + ".java"; 119 } 120 121 128 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 129 { 130 if (super.matchesGenerationRules(clazz) == false) { 131 return false; 132 } 133 134 Log log = LogUtil.getLog(RemoteInterfaceSubTask.class, "matchesGenerationRules"); 135 136 if (!InterfaceTagsHandler.isRemoteEjb(getCurrentClass())) { 137 log.debug("Reject file " + clazz.getQualifiedName() + " because of different view-type"); 138 return false; 139 } 140 141 XTag interfaceTag = getCurrentClass().getDoc().getTag("ejb:interface"); 142 143 if (interfaceTag == null) { 144 return true; 145 } 146 147 String generate = interfaceTag.getAttributeValue("generate"); 148 149 if ((generate != null) && (generate.indexOf("remote") == -1)) { 150 log.debug("Skip remote interface for " + clazz.getQualifiedName() + " because of generate=" + generate + " flag."); 151 return false; 152 } 153 154 return true; 155 } 156 157 162 protected void engineStarted() throws XDocletException 163 { 164 System.out.println(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.GENERATING_REMOTE_FOR, 165 new String []{getCurrentClass().getQualifiedName()})); 166 } 167 } 168 | Popular Tags |