langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
changeset 14542 7062120649c2
parent 14368 6f4c62de6985
child 14549 0599d73bf1da
equal deleted inserted replaced
14541:36f9d11fc9aa 14542:7062120649c2
    44  * @author Robert Field
    44  * @author Robert Field
    45  * @author Jamie Ho
    45  * @author Jamie Ho
    46  *
    46  *
    47  */
    47  */
    48 public class HtmlDoclet extends AbstractDoclet {
    48 public class HtmlDoclet extends AbstractDoclet {
       
    49     // An instance will be created by validOptions, and used by start.
       
    50     private static HtmlDoclet docletToStart = null;
       
    51 
    49     public HtmlDoclet() {
    52     public HtmlDoclet() {
    50         configuration = (ConfigurationImpl) configuration();
    53         configuration = new ConfigurationImpl();
    51     }
    54     }
    52 
    55 
    53     /**
    56     /**
    54      * The global configuration information for this run.
    57      * The global configuration information for this run.
    55      */
    58      */
    56     public ConfigurationImpl configuration;
    59     public final ConfigurationImpl configuration;
    57 
    60 
    58     /**
    61     /**
    59      * The "start" method as required by Javadoc.
    62      * The "start" method as required by Javadoc.
    60      *
    63      *
    61      * @param root the root of the documentation tree.
    64      * @param root the root of the documentation tree.
    62      * @see com.sun.javadoc.RootDoc
    65      * @see com.sun.javadoc.RootDoc
    63      * @return true if the doclet ran without encountering any errors.
    66      * @return true if the doclet ran without encountering any errors.
    64      */
    67      */
    65     public static boolean start(RootDoc root) {
    68     public static boolean start(RootDoc root) {
    66         try {
    69         // In typical use, options will have been set up by calling validOptions,
    67             HtmlDoclet doclet = new HtmlDoclet();
    70         // which will create an HtmlDoclet for use here.
    68             return doclet.start(doclet, root);
    71         HtmlDoclet doclet;
    69         } finally {
    72         if (docletToStart != null) {
    70             ConfigurationImpl.reset();
    73             doclet = docletToStart;
    71         }
    74             docletToStart = null;
       
    75         } else {
       
    76             doclet = new HtmlDoclet();
       
    77         }
       
    78         return doclet.start(doclet, root);
    72     }
    79     }
    73 
    80 
    74     /**
    81     /**
    75      * Create the configuration instance.
    82      * Create the configuration instance.
    76      * Override this method to use a different
    83      * Override this method to use a different
    77      * configuration.
    84      * configuration.
    78      */
    85      */
    79     public Configuration configuration() {
    86     public Configuration configuration() {
    80         return ConfigurationImpl.getInstance();
    87         return configuration;
    81     }
    88     }
    82 
    89 
    83     /**
    90     /**
    84      * Start the generation of files. Call generate methods in the individual
    91      * Start the generation of files. Call generate methods in the individual
    85      * writers, which will in turn genrate the documentation files. Call the
    92      * writers, which will in turn genrate the documentation files. Call the
   218                 prev = packages[i];
   225                 prev = packages[i];
   219             }
   226             }
   220         }
   227         }
   221     }
   228     }
   222 
   229 
       
   230     public static final ConfigurationImpl sharedInstanceForOptions =
       
   231             new ConfigurationImpl();
       
   232 
   223     /**
   233     /**
   224      * Check for doclet added options here.
   234      * Check for doclet added options here.
   225      *
   235      *
   226      * @return number of arguments to option. Zero return means
   236      * @return number of arguments to option. Zero return means
   227      * option not known.  Negative value means error occurred.
   237      * option not known.  Negative value means error occurred.
   228      */
   238      */
   229     public static int optionLength(String option) {
   239     public static int optionLength(String option) {
   230         // Construct temporary configuration for check
   240         // Construct temporary configuration for check
   231         return (ConfigurationImpl.getInstance()).optionLength(option);
   241         return sharedInstanceForOptions.optionLength(option);
   232     }
   242     }
   233 
   243 
   234     /**
   244     /**
   235      * Check that options have the correct arguments here.
   245      * Check that options have the correct arguments here.
   236      * <P>
   246      * <P>
   242      *
   252      *
   243      * @return true if the options are valid.
   253      * @return true if the options are valid.
   244      */
   254      */
   245     public static boolean validOptions(String options[][],
   255     public static boolean validOptions(String options[][],
   246             DocErrorReporter reporter) {
   256             DocErrorReporter reporter) {
   247         // Construct temporary configuration for check
   257         docletToStart = new HtmlDoclet();
   248         return (ConfigurationImpl.getInstance()).validOptions(options, reporter);
   258         return docletToStart.configuration.validOptions(options, reporter);
   249     }
   259     }
   250 
   260 
   251     /**
   261     /**
   252      * Copy a file in the resources directory to the destination directory.
   262      * Copy a file in the resources directory to the destination directory.
   253      * @param resource   The name of the resource file to copy
   263      * @param resource   The name of the resource file to copy