01: package org.vraptor.config;
02:
03: import org.apache.log4j.Logger;
04: import org.vraptor.component.ComponentInstantiationException;
05: import org.vraptor.converter.Converter;
06: import org.vraptor.converter.ConverterManager;
07: import org.vraptor.reflection.ReflectionUtil;
08: import org.vraptor.webapp.WebApplication;
09:
10: /**
11: * Models the xml portion to deal with component classes.
12: *
13: * @author Guilherme Silveira
14: */
15: public class ConverterConfig implements ConfigItem {
16:
17: private static final Logger LOG = Logger
18: .getLogger(ConverterConfig.class);
19:
20: private Class<? extends Converter> type;
21:
22: @SuppressWarnings("unchecked")
23: public <T> ConverterConfig(Class<T> clazz) {
24: super ();
25: this .type = (Class<? extends Converter>) clazz;
26: }
27:
28: public Class<?> getConverterClass() {
29: return type;
30: }
31:
32: public void register(WebApplication application)
33: throws ConfigException {
34: ConverterManager manager = application.getConverterManager();
35: register(manager);
36: }
37:
38: void register(ConverterManager manager) {
39: try {
40: Converter converter = (Converter) ReflectionUtil
41: .instantiate(this .type);
42: manager.register(converter);
43: } catch (ComponentInstantiationException e) {
44: LOG
45: .error(
46: "Unable to instantiate and register converter",
47: e);
48: }
49: }
50:
51: public boolean isComponent() {
52: return true;
53: }
54:
55: public boolean isManager() {
56: return false;
57: }
58:
59: }
|