01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.integration.spring;
16:
17: import org.araneaframework.Environment;
18: import org.araneaframework.Service;
19: import org.araneaframework.core.ServiceFactory;
20: import org.springframework.beans.factory.BeanFactory;
21:
22: /**
23: * A simple factory to be used in the xml configuration files for creating services with
24: * factories. By setting a bean id via <code>setBeanId(String)</code> it is possible to
25: * construct a bean with factory found in Environment under key <code>beanFactoryClass</code>.
26: *
27: * @author Taimo Peelo (taimo@araneaframework.org)
28: */
29: public class SpringServiceFactory implements ServiceFactory {
30: protected Class beanFactoryClass = BeanFactory.class;
31: protected String beanId;
32:
33: /**
34: * Set the class under which BeanFactory resides in the Environment.
35: * @param beanFactoryClass the class under which BeanFactory resides in the Environment.
36: */
37: public void setBeanFactoryClass(Class beanFactoryClass) {
38: this .beanFactoryClass = beanFactoryClass;
39: }
40:
41: /**
42: * The id of the bean in the configuration.
43: */
44: public void setBeanId(String beanId) {
45: this .beanId = beanId;
46: }
47:
48: public Service buildService(Environment env) {
49: BeanFactory factory = (BeanFactory) env
50: .requireEntry(beanFactoryClass);
51: return (Service) factory.getBean(beanId);
52: }
53: }
|