containerutil.java
来自「反向的AJAX。最大的特性是我们成为反向的Ajax。DWR1.x允许你用java」· Java 代码 · 共 601 行 · 第 1/2 页
JAVA
601 行
foundConfig = true; try { Configurator configurator = (Configurator) LocalUtil.classNewInstance(INIT_CUSTOM_CONFIGURATOR, value, Configurator.class); configurator.configure(container); log.debug("Loaded config from: " + value); } catch (Exception ex) { log.warn("Failed to start custom configurator", ex); } } } return foundConfig; } /** * Annotations must not break 1.3, so we use reflection to create an * <code>org.directwebremoting.annotations.AnnotationsConfigurator</code> * and the catch all sorts of random exceptions for the benefit of * Websphere. * @param container The container to configure * @return true if the configuration worked. */ public static boolean configureFromAnnotations(Container container) { try { Class annotationCfgClass = LocalUtil.classForName("org.directwebremoting.annotations.AnnotationsConfigurator"); Configurator configurator = (Configurator) annotationCfgClass.newInstance(); configurator.configure(container); log.debug("Java5 AnnotationsConfigurator enabled"); return true; } catch (UnsupportedClassVersionError ex) { // This will happen in JDK 1.4 and below return false; } catch (ClassNotFoundException ex) { // This will happen when run in an IDE without the java5 tree log.warn("AnnotationsConfigurator is missing. Are you running from within an IDE?"); return false; } catch (Exception ex) { // This happens if there is a bug in AnnotationsConfigurator log.warn("Failed to start annotations", ex); return false; } catch (Throwable ex) { if (ex.getClass().getName().equals(UnsupportedClassVersionError.class.getName())) { log.error("Caught impossible Throwable", ex); return false; } else if (ex.getClass().getName().equals(LinkageError.class.getName())) { log.error("Caught impossible Throwable", ex); return false; } else if (ex instanceof Error) { log.fatal("Rethrowing Error:" + ex); throw (Error) ex; } else { // This can't happen: We've handled all Exceptions, and // Errors, so we can't get to execute this code. log.error("Ilogical catch state", ex); return false; } } } /** * Allow all the configurators to have a go at the container in turn * @param container The container to configure * @param configurators A list of configurators to run against the container */ public static void configure(Container container, List configurators) { // Allow all the configurators to have a go for (Iterator it = configurators.iterator(); it.hasNext();) { Configurator configurator = (Configurator) it.next(); log.debug("** Adding config from " + configurator); configurator.configure(container); } } /** * Run all the default configuration options on a Container * @param container The container to configure * @param servletConfig The source of init parameters * @throws SAXException If the config file parse fails * @throws ParserConfigurationException If the config file parse fails * @throws IOException If the config file read fails */ public static void configureContainerFully(Container container, ServletConfig servletConfig) throws IOException, ParserConfigurationException, SAXException { configureFromSystemDwrXml(container); boolean foundConfig = configureFromInitParams(container, servletConfig); // The default dwr.xml file that sits by web.xml boolean skip = Boolean.valueOf(servletConfig.getInitParameter(INIT_SKIP_DEFAULT)).booleanValue(); IOException delayedIOException = null; if (!foundConfig && !skip) { try { configureFromDefaultDwrXml(container); } catch (IOException ex) { // This is fatal unless we are on JDK5+ AND using annotations delayedIOException = ex; } } if (!configureFromAnnotations(container)) { log.debug("Java5 AnnotationsConfigurator disabled"); if (delayedIOException != null) { throw delayedIOException; } } } /** * If helps some situations if people can get at the container by looking * in the servlet context, under some name. * The name is specified in an initParameter. * @param container The container to publish * @param servletConfig Source of initParams to dictate publishing and contexts to publish to */ public static void publishContainer(Container container, ServletConfig servletConfig) { ServletContext servletContext = servletConfig.getServletContext(); String publishName = servletConfig.getInitParameter(INIT_PUBLISH_CONTAINER); if (publishName != null) { servletContext.setAttribute(publishName, container); } List containers = (List) servletContext.getAttribute(ATTRIBUTE_CONTAINER_LIST); if (containers == null) { containers = new ArrayList(); } containers.add(container); servletContext.setAttribute(ATTRIBUTE_CONTAINER_LIST, containers); } /** * Get a list of all known Containers for the given {@link ServletContext} * @param servletContext The context in which {@link Container}s are stored. * @return a list of published {@link Container}s. */ public static List getAllPublishedContainers(ServletContext servletContext) { List containers = (List) servletContext.getAttribute(ATTRIBUTE_CONTAINER_LIST); if (containers == null) { containers = new ArrayList(); } return containers; } /** * Internal use only. * <p>If we detect that the server is being shutdown then we want to kill * any reverse ajax threads. * @param containers The list of containers to look for ServerLoadMonitors in * @param title What causes this (for debug purposes) */ public static void shutdownServerLoadMonitorsInContainerList(List containers, String title) { if (containers == null || containers.size() == 0) { log.debug("No containers to shutdown for: " + title); return; } log.debug("Shutting down containers for: " + title); for (Iterator it = containers.iterator(); it.hasNext();) { Container container = (Container) it.next(); ServerLoadMonitor monitor = (ServerLoadMonitor) container.getBean(ServerLoadMonitor.class.getName()); monitor.shutdown(); } } /** * Create a bunch of debug information about a container * @param container The container to print debug information about */ public static void debugConfig(Container container) { if (log.isDebugEnabled()) { // Container level debug log.debug("Container"); log.debug(" Type: " + container.getClass().getName()); Collection beanNames = container.getBeanNames(); for (Iterator it = beanNames.iterator(); it.hasNext();) { String name = (String) it.next(); Object object = container.getBean(name); if (object instanceof String) { log.debug(" Param: " + name + " = " + object + " (" + object.getClass().getName() + ")"); } else { log.debug(" Bean: " + name + " = " + object + " (" + object.getClass().getName() + ")"); } } // AccessControl debugging AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName()); log.debug("AccessControl"); log.debug(" Type: " + accessControl.getClass().getName()); // AjaxFilterManager debugging AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName()); log.debug("AjaxFilterManager"); log.debug(" Type: " + ajaxFilterManager.getClass().getName()); // ConverterManager debugging ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName()); log.debug("ConverterManager"); log.debug(" Type: " + converterManager.getClass().getName()); // CreatorManager debugging CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName()); log.debug("CreatorManager"); log.debug(" Type: " + creatorManager.getClass().getName()); Collection creatorNames = creatorManager.getCreatorNames(); for (Iterator it = creatorNames.iterator(); it.hasNext();) { String creatorName = (String) it.next(); Creator creator = creatorManager.getCreator(creatorName); log.debug(" Creator: " + creatorName + " = " + creator + " (" + creator.getClass().getName() + ")"); } } } /** * Init parameter: Set a dwr.xml config file. * This is only a prefix since we might have more than 1 config file. */ public static final String INIT_CONFIG = "config"; /** * Init parameter: Skip reading the default config file if none are specified. */ public static final String INIT_SKIP_DEFAULT = "skipDefaultConfig"; /** * Init parameter: If we are doing Servlet.log logging, to what level? */ public static final String INIT_LOGLEVEL = "logLevel"; /** * Init parameter: Should we publish the {@link Container} to the servlet * context, and if so, under what name? */ public static final String INIT_PUBLISH_CONTAINER = "publishContainerAs"; /** * Init parameter: If you wish to use a custom configurator, place its * class name here */ public static final String INIT_CUSTOM_CONFIGURATOR = "customConfigurator"; /** * The name under which we publish all {@link Container}s. */ public static final String ATTRIBUTE_CONTAINER_LIST = "org.directwebremoting.ContainerList"; /** * The log stream */ private static final Logger log = Logger.getLogger(ContainerUtil.class);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?