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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 798
4868a36f6fd8
child 1359
25e14ad23cef
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

     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  * This code is not part of an API.
    46  * It is implementation that is subject to change.
    47  * Do not use it as an API
    48  *
    49  * @author Jamie Ho
    50  * @since 1.5
    51  */
    53 public abstract class AbstractBuilder {
    55     /**
    56      * The configuration used in this run of the doclet.
    57      */
    58     protected Configuration configuration;
    60     /**
    61      * Keep track of which packages we have seen for
    62      * efficiency purposes.  We don't want to copy the
    63      * doc files multiple times for a single package.
    64      */
    65     protected static Set<String> containingPackagesSeen;
    67     /**
    68      * True if we want to print debug output.
    69      */
    70     protected static final boolean DEBUG = false;
    72     /**
    73      * Construct a Builder.
    74      * @param configuration the configuration used in this run
    75      *        of the doclet.
    76      */
    77     public AbstractBuilder(Configuration configuration) {
    78         this.configuration = configuration;
    79     }
    81     /**
    82      * Return the name of this builder.
    83      *
    84      * @return the name of the builder.
    85      */
    86     public abstract String getName();
    88     /**
    89      * Build the documentation.
    90      *
    91      * @throws IOException there was a problem writing the output.
    92      */
    93     public abstract void build() throws IOException;
    95     /**
    96      * Build the documentation, as specified by the given XML element.
    97      *
    98      * @param node the XML element that specifies which component to document.
    99      * @param contentTree content tree to which the documentation will be added
   100      */
   101     protected void build(XMLNode node, Content contentTree) {
   102         String component = node.name;
   103         try {
   104             invokeMethod("build" + component,
   105                     new Class<?>[]{XMLNode.class, Content.class},
   106                     new Object[]{node, contentTree});
   107         } catch (NoSuchMethodException e) {
   108             e.printStackTrace();
   109             configuration.root.printError("Unknown element: " + component);
   110             throw new DocletAbortException();
   111         } catch (InvocationTargetException e) {
   112             e.getCause().printStackTrace();
   113         } catch (Exception e) {
   114             e.printStackTrace();
   115             configuration.root.printError("Exception " +
   116                     e.getClass().getName() +
   117                     " thrown while processing element: " + component);
   118             throw new DocletAbortException();
   119         }
   120     }
   122     /**
   123      * Build the documentation, as specified by the children of the given XML element.
   124      *
   125      * @param node the XML element that specifies which components to document.
   126      * @param contentTree content tree to which the documentation will be added
   127      */
   128     protected void buildChildren(XMLNode node, Content contentTree) {
   129         for (XMLNode child : node.children)
   130             build(child, contentTree);
   131     }
   133     /**
   134      * Given the name and parameters, invoke the method in the builder.  This
   135      * method is required to invoke the appropriate build method as instructed
   136      * by the builder XML file.
   137      *
   138      * @param methodName   the name of the method that we would like to invoke.
   139      * @param paramClasses the types for each parameter.
   140      * @param params       the parameters of the method.
   141      */
   142     protected void invokeMethod(String methodName, Class<?>[] paramClasses,
   143             Object[] params)
   144     throws Exception {
   145         if (DEBUG) {
   146             configuration.root.printError("DEBUG: " + this.getClass().getName() + "." + methodName);
   147         }
   148         Method method = this.getClass().getMethod(methodName, paramClasses);
   149         method.invoke(this, params);
   150     }
   151 }

mercurial