author | mcimadamore |
Tue, 13 Jan 2009 13:27:14 +0000 | |
changeset 1789 | 7ac8c0815000 |
parent 1264 | 076a3cde30d5 |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
1264 | 2 |
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
10 | 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 |
*/ |
|
25 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.builders; |
|
27 |
||
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.*; |
|
33 |
||
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 |
*/ |
|
51 |
||
52 |
public abstract class AbstractBuilder { |
|
53 |
||
54 |
/** |
|
55 |
* The configuration used in this run of the doclet. |
|
56 |
*/ |
|
57 |
protected Configuration configuration; |
|
58 |
||
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 |
*/ |
|
868 | 64 |
protected static Set<String> containingPackagesSeen; |
10 | 65 |
|
66 |
/** |
|
67 |
* True if we want to print debug output. |
|
68 |
*/ |
|
69 |
protected static final boolean DEBUG = false; |
|
70 |
||
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 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Return the name of this builder. |
|
82 |
* |
|
83 |
* @return the name of the builder. |
|
84 |
*/ |
|
85 |
public abstract String getName(); |
|
86 |
||
87 |
/** |
|
88 |
* Build the documentation. |
|
89 |
* |
|
90 |
* @throws IOException there was a problem writing the output. |
|
91 |
*/ |
|
92 |
public abstract void build() throws IOException; |
|
93 |
||
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 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
100 |
protected void build(List<?> elements) { |
10 | 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 : |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
106 |
((List<?>) element).get(0)); |
10 | 107 |
try { |
108 |
invokeMethod("build" + component, |
|
109 |
element instanceof String ? |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
110 |
new Class<?>[] {} : |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
111 |
new Class<?>[] {List.class}, |
10 | 112 |
element instanceof String ? |
113 |
new Object[] {} : |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
114 |
new Object[] {((List<?>) element).subList(1, |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
115 |
((List<?>) element).size())}); |
10 | 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 |
} |
|
131 |
||
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 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
141 |
protected abstract void invokeMethod(String methodName, Class<?>[] paramClasses, |
10 | 142 |
Object[] params) |
143 |
throws Exception; |
|
144 |
} |