Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boiler plate code between the web browser and your Java code.
/*
* Copyright 2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.directwebremoting.spring;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.create.NewCreator;
import org.directwebremoting.filter.ExtraLatencyAjaxFilter;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* The Spring namespace handler which handles all elements that are defined as
* part of the DWR namespace, except .
* The DWR namespace is defined in the spring-dwr-X.X.xsd file. All
* elements that are encountered in Spring configuration files are automatically
* converted to their actual bean representation in the Spring bean registry.
*
* @author Erik Wiersma
* @author Bram Smeets
* @author Jose Noheda
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public abstract class DwrNamespaceHandler extends NamespaceHandlerSupport
{
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
*/
public void init()
{
// register bean definition parsers and decorators for all dwr namespace elements
registerBeanDefinitionParser("configuration", new ConfigurationBeanDefinitionParser());
registerBeanDefinitionParser("controller", new ControllerBeanDefinitionParser());
registerBeanDefinitionParser("url-mapping", new UrlMappingBeanDefinitionParser());
registerBeanDefinitionDecorator("init", new InitDefinitionDecorator());
registerBeanDefinitionDecorator("create", new CreatorBeanDefinitionDecorator());
registerBeanDefinitionDecorator("convert", new ConverterBeanDefinitionDecorator());
registerBeanDefinitionDecorator("signatures", new SignaturesBeanDefinitionDecorator());
registerBeanDefinitionDecorator("remote", new RemoteBeanDefinitionDecorator());
}
protected static BeanDefinition registerSpringConfiguratorIfNecessary(BeanDefinitionRegistry registry)
{
if (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID))
{
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class);
builder.addPropertyValue("creators", new ManagedMap());
builder.addPropertyValue("converters", new ManagedMap());
registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID, builder.getBeanDefinition());
}
return registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID);
}
/**
* Registers a new {@link org.directwebremoting.extend.Creator} in the registry using name javascript.
* @param registry The definition of all the Beans
* @param javascript The name of the bean in the registry.
* @param creatorConfig
* @param params
* @param children The node list to check for nested elements
*/
@SuppressWarnings("unchecked")
protected void registerCreator(BeanDefinitionRegistry registry, String javascript, BeanDefinitionBuilder creatorConfig, Map params, NodeList children)
{
registerSpringConfiguratorIfNecessary(registry);
List includes = new ArrayList();
creatorConfig.addPropertyValue("includes", includes);
List excludes = new ArrayList();
creatorConfig.addPropertyValue("excludes", excludes);
Properties auth = new Properties();
creatorConfig.addPropertyValue("auth", auth);
// check to see if there are any nested elements here
for (int i = 0; i < children.getLength(); i++)
{
Node node = children.item(i);
if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE)
{
continue;
}
Element child = (Element) node;
if ("dwr:latencyfilter".equals(node.getNodeName()))
{
BeanDefinitionBuilder beanFilter = BeanDefinitionBuilder.rootBeanDefinition(ExtraLatencyAjaxFilter.class);
beanFilter.addPropertyValue("delay", child.getAttribute("delay"));
BeanDefinitionHolder holder2 = new BeanDefinitionHolder(beanFilter.getBeanDefinition(), "__latencyFilter_" + javascript);
BeanDefinitionReaderUtils.registerBeanDefinition(holder2, registry);
ManagedList filterList = new ManagedList();
filterList.add(new RuntimeBeanReference("__latencyFilter_" + javascript));
creatorConfig.addPropertyValue("filters", filterList);
}
else if ("dwr:include".equals(node.getNodeName()))
{
includes.add(child.getAttribute("method"));
}
else if ("dwr:exclude".equals(node.getNodeName()))
{
excludes.add(child.getAttribute("method"));
}
else if ("dwr:auth".equals(node.getNodeName()))
{
auth.setProperty(child.getAttribute("method"), child.getAttribute("role"));
}
else if ("dwr:convert".equals(node.getNodeName()))
{
Element element = (Element) node;
String type = element.getAttribute("type");
String className = element.getAttribute("class");
ConverterConfig converterConfig = new ConverterConfig();
converterConfig.setType(type);
parseConverterSettings(converterConfig, element);
lookupConverters(registry).put(className, converterConfig);
}
else if ("dwr:filter".equals(node.getNodeName()))
{
Element element = (Element) node;
String filterClass = element.getAttribute("class");
BeanDefinitionBuilder beanFilter;
try
{
beanFilter = BeanDefinitionBuilder.rootBeanDefinition(ClassUtils.forName(filterClass));
}
catch (ClassNotFoundException e)
{
throw new IllegalArgumentException("DWR filter class '" + filterClass + "' was not found. " + "Check the class name specified in exists");
}
BeanDefinitionHolder holder2 = new BeanDefinitionHolder(beanFilter.getBeanDefinition(), "__filter_" + filterClass + "_" + javascript);
BeanDefinitionReaderUtils.registerBeanDefinition(holder2, registry);
ManagedList filterList = new ManagedList();
filterList.add(new RuntimeBeanReference("__filter_" + filterClass + "_" + javascript));
creatorConfig.addPropertyValue("filters", filterList);
}
else if ("dwr:param".equals(node.getNodeName()))
{
Element element = (Element) node;
String name = element.getAttribute("name");
String value = element.getAttribute("value");
params.put(name, value);
}
else
{
throw new RuntimeException("an unknown dwr:remote sub node was fouund: " + node.getNodeName());
}
}
creatorConfig.addPropertyValue("params", params);
String creatorConfigName = "__" + javascript;
BeanDefinitionHolder holder3 = new BeanDefinitionHolder(creatorConfig.getBeanDefinition(), creatorConfigName);
BeanDefinitionReaderUtils.registerBeanDefinition(holder3, registry);
lookupCreators(registry).put(javascript, new RuntimeBeanReference(creatorConfigName));
}
protected class ConfigurationBeanDefinitionParser implements BeanDefinitionParser
{
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@SuppressWarnings("unchecked")
public BeanDefinition parse(Element element, ParserContext parserContext)
{
BeanDefinitionRegistry registry = parserContext.getRegistry();
BeanDefinition beanDefinition = registerSpringConfiguratorIfNecessary(registry);
Element initElement = DomUtils.getChildElementByTagName(element, "init");
if (initElement != null)
{
decorate(initElement, new BeanDefinitionHolder(beanDefinition, DEFAULT_SPRING_CONFIGURATOR_ID), parserContext);
}
List createElements = DomUtils.getChildElementsByTagName(element, "create");
for (Element createElement : createElements)
{
decorate(createElement, new BeanDefinitionHolder(beanDefinition, DEFAULT_SPRING_CONFIGURATOR_ID), parserContext);
}
List convertElements = DomUtils.getChildElementsByTagName(element, "convert");
for (Element convertElement : convertElements)
{
decorate(convertElement, new BeanDefinitionHolder(beanDefinition, DEFAULT_SPRING_CONFIGURATOR_ID), parserContext);
}
List signatureElements = DomUtils.getChildElementsByTagName(element, "signatures");
for (Element signatureElement : signatureElements)
{
decorate(signatureElement, new BeanDefinitionHolder(beanDefinition, DEFAULT_SPRING_CONFIGURATOR_ID), parserContext);
}
return beanDefinition;
}
}
protected static class ControllerBeanDefinitionParser implements BeanDefinitionParser
{
/* (non-Javadoc)
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@SuppressWarnings("unchecked")
public BeanDefinition parse(Element element, ParserContext parserContext)
{
BeanDefinitionBuilder dwrController = BeanDefinitionBuilder.rootBeanDefinition(DwrController.class);
List