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

Fri, 18 Jun 2010 21:13:56 -0700

author
jjg
date
Fri, 18 Jun 2010 21:13:56 -0700
changeset 589
4177f5bdd189
parent 554
9d9f26857129
child 766
90af8d87741f
permissions
-rw-r--r--

6961178: Allow doclet.xml to contain XML attributes
Reviewed-by: bpatel

     1 /*
     2  * Copyright (c) 2003, 2008, 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 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 element.
    96      *
    97      * @param node the XML element that specifies which component to document.
    98      */
    99     protected void build(XMLNode node) {
   100         String component = node.name;
   101         try {
   102             invokeMethod("build" + component,
   103                     new Class<?>[] { XMLNode.class },
   104                     new Object[] { node });
   105         } catch (NoSuchMethodException e) {
   106             e.printStackTrace();
   107             configuration.root.printError("Unknown element: " + component);
   108             throw new DocletAbortException();
   109         } catch (InvocationTargetException e) {
   110             e.getCause().printStackTrace();
   111         } catch (Exception e) {
   112             e.printStackTrace();
   113             configuration.root.printError("Exception " +
   114                 e.getClass().getName() +
   115                 " thrown while processing element: " + component);
   116             throw new DocletAbortException();
   117         }
   118     }
   120     /**
   121      * Build the documentation, as specified by the children of the given XML element.
   122      *
   123      * @param node the XML element that specifies which components to document.
   124      */
   125     protected void buildChildren(XMLNode node) {
   126         for (XMLNode child: node.children)
   127             build(child);
   128     }
   130     /**
   131      * Given the name and parameters, invoke the method in the builder.  This
   132      * method is required to invoke the appropriate build method as instructed
   133      * by the builder XML file.
   134      *
   135      * @param methodName   the name of the method that we would like to invoke.
   136      * @param paramClasses the types for each parameter.
   137      * @param params       the parameters of the method.
   138      */
   139     protected void invokeMethod(String methodName, Class<?>[] paramClasses,
   140             Object[] params)
   141     throws Exception {
   142         if (DEBUG) {
   143             configuration.root.printError("DEBUG: " + this.getClass().getName()
   144                 + "." + methodName);
   145         }
   146         Method method = this.getClass().getMethod(methodName, paramClasses);
   147         method.invoke(this, params);
   148     }
   149 }

mercurial