src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/PackageSummaryBuilder.java

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 243
edd944553131
child 589
4177f5bdd189
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.internal.toolkit.builders;
    28 import com.sun.tools.doclets.internal.toolkit.util.*;
    29 import com.sun.tools.doclets.internal.toolkit.*;
    30 import com.sun.javadoc.*;
    31 import java.io.*;
    32 import java.util.*;
    33 import java.lang.reflect.*;
    35 /**
    36  * Builds the summary for a given package.
    37  *
    38  * This code is not part of an API.
    39  * It is implementation that is subject to change.
    40  * Do not use it as an API
    41  *
    42  * @author Jamie Ho
    43  * @author Bhavesh Patel (Modified)
    44  * @since 1.5
    45  */
    46 public class PackageSummaryBuilder extends AbstractBuilder {
    48         /**
    49          * The root element of the package summary XML is {@value}.
    50          */
    51         public static final String ROOT = "PackageDoc";
    53         /**
    54          * The package being documented.
    55          */
    56         private PackageDoc packageDoc;
    58         /**
    59          * The doclet specific writer that will output the result.
    60          */
    61         private PackageSummaryWriter packageWriter;
    63         private PackageSummaryBuilder(Configuration configuration) {
    64                 super(configuration);
    65         }
    67         /**
    68          * Construct a new PackageSummaryBuilder.
    69          * @param configuration the current configuration of the doclet.
    70          * @param pkg the package being documented.
    71          * @param packageWriter the doclet specific writer that will output the
    72          *        result.
    73          *
    74          * @return an instance of a PackageSummaryBuilder.
    75          */
    76         public static PackageSummaryBuilder getInstance(
    77                 Configuration configuration,
    78                 PackageDoc pkg,
    79                 PackageSummaryWriter packageWriter) {
    80                 PackageSummaryBuilder builder =
    81                         new PackageSummaryBuilder(configuration);
    82                 builder.packageDoc = pkg;
    83                 builder.packageWriter = packageWriter;
    84                 return builder;
    85         }
    87         /**
    88          * {@inheritDoc}
    89          */
    90         public void invokeMethod(
    91                 String methodName,
    92                 Class<?>[] paramClasses,
    93                 Object[] params)
    94                 throws Exception {
    95                 if (DEBUG) {
    96                         configuration.root.printError(
    97                                 "DEBUG: " + this.getClass().getName() + "." + methodName);
    98                 }
    99                 Method method = this.getClass().getMethod(methodName, paramClasses);
   100                 method.invoke(this, params);
   101         }
   103         /**
   104          * Build the package summary.
   105          */
   106         public void build() throws IOException {
   107                 if (packageWriter == null) {
   108                         //Doclet does not support this output.
   109                         return;
   110                 }
   111                 build(LayoutParser.getInstance(configuration).parseXML(ROOT));
   112         }
   114         /**
   115          * {@inheritDoc}
   116          */
   117         public String getName() {
   118                 return ROOT;
   119         }
   121         /**
   122          * Build the package documentation.
   123          */
   124         public void buildPackageDoc(List<?> elements) throws Exception {
   125                 build(elements);
   126                 packageWriter.close();
   127                 Util.copyDocFiles(
   128                         configuration,
   129                         Util.getPackageSourcePath(configuration, packageDoc),
   130                         DirectoryManager.getDirectoryPath(packageDoc)
   131                                 + File.separator
   132                                 + DocletConstants.DOC_FILES_DIR_NAME,
   133                         true);
   134         }
   136         /**
   137          * Build the header of the summary.
   138          */
   139         public void buildPackageHeader() {
   140                 packageWriter.writePackageHeader(Util.getPackageName(packageDoc));
   141         }
   143         /**
   144          * Build the description of the summary.
   145          */
   146         public void buildPackageDescription() {
   147                 if (configuration.nocomment) {
   148                         return;
   149                 }
   150                 packageWriter.writePackageDescription();
   151         }
   153         /**
   154          * Build the tags of the summary.
   155          */
   156         public void buildPackageTags() {
   157                 if (configuration.nocomment) {
   158                         return;
   159                 }
   160                 packageWriter.writePackageTags();
   161         }
   163         /**
   164          * Build the package summary.
   165          */
   166         public void buildSummary(List<?> elements) {
   167                 build(elements);
   168         }
   170         /**
   171          * Build the overall header.
   172          */
   173         public void buildSummaryHeader() {
   174                 packageWriter.writeSummaryHeader();
   175         }
   177         /**
   178          * Build the overall footer.
   179          */
   180         public void buildSummaryFooter() {
   181                 packageWriter.writeSummaryFooter();
   182         }
   184         /**
   185          * Build the summary for the classes in this package.
   186          */
   187         public void buildClassSummary() {
   188             String classTableSummary =
   189                     configuration.getText("doclet.Member_Table_Summary",
   190                     configuration.getText("doclet.Class_Summary"),
   191                     configuration.getText("doclet.classes"));
   192             String[] classTableHeader = new String[] {
   193                 configuration.getText("doclet.Class"),
   194                 configuration.getText("doclet.Description")
   195             };
   196             ClassDoc[] classes =
   197                         packageDoc.isIncluded()
   198                                 ? packageDoc.ordinaryClasses()
   199                                 : configuration.classDocCatalog.ordinaryClasses(
   200                                         Util.getPackageName(packageDoc));
   201                 if (classes.length > 0) {
   202                         packageWriter.writeClassesSummary(
   203                                 classes,
   204                                 configuration.getText("doclet.Class_Summary"),
   205                                 classTableSummary, classTableHeader);
   206                 }
   207         }
   209         /**
   210          * Build the summary for the interfaces in this package.
   211          */
   212         public void buildInterfaceSummary() {
   213             String interfaceTableSummary =
   214                     configuration.getText("doclet.Member_Table_Summary",
   215                     configuration.getText("doclet.Interface_Summary"),
   216                     configuration.getText("doclet.interfaces"));
   217             String[] interfaceTableHeader = new String[] {
   218                 configuration.getText("doclet.Interface"),
   219                 configuration.getText("doclet.Description")
   220             };
   221             ClassDoc[] interfaces =
   222                         packageDoc.isIncluded()
   223                                 ? packageDoc.interfaces()
   224                                 : configuration.classDocCatalog.interfaces(
   225                                         Util.getPackageName(packageDoc));
   226                 if (interfaces.length > 0) {
   227                         packageWriter.writeClassesSummary(
   228                                 interfaces,
   229                                 configuration.getText("doclet.Interface_Summary"),
   230                                 interfaceTableSummary, interfaceTableHeader);
   231                 }
   232         }
   234         /**
   235          * Build the summary for the enums in this package.
   236          */
   237         public void buildAnnotationTypeSummary() {
   238             String annotationtypeTableSummary =
   239                     configuration.getText("doclet.Member_Table_Summary",
   240                     configuration.getText("doclet.Annotation_Types_Summary"),
   241                     configuration.getText("doclet.annotationtypes"));
   242             String[] annotationtypeTableHeader = new String[] {
   243                 configuration.getText("doclet.AnnotationType"),
   244                 configuration.getText("doclet.Description")
   245             };
   246             ClassDoc[] annotationTypes =
   247                         packageDoc.isIncluded()
   248                                 ? packageDoc.annotationTypes()
   249                                 : configuration.classDocCatalog.annotationTypes(
   250                                         Util.getPackageName(packageDoc));
   251                 if (annotationTypes.length > 0) {
   252                         packageWriter.writeClassesSummary(
   253                                 annotationTypes,
   254                                 configuration.getText("doclet.Annotation_Types_Summary"),
   255                                 annotationtypeTableSummary, annotationtypeTableHeader);
   256                 }
   257         }
   259         /**
   260          * Build the summary for the enums in this package.
   261          */
   262         public void buildEnumSummary() {
   263             String enumTableSummary =
   264                     configuration.getText("doclet.Member_Table_Summary",
   265                     configuration.getText("doclet.Enum_Summary"),
   266                     configuration.getText("doclet.enums"));
   267             String[] enumTableHeader = new String[] {
   268                 configuration.getText("doclet.Enum"),
   269                 configuration.getText("doclet.Description")
   270             };
   271             ClassDoc[] enums =
   272                         packageDoc.isIncluded()
   273                                 ? packageDoc.enums()
   274                                 : configuration.classDocCatalog.enums(
   275                                         Util.getPackageName(packageDoc));
   276                 if (enums.length > 0) {
   277                         packageWriter.writeClassesSummary(
   278                                 enums,
   279                                 configuration.getText("doclet.Enum_Summary"),
   280                                 enumTableSummary, enumTableHeader);
   281                 }
   282         }
   284         /**
   285          * Build the summary for the exceptions in this package.
   286          */
   287         public void buildExceptionSummary() {
   288             String exceptionTableSummary =
   289                     configuration.getText("doclet.Member_Table_Summary",
   290                     configuration.getText("doclet.Exception_Summary"),
   291                     configuration.getText("doclet.exceptions"));
   292             String[] exceptionTableHeader = new String[] {
   293                 configuration.getText("doclet.Exception"),
   294                 configuration.getText("doclet.Description")
   295             };
   296             ClassDoc[] exceptions =
   297                         packageDoc.isIncluded()
   298                                 ? packageDoc.exceptions()
   299                                 : configuration.classDocCatalog.exceptions(
   300                                         Util.getPackageName(packageDoc));
   301                 if (exceptions.length > 0) {
   302                         packageWriter.writeClassesSummary(
   303                                 exceptions,
   304                                 configuration.getText("doclet.Exception_Summary"),
   305                                 exceptionTableSummary, exceptionTableHeader);
   306                 }
   307         }
   309         /**
   310          * Build the summary for the errors in this package.
   311          */
   312         public void buildErrorSummary() {
   313             String errorTableSummary =
   314                     configuration.getText("doclet.Member_Table_Summary",
   315                     configuration.getText("doclet.Error_Summary"),
   316                     configuration.getText("doclet.errors"));
   317             String[] errorTableHeader = new String[] {
   318                 configuration.getText("doclet.Error"),
   319                 configuration.getText("doclet.Description")
   320             };
   321             ClassDoc[] errors =
   322                         packageDoc.isIncluded()
   323                                 ? packageDoc.errors()
   324                                 : configuration.classDocCatalog.errors(
   325                                         Util.getPackageName(packageDoc));
   326                 if (errors.length > 0) {
   327                         packageWriter.writeClassesSummary(
   328                                 errors,
   329                                 configuration.getText("doclet.Error_Summary"),
   330                                 errorTableSummary, errorTableHeader);
   331                 }
   332         }
   334         /**
   335          * Build the footer of the summary.
   336          */
   337         public void buildPackageFooter() {
   338                 packageWriter.writePackageFooter();
   339         }
   340 }

mercurial