2 * This is a utility project for wide range of applications
4 * Copyright (C) 8 Imran M Yousuf (imyousuf@smartitengineering.com)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 10-1 USA
18 package com
.smartitengineering
.util
.bean
;
20 import org
.apache
.commons
.lang
.StringUtils
;
23 * A simply adapter for spring bean factory to be used for injection
26 public class SpringBeanFactory
27 implements BeanFactory
{
29 private org
.springframework
.beans
.factory
.BeanFactory beanFactory
;
31 public SpringBeanFactory(
32 org
.springframework
.beans
.factory
.BeanFactory beanFactory
) {
33 if (beanFactory
== null) {
34 throw new IllegalArgumentException(
35 "Spring bean factory can not be null!");
37 this.beanFactory
= beanFactory
;
40 public boolean containsBean(String beanName
)
41 throws IllegalArgumentException
{
42 if (StringUtils
.isBlank(beanName
)) {
43 throw new IllegalArgumentException("Bean Name can not be blank!");
45 return beanFactory
.containsBean(beanName
);
48 public Object
getBean(String beanName
)
49 throws IllegalArgumentException
{
50 if (StringUtils
.isBlank(beanName
)) {
51 throw new IllegalArgumentException("Bean Name can not be blank!");
53 if (!containsBean(beanName
)) {
54 throw new IllegalArgumentException("No such bean in factory!");
56 return beanFactory
.getBean(beanName
);