1 5 package xdoclet.modules.web; 6 7 import org.apache.commons.logging.Log; 8 9 import xjavadoc.XClass; 10 import xjavadoc.XTag; 11 12 import xdoclet.TemplateSubTask; 13 import xdoclet.XDocletException; 14 import xdoclet.XDocletMessages; 15 16 import xdoclet.tagshandler.PackageTagsHandler; 17 18 import xdoclet.util.LogUtil; 19 import xdoclet.util.Translator; 20 21 32 public class ServiceEndpointSubTask extends TemplateSubTask 33 { 34 public final static String DEFAULT_SERVICE_ENDPOINT_CLASS_PATTERN = "{0}"; 35 public final static String SERVICE_ENDPOINT = "service-endpoint"; 36 public final static String WEB_SERVLET = "web.servlet"; 37 38 protected final static String DEFAULT_TEMPLATE_FILE = "resources/service-endpoint.xdt"; 39 40 47 protected String serviceEndpointClassPattern; 48 49 52 public ServiceEndpointSubTask() 53 { 54 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE)); 55 setDestinationFile(getServiceEndpointClassPattern() + ".java"); 56 } 57 58 66 public String getServiceEndpointClassPattern() 67 { 68 if (serviceEndpointClassPattern != null) { 69 return serviceEndpointClassPattern; 70 } 71 else { 72 return DEFAULT_SERVICE_ENDPOINT_CLASS_PATTERN; 73 } 74 } 75 76 82 public void setPattern(String newPattern) 83 { 84 serviceEndpointClassPattern = newPattern; 85 } 86 87 92 public void validateOptions() throws XDocletException 93 { 94 super.validateOptions(); 95 96 if (getServiceEndpointClassPattern() == null || getServiceEndpointClassPattern().trim().equals("")) { 97 throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String []{"pattern"})); 98 } 99 100 if (getServiceEndpointClassPattern().indexOf("{0}") == -1) { 101 throw new XDocletException(Translator.getString(XDocletModulesWebMessages.class, XDocletModulesWebMessages.PATTERN_HAS_NO_PLACEHOLDER)); 102 } 103 } 104 105 106 113 protected String getGeneratedFileName(XClass clazz) throws XDocletException 114 { 115 return PackageTagsHandler.packageNameAsPathFor(WebTagsHandler.serviceEndpoint(clazz)) + ".java"; 116 } 117 118 119 126 protected boolean matchesGenerationRules(XClass clazz) throws XDocletException 127 { 128 if (super.matchesGenerationRules(clazz) == false) { 129 return false; 130 } 131 132 XTag interfaceTag = clazz.getDoc().getTag(WEB_SERVLET); 133 134 Log log = LogUtil.getLog(ServiceEndpointSubTask.class, "matchesGenerationRules"); 135 136 if (interfaceTag == null) { 137 log.debug("Reject file " + clazz.getQualifiedName() + " because of not being a servlet"); 138 return false; 139 } 140 141 return true; 142 } 143 144 149 protected void engineStarted() throws XDocletException 150 { 151 System.out.println(Translator.getString(XDocletModulesWebMessages.class, XDocletModulesWebMessages.GENERATING_SERVICE_ENDPOINT_FOR, 152 new String []{getCurrentClass().getQualifiedName()})); 153 } 154 } 155 | Popular Tags |