1 package org.codehaus.plexus.component.configurator;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import java.lang.reflect.InvocationTargetException;
28 import java.lang.reflect.Method;
29
30 import org.codehaus.classworlds.ClassRealmAdapter;
31 import org.codehaus.plexus.classworlds.realm.ClassRealm;
32 import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
33 import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup;
34 import org.codehaus.plexus.component.configurator.expression.DefaultExpressionEvaluator;
35 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
36 import org.codehaus.plexus.configuration.PlexusConfiguration;
37
38
39
40
41 public abstract class AbstractComponentConfigurator implements ComponentConfigurator {
42
43
44
45
46
47
48
49 protected ConverterLookup converterLookup = new DefaultConverterLookup();
50
51 public void configureComponent(Object component, PlexusConfiguration configuration, ClassRealm containerRealm)
52 throws ComponentConfigurationException {
53 configureComponent(component, configuration, new DefaultExpressionEvaluator(), containerRealm);
54 }
55
56 public void configureComponent(
57 Object component,
58 PlexusConfiguration configuration,
59 ExpressionEvaluator expressionEvaluator,
60 ClassRealm containerRealm)
61 throws ComponentConfigurationException {
62 configureComponent(component, configuration, expressionEvaluator, containerRealm, null);
63 }
64
65 public void configureComponent(
66 final Object component,
67 final PlexusConfiguration configuration,
68 final ExpressionEvaluator expressionEvaluator,
69 final ClassRealm containerRealm,
70 final ConfigurationListener listener)
71 throws ComponentConfigurationException {
72
73
74
75
76 final org.codehaus.classworlds.ClassRealm cr = ClassRealmAdapter.getInstance(containerRealm);
77
78 Method method;
79
80 try {
81 try {
82 method = getClass()
83 .getMethod(
84 "configureComponent",
85 Object.class,
86 PlexusConfiguration.class,
87 ExpressionEvaluator.class,
88 org.codehaus.classworlds.ClassRealm.class,
89 ConfigurationListener.class);
90 method.invoke(this, component, configuration, expressionEvaluator, cr, listener);
91 } catch (final NoSuchMethodException e) {
92 method = getClass()
93 .getMethod(
94 "configureComponent",
95 Object.class,
96 PlexusConfiguration.class,
97 ExpressionEvaluator.class,
98 org.codehaus.classworlds.ClassRealm.class);
99 method.invoke(this, component, configuration, expressionEvaluator, cr);
100 }
101 } catch (final InvocationTargetException e) {
102 if (e.getCause() instanceof ComponentConfigurationException) {
103 throw (ComponentConfigurationException) e.getCause();
104 } else if (e.getCause() instanceof RuntimeException) {
105 throw (RuntimeException) e.getCause();
106 } else if (e.getCause() instanceof Error) {
107 throw (Error) e.getCause();
108 }
109 throw new ComponentConfigurationException(
110 "Incompatible configurator " + getClass().getName(), e);
111 } catch (final Exception e) {
112 throw new ComponentConfigurationException(
113 "Incompatible configurator " + getClass().getName(), e);
114 }
115 }
116 }