xwork2.0源代码,理解struts2

  • y3_738153
    了解作者
  • 4.2MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-13 07:07
    上传日期
这个包是struts2中的xwork包的源代码,我专门下载共大家学习使用。
xwork-2.0-RC1-src.zip
内容介绍
/* * Copyright (c) 2002-2006 by OpenSymphony * All rights reserved. */ package com.opensymphony.xwork2.config.providers; import com.opensymphony.xwork2.util.ClassLoaderUtil; import com.opensymphony.xwork2.util.FileManager; import com.opensymphony.xwork2.util.TextUtils; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.XWorkException; import com.opensymphony.xwork2.config.*; 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.DomHelper; import com.opensymphony.xwork2.util.location.LocatableProperties; import com.opensymphony.xwork2.util.location.Location; import com.opensymphony.xwork2.util.location.LocationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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: 1215 $ */ public class XmlConfigurationProvider implements ConfigurationProvider { private static final Log LOG = LogFactory.getLog(XmlConfigurationProvider.class); private List<Document> documents; private Set<String> includedFileNames; private String configFileName; private ObjectFactory objectFactory; private Set<String> loadedFileUrls = new HashSet<String>(); private boolean errorIfMissing; private Map<String,String> dtdMappings; private Configuration configuration; 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.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 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.includedFileNames = configuration.getLoadedFileNames(); loadDocuments(configFileName); } public void destroy() { } 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; } 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 (nodeName.equals("bean")) { 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 (!TextUtils.stringSet(name)) { name = Container.DEFAULT_NAME; } try { Class cimpl = ClassLoaderUtil.loadClass(impl, getClass()); Class ctype = cimpl; if (TextUtils.stringSet(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)); 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 c
评论
    相关推荐
    • Struts
      Struts简易教程
    • struts
      Apache Struts项目提供了Apache Struts 2 Web框架,该框架是用于创建基于Web的Java应用程序的全面的模块化工具堆栈。 来自WebWork 2框架的Struts 2,对于重视解决难题的优雅解决方案的团队来说,是一个绝佳的选择。...
    • struts
      struts源代码与例子
    • struts 2.0
      strus 2.0:融struts与webwork于一体,相比struts 1.0有了更人性化的改进,其中webwork的集成,更是对struts自身不足的极大补充,让我们一起学习。
    • 框架struts
      如何搭建一个struts框架,包括2个例子(struts2.1之前和struts2.1之后所需的jar不同,文档有详解),注意点等
    • struts配置
      truts2.5之前的版本有点不同,还需要xwork-core.jar,不需要log4j-api-2.7.jar。原因是struts2.5把xwork的源码 合并到了struts-core中。struts2.5之前使用logging API,而struts2.5用log4j 2 API取代。
    • struts
      Apache Struts项目提供了Apache Struts 2 Web框架,该框架是用于创建基于Web的Java应用程序的全面的模块化工具堆栈。 来自WebWork 2框架的Struts 2,对于重视解决难题的优雅解决方案的团队来说,是一个绝佳的选择。...
    • struts
      Apache Struts项目提供了Apache Struts 2 Web框架,该框架是用于创建基于Web的Java应用程序的全面的模块化工具堆栈。 来自WebWork 2框架的Struts 2,对于重视解决难题的优雅解决方案的团队来说,是一个绝佳的选择。...
    • struts2.1.8
      Struts 2是Struts的下一代产品。是在 struts 和WebWork的技术基础上进行了合并,全新的Struts 2框架。其全新的Struts 2的体系结构与Struts 1的体系结构的差别巨大。Struts 2以WebWork为核心,采用拦截器的机制来处理...
    • struts2.1.6
      struts2改善和完善了struts1中的一些缺陷,struts1中一些悬而未决问题在struts2得到了解决,在struts2中直接使用action的属性来封装请求参数,可以指定只对某个方法进行校验,当一个Action继承了ActionSupport且在这...