View Javadoc
1 /* 2 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Tag.java,v 1.6 2002/05/17 15:18:12 jstrachan Exp $ 3 * $Revision: 1.6 $ 4 * $Date: 2002/05/17 15:18:12 $ 5 * 6 * ==================================================================== 7 * 8 * The Apache Software License, Version 1.1 9 * 10 * Copyright (c) 1999-2002 The Apache Software Foundation. All rights 11 * reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in 22 * the documentation and/or other materials provided with the 23 * distribution. 24 * 25 * 3. The end-user documentation included with the redistribution, if 26 * any, must include the following acknowlegement: 27 * "This product includes software developed by the 28 * Apache Software Foundation (http://www.apache.org/)." 29 * Alternately, this acknowlegement may appear in the software itself, 30 * if and wherever such third-party acknowlegements normally appear. 31 * 32 * 4. The names "The Jakarta Project", "Commons", and "Apache Software 33 * Foundation" must not be used to endorse or promote products derived 34 * from this software without prior written permission. For written 35 * permission, please contact apache@apache.org. 36 * 37 * 5. Products derived from this software may not be called "Apache" 38 * nor may "Apache" appear in their names without prior written 39 * permission of the Apache Group. 40 * 41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * ==================================================================== 54 * 55 * This software consists of voluntary contributions made by many 56 * individuals on behalf of the Apache Software Foundation. For more 57 * information on the Apache Software Foundation, please see 58 * <http://www.apache.org/>;. 59 * 60 * $Id: Tag.java,v 1.6 2002/05/17 15:18:12 jstrachan Exp $ 61 */ 62 63 package org.apache.commons.jelly.util; 64 65 import java.io.*; 66 import java.util.*; 67 import com.sun.javadoc.*; 68 69 import org.dom4j.io.OutputFormat; 70 import org.dom4j.io.XMLWriter; 71 72 import org.xml.sax.*; 73 import org.xml.sax.helpers.*; 74 75 /*** 76 * Main Doclet class to generate JavaDocXML. This doclet generates the 77 * document conforming to DTD specified in javadoc-v04draft.dtd. 78 * @author <a href="mailto:gopi@aztecsoft.com">Gopinath M.R.</a> 79 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 80 */ 81 82 public class XMLDoclet extends Doclet { 83 84 private String xmlns = "jvx"; 85 private String encodingFormat="UTF-8"; 86 private String localName = "javadoc"; 87 private ContentHandler cm = null; 88 private String targetFileName="target/javadoc.xml"; 89 private Attributes emptyAtts = new AttributesImpl(); 90 91 public XMLDoclet (RootDoc root) throws Exception { 92 FileOutputStream writer = new FileOutputStream(targetFileName); 93 OutputFormat format = OutputFormat.createPrettyPrint(); 94 XMLWriter xmlWriter = new XMLWriter(writer, format); 95 try { 96 cm = xmlWriter; 97 cm.startDocument(); 98 javadocXML(root); 99 cm.endDocument(); 100 xmlWriter.close(); 101 } 102 catch (IOException e) { 103 xmlWriter.close(); 104 throw e; 105 } 106 } 107 108 /*** 109 * Generates the xml data for the top element. 110 * <xmp><!ELEMENT javadoc (package*, class*, interface*)></xmp> 111 */ 112 private void javadocXML(RootDoc root) throws SAXException { 113 cm.startElement(xmlns, localName, "javadoc", emptyAtts); 114 PackageDoc[] packageArray = root.specifiedPackages(); 115 116 // Generate for packages. 117 for (int i = 0; i < packageArray.length; ++i) { 118 packageXML(packageArray[i]); 119 } 120 121 // Generate for classes. 122 ClassDoc[] classArray = root.specifiedClasses(); 123 Vector interfaceVector = new Vector(); 124 for (int i = 0; i < classArray.length; ++i) { 125 if (classArray[i].isInterface()) { 126 interfaceVector.addElement(classArray[i]); 127 } else { 128 classXML(classArray[i]); 129 } 130 } 131 132 // Generate for interfaces. 133 Enumeration interfaceEnum = interfaceVector.elements(); 134 if (interfaceEnum.hasMoreElements()) { 135 ClassDoc interfaceDoc = (ClassDoc)interfaceEnum.nextElement(); 136 interfaceXML(interfaceDoc); 137 } 138 cm.endElement(xmlns, localName, "javadoc"); 139 } 140 141 /*** 142 * Generates doc for "package". 143 * <xmp><!ELEMENT package (doc?, package*, class*, interface*)> 144 *<!ATTLIST package 145 * name CDATA #REQUIRED></xmp> 146 */ 147 private void packageXML(PackageDoc packageDoc) throws SAXException { 148 AttributesImpl atts = new AttributesImpl(); 149 atts.addAttribute(xmlns, localName, "name", "String", packageDoc.name()); 150 cm.startElement(xmlns, localName, "package", atts); 151 152 // generate Doc element. 153 docXML(packageDoc); 154 155 // TODO:generate Package elements. 156 // doubt: How package can exist inside a package? 157 158 /* Generate for classes. */ 159 // for ordinary classes. 160 ClassDoc[] classArray = packageDoc.ordinaryClasses(); 161 for (int i = 0; i < classArray.length; ++i) { 162 classXML(classArray[i]); 163 } 164 // for Exception classes. 165 classArray = packageDoc.exceptions(); 166 for (int i = 0; i < classArray.length; ++i) { 167 classXML(classArray[i]); 168 } 169 // for Error classes 170 classArray = packageDoc.errors(); 171 for (int i = 0; i < classArray.length; ++i) { 172 classXML(classArray[i]); 173 } 174 175 /* Generate for interfaces. */ 176 ClassDoc[] interfaceArray = packageDoc.interfaces(); 177 for (int i = 0; i < interfaceArray.length; ++i) { 178 interfaceXML(interfaceArray[i]); 179 } 180 181 cm.endElement(xmlns, localName, "package"); 182 } 183 184 /*** 185 * Generates doc for element "class". 186 * <xmp> <!ELEMENT class (doc?, 187 * extends_class?, 188 * implements?, 189 * constructor*, 190 * method*, 191 * innerclass*)> 192 * <!ATTLIST class 193 * %name; 194 * %extensibility; 195 * %class.access;></xmp> 196 */ 197 private void classXML(ClassDoc classDoc) throws SAXException { 198 AttributesImpl atts = new AttributesImpl(); 199 atts.addAttribute(xmlns, localName, "name", "String", classDoc.name()); 200 201 String extensibility = "default"; 202 if (classDoc.isAbstract()) { 203 extensibility = "abstract"; 204 } else if (classDoc.isFinal()) { 205 extensibility = "final"; 206 } 207 atts.addAttribute(xmlns, localName, "extensibility", "String", extensibility); 208 String access = "package"; 209 if (classDoc.isPublic()) { 210 access = "public"; 211 } 212 atts.addAttribute(xmlns, localName, "access", "String", access); 213 cm.startElement(xmlns, localName, "class", atts); 214 215 // generate "doc" sub-element 216 docXML(classDoc); 217 218 // generate "extends_class" sub-element 219 extendsXML(classDoc); 220 221 // generate "implements" sub-element 222 implementsXML(classDoc); 223 224 // generate "field" sub-elements 225 FieldDoc[] fieldArray = classDoc.fields(); 226 for (int i = 0; i < fieldArray.length; ++i) { 227 fieldXML(fieldArray[i]); 228 } 229 230 // generate "constructor" sub-elements 231 ConstructorDoc[] constructorArray = classDoc.constructors(); 232 for (int i = 0; i < constructorArray.length; ++i) { 233 constructorXML(constructorArray[i]); 234 } 235 236 // generate "method" sub-elements 237 MethodDoc[] methodArray = classDoc.methods(); 238 for (int i = 0; i < methodArray.length; ++i) { 239 methodXML(methodArray[i]); 240 } 241 242 // generate "innerclass" sub-elements 243 ClassDoc[] innerClassArray = classDoc.innerClasses(); 244 for (int i = 0; i < innerClassArray.length; ++i) { 245 innerClassXML(innerClassArray[i]); 246 } 247 248 cm.endElement(xmlns, localName, "class"); 249 } 250 251 /*** 252 * Generates doc for element "extends_class" 253 * <xmp><!ELEMENT extends_class (classref+)></xmp> 254 */ 255 private void extendsXML(ClassDoc classDoc) throws SAXException { 256 if (classDoc.superclass() != null) { 257 cm.startElement(xmlns, localName, "extends_class", emptyAtts); 258 createRefXML("classref", classDoc.superclass().qualifiedName()); 259 cm.endElement(xmlns, localName, "extends_class"); 260 } 261 } 262 263 /*** 264 * Generates doc for element "innerclass" 265 * <xmp> <!ELEMENT innerclass (doc?, 266 * extends?, 267 * implements?, 268 * field*, 269 * constructor*, 270 * method*)> 271 * <!ATTLIST innerclass 272 * %name; 273 * %access; 274 * %abstract; 275 * %anonymous; 276 * %final; 277 * %static;></xmp> 278 */ 279 private void innerClassXML(ClassDoc classDoc) throws SAXException { 280 AttributesImpl atts = new AttributesImpl(); 281 atts.addAttribute(xmlns, localName, "name", "String", classDoc.name()); 282 String access = "package"; 283 if (classDoc.isPublic()) { 284 access = "public"; 285 } 286 atts.addAttribute(xmlns, localName, "access", "String", access); 287 atts.addAttribute(xmlns, localName, "abstract", "String", ""+ classDoc.isAbstract()); 288 String anonymous = "false"; 289 if (classDoc.name().equals("")) { 290 anonymous = "true"; 291 } 292 atts.addAttribute(xmlns, localName, "anonymous", "String", ""+ anonymous); 293 atts.addAttribute(xmlns, localName, "final", "String", ""+ "" + classDoc.isFinal()); 294 atts.addAttribute(xmlns, localName, "static", "String", ""+ "" + classDoc.isStatic()); 295 cm.startElement(xmlns, localName, "innerclass", atts); 296 297 // generate "doc" sub-element 298 docXML(classDoc); 299 300 // generate "extends" sub-element 301 extendsXML(classDoc); 302 303 // generate "implements" sub-element 304 implementsXML(classDoc); 305 306 // generate "field" sub-elements 307 FieldDoc[] fieldArray = classDoc.fields(); 308 for (int i = 0; i < fieldArray.length; ++i) { 309 fieldXML(fieldArray[i]); 310 } 311 312 // generate "constructor" sub-elements 313 ConstructorDoc[] constructorArray = classDoc.constructors(); 314 for (int i = 0; i < constructorArray.length; ++i) { 315 constructorXML(constructorArray[i]); 316 } 317 318 // generate "method" sub-elements 319 MethodDoc[] methodArray = classDoc.methods(); 320 for (int i = 0; i < methodArray.length; ++i) { 321 methodXML(methodArray[i]); 322 } 323 324 cm.endElement(xmlns, localName,"innerclass"); 325 } 326 327 /*** 328 * Generates doc for element "interface" 329 * <xmp><!ELEMENT interface (doc?, 330 * extends_interface?, 331 * field*, 332 * method*)> 333 * <!ATTLIST interface 334 * %name; 335 * %access;></xmp> 336 */ 337 private void interfaceXML(ClassDoc interfaceDoc) throws SAXException { 338 AttributesImpl atts = new AttributesImpl(); 339 atts.addAttribute(xmlns, localName, "name", "String", interfaceDoc.name()); 340 String access = "package"; 341 if (interfaceDoc.isPublic()) { 342 access = "public"; 343 } 344 atts.addAttribute(xmlns, localName, "access", "String", access); 345 cm.startElement(xmlns, localName, "interface", atts); 346 347 // generate "doc" sub-element 348 docXML(interfaceDoc); 349 350 // generate "extends_interface" 351 extends_interfaceXML(interfaceDoc); 352 353 // generate "field" sub-elements 354 FieldDoc[] fieldArray = interfaceDoc.fields(); 355 for (int i = 0; i < fieldArray.length; ++i) { 356 fieldXML(fieldArray[i]); 357 } 358 359 // generate "method" sub-elements 360 MethodDoc[] methodArray = interfaceDoc.methods(); 361 for (int i = 0; i < methodArray.length; ++i) { 362 methodXML(methodArray[i]); 363 } 364 cm.endElement(xmlns, localName, "interface"); 365 } 366 367 /*** 368 * Generates doc for element "extends_interface" 369 * <xmp><!ELEMENT extends_interface (interfaceref+)></xmp> 370 */ 371 private void extends_interfaceXML(ClassDoc interfaceDoc) throws SAXException { 372 ClassDoc[] interfaceArray = interfaceDoc.interfaces(); 373 if (interfaceArray.length > 0) { 374 cm.startElement(xmlns, localName, "extends_interface", emptyAtts); 375 for (int i = 0; i < interfaceArray.length; ++i) { 376 createRefXML("interfaceref", interfaceArray[i].qualifiedName()); 377 } 378 cm.endElement(xmlns, localName, "extends_interface"); 379 } 380 } 381 382 /*** 383 * Generates doc for element "implements" 384 * <xmp><!ELEMENT implements (interfaceref+)></xmp> 385 */ 386 private void implementsXML(ClassDoc classDoc) throws SAXException { 387 ClassDoc[] interfaceArray = classDoc.interfaces(); 388 if (interfaceArray.length > 0) { 389 cm.startElement(xmlns, localName, "implements", emptyAtts); 390 for (int i = 0; i < interfaceArray.length; ++i) { 391 createRefXML("interfaceref", interfaceArray[i].qualifiedName()); 392 } 393 cm.endElement(xmlns, localName, "implements"); 394 } 395 if (classDoc.superclass() != null) { 396 implementsXML(classDoc.superclass()); 397 } 398 } 399 400 /*** 401 * Generates doc for element "throws" 402 * <xmp><!ELEMENT throws (classref)+></xmp> 403 */ 404 private void throwsXML(ExecutableMemberDoc member) throws SAXException { 405 ThrowsTag[] tagArray = member.throwsTags(); 406 if(tagArray.length > 0) { 407 cm.startElement(xmlns, localName, "throws", emptyAtts); 408 for (int i = 0; i < tagArray.length; ++i) { 409 ClassDoc exceptionClass = tagArray[i].exception(); 410 String name = null; 411 if (exceptionClass == null) { 412 name = tagArray[i].exceptionName(); 413 } else { 414 name = tagArray[i].exception().qualifiedName(); 415 } 416 createRefXML("classref", name); 417 } 418 cm.endElement(xmlns, localName, "throws"); 419 } 420 } 421 422 /*** 423 * Generates doc for following elements 424 * <xmp> <!ELEMENT classref EMPTY> 425 * <!ATTLIST classref %name;> 426 * <!ELEMENT interfaceref EMPTY> 427 * <!ATTLIST interfaceref %name;> 428 * <!ELEMENT methodref EMPTY> 429 * <!ATTLIST methodref %name;> 430 * <!ELEMENT packageref EMPTY> 431 * <!ATTLIST packageref %name;></xmp> 432 */ 433 private void createRefXML(String elementName, String nameValue) throws SAXException { 434 AttributesImpl atts = new AttributesImpl(); 435 atts.addAttribute(xmlns, localName, "name", "String", nameValue); 436 cm.startElement(xmlns, localName, elementName, atts); 437 cm.endElement(xmlns, localName, elementName); 438 } 439 440 /*** 441 * Generates doc for "(classref|interfaceref|primitive)" sub-element 442 */ 443 private void createTypeRef(Type type) throws SAXException { 444 String qualifiedName = type.qualifiedTypeName(); 445 ClassDoc fieldType = type.asClassDoc(); 446 if (fieldType == null) { 447 // primitive data type 448 AttributesImpl subElmAtts = new AttributesImpl(); 449 subElmAtts.addAttribute(xmlns, localName, "type", "String", qualifiedName); 450 cm.startElement(xmlns, localName, "primitive", subElmAtts); 451 cm.endElement(xmlns, localName, "primitive"); 452 } else if (fieldType.isInterface()) { 453 // interface 454 createRefXML("interfaceref", qualifiedName); 455 } else { 456 // class 457 createRefXML("classref", qualifiedName); 458 } 459 } 460 461 /*** 462 * Generates doc for element "field" 463 * <xmp> <!ELEMENT field (doc?, (classref | interfaceref | primitive))> 464 * <!ATTLIST field 465 * %name; 466 * %access; 467 * %dimension; 468 * %synthetic; 469 * %static; 470 * %final; 471 * %transient; 472 * %volatile;></xmp> 473 */ 474 private void fieldXML(FieldDoc field) throws SAXException { 475 AttributesImpl atts = new AttributesImpl(); 476 477 atts.addAttribute(xmlns, localName, "name", "String", field.name()); 478 479 String access = "package"; 480 if (field.isPrivate()) { 481 access = "private"; 482 } else if (field.isProtected()) { 483 access = "protected"; 484 } else if (field.isPublic()) { 485 access = "public"; 486 } 487 atts.addAttribute(xmlns, localName, "access", "String", access); 488 489 atts.addAttribute(xmlns, localName, "dimension", "String", field.type().dimension()); 490 atts.addAttribute(xmlns, localName, "synthetic", "String", "" + field.isSynthetic()); 491 atts.addAttribute(xmlns, localName, "static", "String", "" + field.isStatic()); 492 atts.addAttribute(xmlns, localName, "final", "String", "" + field.isFinal()); 493 atts.addAttribute(xmlns, localName, "transient", "String", "" + field.isTransient()); 494 atts.addAttribute(xmlns, localName, "volatile", "String", "" + field.isVolatile()); 495 cm.startElement(xmlns, localName, "field", atts); 496 497 // generate "doc" sub-element 498 docXML(field); 499 500 // generate "(classref|interfaceref|primitive)" sub-element 501 createTypeRef(field.type()); // foo , field.qualifiedName()); 502 503 cm.endElement(xmlns, localName, "field"); 504 } 505 506 /*** 507 * Generates doc for element "constructor" 508 * <xmp><!ELEMENT constructor (doc?, parameter*, throws*)> 509 * <!ATTLIST constructor 510 * %name; 511 * %access; 512 * %synthetic;></xmp> 513 */ 514 private void constructorXML(ConstructorDoc constrDoc) throws SAXException { 515 AttributesImpl atts = new AttributesImpl(); 516 atts.addAttribute(xmlns, localName, "name", "String", constrDoc.qualifiedName()); 517 String access = "package"; 518 if (constrDoc.isPrivate()) { 519 access = "private"; 520 } else if (constrDoc.isProtected()) { 521 access = "protected"; 522 } else if (constrDoc.isPublic()) { 523 access = "public"; 524 } 525 atts.addAttribute(xmlns, localName, "access", "String", access); 526 atts.addAttribute(xmlns, localName, "synthetic", "String", "" + constrDoc.isSynthetic()); 527 cm.startElement(xmlns, localName, "constructor", atts); 528 529 // generate "doc" sub-element 530 docXML(constrDoc); 531 532 // generate "parameter" sub-elements 533 Parameter[] parameterArray = constrDoc.parameters(); 534 for (int i = 0; i < parameterArray.length; ++i) { 535 parameterXML(parameterArray[i]); 536 } 537 538 // generate "throws" sub-element 539 throwsXML(constrDoc); 540 541 cm.endElement(xmlns, localName, "constructor"); 542 } 543 544 /*** 545 * Generates doc for element "method" 546 * <xmp> <!ELEMENT method (doc?, returns, parameter*, throws*)> 547 * <!ATTLIST method 548 * %name; 549 * %access; 550 * %extensibility; 551 * %native; 552 * %synthetic; 553 * %static; 554 * %synchronized;></xmp> 555 */ 556 private void methodXML(MethodDoc methodDoc) throws SAXException { 557 AttributesImpl atts = new AttributesImpl(); 558 //atts.addAttribute(xmlns, localName, "", String, ); 559 atts.addAttribute(xmlns, localName, "name", "String", methodDoc.name()); 560 561 String access = "package"; 562 if (methodDoc.isPrivate()) { 563 access = "private"; 564 } else if (methodDoc.isProtected()) { 565 access = "protected"; 566 } else if (methodDoc.isPublic()) { 567 access = "public"; 568 } 569 atts.addAttribute(xmlns, localName, "access", "String", access); 570 571 String extensibility = "default"; 572 if (methodDoc.isAbstract()) { 573 extensibility = "abstract"; 574 } else if (methodDoc.isFinal()) { 575 extensibility = "final"; 576 } 577 atts.addAttribute(xmlns, localName, "extensiblity", "String", extensibility); 578 579 atts.addAttribute(xmlns, localName, "native", "String", ""+ methodDoc.isNative()); 580 atts.addAttribute(xmlns, localName, "synthetic", "String", "" + methodDoc.isSynthetic()); 581 atts.addAttribute(xmlns, localName, "static", "String", "" + methodDoc.isStatic()); 582 atts.addAttribute(xmlns, localName, "synchronized", "String", ""+ methodDoc.isSynchronized()); 583 cm.startElement(xmlns, localName, "method", atts); 584 585 // generate "doc" sub-element 586 docXML(methodDoc); 587 588 // generate "returns" sub-element 589 returnsXML(methodDoc.returnType()); 590 591 // generate "parameter" sub-elements 592 Parameter[] parameterArray = methodDoc.parameters(); 593 for (int i = 0; i < parameterArray.length; ++i) { 594 parameterXML(parameterArray[i]); 595 } 596 597 // generate "throws" sub-element 598 throwsXML(methodDoc); 599 600 cm.endElement(xmlns, localName, "method"); 601 } 602 603 /*** 604 * Generates doc for element "returns" 605 * <xmp> <!ELEMENT returns (classref | interfaceref | primitive)> 606 * <!ATTLIST returns %dimension;></xmp> 607 */ 608 private void returnsXML(Type type) throws SAXException { 609 AttributesImpl atts = new AttributesImpl(); 610 atts.addAttribute(xmlns, localName, "dimension", "String", type.dimension()); 611 cm.startElement(xmlns, localName, "returns", atts); 612 613 // generate "(classref|interfaceref|primitive)" sub-element 614 createTypeRef(type); 615 616 cm.endElement(xmlns, localName, "returns"); 617 } 618 619 /*** 620 * Generates doc for element "parameter" 621 * <xmp> <!ELEMENT parameter (classref | interfaceref | primitive)> 622 * <!ATTLIST parameter 623 * %name; 624 * %final; 625 * %dimension;></xmp> 626 */ 627 private void parameterXML(Parameter parameter) throws SAXException { 628 AttributesImpl atts = new AttributesImpl(); 629 atts.addAttribute(xmlns, localName, "name", "String", parameter.name()); 630 boolean isFinal = false; 631 Type type = parameter.type(); 632 if (type.asClassDoc() == null) { 633 isFinal = true; 634 } 635 atts.addAttribute(xmlns, localName, "final", "String", ""+ "" + isFinal); 636 atts.addAttribute(xmlns, localName, "dimension", "String", parameter.type().dimension()); 637 cm.startElement(xmlns, localName, "parameter", atts); 638 639 // generate "(classref|interfaceref|primitive)" sub-element 640 createTypeRef(parameter.type()); 641 642 cm.endElement(xmlns, localName,"parameter"); 643 } 644 645 /*** 646 * Generates doc for element "doc" 647 * <xmp><!ELEMENT doc (#PCDATA | 648 * linktag | 649 * authortag | 650 * versiontag | 651 * paramtag | 652 * returntag | 653 * exceptiontag | 654 * throwstag | 655 * seetag | 656 * sincetag | 657 * deprecatedtag | 658 * serialtag | 659 * serialfieldtag | 660 * serialdatatag)*></xmp> 661 */ 662 private void docXML(Doc doc) throws SAXException { 663 String commentText = ""; 664 boolean createDoc = false; 665 commentText = doc.commentText(); 666 if (! commentText.equals("")) { 667 createDoc = true; 668 } 669 Tag[] tags = doc.tags(); 670 if (tags.length > 0) { 671 createDoc = true; 672 } 673 if (createDoc) { 674 cm.startElement(xmlns, localName, "doc", emptyAtts); 675 if (! commentText.equals("")) { 676 cm.characters(commentText.toCharArray(), 0, commentText.length()); 677 } 678 for (int i = 0; i < tags.length; ++i) { 679 tagXML(tags[i]); 680 } 681 cm.endElement(xmlns, localName, "doc"); 682 } 683 } 684 685 /*** 686 * Generates doc for all tag elements. 687 */ 688 private void tagXML(Tag tag) throws SAXException { 689 String name = tag.name().substring(1) + "tag"; 690 if (! tag.text().equals("")) { 691 cm.startElement(xmlns, localName, name, emptyAtts); 692 cm.characters(tag.text().toCharArray(), 0, tag.text().length()); 693 cm.endElement(xmlns, localName, name); 694 } 695 } 696 697 public static boolean start(RootDoc root) { 698 try { 699 new XMLDoclet(root); 700 return true; 701 } catch (Exception e) { 702 e.printStackTrace(); 703 System.exit(1); 704 return false; 705 } 706 } 707 }

This page was automatically generated by Maven