⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dwrnamespacehandler.java

📁 反向的AJAX。最大的特性是我们成为反向的Ajax。DWR1.x允许你用javascript异步的访问java代码。DWR2.0在这上允许你建立异步java访问javascript代码。 反向的Aj
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }    }    /**     * Parse the <code>&lt;dwr:init&gt;</code> elements     */    protected class InitDefinitionDecorator implements BeanDefinitionDecorator    {        public BeanDefinitionHolder decorate(Node parent, BeanDefinitionHolder definition, ParserContext parserContext)        {                       Map converters = new HashMap();            Map creators = new HashMap();            NodeList inits = parent.getChildNodes();            for (int j = 0; j < inits.getLength(); j++)            {                Node node = inits.item(j);                if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE)                {                    continue;                }                Element child = (Element)inits.item(j);                if (child.getNodeName().equals(ELEMENT_CREATOR))                {                    String id = child.getAttribute(ATTRIBUTE_ID);                    String className = child.getAttribute(ATTRIBUTE_CLASS);                    creators.put(id, className);                }                else if (child.getNodeName().equals(ELEMENT_CONVERTER))                {                    String id = child.getAttribute(ATTRIBUTE_ID);                    String className = child.getAttribute(ATTRIBUTE_CLASS);                    converters.put(id, className);                }                else                {                    throw new RuntimeException("An unknown sub node '" + child.getNodeName() +                             "' was found while parsing dwr:init");                }            }                        BeanDefinition configurator = registerSpringConfiguratorIfNecessary(parserContext.getRegistry());            configurator.getPropertyValues().addPropertyValue("creatorTypes", creators);            configurator.getPropertyValues().addPropertyValue("converterTypes", converters);            return definition;        }    }        /**     * Uses the BeanDefinitionDecorator since we need access to the name of the parent definition??     * Register the creatores: spring, new, null, scripted, jsf, struts, pageflow     */    protected class CreatorBeanDefinitionDecorator implements BeanDefinitionDecorator    {                public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext)        {            Element element = (Element) node;            String javascript = element.getAttribute("javascript");            String creatorType = element.getAttribute("type");            BeanDefinitionBuilder creatorConfig = BeanDefinitionBuilder.rootBeanDefinition(CreatorConfig.class);                        // Configure "known" creators in the CreatorConfig. If unknown then just create the configuration            // and leave it up DWR itself to decide if it's a valid creator type            BeanDefinitionBuilder creator;            Map params = new HashMap();                        if ("spring".equals(creatorType))            {                // TODO Refactor so that both spring creators use the same code...                BeanDefinitionBuilder springCreator = BeanDefinitionBuilder.rootBeanDefinition(BeanCreator.class);                                springCreator.addPropertyValue("javascript", javascript);                                NodeList children = element.getChildNodes();                for (int i = 0; i < children.getLength(); i++)                {                    Node childNode = children.item(i);                    if (childNode.getNodeType() == Node.TEXT_NODE || childNode.getNodeType() == Node.COMMENT_NODE)                    {                        continue;                    }                                        Element child = (Element) childNode;                    String paramName = child.getAttribute("name");                    String value = child.getAttribute("value");                    if ("beanName".equals(paramName) || "beanId".equals(paramName)) {                        springCreator.addPropertyValue("beanId", value);                    } else {                        params.put(paramName, value);                        }                }                                creatorConfig.addPropertyValue("creator", springCreator.getBeanDefinition());                     }            else if ("new".equals(creatorType))            {                creator = BeanDefinitionBuilder.rootBeanDefinition(NewCreator.class);                creator.addPropertyValue("className", node.getAttributes().getNamedItem("class").getNodeValue());                creator.addPropertyValue("javascript", javascript);                creatorConfig.addPropertyValue("creator", creator.getBeanDefinition());            }            else if ("null".equals(creatorType))            {                creatorConfig.addPropertyValue("creatorType", "none");                String className = element.getAttribute("class");                if (className == null || "".equals(className))                 {                    throw new BeanInitializationException("'class' is a required attribute for the declaration <dwr:creator type=\"null\"" +                             " javascript=\"" + javascript + "\" ... />");                }                params.put("class", className);            }            else if ("pageflow".equals(creatorType))            {                creatorConfig.addPropertyValue("creatorType", creatorType);            }            else if ("jsf".equals(creatorType) || "scripted".equals(creatorType) || "struts".equals(creatorType))            {                creatorConfig.addPropertyValue("creatorType", creatorType);            }            else            {                if (log.isDebugEnabled())                {                    log.debug("Looking up creator type '" + creatorType + "'");                }                // TODO We should delay the initialization of the creatorClass until after the bean                 // definitions have been parsed.                  BeanDefinition configurator = registerSpringConfiguratorIfNecessary(parserContext.getRegistry());                PropertyValue registeredCreators = configurator.getPropertyValues().getPropertyValue("creatorTypes");                Map registeredCreatorMap = (Map)registeredCreators.getValue();                String creatorClass = (String)registeredCreatorMap.get(creatorType);                if (creatorClass == null)                {                    // the creator type should have been registered                    throw new UnsupportedOperationException("Type " + creatorType + " is not supported " +                             " or the custom creator has not been registered dwr:init");                                    }                 else                 {                    try                     {                        Class clazz = Class.forName(creatorClass);                        creator = BeanDefinitionBuilder.rootBeanDefinition(clazz);                        creatorConfig.addPropertyValue("creator", creator.getBeanDefinition());                        String className = element.getAttribute("class");                        if (StringUtils.hasText(className))                        {                            params.put("class", className);                        }                    }                     catch (ClassNotFoundException ex)                     {                        throw new FatalBeanException("ClassNotFoundException trying to register " +                                  " creator '" + creatorClass +  "' for javascript type '" + javascript +"'. Check the " +                                 " class in the classpath and that the creator is register in dwr:init", ex);                    }                }            }            registerCreator(parserContext.getRegistry(), javascript, creatorConfig, params, node.getChildNodes());            return definition;        }    }    protected class SignaturesBeanDefinitionDecorator implements BeanDefinitionDecorator    {        public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext)        {            BeanDefinitionRegistry registry = parserContext.getRegistry();            BeanDefinition config = registerSpringConfiguratorIfNecessary(registry);            StringBuffer sigtext = new StringBuffer();            NodeList children = node.getChildNodes();            for (int i = 0; i < children.getLength(); i++)            {                Node child = children.item(i);                if (child.getNodeType() != Node.TEXT_NODE && child.getNodeType() != Node.CDATA_SECTION_NODE)                {                    log.warn("Ignoring illegal node type: " + child.getNodeType());                    continue;                }                sigtext.append(child.getNodeValue());            }            config.getPropertyValues().addPropertyValue("signatures", sigtext.toString());            return definition;        }    }    protected Map lookupCreators(BeanDefinitionRegistry registry)    {        BeanDefinition config = registerSpringConfiguratorIfNecessary(registry);        return (Map) config.getPropertyValues().getPropertyValue("creators").getValue();    }    protected Map lookupConverters(BeanDefinitionRegistry registry)    {        BeanDefinition config = registerSpringConfiguratorIfNecessary(registry);        return (Map) config.getPropertyValues().getPropertyValue("converters").getValue();    }    protected final static String DEFAULT_SPRING_CONFIGURATOR_ID = "__dwrConfiguration";    /**     * The log stream     */    protected static final Logger log = Logger.getLogger(DwrNamespaceHandler.class);        /*     * The element names     */    private static final String ELEMENT_CONVERTER = "dwr:converter";        private static final String ELEMENT_CREATOR = "dwr:creator";        /*     * The attribute names     */    private static final String ATTRIBUTE_ID = "id";    private static final String ATTRIBUTE_CLASS = "class";        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -