in src/java/org/apache/turbine/services/template/TurbineTemplateService.java [711:816]
private void initMapper(Configuration conf)
throws InitializationException
{
// Create a registry with the number of Template Types managed by this service.
// We could use a List object here and extend the number of managed objects
// dynamically. However, by using an Object Array, we get much more performance
// out of the Template Service.
mapperRegistry = new Mapper[TEMPLATE_TYPES];
String [] mapperNames = new String [] {
Page.NAME, Screen.NAME, Layout.NAME, Navigation.NAME,
LAYOUT_TEMPLATE_NAME, SCREEN_TEMPLATE_NAME, NAVIGATION_TEMPLATE_NAME
};
Class<?> [] mapperKeys = new Class<?> [] {
Page.class, Screen.class, Layout.class, Navigation.class,
Layout.class, Screen.class, Navigation.class
};
String [] mapperClasses = new String [] {
DirectMapper.class.getName(),
ClassMapper.class.getName(),
ClassMapper.class.getName(),
ClassMapper.class.getName(),
LayoutTemplateMapper.class.getName(),
ScreenTemplateMapper.class.getName(),
DirectTemplateMapper.class.getName()
};
AssemblerBrokerService ab = (AssemblerBrokerService)TurbineServices.getInstance()
.getService(AssemblerBrokerService.SERVICE_NAME);
int [] mapperCacheSize = new int [mapperKeys.length];
Loader<? extends Assembler> [] mapperLoader = new Loader<?>[mapperKeys.length];
for (int i = 0; i < mapperKeys.length; i++)
{
mapperLoader[i] = ab.getLoader((Class<? extends Assembler>)mapperKeys[i]);
mapperCacheSize[i] = (mapperLoader[i] != null) ? mapperLoader[i].getCacheSize() : 0;
}
// HACK: to achieve the same behavior as before
mapperLoader[LAYOUT_TEMPLATE_KEY] = null;
mapperLoader[SCREEN_TEMPLATE_KEY] = null;
mapperLoader[NAVIGATION_TEMPLATE_KEY] = null;
String [] mapperDefaultProperty = new String [] {
TemplateEngineService.DEFAULT_PAGE,
TemplateEngineService.DEFAULT_SCREEN,
TemplateEngineService.DEFAULT_LAYOUT,
TemplateEngineService.DEFAULT_NAVIGATION,
TemplateEngineService.DEFAULT_LAYOUT_TEMPLATE,
TemplateEngineService.DEFAULT_SCREEN_TEMPLATE,
TemplateEngineService.DEFAULT_NAVIGATION_TEMPLATE
};
char [] mapperSeparator = new char [] { '.', '.', '.', '.', '/', '/', '/' };
String [] mapperPrefix = new String [] {
null, null, null, null,
Layout.PREFIX,
Screen.PREFIX,
Navigation.PREFIX };
for (int i = 0; i < TEMPLATE_TYPES; i++)
{
StringBuilder mapperProperty = new StringBuilder();
mapperProperty.append("mapper.");
mapperProperty.append(mapperNames[i]);
mapperProperty.append(".class");
String mapperClass =
conf.getString(mapperProperty.toString(), mapperClasses[i]);
log.info("Using {} to map {} elements", mapperClass, mapperNames[i]);
Mapper tm = null;
try
{
FactoryService factory = (FactoryService)TurbineServices.getInstance().getService(FactoryService.ROLE);
tm = factory.getInstance(mapperClass);
}
catch (FactoryException e)
{
throw new InitializationException("", e);
}
tm.setUseCache(useCache);
tm.setCacheSize(mapperCacheSize[i]);
tm.setDefaultProperty(mapperDefaultProperty[i]);
tm.setSeparator(mapperSeparator[i]);
if (mapperLoader[i] != null && tm instanceof ClassMapper)
{
((ClassMapper) tm).setLoader(mapperLoader[i]);
}
if (mapperPrefix[i] != null && tm instanceof BaseTemplateMapper)
{
((BaseTemplateMapper) tm).setPrefix(mapperPrefix[i]);
}
registerMapper(i, tm);
}
}