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