| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LazyFactoryBean |
|
| 1.0;1 |
| 1 | package org.jtheque.core.spring.factory; | |
| 2 | ||
| 3 | import org.springframework.beans.factory.config.AbstractFactoryBean; | |
| 4 | ||
| 5 | import java.lang.reflect.Proxy; | |
| 6 | ||
| 7 | /* | |
| 8 | * This file is part of JTheque. | |
| 9 | * | |
| 10 | * JTheque is free software: you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation, either version 3 of the License. | |
| 13 | * | |
| 14 | * JTheque is distributed in the hope that it will be useful, | |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | * GNU General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | */ | |
| 22 | ||
| 23 | /** | |
| 24 | * A factory bean for keep a proxy of a bean. | |
| 25 | * | |
| 26 | * @author Baptiste Wicht | |
| 27 | */ | |
| 28 | public final class LazyFactoryBean extends AbstractFactoryBean { | |
| 29 | private final String beanName; | |
| 30 | private final boolean swing; | |
| 31 | private final Class<?> beanClass; | |
| 32 | ||
| 33 | /** | |
| 34 | * Construct a new LazyFactoryBean. | |
| 35 | * | |
| 36 | * @param beanName The name of the bean to keep the proxy for. | |
| 37 | * @param swing A boolean tag indicating if the bean is swing bean. | |
| 38 | * @param beanClass The class of the bean to keep the proxy for. | |
| 39 | */ | |
| 40 | public LazyFactoryBean(String beanName, boolean swing, Class<?> beanClass) { | |
| 41 | 0 | super(); |
| 42 | ||
| 43 | 0 | this.beanName = beanName; |
| 44 | 0 | this.swing = swing; |
| 45 | 0 | this.beanClass = beanClass; |
| 46 | 0 | } |
| 47 | ||
| 48 | @Override | |
| 49 | public Class<?> getObjectType() { | |
| 50 | 0 | return beanClass; |
| 51 | } | |
| 52 | ||
| 53 | @Override | |
| 54 | protected Object createInstance() { | |
| 55 | 0 | return Proxy.newProxyInstance( |
| 56 | ClassLoader.getSystemClassLoader(), | |
| 57 | beanClass.getInterfaces(), | |
| 58 | new LazyProxyHandler(beanName, swing)); | |
| 59 | } | |
| 60 | } |