JForum.java可以称为是jforum的引擎,它继承自net.jforum.JForumBaseServlet类,并间接的继承了HttpServlet。当第一次请求该应用的时候,servlet容器将加载该类,并调用其初始化方法init(ServletConfig config),并调用service方法处理请求。(但最好配置成加载应用的时候就初始化该类) 一、init(ServletConfig config) (一)调用其父类init(config)方法 该方法主要职责是加载主要配置文件,配置jfreemarker的模板引擎,并保存到net.jforum. JForumExecutionContext类。 详细内容包括: | |
4.调用ConfigLoader.startSystemglobals(appPath)加载全局变量文件SystemGlobals.properties以及用户自定义的配置文件,例如,mysql.properties文件。
5.调用ConfigLoader.startCacheEngine()启动缓存引擎 a、获取缓存引擎实现类,SystemGlobals.getValue(…) b、加载并初始化缓存引擎类 c、获取、加载并实例化可缓存的对象(主要是repository包下的类,如ForumRepository),同时将缓存引擎实例注入到可缓存的对象中。 6.创建freemark的Configuration类实例,并进行相应设置 调用ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR)),加载modulesMapping.properties模块映射文件 7.调用this.loadConfigStuff()方法,加载其他属性文件 ConfigLoader.loadUrlPatterns(),加载urlPattern.properties文件 (二)调用父类startApplication()方法 1.SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));加载generic_quries.sql文件 2.SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));加载相应数据库的sql文件 3.String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG); 4.SystemGlobals.loadAdditionalDefaults(filename); 5.加载任务调度文件quartz-jforum.properites 6.ConfigLoader.createLoginAuthenticator(); 7.创建net.jforum.sso.DefaultLoginAuthenticator对象,并注册到SystemGlobals对象中。 8.ConfigLoader.loadDaoImplementation(); 9.加载并初始化net.jforum.dao.mysql.MysqlDataAccessDriver类,该类是访问各种DAO入口。 10.ConfigLoader.listenForChanges(); 11.ConfigLoader.startSearchIndexer(); 12.ConfigLoader.startSummaryJob(); (三)调用ForumStartup.startDatabase()方法 创建DBConnection实例 加载论坛主要信息,包括ForumDAO, CategoryDAO, ConfigDAO的相关信息以及论坛的总体数据(loadUsersInfo()如用户总数, (八)SmiliesRepository.loadSmilies() (九)BanlistRepository.loadBanlist() 二、service(HttpServletRequest req, HttpServletResponse res)方法 (二)实例化JForumContext对象forumContext = new JForumContext(request.getContextPath(),SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION), request, response); (三)将forumContext注册到JForumExecutionContext ex = JForumExecutionContext.get();ex.setForumContext(forumContext); JForumExecutionContext.set(ex); (四)进一步进行freemarker的配置模板引擎 ontrollerUtils utils = new ControllerUtils(); 获取moduleClass所对应的Command对象实例 三.几个重要java类 1.net.jforum.util.preferences.SystemGlobls.java 存储了系统的全局变量,通过该类可以获取SystemGlobals.properties和相关配置文件的值。主要存储内容包括: defaults = new Properties(),用于存储SystemGlobals.properties中的属性 installation = new Properties(),用于存储额外的属性配置文件,主要是安装jforum时候生成的jforum-custom.conf文件。 additionalDefaultsList = new ArrayList(),用于记录所加载过的附加的属性文件名。 queries = new Properties(),用于存储sql语句 transientValues = new Properties()存放瞬时变量 objectProperties = new HashMap(),存储对象 2.net.jforum.ConfigLoader.java 加载forum配置文件的通用工具类。主要方法及作用如下: startSystemglobals(String appPath) 该方法调用了SystemGlobals的方法加载了SystemGlobals.properties、jforum-custom.cof、mysql.properties文件。 startCacheEngine() loadModulesMapping(String baseConfigDir)加载 ModulesMapping.proerties。 |
jforum初始化
最新推荐文章于 2024-10-05 18:40:41 发布