001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.internal.toolkit.builders;
027:
028: import com.sun.tools.doclets.internal.toolkit.util.*;
029: import com.sun.tools.doclets.internal.toolkit.*;
030: import com.sun.javadoc.*;
031: import java.io.*;
032: import java.util.*;
033: import java.lang.reflect.*;
034:
035: /**
036: * Builds the summary for a given package.
037: *
038: * This code is not part of an API.
039: * It is implementation that is subject to change.
040: * Do not use it as an API
041: *
042: * @author Jamie Ho
043: * @since 1.5
044: */
045: public class PackageSummaryBuilder extends AbstractBuilder {
046:
047: /**
048: * The root element of the package summary XML is {@value}.
049: */
050: public static final String ROOT = "PackageDoc";
051:
052: /**
053: * The package being documented.
054: */
055: private PackageDoc packageDoc;
056:
057: /**
058: * The doclet specific writer that will output the result.
059: */
060: private PackageSummaryWriter packageWriter;
061:
062: private PackageSummaryBuilder(Configuration configuration) {
063: super (configuration);
064: }
065:
066: /**
067: * Construct a new PackageSummaryBuilder.
068: * @param configuration the current configuration of the doclet.
069: * @param pkg the package being documented.
070: * @param packageWriter the doclet specific writer that will output the
071: * result.
072: *
073: * @return an instance of a PackageSummaryBuilder.
074: */
075: public static PackageSummaryBuilder getInstance(
076: Configuration configuration, PackageDoc pkg,
077: PackageSummaryWriter packageWriter) {
078: PackageSummaryBuilder builder = new PackageSummaryBuilder(
079: configuration);
080: builder.packageDoc = pkg;
081: builder.packageWriter = packageWriter;
082: return builder;
083: }
084:
085: /**
086: * {@inheritDoc}
087: */
088: public void invokeMethod(String methodName, Class[] paramClasses,
089: Object[] params) throws Exception {
090: if (DEBUG) {
091: configuration.root.printError("DEBUG: "
092: + this .getClass().getName() + "." + methodName);
093: }
094: Method method = this .getClass().getMethod(methodName,
095: paramClasses);
096: method.invoke(this , params);
097: }
098:
099: /**
100: * Build the package summary.
101: */
102: public void build() throws IOException {
103: if (packageWriter == null) {
104: //Doclet does not support this output.
105: return;
106: }
107: build(LayoutParser.getInstance(configuration).parseXML(ROOT));
108: }
109:
110: /**
111: * {@inheritDoc}
112: */
113: public String getName() {
114: return ROOT;
115: }
116:
117: /**
118: * Build the package documentation.
119: */
120: public void buildPackageDoc(List elements) throws Exception {
121: build(elements);
122: packageWriter.close();
123: Util.copyDocFiles(configuration, Util.getPackageSourcePath(
124: configuration, packageDoc), DirectoryManager
125: .getDirectoryPath(packageDoc)
126: + File.separator + DocletConstants.DOC_FILES_DIR_NAME,
127: true);
128: }
129:
130: /**
131: * Build the header of the summary.
132: */
133: public void buildPackageHeader() {
134: packageWriter.writePackageHeader(Util
135: .getPackageName(packageDoc));
136: }
137:
138: /**
139: * Build the description of the summary.
140: */
141: public void buildPackageDescription() {
142: if (configuration.nocomment) {
143: return;
144: }
145: packageWriter.writePackageDescription();
146: }
147:
148: /**
149: * Build the tags of the summary.
150: */
151: public void buildPackageTags() {
152: if (configuration.nocomment) {
153: return;
154: }
155: packageWriter.writePackageTags();
156: }
157:
158: /**
159: * Build the package summary.
160: */
161: public void buildSummary(List elements) {
162: build(elements);
163: }
164:
165: /**
166: * Build the overall header.
167: */
168: public void buildSummaryHeader() {
169: packageWriter.writeSummaryHeader();
170: }
171:
172: /**
173: * Build the overall footer.
174: */
175: public void buildSummaryFooter() {
176: packageWriter.writeSummaryFooter();
177: }
178:
179: /**
180: * Build the summary for the classes in this package.
181: */
182: public void buildClassSummary() {
183: ClassDoc[] classes = packageDoc.isIncluded() ? packageDoc
184: .ordinaryClasses() : configuration.classDocCatalog
185: .ordinaryClasses(Util.getPackageName(packageDoc));
186: if (classes.length > 0) {
187: packageWriter.writeClassesSummary(classes, configuration
188: .getText("doclet.Class_Summary"));
189: }
190: }
191:
192: /**
193: * Build the summary for the interfaces in this package.
194: */
195: public void buildInterfaceSummary() {
196: ClassDoc[] interfaces = packageDoc.isIncluded() ? packageDoc
197: .interfaces() : configuration.classDocCatalog
198: .interfaces(Util.getPackageName(packageDoc));
199: if (interfaces.length > 0) {
200: packageWriter.writeClassesSummary(interfaces, configuration
201: .getText("doclet.Interface_Summary"));
202: }
203: }
204:
205: /**
206: * Build the summary for the enums in this package.
207: */
208: public void buildAnnotationTypeSummary() {
209: ClassDoc[] annotationTypes = packageDoc.isIncluded() ? packageDoc
210: .annotationTypes()
211: : configuration.classDocCatalog.annotationTypes(Util
212: .getPackageName(packageDoc));
213: if (annotationTypes.length > 0) {
214: packageWriter
215: .writeClassesSummary(annotationTypes, configuration
216: .getText("doclet.Annotation_Types_Summary"));
217: }
218: }
219:
220: /**
221: * Build the summary for the enums in this package.
222: */
223: public void buildEnumSummary() {
224: ClassDoc[] enums = packageDoc.isIncluded() ? packageDoc.enums()
225: : configuration.classDocCatalog.enums(Util
226: .getPackageName(packageDoc));
227: if (enums.length > 0) {
228: packageWriter.writeClassesSummary(enums, configuration
229: .getText("doclet.Enum_Summary"));
230: }
231: }
232:
233: /**
234: * Build the summary for the exceptions in this package.
235: */
236: public void buildExceptionSummary() {
237: ClassDoc[] exceptions = packageDoc.isIncluded() ? packageDoc
238: .exceptions() : configuration.classDocCatalog
239: .exceptions(Util.getPackageName(packageDoc));
240: if (exceptions.length > 0) {
241: packageWriter.writeClassesSummary(exceptions, configuration
242: .getText("doclet.Exception_Summary"));
243: }
244: }
245:
246: /**
247: * Build the summary for the errors in this package.
248: */
249: public void buildErrorSummary() {
250: ClassDoc[] errors = packageDoc.isIncluded() ? packageDoc
251: .errors() : configuration.classDocCatalog.errors(Util
252: .getPackageName(packageDoc));
253: if (errors.length > 0) {
254: packageWriter.writeClassesSummary(errors, configuration
255: .getText("doclet.Error_Summary"));
256: }
257: }
258:
259: /**
260: * Build the footer of the summary.
261: */
262: public void buildPackageFooter() {
263: packageWriter.writePackageFooter();
264: }
265: }
|