/** * Entry-point for obtaining singleton instance of Factory. The default factory class * that will be instantiated can be overridden with the environment * entry <code>sitemesh.factory</code>. */ public static Factory getInstance(Config config) { Factory instance = (Factory)config.getServletContext().getAttribute(SITEMESH_FACTORY); if (instance == null) { String factoryClass = getEnvEntry("sitemesh.factory", "com.opensymphony.module.sitemesh.factory.DefaultFactory"); try { Class cls = ClassLoaderUtil.loadClass(factoryClass, config.getClass()); Constructor con = cls.getConstructor(new Class[] { Config.class }); instance = (Factory)con.newInstance(new Config[] { config }); config.getServletContext().setAttribute(SITEMESH_FACTORY, instance); } catch (InvocationTargetException e) { throw new FactoryException("Cannot construct Factory : " + factoryClass, e.getTargetException()); } catch (Exception e) { throw new FactoryException("Cannot construct Factory : " + factoryClass, e); } } instance.refresh(); return instance; }