Thu, 15 Nov 2012 09:18:36 -0800
8000800: javadoc uses static non-final fields
Reviewed-by: bpatel
1 /*
2 * Copyright (c) 2003, 2012, 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 java.io.*;
29 import java.lang.reflect.*;
30 import java.util.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
33 import com.sun.tools.doclets.internal.toolkit.util.*;
35 /**
36 * The superclass for all builders. A builder is a class that provides
37 * the structure and content of API documentation. A builder is completely
38 * doclet independent which means that any doclet can use builders to
39 * construct documentation, as long as it impelements the appropriate
40 * writer interfaces. For example, if a doclet wanted to use
41 * {@link ConstantsSummaryBuilder} to build a constant summary, all it has to
42 * do is implement the ConstantsSummaryWriter interface and pass it to the
43 * builder using a WriterFactory.
44 *
45 * <p><b>This is NOT part of any supported API.
46 * If you write code that depends on this, you do so at your own risk.
47 * This code and its internal interfaces are subject to change or
48 * deletion without notice.</b>
49 *
50 * @author Jamie Ho
51 * @since 1.5
52 */
54 public abstract class AbstractBuilder {
55 public static class Context {
56 /**
57 * The configuration used in this run of the doclet.
58 */
59 final Configuration configuration;
61 /**
62 * Keep track of which packages we have seen for
63 * efficiency purposes. We don't want to copy the
64 * doc files multiple times for a single package.
65 */
66 final Set<String> containingPackagesSeen;
68 /**
69 * Shared parser for the builder XML file
70 */
71 final LayoutParser layoutParser;
73 Context(Configuration configuration,
74 Set<String> containingPackagesSeen,
75 LayoutParser layoutParser) {
76 this.configuration = configuration;
77 this.containingPackagesSeen = containingPackagesSeen;
78 this.layoutParser = layoutParser;
79 }
80 }
82 /**
83 * The configuration used in this run of the doclet.
84 */
85 protected final Configuration configuration;
87 /**
88 * Keep track of which packages we have seen for
89 * efficiency purposes. We don't want to copy the
90 * doc files multiple times for a single package.
91 */
92 protected final Set<String> containingPackagesSeen;
94 protected final LayoutParser layoutParser;
96 /**
97 * True if we want to print debug output.
98 */
99 protected static final boolean DEBUG = false;
101 /**
102 * Construct a Builder.
103 * @param configuration the configuration used in this run
104 * of the doclet.
105 */
106 public AbstractBuilder(Context c) {
107 this.configuration = c.configuration;
108 this.containingPackagesSeen = c.containingPackagesSeen;
109 this.layoutParser = c.layoutParser;
110 }
112 /**
113 * Return the name of this builder.
114 *
115 * @return the name of the builder.
116 */
117 public abstract String getName();
119 /**
120 * Build the documentation.
121 *
122 * @throws IOException there was a problem writing the output.
123 */
124 public abstract void build() throws IOException;
126 /**
127 * Build the documentation, as specified by the given XML element.
128 *
129 * @param node the XML element that specifies which component to document.
130 * @param contentTree content tree to which the documentation will be added
131 */
132 protected void build(XMLNode node, Content contentTree) {
133 String component = node.name;
134 try {
135 invokeMethod("build" + component,
136 new Class<?>[]{XMLNode.class, Content.class},
137 new Object[]{node, contentTree});
138 } catch (NoSuchMethodException e) {
139 e.printStackTrace();
140 configuration.root.printError("Unknown element: " + component);
141 throw new DocletAbortException();
142 } catch (InvocationTargetException e) {
143 e.getCause().printStackTrace();
144 } catch (Exception e) {
145 e.printStackTrace();
146 configuration.root.printError("Exception " +
147 e.getClass().getName() +
148 " thrown while processing element: " + component);
149 throw new DocletAbortException();
150 }
151 }
153 /**
154 * Build the documentation, as specified by the children of the given XML element.
155 *
156 * @param node the XML element that specifies which components to document.
157 * @param contentTree content tree to which the documentation will be added
158 */
159 protected void buildChildren(XMLNode node, Content contentTree) {
160 for (XMLNode child : node.children)
161 build(child, contentTree);
162 }
164 /**
165 * Given the name and parameters, invoke the method in the builder. This
166 * method is required to invoke the appropriate build method as instructed
167 * by the builder XML file.
168 *
169 * @param methodName the name of the method that we would like to invoke.
170 * @param paramClasses the types for each parameter.
171 * @param params the parameters of the method.
172 */
173 protected void invokeMethod(String methodName, Class<?>[] paramClasses,
174 Object[] params)
175 throws Exception {
176 if (DEBUG) {
177 configuration.root.printError("DEBUG: " + this.getClass().getName() + "." + methodName);
178 }
179 Method method = this.getClass().getMethod(methodName, paramClasses);
180 method.invoke(this, params);
181 }
182 }