home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / tooldocs / javadoc / source / standard / SerialFieldSubWriter.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  5.0 KB  |  177 lines

  1. /*
  2.  * @(#)SerialFieldSubWriter.java    1.13 98/08/24
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package com.sun.tools.doclets.standard;
  16.  
  17. import com.sun.javadoc.*;
  18. import com.sun.tools.doclets.*;
  19. import java.util.Arrays;
  20.  
  21. /**
  22.  * Generate serialized form for serializable fields.
  23.  * Documentation denoted by the tags <code>serial</code> and
  24.  * <code>serialField<\code> is processed.
  25.  *
  26.  * @author Joe Fialli
  27.  */
  28. public class SerialFieldSubWriter extends FieldSubWriter {
  29.     ProgramElementDoc[] members = null;
  30.  
  31.     SerialFieldSubWriter(SubWriterHolderWriter writer) {
  32.         super(writer);
  33.     }
  34.  
  35.     public ProgramElementDoc[] members(ClassDoc cd) {
  36.     if (members == null) { 
  37.         FieldDoc[] array = cd.serializableFields();
  38.         Arrays.sort(array);
  39.         members = eligibleMembers(array);
  40.     }
  41.     return members;
  42.     }
  43.  
  44.     void printSignature(MemberDoc member) {
  45.         FieldDoc field = (FieldDoc)member;
  46.         printHead(member);
  47.     writer.pre();
  48.         printTypeLink(field.type());
  49.         print(' ');
  50.         bold(field.name());
  51.     writer.preEnd();
  52.     }
  53.  
  54.     protected void printHeader(ClassDoc cd) {
  55.         writer.anchor("serializedForm");
  56.     printSerializableClassComment(cd);
  57.     writer.printTableHeadingBackground(writer.getText("doclet.Serialized_Form_fields"));
  58.     }
  59.  
  60.     /**
  61.      * javadoc comments for "serialPersistentFields" is considered
  62.      * as serializable class comments, not field comments.
  63.      */
  64.     private void printSerializableClassComment(ClassDoc cd) {
  65.     if (cd.definesSerializableFields()) {
  66.         FieldDoc serialPersistentFields = (FieldDoc)(members(cd)[0]);
  67.         String comment = serialPersistentFields.commentText();
  68.         if (comment.length() > 0) {
  69.         writer.printTableHeadingBackground(writer.getText("doclet.Serialized_Form_class"));
  70.         printFullComment(serialPersistentFields);
  71.         }
  72.     }
  73.     }
  74.  
  75.     protected void printBodyHtmlEnd(ClassDoc cd) {
  76.     }
  77.  
  78.     /**
  79.      * Print a default Serializable field or
  80.      * print all Serializable fields documented by
  81.      * <code>serialField</code> tags.
  82.      */
  83.     protected void printMember(ProgramElementDoc member) {
  84.         FieldDoc field = (FieldDoc)member;
  85.     ClassDoc cd = field.containingClass();
  86.     if (cd.definesSerializableFields()) {
  87.  
  88.         // Process Serializable Fields specified as array of ObjectStreamFields.
  89.         //Print a member for each serialField tag.
  90.         //(There should be one serialField tag per ObjectStreamField element.)
  91.         SerialFieldTag[] tags = field.serialFieldTags();
  92.         Arrays.sort(tags);
  93.         for (int i = 0; i < tags.length; i++) {
  94.         if (i > 0) {
  95.             writer.printMemberHeader();
  96.         } 
  97.         printSignature(tags[i]);
  98.         printComment(tags[i]);
  99.                 writer.printMemberFooter();
  100.         }
  101.     } else {
  102.  
  103.         // Process default Serializable field.
  104.         if ((field.tags("serial").length == 0) && ! field.isSynthetic()) {
  105.            Standard.configuration().
  106.            standardmessage.warning("doclet.MissingSerialTag",
  107.                   cd.qualifiedName(), field.name());
  108.         }
  109.         printSignature(field);
  110.         printFullComment(field);
  111.     }
  112.     }
  113.  
  114.     /*
  115.      * Print comment for a default Serializable field.
  116.      *
  117.      * If serial tag has an optional comment, append the
  118.      * comment to the javadoc comment for the field.
  119.      */
  120.     protected void printComment(ProgramElementDoc member) {
  121.     String fieldComment = member.commentText();
  122.         if (fieldComment.length() > 0) {
  123.             writer.dd();
  124.             print(fieldComment);
  125.     }
  126.  
  127.     Tag[] tags = member.tags("serial");
  128.     if (tags.length > 0 && tags[0].text().length() > 0) {
  129.         String serialComment = tags[0].text();
  130.             writer.dd();
  131.         print(serialComment);
  132.     }
  133.     }
  134.  
  135.     /* Methods for processing serialField fieldName fieldType description.*/
  136.     void printSignature(SerialFieldTag sftag) {
  137.     writer.pre();
  138.     ClassDoc fieldTypeDoc = sftag.fieldTypeDoc();
  139.     if (fieldTypeDoc != null) {
  140.         writer.printClassLink(fieldTypeDoc);
  141.         } else {
  142.         writer.print(sftag.fieldType());
  143.     }
  144.         print(' ');
  145.         bold(sftag.fieldName());
  146.     writer.preEnd();
  147.     }
  148.  
  149.     private void printComment(SerialFieldTag sftag) {
  150.     writer.dl();
  151.         writer.dd();
  152.         writer.print(sftag.description());
  153.     writer.dlEnd();
  154.     }
  155.  
  156.     /* The methods following this comment have no meaning for SerialFields.*/
  157.     protected void printDeprecatedLink(ProgramElementDoc member) {
  158.     }
  159.  
  160.     public void printSummaryLabel(ClassDoc cd) {
  161.     }
  162.  
  163.     public void printInheritedSummaryLabel(ClassDoc cd) {
  164.     }
  165.  
  166.     protected void printSummaryLink(ClassDoc cd, ProgramElementDoc member) {
  167.     }
  168.  
  169.     protected void printInheritedSummaryLink(ClassDoc cd,
  170.                                              ProgramElementDoc member) {
  171.     }
  172.  
  173.     protected void printSummaryType(ProgramElementDoc member) {
  174.     }
  175. }
  176.  
  177.