aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.internal.toolkit.builders; aoqi@0: aoqi@0: import java.io.*; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.javac.jvm.Profile; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * Builds the summary for a given profile. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Bhavesh Patel aoqi@0: */ aoqi@0: public class ProfileSummaryBuilder extends AbstractBuilder { aoqi@0: /** aoqi@0: * The root element of the profile summary XML is {@value}. aoqi@0: */ aoqi@0: public static final String ROOT = "ProfileDoc"; aoqi@0: aoqi@0: /** aoqi@0: * The profile being documented. aoqi@0: */ aoqi@0: private final Profile profile; aoqi@0: aoqi@0: /** aoqi@0: * The doclet specific writer that will output the result. aoqi@0: */ aoqi@0: private final ProfileSummaryWriter profileWriter; aoqi@0: aoqi@0: /** aoqi@0: * The content that will be added to the profile summary documentation tree. aoqi@0: */ aoqi@0: private Content contentTree; aoqi@0: aoqi@0: /** aoqi@0: * The profile package being documented. aoqi@0: */ aoqi@0: private PackageDoc pkg; aoqi@0: aoqi@0: /** aoqi@0: * Construct a new ProfileSummaryBuilder. aoqi@0: * aoqi@0: * @param context the build context. aoqi@0: * @param profile the profile being documented. aoqi@0: * @param profileWriter the doclet specific writer that will output the aoqi@0: * result. aoqi@0: */ aoqi@0: private ProfileSummaryBuilder(Context context, aoqi@0: Profile profile, ProfileSummaryWriter profileWriter) { aoqi@0: super(context); aoqi@0: this.profile = profile; aoqi@0: this.profileWriter = profileWriter; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a new ProfileSummaryBuilder. aoqi@0: * aoqi@0: * @param context the build context. aoqi@0: * @param profile the profile being documented. aoqi@0: * @param profileWriter the doclet specific writer that will output the aoqi@0: * result. aoqi@0: * aoqi@0: * @return an instance of a ProfileSummaryBuilder. aoqi@0: */ aoqi@0: public static ProfileSummaryBuilder getInstance(Context context, aoqi@0: Profile profile, ProfileSummaryWriter profileWriter) { aoqi@0: return new ProfileSummaryBuilder(context, profile, profileWriter); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the profile summary. aoqi@0: */ aoqi@0: public void build() throws IOException { aoqi@0: if (profileWriter == null) { aoqi@0: //Doclet does not support this output. aoqi@0: return; aoqi@0: } aoqi@0: build(layoutParser.parseXML(ROOT), contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public String getName() { aoqi@0: return ROOT; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the profile documentation. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param contentTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildProfileDoc(XMLNode node, Content contentTree) throws Exception { aoqi@0: contentTree = profileWriter.getProfileHeader(profile.name); aoqi@0: buildChildren(node, contentTree); aoqi@0: profileWriter.addProfileFooter(contentTree); aoqi@0: profileWriter.printDocument(contentTree); aoqi@0: profileWriter.close(); aoqi@0: Util.copyDocFiles(configuration, DocPaths.profileSummary(profile.name)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the content for the profile doc. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param contentTree the content tree to which the profile contents aoqi@0: * will be added aoqi@0: */ aoqi@0: public void buildContent(XMLNode node, Content contentTree) { aoqi@0: Content profileContentTree = profileWriter.getContentHeader(); aoqi@0: buildChildren(node, profileContentTree); aoqi@0: contentTree.addContent(profileContentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the profile summary. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param profileContentTree the profile content tree to which the summaries will aoqi@0: * be added aoqi@0: */ aoqi@0: public void buildSummary(XMLNode node, Content profileContentTree) { aoqi@0: Content summaryContentTree = profileWriter.getSummaryHeader(); aoqi@0: buildChildren(node, summaryContentTree); aoqi@0: profileContentTree.addContent(profileWriter.getSummaryTree(summaryContentTree)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the profile package summary. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param summaryContentTree the content tree to which the summaries will aoqi@0: * be added aoqi@0: */ aoqi@0: public void buildPackageSummary(XMLNode node, Content summaryContentTree) { aoqi@0: PackageDoc[] packages = configuration.profilePackages.get(profile.name); aoqi@0: for (int i = 0; i < packages.length; i++) { aoqi@0: this.pkg = packages[i]; aoqi@0: Content packageSummaryContentTree = profileWriter.getPackageSummaryHeader(this.pkg); aoqi@0: buildChildren(node, packageSummaryContentTree); aoqi@0: summaryContentTree.addContent(profileWriter.getPackageSummaryTree( aoqi@0: packageSummaryContentTree)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the summary for the interfaces in the package. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param packageSummaryContentTree the tree to which the interface summary aoqi@0: * will be added aoqi@0: */ aoqi@0: public void buildInterfaceSummary(XMLNode node, Content packageSummaryContentTree) { aoqi@0: String interfaceTableSummary = aoqi@0: configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Interface_Summary"), aoqi@0: configuration.getText("doclet.interfaces")); aoqi@0: String[] interfaceTableHeader = new String[] { aoqi@0: configuration.getText("doclet.Interface"), aoqi@0: configuration.getText("doclet.Description") aoqi@0: }; aoqi@0: ClassDoc[] interfaces = pkg.interfaces(); aoqi@0: if (interfaces.length > 0) { aoqi@0: profileWriter.addClassesSummary( aoqi@0: interfaces, aoqi@0: configuration.getText("doclet.Interface_Summary"), aoqi@0: interfaceTableSummary, interfaceTableHeader, packageSummaryContentTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the summary for the classes in the package. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param packageSummaryContentTree the tree to which the class summary will aoqi@0: * be added aoqi@0: */ aoqi@0: public void buildClassSummary(XMLNode node, Content packageSummaryContentTree) { aoqi@0: String classTableSummary = aoqi@0: configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Class_Summary"), aoqi@0: configuration.getText("doclet.classes")); aoqi@0: String[] classTableHeader = new String[] { aoqi@0: configuration.getText("doclet.Class"), aoqi@0: configuration.getText("doclet.Description") aoqi@0: }; aoqi@0: ClassDoc[] classes = pkg.ordinaryClasses(); aoqi@0: if (classes.length > 0) { aoqi@0: profileWriter.addClassesSummary( aoqi@0: classes, aoqi@0: configuration.getText("doclet.Class_Summary"), aoqi@0: classTableSummary, classTableHeader, packageSummaryContentTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the summary for the enums in the package. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param packageSummaryContentTree the tree to which the enum summary will aoqi@0: * be added aoqi@0: */ aoqi@0: public void buildEnumSummary(XMLNode node, Content packageSummaryContentTree) { aoqi@0: String enumTableSummary = aoqi@0: configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Enum_Summary"), aoqi@0: configuration.getText("doclet.enums")); aoqi@0: String[] enumTableHeader = new String[] { aoqi@0: configuration.getText("doclet.Enum"), aoqi@0: configuration.getText("doclet.Description") aoqi@0: }; aoqi@0: ClassDoc[] enums = pkg.enums(); aoqi@0: if (enums.length > 0) { aoqi@0: profileWriter.addClassesSummary( aoqi@0: enums, aoqi@0: configuration.getText("doclet.Enum_Summary"), aoqi@0: enumTableSummary, enumTableHeader, packageSummaryContentTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the summary for the exceptions in the package. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param packageSummaryContentTree the tree to which the exception summary will aoqi@0: * be added aoqi@0: */ aoqi@0: public void buildExceptionSummary(XMLNode node, Content packageSummaryContentTree) { aoqi@0: String exceptionTableSummary = aoqi@0: configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Exception_Summary"), aoqi@0: configuration.getText("doclet.exceptions")); aoqi@0: String[] exceptionTableHeader = new String[] { aoqi@0: configuration.getText("doclet.Exception"), aoqi@0: configuration.getText("doclet.Description") aoqi@0: }; aoqi@0: ClassDoc[] exceptions = pkg.exceptions(); aoqi@0: if (exceptions.length > 0) { aoqi@0: profileWriter.addClassesSummary( aoqi@0: exceptions, aoqi@0: configuration.getText("doclet.Exception_Summary"), aoqi@0: exceptionTableSummary, exceptionTableHeader, packageSummaryContentTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the summary for the errors in the package. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param packageSummaryContentTree the tree to which the error summary will aoqi@0: * be added aoqi@0: */ aoqi@0: public void buildErrorSummary(XMLNode node, Content packageSummaryContentTree) { aoqi@0: String errorTableSummary = aoqi@0: configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Error_Summary"), aoqi@0: configuration.getText("doclet.errors")); aoqi@0: String[] errorTableHeader = new String[] { aoqi@0: configuration.getText("doclet.Error"), aoqi@0: configuration.getText("doclet.Description") aoqi@0: }; aoqi@0: ClassDoc[] errors = pkg.errors(); aoqi@0: if (errors.length > 0) { aoqi@0: profileWriter.addClassesSummary( aoqi@0: errors, aoqi@0: configuration.getText("doclet.Error_Summary"), aoqi@0: errorTableSummary, errorTableHeader, packageSummaryContentTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the summary for the annotation type in the package. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param packageSummaryContentTree the tree to which the annotation type aoqi@0: * summary will be added aoqi@0: */ aoqi@0: public void buildAnnotationTypeSummary(XMLNode node, Content packageSummaryContentTree) { aoqi@0: String annotationtypeTableSummary = aoqi@0: configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Annotation_Types_Summary"), aoqi@0: configuration.getText("doclet.annotationtypes")); aoqi@0: String[] annotationtypeTableHeader = new String[] { aoqi@0: configuration.getText("doclet.AnnotationType"), aoqi@0: configuration.getText("doclet.Description") aoqi@0: }; aoqi@0: ClassDoc[] annotationTypes = pkg.annotationTypes(); aoqi@0: if (annotationTypes.length > 0) { aoqi@0: profileWriter.addClassesSummary( aoqi@0: annotationTypes, aoqi@0: configuration.getText("doclet.Annotation_Types_Summary"), aoqi@0: annotationtypeTableSummary, annotationtypeTableHeader, aoqi@0: packageSummaryContentTree); aoqi@0: } aoqi@0: } aoqi@0: }