|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SpringLookupFactory.java | 100% | 100% | 100% | 100% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.hivemind.lib.impl; | |
16 | ||
17 | import org.apache.hivemind.ServiceImplementationFactory; | |
18 | import org.apache.hivemind.ServiceImplementationFactoryParameters; | |
19 | import org.apache.hivemind.impl.BaseLocatable; | |
20 | import org.springframework.beans.factory.BeanFactory; | |
21 | ||
22 | /** | |
23 | * Implementation of {@link org.apache.hivemind.ServiceImplementationFactory} that doesn't create | |
24 | * beans, but instead it looks them up inside a Spring | |
25 | * {@link org.springframework.beans.factory.BeanFactory}. | |
26 | * | |
27 | * @author Howard Lewis Ship | |
28 | */ | |
29 | public class SpringLookupFactory extends BaseLocatable implements ServiceImplementationFactory | |
30 | { | |
31 | /** @since 1.1 */ | |
32 | private BeanFactory _defaultBeanFactory; | |
33 | ||
34 | 3 | public Object createCoreServiceImplementation( |
35 | ServiceImplementationFactoryParameters factoryParameters) | |
36 | { | |
37 | 3 | SpringBeanParameter p = (SpringBeanParameter) factoryParameters.getFirstParameter(); |
38 | 3 | String beanName = p.getName(); |
39 | ||
40 | 3 | BeanFactory f = p.getBeanFactory(); |
41 | ||
42 | 3 | if (f == null) |
43 | 2 | f = _defaultBeanFactory; |
44 | ||
45 | 3 | return f.getBean(beanName, factoryParameters.getServiceInterface()); |
46 | } | |
47 | ||
48 | /** @since 1.1 */ | |
49 | 2 | public void setDefaultBeanFactory(BeanFactory defaultBeanFactory) |
50 | { | |
51 | 2 | _defaultBeanFactory = defaultBeanFactory; |
52 | } | |
53 | } |
|