All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pustefixframework.cdi.SpringBean Maven / Gradle / Ivy

There is a newer version: 0.22.22
Show newest version
/*
 * This file is part of Pustefix.
 *
 * Pustefix is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Pustefix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Pustefix; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.pustefixframework.cdi;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;

import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;

/**
 * CDI Bean interface implementation for Spring beans.
 * Delegates creation/destroying of concrete bean instances
 * to a Spring BeanFactory.
 * 
 * @author [email protected]
 *
 */
public class SpringBean implements Bean {
    
    private String beanName;
    private Class beanClass;
    private Set beanTypes;
    private Set qualifiers;
    private Set> stereotypes;
    private BeanFactoryAdapter beanFactory;
       
    public SpringBean(BeanFactoryAdapter beanFactory, String beanName, Class beanClass, 
            Set beanTypes, Set qualifiers, Set> stereotypes) {
        this.beanFactory = beanFactory;
        this.beanName = beanName;
        this.beanClass = beanClass;
        this.beanTypes = beanTypes;
        this.qualifiers = qualifiers;
        this.stereotypes = stereotypes;
    }
        
    public String getName() {
        return beanName;
    }
   
    public Class getBeanClass() {
        return beanClass;
    }
       
    public Set getTypes() {
        return beanTypes;
    }
   
    public Set getQualifiers() {
        return qualifiers;
    }
       
    public Set> getStereotypes() {
        return stereotypes;
    }
   
    public Class getScope() {
        return Dependent.class;
    }
    
    public Set getInjectionPoints() {
        return Collections.emptySet();
    }
        
    public boolean isAlternative() {
        return false;
    }
   
    public boolean isNullable() {
        return true;
    }
   
    public Object create(CreationalContext creationalContext) {
        return beanFactory.getBean(beanName);
    }
   
    public void destroy(Object beanInstance, CreationalContext creationalContext) {
        beanFactory.destroyBean(beanName, beanInstance);
    }

}