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.tagshandler.PackageTagsHandler; 18 19 import xdoclet.util.LogUtil; 20 import xdoclet.util.Translator; 21 22 34 35 public class ServiceEndpointSubTask extends AbstractEjbCodeGeneratorSubTask 36 { 37 public final static String DEFAULT_SERVICE_ENDPOINT_CLASS_PATTERN = "{0}"; 38 39 protected final static String DEFAULT_TEMPLATE_FILE = "resources/service-endpoint.xdt"; 40 41 48 protected String serviceEndpointClassPattern; 49 50 53 public ServiceEndpointSubTask() 54 { 55 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 56 setDestinationFile(getServiceEndpointClassPattern() + ".java"); 57 addOfType("javax.ejb.SessionBean"); 58 } 59 60 68 public String getServiceEndpointClassPattern() 69 { 70 if (serviceEndpointClassPattern != null) { 71 return serviceEndpointClassPattern; 72 } 73 else { 74 return DEFAULT_SERVICE_ENDPOINT_CLASS_PATTERN; 75 } 76 } 77 78 84 public void setPattern(String newPattern) 85 { 86 serviceEndpointClassPattern = newPattern; 87 } 88 89 94 public void validateOptions() throws XDocletException 95 { 96 super.validateOptions(); 97 98 if (getServiceEndpointClassPattern() == null || getServiceEndpointClassPattern().trim().equals("")) { 99 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 100 } 101 102 if (getServiceEndpointClassPattern().indexOf("{0}") == -1) { 103 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.PATTERN_HAS_NO_PLACEHOLDER)); 104 } 105 } 106 107 108 115 protected String getGeneratedFileName(XClass clazz) throws XDocletException 116 { 117 return PackageTagsHandler.packageNameAsPathFor(InterfaceTagsHandler.getComponentInterface(InterfaceTagsHandler.SERVICE_ENDPOINT, 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(ServiceEndpointSubTask.class, "matchesGenerationRules"); 134 135 if (!InterfaceTagsHandler.isServiceEndpointEjb(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:interface"); 141 142 if (interfaceTag == null) { 143 return true; 144 } 145 146 String generate = interfaceTag.getAttributeValue("generate"); 147 148 if ((generate != null) && (generate.indexOf(InterfaceTagsHandler.SERVICE_ENDPOINT) == -1)) { 149 log.debug("Skip service-endpoint 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_SERVICE_ENDPOINT_FOR, 164 new String []{getCurrentClass().getQualifiedName()})); 165 } 166 } 167 | Popular Tags |