Wrapper from new definition factory interface to old interface.
This class provides mapping from the old interface's life cycle to the new life cycle.
| Method from org.apache.struts.tiles.definition.ComponentDefinitionsFactoryWrapper Detail: |
public static Map createConfigMap(DefinitionsFactoryConfig config) {
Map map = new HashMap(config.getAttributes());
// Add property attributes using old names
map.put(
DefinitionsFactoryConfig.DEFINITIONS_CONFIG_PARAMETER_NAME,
config.getDefinitionConfigFiles());
map.put(
DefinitionsFactoryConfig.PARSER_VALIDATE_PARAMETER_NAME,
(config.getParserValidate() ? Boolean.TRUE.toString() : Boolean.FALSE.toString()));
if (!"org.apache.struts.tiles.xmlDefinition.I18nFactorySet"
.equals(config.getFactoryClassname())) {
map.put(
DefinitionsFactoryConfig.FACTORY_CLASSNAME_PARAMETER_NAME,
config.getFactoryClassname());
}
return map;
}
Create map of configuration attributes from configuration object.
Mapping is done between old names and new names. |
protected ComponentDefinitionsFactory createFactoryInstance(String classname) throws DefinitionsFactoryException {
try {
Class factoryClass = RequestUtils.applicationClass(classname);
Object factory = factoryClass.newInstance();
return (ComponentDefinitionsFactory) factory;
} catch (ClassCastException ex) { // Bad classname
throw new DefinitionsFactoryException(
"Error - createDefinitionsFactory : Factory class '"
+ classname
+ " must implement 'DefinitionsFactory'.",
ex);
} catch (ClassNotFoundException ex) { // Bad classname
throw new DefinitionsFactoryException(
"Error - createDefinitionsFactory : Bad class name '"
+ classname
+ "'.",
ex);
} catch (InstantiationException ex) { // Bad constructor or error
throw new DefinitionsFactoryException(ex);
} catch (IllegalAccessException ex) {
throw new DefinitionsFactoryException(ex);
}
}
|
public void destroy() {
factory = null;
}
Do nothing because old life cycle has no equivalent. |
public DefinitionsFactoryConfig getConfig() {
return config;
}
Get underlying factory configuration. |
public ComponentDefinition getDefinition(String name,
ServletRequest request,
ServletContext servletContext) throws NoSuchDefinitionException, DefinitionsFactoryException {
return factory.getDefinition(name, request, servletContext);
}
Get requested definition. |
public ComponentDefinitionsFactory getInternalFactory() {
return factory;
}
|
public void init(DefinitionsFactoryConfig config,
ServletContext servletContext) throws DefinitionsFactoryException {
this.config = config;
// create factory and initialize it
if (factory == null) {
factory = createFactoryInstance(config.getFactoryClassname());
}
factory.initFactory(servletContext, createConfigMap(config));
}
Call underlying factory init method. |
public void setConfig(DefinitionsFactoryConfig config,
ServletContext servletContext) throws DefinitionsFactoryException {
ComponentDefinitionsFactory newFactory =
createFactoryInstance(config.getFactoryClassname());
newFactory.initFactory(servletContext, createConfigMap(config));
factory = newFactory;
}
Set underlying factory configuration. |
public String toString() {
return getInternalFactory().toString();
}
Return String representation.
Calls toString() on underlying factory. |