1 5 package xdoclet.modules.wsee; 6 7 import java.io.File ; 8 import java.text.MessageFormat ; 9 import java.util.Collection ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 import java.util.Properties ; 13 import java.util.StringTokenizer ; 14 15 import xjavadoc.XClass; 16 import xjavadoc.XPackage; 17 import xjavadoc.XTag; 18 19 import xdoclet.ConfigParamIntrospector; 20 import xdoclet.DocletContext; 21 import xdoclet.DocletSupport; 22 import xdoclet.XDocletException; 23 24 import xdoclet.XDocletTagSupport; 25 import xdoclet.tagshandler.PackageTagsHandler; 26 27 36 37 public class WseeTagsHandler extends XDocletTagSupport 38 { 39 42 public final static String PORT_COMPONENT = "wsee.port-component"; 43 46 public final static String HANDLER = "wsee.handler"; 47 48 51 public XTag currentHandler; 52 53 60 public static boolean isPortComponent(XClass clazz) 61 throws XDocletException 62 { 63 return clazz.getDoc().hasTag(PORT_COMPONENT); 64 } 65 66 73 public static String getNamespaceForPackage(XPackage pak) 74 { 75 return getNamespaceForPackage(pak.getName()); 76 } 77 78 84 public static String getNamespaceForPackage(String pak) 85 { 86 List packageSubstitutions = getPackageNamespaceMappings(); 87 88 for (int i = 0; i < packageSubstitutions.size(); i++) { 89 WseeDocletTask.PackageNamespaceMapping ps = (WseeDocletTask.PackageNamespaceMapping) packageSubstitutions.get(i); 90 StringTokenizer st = new StringTokenizer (ps.getPackages(), ",", false); 91 92 while (st.hasMoreTokens()) { 93 String packages = st.nextToken(); 94 95 if (pak.startsWith(packages)) { 96 return ps.getNamespace() + pak.substring(packages.length()).replace('.', '-'); 97 } 98 } 99 } 100 101 return "urn-" + pak.replace('.', '-'); 102 } 103 104 109 public static List getPackageNamespaceMappings() 110 { 111 List packageNamespaceMappings = (List ) DocletContext.getInstance().getConfigParam("packageNamespaceMappings"); 114 115 return packageNamespaceMappings; 116 } 117 118 125 public String getNamespaceURI(XClass clazz) 126 throws XDocletException 127 { 128 XTag wsTag = clazz.getDoc().getTag("wsee.port-component"); 129 String nameSpace = null; 130 131 if (wsTag == null) { 132 wsTag = clazz.getDoc().getTag("wsee.jaxrpc-mapping"); 133 } 134 if (wsTag != null) { 135 nameSpace = wsTag.getAttributeValue("namespace-uri"); 136 } 137 if (nameSpace == null) { 138 nameSpace = getNamespaceForPackage(clazz.getContainingPackage()); 139 } 140 return nameSpace; 141 } 142 143 154 public void forAllPortComponents(String template, Properties attributes) 155 throws XDocletException 156 { 157 Collection classes = getXJavaDoc().getSourceClasses(); 158 159 for (Iterator i = classes.iterator(); i.hasNext(); ) { 160 XClass clazz = (XClass) i.next(); 161 162 setCurrentClass(clazz); 163 164 if (DocletSupport.isDocletGenerated(getCurrentClass())) { 165 continue; 166 } 167 168 if (isPortComponent(getCurrentClass())) { 169 generate(template); 170 } 171 } 172 } 173 174 182 public String serviceEndpoint(Properties props) throws XDocletException 183 { 184 XClass clazz = getCurrentClass(); 185 String pkg = PackageTagsHandler.getPackageNameFor(clazz.getContainingPackage(), true); 186 XTag ejbTag = null; 187 String spec = null; 188 189 if (clazz.getDoc().hasTag("ejb.bean")) { 190 ejbTag = clazz.getDoc().getTag("ejb.interface"); 191 if (ejbTag != null) { 192 spec = ejbTag.getAttributeValue("service-endpoint-class"); 193 } 194 if (spec == null || "".equals(spec)) { 196 spec = pkg + "." + clazz.getName(); 197 if (spec.endsWith("Bean")) 198 spec = spec.substring(0, spec.length() - 4); 199 } 200 } 201 else { 202 203 ejbTag = clazz.getDoc().getTag("web.servlet"); 204 if (ejbTag != null) { 205 spec = ejbTag.getAttributeValue("service-endpoint-class"); 206 } 207 if (spec == null || "".equals(spec)) { 208 spec = pkg + "." + clazz.getName(); 209 spec += "Service"; 210 } 211 } 212 213 return spec; 214 } 215 216 224 public String serviceEndpointLink(Properties props) 225 throws XDocletException 226 { 227 XClass clazz = getCurrentClass(); 228 XTag ejbTag = clazz.getDoc().getTag("ejb.bean"); 229 230 if (ejbTag != null) { 231 return "<ejb-link>" + ejbTag.getAttributeValue("name") + "</ejb-link>"; 232 } 233 ejbTag = clazz.getDoc().getTag("web.servlet"); 234 if (ejbTag != null) { 235 return "<servlet-link>" 236 + ejbTag.getAttributeValue("name") 237 + "</servlet-link>"; 238 } 239 return null; 240 } 241 242 249 public String namespaceURI() 250 throws XDocletException 251 { 252 String ns = ""; 253 254 if (getCurrentClass() != null) { 255 ns = getNamespaceURI(getCurrentClass()); 256 } 257 else if (getCurrentPackage() != null) { 258 ns = getNamespaceForPackage(getCurrentPackage()); 259 } 260 else { 261 List nsmappings = getPackageNamespaceMappings(); 263 264 if (!nsmappings.isEmpty()) { 265 WseeDocletTask.PackageNamespaceMapping ps = (WseeDocletTask.PackageNamespaceMapping) nsmappings.get(0); 266 267 ns = ps.getNamespace(); 268 } 269 } 270 return ns; 271 } 272 273 281 public void forAllHandlers(String template, Properties attributes) 282 throws XDocletException 283 { 284 XClass clazz = getCurrentClass(); 285 Iterator allTags = clazz.getDoc().getTags(HANDLER).iterator(); 286 287 while (allTags.hasNext()) { 288 currentHandler = (XTag) allTags.next(); 289 generate(template); 290 } 291 292 } 293 294 303 public void ifHasHandlerTag(String template, Properties props) 304 throws XDocletException 305 { 306 if (handlerTagValue(props) != null) { 307 generate(template); 308 } 309 } 310 311 320 public String handlerTagValue(Properties props) throws XDocletException 321 { 322 return currentHandler.getAttributeValue(props.getProperty("paramName")); 323 } 324 325 333 public void ifWsdlPerClass(String template, Properties props) throws XDocletException 334 { 335 if (isWsdlPerClass()) 336 generate(template); 337 } 338 339 347 public void ifNotWsdlPerClass(String template, Properties props) throws XDocletException 348 { 349 if (!isWsdlPerClass()) 350 generate(template); 351 } 352 353 364 public String wsdlFilename(Properties props) 365 { 366 XClass clazz = getCurrentClass(); 367 String wsdlPattern = getWsdlFilePattern(); 368 369 String packageName = null; 370 String file = null; 371 372 if (isWsdlPerClass()) { 373 374 boolean prefixWithPackage = false; 375 String hasPrefix = props.getProperty("prefixWithPackage"); 376 377 if (hasPrefix != null && !"".equals(hasPrefix)) { 378 prefixWithPackage = Boolean.getBoolean(hasPrefix); 379 } 380 381 if (prefixWithPackage) { 382 packageName = PackageTagsHandler.packageNameAsPathWithoutSubstitutionFor(clazz.getContainingPackage()); 383 } 384 385 String serviceName = getCurrentClass().getDoc().getTagAttributeValue(WseeTagsHandler.PORT_COMPONENT, "name"); 386 387 file = new File (packageName, serviceName).toString(); 388 } 389 390 String prefix = "WEB-INF/"; 392 393 if (clazz != null && clazz.getDoc().hasTag("ejb.bean")) { 394 prefix = "META-INF/"; 395 } 396 return prefix + MessageFormat.format(wsdlPattern, new Object []{file}); 397 } 398 399 409 public String jaxrpcMappingFilename(Properties props) 410 { 411 XClass clazz = getCurrentClass(); 412 String jaxrpcPattern = getJaxrpcFilePattern(); 413 414 String packageName = null; 415 String file = null; 416 417 if (isJaxrpcPerClass()) { 418 419 boolean prefixWithPackage = true; 420 String hasPrefix = props.getProperty("prefixWithPackage"); 421 422 if (hasPrefix != null && !"".equals(hasPrefix)) { 423 prefixWithPackage = Boolean.getBoolean(hasPrefix); 424 } 425 426 if (prefixWithPackage) { 427 packageName = PackageTagsHandler.packageNameAsPathWithoutSubstitutionFor(clazz.getContainingPackage()); 428 } 429 430 file = new File (packageName, getCurrentClass().getName()).toString(); 431 } 432 433 434 String prefix = "WEB-INF/"; 436 437 if (clazz != null && clazz.getDoc().hasTag("ejb.bean")) { 438 prefix = "META-INF/"; 439 } 440 return prefix + MessageFormat.format(jaxrpcPattern, new Object []{file}); 441 } 442 443 448 protected boolean isWsdlPerClass() 449 { 450 return getWsdlFilePattern().indexOf("{0}") != -1; 451 } 452 453 458 protected boolean isJaxrpcPerClass() 459 { 460 return getJaxrpcFilePattern().indexOf("{0}") != -1; 461 } 462 463 468 protected String getWsdlFilePattern() 469 { 470 String pattern = null; 471 Object wsdlFile = DocletContext.getInstance().getConfigParam("wsdlFile"); 472 473 if (wsdlFile == ConfigParamIntrospector.NULL || "".equals(wsdlFile)) { 474 pattern = WsdlSubTask.DEFAULT_WSDL_FILE_PATTERN; 475 } 476 else { 477 pattern = (String ) wsdlFile; 478 } 479 return pattern; 480 } 481 482 487 protected String getJaxrpcFilePattern() 488 { 489 String pattern = ""; 490 Object jaxrpcFile = DocletContext.getInstance().getConfigParam("jaxrpcMappingFile"); 491 492 if (jaxrpcFile != ConfigParamIntrospector.NULL) { 493 pattern = (String ) jaxrpcFile; 494 } 495 return pattern; 496 } 497 } 498 | Popular Tags |