com.opensymphony.xwork2.config.providers
Class XmlConfigurationProvider

java.lang.Object
  extended by com.opensymphony.xwork2.config.providers.XmlConfigurationProvider
All Implemented Interfaces:
ConfigurationProvider, ContainerProvider, PackageProvider
Direct Known Subclasses:
StrutsXmlConfigurationProvider

public class XmlConfigurationProvider
extends Object
implements ConfigurationProvider

Looks in the classpath for an XML file, "xwork.xml" by default, and uses it for the XWork configuration.

Version:
$Revision: 1756 $
Author:
tmjee, Rainer Hermanns, Neo

Field Summary
private  String configFileName
           
private  Configuration configuration
           
private  List<Document> documents
           
private  Map<String,String> dtdMappings
           
private  boolean errorIfMissing
           
private  Set<String> includedFileNames
           
private  Set<String> loadedFileUrls
           
private static Logger LOG
           
private  ObjectFactory objectFactory
           
private  boolean throwExceptionOnDuplicateBeans
           
 
Constructor Summary
XmlConfigurationProvider()
           
XmlConfigurationProvider(String filename)
           
XmlConfigurationProvider(String filename, boolean errorIfMissing)
           
 
Method Summary
protected  void addAction(Element actionElement, PackageConfig.Builder packageContext)
           
protected  PackageConfig addPackage(Element packageElement)
          Create a PackageConfig from an XML element representing it.
protected  void addResultTypes(PackageConfig.Builder packageContext, Element element)
           
protected  List buildExceptionMappings(Element element, PackageConfig.Builder packageContext)
          Build a map of ResultConfig objects from below a given XML element.
protected  List buildInterceptorList(Element element, PackageConfig.Builder context)
           
protected  PackageConfig.Builder buildPackageContext(Element packageElement)
          This method builds a package context by looking for the parents of this new package.
protected  Map buildResults(Element element, PackageConfig.Builder packageContext)
          Build a map of ResultConfig objects from below a given XML element.
 void destroy()
          Called before removed from the configuration manager
 boolean equals(Object o)
           
protected  Iterator<URL> getConfigurationUrls(String fileName)
           
 Map<String,String> getDtdMappings()
          Returns an unmodifiable map of DTD mappings
private  void handleWildCardIncludes(String includeFileName, List<Document> docs, Element child)
           
 int hashCode()
           
 void init(Configuration configuration)
          Initializes with the configuration
private  List loadConfigurationFiles(String fileName, Element includeElement)
           
protected  void loadDefaultActionRef(PackageConfig.Builder packageContext, Element element)
           
protected  void loadDefaultClassRef(PackageConfig.Builder packageContext, Element element)
           
protected  void loadDefaultInterceptorRef(PackageConfig.Builder packageContext, Element element)
           
private  void loadDocuments(String configFileName)
           
protected  void loadExtraConfiguration(Document doc)
          Allows subclasses to load extra information from the document
protected  void loadGlobalResults(PackageConfig.Builder packageContext, Element packageElement)
          Load all of the global results for this package from the XML element.
protected  void loadGobalExceptionMappings(PackageConfig.Builder packageContext, Element packageElement)
          Load all of the global results for this package from the XML element.
protected  void loadInterceptors(PackageConfig.Builder context, Element element)
           
protected  InterceptorStackConfig loadInterceptorStack(Element element, PackageConfig.Builder context)
           
protected  void loadInterceptorStacks(Element element, PackageConfig.Builder context)
           
 void loadPackages()
          Loads the packages for the configuration.
private  List lookupInterceptorReference(PackageConfig.Builder context, Element interceptorRefElement)
          Looks up the Interceptor Class from the interceptor-ref name and creates an instance, which is added to the provided List, or, if this is a ref to a stack, it adds the Interceptor instances from the List to this stack.
 boolean needsReload()
          Tells whether the ConfigurationProvider should reload its configuration.
 void register(ContainerBuilder containerBuilder, LocatableProperties props)
          Registers beans and properties for the Container
private  void reloadRequiredPackages(List<Element> reloads)
           
 void setDtdMappings(Map<String,String> mappings)
           
 void setObjectFactory(ObjectFactory objectFactory)
           
 void setThrowExceptionOnDuplicateBeans(boolean val)
           
protected  boolean verifyAction(String className, String name, Location loc)
           
protected  Class verifyResultType(String className, Location loc)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG

documents

private List<Document> documents

includedFileNames

private Set<String> includedFileNames

configFileName

private String configFileName

objectFactory

private ObjectFactory objectFactory

loadedFileUrls

private Set<String> loadedFileUrls

errorIfMissing

private boolean errorIfMissing

dtdMappings

private Map<String,String> dtdMappings

configuration

private Configuration configuration

throwExceptionOnDuplicateBeans

private boolean throwExceptionOnDuplicateBeans
Constructor Detail

XmlConfigurationProvider

public XmlConfigurationProvider()

XmlConfigurationProvider

public XmlConfigurationProvider(String filename)

XmlConfigurationProvider

public XmlConfigurationProvider(String filename,
                                boolean errorIfMissing)
Method Detail

setThrowExceptionOnDuplicateBeans

public void setThrowExceptionOnDuplicateBeans(boolean val)

setDtdMappings

public void setDtdMappings(Map<String,String> mappings)

setObjectFactory

public void setObjectFactory(ObjectFactory objectFactory)

getDtdMappings

public Map<String,String> getDtdMappings()
Returns an unmodifiable map of DTD mappings


init

public void init(Configuration configuration)
Description copied from interface: ContainerProvider
Initializes with the configuration

Specified by:
init in interface ContainerProvider
Specified by:
init in interface PackageProvider
Parameters:
configuration - The configuration

destroy

public void destroy()
Description copied from interface: ContainerProvider
Called before removed from the configuration manager

Specified by:
destroy in interface ContainerProvider

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

loadDocuments

private void loadDocuments(String configFileName)

register

public void register(ContainerBuilder containerBuilder,
                     LocatableProperties props)
              throws ConfigurationException
Description copied from interface: ContainerProvider
Registers beans and properties for the Container

Specified by:
register in interface ContainerProvider
Parameters:
containerBuilder - The builder to register beans with
props - The properties to register constants with
Throws:
ConfigurationException - If anything goes wrong

loadPackages

public void loadPackages()
                  throws ConfigurationException
Description copied from interface: PackageProvider
Loads the packages for the configuration.

Specified by:
loadPackages in interface PackageProvider
Throws:
ConfigurationException

reloadRequiredPackages

private void reloadRequiredPackages(List<Element> reloads)

needsReload

public boolean needsReload()
Tells whether the ConfigurationProvider should reload its configuration. This method should only be called if ConfigurationManager.isReloadingConfigs() is true.

Specified by:
needsReload in interface ContainerProvider
Specified by:
needsReload in interface PackageProvider
Returns:
true if the file has been changed since the last time we read it

addAction

protected void addAction(Element actionElement,
                         PackageConfig.Builder packageContext)
                  throws ConfigurationException
Throws:
ConfigurationException

verifyAction

protected boolean verifyAction(String className,
                               String name,
                               Location loc)

addPackage

protected PackageConfig addPackage(Element packageElement)
                            throws ConfigurationException
Create a PackageConfig from an XML element representing it.

Throws:
ConfigurationException

addResultTypes

protected void addResultTypes(PackageConfig.Builder packageContext,
                              Element element)

verifyResultType

protected Class verifyResultType(String className,
                                 Location loc)

buildInterceptorList

protected List buildInterceptorList(Element element,
                                    PackageConfig.Builder context)
                             throws ConfigurationException
Throws:
ConfigurationException

buildPackageContext

protected PackageConfig.Builder buildPackageContext(Element packageElement)
This method builds a package context by looking for the parents of this new package.

If no parents are found, it will return a root package.


buildResults

protected Map buildResults(Element element,
                           PackageConfig.Builder packageContext)
Build a map of ResultConfig objects from below a given XML element.


buildExceptionMappings

protected List buildExceptionMappings(Element element,
                                      PackageConfig.Builder packageContext)
Build a map of ResultConfig objects from below a given XML element.


loadDefaultInterceptorRef

protected void loadDefaultInterceptorRef(PackageConfig.Builder packageContext,
                                         Element element)

loadDefaultActionRef

protected void loadDefaultActionRef(PackageConfig.Builder packageContext,
                                    Element element)

loadGlobalResults

protected void loadGlobalResults(PackageConfig.Builder packageContext,
                                 Element packageElement)
Load all of the global results for this package from the XML element.


loadDefaultClassRef

protected void loadDefaultClassRef(PackageConfig.Builder packageContext,
                                   Element element)

loadGobalExceptionMappings

protected void loadGobalExceptionMappings(PackageConfig.Builder packageContext,
                                          Element packageElement)
Load all of the global results for this package from the XML element.


loadInterceptorStack

protected InterceptorStackConfig loadInterceptorStack(Element element,
                                                      PackageConfig.Builder context)
                                               throws ConfigurationException
Throws:
ConfigurationException

loadInterceptorStacks

protected void loadInterceptorStacks(Element element,
                                     PackageConfig.Builder context)
                              throws ConfigurationException
Throws:
ConfigurationException

loadInterceptors

protected void loadInterceptors(PackageConfig.Builder context,
                                Element element)
                         throws ConfigurationException
Throws:
ConfigurationException

loadConfigurationFiles

private List loadConfigurationFiles(String fileName,
                                    Element includeElement)

handleWildCardIncludes

private void handleWildCardIncludes(String includeFileName,
                                    List<Document> docs,
                                    Element child)

getConfigurationUrls

protected Iterator<URL> getConfigurationUrls(String fileName)
                                      throws IOException
Throws:
IOException

loadExtraConfiguration

protected void loadExtraConfiguration(Document doc)
Allows subclasses to load extra information from the document

Parameters:
doc - The configuration document

lookupInterceptorReference

private List lookupInterceptorReference(PackageConfig.Builder context,
                                        Element interceptorRefElement)
                                 throws ConfigurationException
Looks up the Interceptor Class from the interceptor-ref name and creates an instance, which is added to the provided List, or, if this is a ref to a stack, it adds the Interceptor instances from the List to this stack.

Parameters:
interceptorRefElement - Element to pull interceptor ref data from
context - The PackageConfig to lookup the interceptor from
Returns:
A list of Interceptor objects
Throws:
ConfigurationException


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.