src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AbstractBuilder.java

Tue, 15 Jul 2008 19:22:51 -0700

author
jjg
date
Tue, 15 Jul 2008 19:22:51 -0700
changeset 74
5a9172b251dd
parent 1
9a66ca7c79fa
child 117
24a47c3062fe
permissions
-rw-r--r--

6657907: javadoc has unchecked warnings
Reviewed-by: bpatel

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

mercurial