1
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
28 package org.objectledge.configuration;
29
30 import org.jcontainer.dna.Configuration;
31 import org.objectledge.pico.customization.CustomizedComponentProvider;
32 import org.objectledge.pico.customization.UnsupportedKeyTypeException;
33 import org.picocontainer.PicoContainer;
34 import org.picocontainer.PicoInitializationException;
35 import org.picocontainer.PicoIntrospectionException;
36 import org.picocontainer.PicoVerificationException;
37
38 /***
39 * Provides Configuration objects to the components being initialized using ConfigurationFactory.
40 *
41 * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
42 * @version $Id: CustomizedConfigurationProvider.java,v 1.4 2005/02/04 02:28:03 rafal Exp $
43 */
44 public class CustomizedConfigurationProvider
45 implements CustomizedComponentProvider
46 {
47 private ConfigurationFactory configurationFactory;
48
49 /***
50 * Creates new CustomizedConfigurationProvider instance.
51 *
52 * @param configurationFactory the configuration factory.
53 */
54 public CustomizedConfigurationProvider(ConfigurationFactory configurationFactory)
55 {
56 this.configurationFactory = configurationFactory;
57 }
58
59 /***
60 * {@inheritDoc}
61 */
62 public Object getCustomizedComponentInstance(PicoContainer container, Object componentKey,
63 Class componentImplementation)
64 throws PicoInitializationException, PicoIntrospectionException
65 {
66 String componentName = getComponentName(componentKey);
67 return configurationFactory.getConfig(componentName, componentImplementation);
68 }
69
70 /***
71 * {@inheritDoc}
72 */
73 public Class getCustomizedComponentImplementation()
74 {
75 return Configuration.class;
76 }
77
78 /***
79 * {@inheritDoc}
80 */
81 public void verify(PicoContainer container) throws PicoVerificationException
82 {
83
84 }
85
86
87
88 /***
89 * Returns human readable name of the component.
90 *
91 * @param componentKey the component key.
92 * @return human readable name of the component.
93 * @throws UnsupportedKeyTypeException if the component key is of unsupported type.
94 */
95 protected String getComponentName(Object componentKey)
96 throws UnsupportedKeyTypeException
97 {
98 if(componentKey instanceof Class)
99 {
100 return ((Class)componentKey).getName();
101 }
102 else if(componentKey instanceof String)
103 {
104 return componentKey.toString();
105 }
106 else
107 {
108 throw new UnsupportedKeyTypeException("unsupported component key type "+
109 componentKey.getClass().getName());
110 }
111 }
112 }