/*
* Copyright (c) 2002-2006 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2.config.providers;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.XWorkException;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.ConfigurationProvider;
import com.opensymphony.xwork2.config.ConfigurationUtil;
import com.opensymphony.xwork2.config.entities.*;
import com.opensymphony.xwork2.config.impl.LocatableFactory;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.inject.Scope;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.DomHelper;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import com.opensymphony.xwork2.util.location.Location;
import com.opensymphony.xwork2.util.location.LocationUtils;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.*;
/**
* Looks in the classpath for an XML file, "xwork.xml" by default,
* and uses it for the XWork configuration.
*
* @author tmjee
* @author Rainer Hermanns
* @author Neo
* @version $Revision: 1985 $
*/
public class XmlConfigurationProvider implements ConfigurationProvider {
private static final Logger LOG = LoggerFactory.getLogger(XmlConfigurationProvider.class);
private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
private List<Document> documents;
private Set<String> totalIncludedUrls;
private String configFileName;
private ObjectFactory objectFactory;
private Set<String> loadedFileUrls = new HashSet<String>();
private boolean errorIfMissing;
private Map<String, String> dtdMappings;
private Configuration configuration;
private boolean throwExceptionOnDuplicateBeans = true;
public XmlConfigurationProvider() {
this("xwork.xml", true);
}
public XmlConfigurationProvider(String filename) {
this(filename, true);
}
public XmlConfigurationProvider(String filename, boolean errorIfMissing) {
this.configFileName = filename;
this.errorIfMissing = errorIfMissing;
Map<String, String> mappings = new HashMap<String, String>();
mappings.put("-//OpenSymphony Group//XWork 2.1.3//EN", "xwork-2.1.3.dtd");
mappings.put("-//OpenSymphony Group//XWork 2.1//EN", "xwork-2.1.dtd");
mappings.put("-//OpenSymphony Group//XWork 2.0//EN", "xwork-2.0.dtd");
mappings.put("-//OpenSymphony Group//XWork 1.1.1//EN", "xwork-1.1.1.dtd");
mappings.put("-//OpenSymphony Group//XWork 1.1//EN", "xwork-1.1.dtd");
mappings.put("-//OpenSymphony Group//XWork 1.0//EN", "xwork-1.0.dtd");
setDtdMappings(mappings);
}
public void setThrowExceptionOnDuplicateBeans(boolean val) {
this.throwExceptionOnDuplicateBeans = val;
}
public void setDtdMappings(Map<String, String> mappings) {
this.dtdMappings = Collections.unmodifiableMap(mappings);
}
@Inject
public void setObjectFactory(ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
}
/** Returns an unmodifiable map of DTD mappings */
public Map<String, String> getDtdMappings() {
return dtdMappings;
}
public void init(Configuration configuration) {
this.configuration = configuration;
this.totalIncludedUrls = configuration.getLoadedUrls();
loadDocuments(configFileName);
}
public void destroy() {
}
@Override
public boolean equals(Object o) {
if(this == o) {
return true;
}
if(!(o instanceof XmlConfigurationProvider)) {
return false;
}
final XmlConfigurationProvider xmlConfigurationProvider = (XmlConfigurationProvider) o;
if((configFileName != null) ? (!configFileName
.equals(xmlConfigurationProvider.configFileName)) : (xmlConfigurationProvider.configFileName != null)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return ((configFileName != null) ? configFileName.hashCode() : 0);
}
private void loadDocuments(String configFileName) {
try {
loadedFileUrls.clear();
documents = loadConfigurationFiles(configFileName, null);
} catch(ConfigurationException e) {
throw e;
} catch(Exception e) {
throw new ConfigurationException("Error loading configuration file " + configFileName, e);
}
}
public void register(ContainerBuilder containerBuilder, LocatableProperties props) throws ConfigurationException {
LOG.info("Parsing configuration file [" + configFileName + "]");
Map<String, Node> loadedBeans = new HashMap<String, Node>();
for(Document doc : documents) {
Element rootElement = doc.getDocumentElement();
NodeList children = rootElement.getChildNodes();
int childSize = children.getLength();
for(int i = 0;i < childSize;i++) {
Node childNode = children.item(i);
if(childNode instanceof Element) {
Element child = (Element) childNode;
final String nodeName = child.getNodeName();
if("bean".equals(nodeName)) {
String type = child.getAttribute("type");
String name = child.getAttribute("name");
String impl = child.getAttribute("class");
String onlyStatic = child.getAttribute("static");
String scopeStr = child.getAttribute("scope");
boolean optional = "true".equals(child.getAttribute("optional"));
Scope scope = Scope.SINGLETON;
if("default".equals(scopeStr)) {
scope = Scope.DEFAULT;
} else if("request".equals(scopeStr)) {
scope = Scope.REQUEST;
} else if("session".equals(scopeStr)) {
scope = Scope.SESSION;
} else if("singleton".equals(scopeStr)) {
scope = Scope.SINGLETON;
} else if("thread".equals(scopeStr)) {
scope = Scope.THREAD;
}
if(StringUtils.isEmpty(name)) {
name = Container.DEFAULT_NAME;
}
try {
Class cimpl = ClassLoaderUtil.loadClass(impl, getClass());
Class ctype = cimpl;
if(StringUtils.isNotEmpty(type)) {
ctype = ClassLoaderUtil.loadClass(type, getClass());
}
if("true".equals(onlyStatic)) {
// Force loading of class to detect no class def found exceptions
cimpl.getDeclaredClasses();
containerBuilder.injectStatics(cimpl);
} else {
if(containerBuilder.contains(ctype, name)) {
Location loc = LocationUtils.getLocation(loadedBeans.get(ctype.getName() + name));
if(throwExceptionOnDuplicateBeans) {
throw new ConfigurationException(
"Bean type " + ctype + " with the name " + name + " has already been loaded by " + loc,
child);
}
}
// Force loading of class to detect no class def found exceptions
cimpl.getDeclaredConstructors();
if(LOG.isDebugEnabled()) {
LOG.debug("Loaded type:" + type + " name:" + name + " impl:" + impl);
}
containerBuilder
.factory(ctype, name, new LocatableFactory(name, ctype, cimpl, scope, childNode),
scope);
}
loadedBeans.put(ctype.getName() + name, child);
} catch(Throwable ex) {
if(!optional) {
throw new ConfigurationException("Unable to load bean: type:" + type + " class:" + impl,
ex, childNode);
} else {
LOG.debug("Unable to load optional cl
没有合适的资源?快使用搜索试试~ 我知道了~
struts2支持方法上传递参数
共17个文件
java:17个
5星 · 超过95%的资源 需积分: 12 22 下载量 52 浏览量
2012-05-31
11:00:05
上传
评论
收藏 43KB RAR 举报
温馨提示
在struts2中可以在方法上传递相应的参数,不需要使用注解,直接使用参数名进行界面传递参数信息,并且可以在界面进行访问
资源推荐
资源详情
资源评论
收起资源包目录
etc.rar (17个子文件)
etc
com
opensymphony
xwork2
ognl
ActionParam.java 256B
accessor
XWorkCollectionPropertyAccessor.java 9KB
XWorkMapPropertyAccessor.java 7KB
util
ActionMethodUtils.java 878B
XWorkListPropertyAccessor.java 7KB
ActionParamPropertyAccessor.java 3KB
ActionSupport.java 7KB
DefaultActionInvocation.java 15KB
conversion
impl
DefaultTypeConverter.java 11KB
util
MethodUtils.java 5KB
ObjectUtils.java 1KB
LocalizedTextUtil.java 31KB
config
Configuration.java 2KB
impl
MockConfiguration.java 3KB
DefaultConfiguration.java 19KB
providers
XmlConfigurationProvider.java 36KB
DefaultTextedTextProvider.java 612B
interceptor
共 17 条
- 1
资源评论
- starlove03122013-11-07不错的实现 只不过感觉实用性不大
- ice_kane2013-10-08比较有帮助。不错
Fly_m
- 粉丝: 40
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功