001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.container.integration.spring;
027:
028: import org.jicarilla.container.JicarillaInstantiationException;
029: import org.jicarilla.container.factories.BeanFactory;
030: import org.jicarilla.lang.Assert;
031: import org.springframework.beans.factory.BeanFactoryAware;
032: import org.springframework.beans.factory.BeanNameAware;
033: import org.springframework.beans.factory.DisposableBean;
034: import org.springframework.beans.factory.InitializingBean;
035:
036: import java.beans.IntrospectionException;
037: import java.util.List;
038: import java.util.Map;
039:
040: /**
041: *
042: *
043: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
044: * @version $Id: SpringComponentFactory.java,v 1.3 2004/03/23 13:37:56 lsimons Exp $
045: */
046: public class SpringComponentFactory extends BeanFactory {
047: final String m_name;
048: final org.springframework.beans.factory.BeanFactory m_factory;
049:
050: public SpringComponentFactory(final String name, final Class clazz,
051: final org.springframework.beans.factory.BeanFactory factory)
052: throws IntrospectionException {
053: this (name, clazz, factory, null);
054: }
055:
056: public SpringComponentFactory(
057: final String name,
058: final Class clazz,
059: final org.springframework.beans.factory.BeanFactory factory,
060: final Map properties) throws IntrospectionException {
061: this (name, clazz, factory, properties, null);
062: }
063:
064: public SpringComponentFactory(
065: final String name,
066: final Class clazz,
067: final org.springframework.beans.factory.BeanFactory factory,
068: final Map properties, final List constructorParameters)
069: throws IntrospectionException {
070: super (clazz, properties, constructorParameters);
071:
072: Assert.assertNotNull("name argument may not be null", name);
073: m_name = name;
074:
075: Assert.assertNotNull("factory argument may not be null",
076: factory);
077: m_factory = factory;
078: }
079:
080: public Object newInstance() {
081: final Object instance = super .newInstance();
082:
083: if (instance instanceof InitializingBean) {
084: try {
085: ((InitializingBean) instance).afterPropertiesSet();
086: } catch (Exception e) {
087: throw new JicarillaInstantiationException(e);
088: }
089: }
090:
091: if (instance instanceof BeanNameAware) {
092: ((BeanNameAware) instance).setBeanName(m_name);
093: }
094:
095: if (instance instanceof BeanFactoryAware) {
096: ((BeanFactoryAware) instance).setBeanFactory(m_factory);
097: }
098:
099: return instance;
100: }
101:
102: public void releaseInstance(final Object o) throws Exception {
103: if (o instanceof DisposableBean) {
104: ((DisposableBean) o).destroy();
105: }
106: super.releaseInstance(o);
107: }
108: }
|