Thu, 02 Oct 2008 19:58:40 -0700
6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell
1 /*
2 * Copyright 2003-2008 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.doclets.internal.toolkit.builders;
28 import com.sun.tools.doclets.internal.toolkit.*;
29 import com.sun.tools.doclets.internal.toolkit.util.*;
30 import java.io.*;
31 import java.lang.reflect.*;
32 import java.util.*;
34 /**
35 * The superclass for all builders. A builder is a class that provides
36 * the structure and content of API documentation. A builder is completely
37 * doclet independent which means that any doclet can use builders to
38 * construct documentation, as long as it impelements the appropriate
39 * writer interfaces. For example, if a doclet wanted to use
40 * {@link ConstantsSummaryBuilder} to build a constant summary, all it has to
41 * do is implement the ConstantsSummaryWriter interface and pass it to the
42 * builder using a WriterFactory.
43 *
44 * This code is not part of an API.
45 * It is implementation that is subject to change.
46 * Do not use it as an API
47 *
48 * @author Jamie Ho
49 * @since 1.5
50 */
52 public abstract class AbstractBuilder {
54 /**
55 * The configuration used in this run of the doclet.
56 */
57 protected Configuration configuration;
59 /**
60 * Keep track of which packages we have seen for
61 * efficiency purposes. We don't want to copy the
62 * doc files multiple times for a single package.
63 */
64 protected static Set<String> containingPackagesSeen;
66 /**
67 * True if we want to print debug output.
68 */
69 protected static final boolean DEBUG = false;
71 /**
72 * Construct a Builder.
73 * @param configuration the configuration used in this run
74 * of the doclet.
75 */
76 public AbstractBuilder(Configuration configuration) {
77 this.configuration = configuration;
78 }
80 /**
81 * Return the name of this builder.
82 *
83 * @return the name of the builder.
84 */
85 public abstract String getName();
87 /**
88 * Build the documentation.
89 *
90 * @throws IOException there was a problem writing the output.
91 */
92 public abstract void build() throws IOException;
94 /**
95 * Build the documentation, as specified by the given XML elements.
96 *
97 * @param elements the XML elements that specify which components to
98 * document.
99 */
100 protected void build(List elements) {
101 for (int i = 0; i < elements.size(); i++ ) {
102 Object element = elements.get(i);
103 String component = (String)
104 ((element instanceof String) ?
105 element :
106 ((List) element).get(0));
107 try {
108 invokeMethod("build" + component,
109 element instanceof String ?
110 new Class[] {} :
111 new Class[] {List.class},
112 element instanceof String ?
113 new Object[] {} :
114 new Object[] {((List) element).subList(1,
115 ((List) element).size())});
116 } catch (NoSuchMethodException e) {
117 e.printStackTrace();
118 configuration.root.printError("Unknown element: " + component);
119 throw new DocletAbortException();
120 } catch (InvocationTargetException e) {
121 e.getCause().printStackTrace();
122 } catch (Exception e) {
123 e.printStackTrace();
124 configuration.root.printError("Exception " +
125 e.getClass().getName() +
126 " thrown while processing element: " + component);
127 throw new DocletAbortException();
128 }
129 }
130 }
132 /**
133 * Given the name and parameters, invoke the method in the builder. This
134 * method is required to invoke the appropriate build method as instructed
135 * by the builder XML file.
136 *
137 * @param methodName the name of the method that we would like to invoke.
138 * @param paramClasses the types for each parameter.
139 * @param params the parameters of the method.
140 */
141 protected abstract void invokeMethod(String methodName, Class[] paramClasses,
142 Object[] params)
143 throws Exception;
144 }