some major refactoring.
[utils] / system / spring / src / main / java / org / wamblee / system / spring / RequiredServiceBean.java
1 package org.wamblee.system.spring;
2
3 import org.springframework.beans.factory.FactoryBean;
4 import org.wamblee.system.ProvidedInterface;
5 import org.wamblee.system.RequiredInterface;
6 import org.wamblee.system.SystemAssemblyException;
7
8 /**
9  * Bean which adds a service required by the spring component to 
10  * the application context so that other spring beans can use it.  
11  *  
12  * @author Erik Brakkee
13  */
14 class RequiredServiceBean implements FactoryBean {
15         
16         private RequiredInterface _required; 
17         
18         /**
19          * Constructs the bean. 
20          * @param aId Id of the bean in the service registry.  
21          */
22         public RequiredServiceBean(String aId) { 
23                 RequiredInterface[] required = SpringComponent.THIS.get().getRequiredServices();
24                 for ( RequiredInterface intf: required) { 
25                         if ( intf.getName().equals(aId)) { 
26                                 _required = intf; 
27                                 return;
28                         }
29                 }
30                 throw new SystemAssemblyException("Cannot resolve provided component '" + aId + "'");
31         }
32
33         @Override
34         public Object getObject() throws Exception {
35                 return _required.getImplementation(Object.class);
36         }
37
38         @Override
39         public Class getObjectType() {
40                 return null;
41         }
42
43         @Override
44         public boolean isSingleton() {
45                 return true; 
46         }
47
48 }