001    package hirondelle.web4j.config;
002    
003    import javax.servlet.ServletConfig;
004    import hirondelle.web4j.StartupTasks;
005    import hirondelle.web4j.database.DAOException;
006    import hirondelle.web4jtools.codegenerator.action.ActionAction;
007    import hirondelle.web4jtools.codegenerator.codes.Enumerations;
008    import hirondelle.web4jtools.util.SaveToFile;
009    import hirondelle.web4jtools.metrics.base.FileInfo;
010    import hirondelle.web4jtools.metrics.comments.CommentsAction;
011    import hirondelle.web4jtools.logview.directories.LogInfoDAO;
012    import hirondelle.web4jtools.logview.simpleview.LogFileDAO;
013    import hirondelle.web4jtools.metrics.tabs.TabsRemoveAction;
014    import hirondelle.web4jtools.metrics.base.BaseInfoDAO;
015    
016    /** Implementation of {@link StartupTasks}, required by WEB4J.  */
017    public final class Startup implements StartupTasks {
018    
019      /** 
020      * Perform startup tasks.
021      *
022      * Calls {@link #lookUpCodeTablesAndPlaceIntoAppScope()}, and calls various static initialization methods.
023      * This method passes around access to the config settings in <tt>web.xml</tt>.
024      */
025      public void startApplication(ServletConfig aConfig, String aDbName) throws DAOException {
026        //has no databases, so no need to branch here
027        fConfig = aConfig;
028        lookUpCodeTablesAndPlaceIntoAppScope();
029        SaveToFile.readConfig(fConfig);
030        ActionAction.readConfig(fConfig);
031        FileInfo.readConfig(fConfig);
032        CommentsAction.readConfig(fConfig);
033        BaseInfoDAO.readConfig(fConfig);
034        LogInfoDAO.readConfig(fConfig);
035        LogFileDAO.readConfig(fConfig);
036        TabsRemoveAction.readConfig(fConfig);
037      }
038      
039      /**
040      * Called upon startup, and when the content of a code table changes.
041      *
042      * <P>Refreshes the copies of code tables placed in application scope.
043      * <em>(In this case, the code tables are enums, and are never changed after application
044      * startup. However, this style is retained, since it is both simple, and possibly useful 
045      * for future use.)</em>
046      */
047      public static void lookUpCodeTablesAndPlaceIntoAppScope() throws DAOException {
048        Enumerations.init(fConfig.getServletContext());
049      }
050      
051      // PRIVATE //
052      private static ServletConfig fConfig;
053    }