1 5 package xdoclet.modules.web; 6 7 import java.text.MessageFormat ; 8 import java.util.ArrayList ; 9 import java.util.Properties ; 10 import java.util.StringTokenizer ; 11 import xjavadoc.XClass; 12 import xjavadoc.XTag; 13 14 import xdoclet.DocletContext; 15 import xdoclet.DocletTask; 16 import xdoclet.XDocletException; 17 18 import xdoclet.XDocletTagSupport; 19 import xdoclet.tagshandler.ClassTagsHandler; 20 import xdoclet.tagshandler.PackageTagsHandler; 21 22 29 public class WebTagsHandler extends XDocletTagSupport 30 { 31 32 39 public static String shortServletName(XClass clazz) 40 { 41 StringTokenizer ejbNameTokens = new StringTokenizer (servletName(clazz), ":./\\-"); 43 String name; 44 45 do { 46 name = ejbNameTokens.nextToken(); 47 } while (ejbNameTokens.hasMoreTokens()); 48 49 return name; 50 } 51 52 public static String serviceEndpoint(XClass clazz) throws XDocletException 53 { 54 String fileName = clazz.getContainingPackage().getName(); 55 String name_pattern = null; 56 String package_pattern = null; 57 String component_interface = null; 58 59 component_interface = clazz.getDoc().getTagAttributeValue(ServiceEndpointSubTask.WEB_SERVLET, ServiceEndpointSubTask.SERVICE_ENDPOINT + "-class"); 60 if (component_interface != null) { 61 return component_interface; 62 } 63 64 name_pattern = clazz.getDoc().getTagAttributeValue(ServiceEndpointSubTask.WEB_SERVLET, ServiceEndpointSubTask.SERVICE_ENDPOINT + "-pattern"); 65 if (name_pattern == null) { 66 ServiceEndpointSubTask seintf_subtask = ((ServiceEndpointSubTask) DocletContext.getInstance(). 67 getSubTaskBy(DocletTask.getSubTaskName(ServiceEndpointSubTask.class))); 68 69 if (seintf_subtask != null) { 70 name_pattern = seintf_subtask.getServiceEndpointClassPattern(); 71 } 72 else { 73 name_pattern = ServiceEndpointSubTask.DEFAULT_SERVICE_ENDPOINT_CLASS_PATTERN; 74 } 75 } 76 77 package_pattern = clazz.getDoc().getTagAttributeValue(ServiceEndpointSubTask.WEB_SERVLET, ServiceEndpointSubTask.SERVICE_ENDPOINT + "-package"); 78 79 String ejb_name = null; 80 81 if (name_pattern.indexOf("{0}") != -1) { 82 ejb_name = MessageFormat.format(name_pattern, new Object []{shortServletName(clazz)}); 83 } 84 else { 85 ejb_name = name_pattern; 86 } 87 88 String subtask_name = null; 89 90 fileName = choosePackage(fileName, package_pattern, subtask_name); 92 fileName += "." + ejb_name; 93 return fileName; 94 } 95 96 public static String serviceEndpoint(Properties properties) throws XDocletException 97 { 98 XClass clazz = getCurrentClass(); 99 100 return serviceEndpoint(clazz); 101 } 102 103 public static String servletName(Properties properties) 104 { 105 return servletName(getCurrentClass()); 106 } 107 108 public static String servletName(XClass clazz) 109 { 110 XTag beanTag = clazz.getDoc().getTag(ServiceEndpointSubTask.WEB_SERVLET); 111 String paramValue = null; 112 113 if (beanTag != null) { 114 paramValue = beanTag.getAttributeValue("name"); 115 } 116 117 if (paramValue == null) { 118 paramValue = clazz.getName(); 119 } 120 return paramValue; 121 } 122 123 public static String choosePackage(String packageName, String packagePattern, String subtask) 124 { 125 126 ArrayList packageSubstitutions = PackageTagsHandler.getPackageSubstitutions(subtask); 127 128 if (packagePattern != null) { 129 return packagePattern; 131 } 132 else { 133 for (int i = 0; i < packageSubstitutions.size(); i++) { 134 PackageTagsHandler.PackageSubstitution ps = (PackageTagsHandler.PackageSubstitution) packageSubstitutions.get(i); 135 StringTokenizer st = new StringTokenizer (ps.getPackages(), ",", false); 136 137 while (st.hasMoreTokens()) { 138 String packages = st.nextToken(); 139 String suffix = "." + packages; 140 141 if (packageName.endsWith(suffix)) { 142 packageName = packageName.substring(0, packageName.length() - suffix.length()) + '.' + ps.getSubstituteWith(); 143 break; 144 } 145 } 146 } 147 } 148 149 return packageName; 150 } 151 152 162 public void forAllEjbRefs(String template) throws XDocletException 163 { 164 ClassTagsHandler.forAllDistinctClassTags(getEngine(), template, "web:ejb-ref", "name"); 165 } 166 167 175 public void forAllEjbLocalRefs(String template) throws XDocletException 176 { 177 ClassTagsHandler.forAllDistinctClassTags(getEngine(), template, "web:ejb-local-ref", "name"); 178 } 179 180 188 public void forAllResourceRefs(String template) throws XDocletException 189 { 190 ClassTagsHandler.forAllDistinctClassTags(getEngine(), template, "web:resource-ref", "name"); 191 } 192 193 201 public void forAllResourceEnvRefs(String template) throws XDocletException 202 { 203 ClassTagsHandler.forAllDistinctClassTags(getEngine(), template, "web:resource-env-ref", "name"); 204 } 205 206 214 public void forAllSecurityRoles(String template) throws XDocletException 215 { 216 ClassTagsHandler.forAllDistinctClassTags(getEngine(), template, "web:security-role", "role-name"); 217 } 218 219 227 public void forAllEnvEntries(String template) throws XDocletException 228 { 229 ClassTagsHandler.forAllDistinctClassTags(getEngine(), template, "web:env-entry", "name"); 230 } 231 232 240 public String extendsFrom(Properties attributes) throws XDocletException 241 { 242 String def_base_class_name = getTagValue( 243 FOR_CLASS, 244 getCurrentClass().getDoc(), 245 ServiceEndpointSubTask.WEB_SERVLET, 246 "service-endpoint-extends", 247 null, 248 "java.rmi.Remote", 249 true, 250 false); 251 252 return def_base_class_name; 253 } 254 255 } 256 | Popular Tags |