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

org.jboss.weld.bean.builtin.AbstractBuiltInBean Maven / Gradle / Ivy

There is a newer version: 3.0.0.Alpha1
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, Red Hat, Inc., and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.weld.bean.builtin;

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.inject.spi.InjectionPoint;

import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bean.attributes.ImmutableBeanAttributes;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.serialization.spi.BeanIdentifier;
import org.jboss.weld.util.Bindings;
import org.jboss.weld.util.collections.ImmutableSet;

public abstract class AbstractBuiltInBean extends RIBean {

    private boolean proxyRequired;
    private final Class type;

    protected AbstractBuiltInBean(BeanIdentifier identifier, BeanManagerImpl beanManager, Class type) {
        super(new BuiltInBeanAttributes(type), identifier, beanManager);
        this.type = type;
    }

    @Override
    public void preInitialize() {
    }

    @Override
    public void internalInitialize(BeanDeployerEnvironment environment) {
        proxyRequired = getScope() != null && isNormalScoped();
    }

    @Override
    public void cleanupAfterBoot() {
        // No-op
    }

    @Override
    public void initializeAfterBeanDiscovery() {
        // No-op
    }

    @Override
    public Set getInjectionPoints() {
        return Collections.emptySet();
    }

    @Override
    public boolean isProxyable() {
        return true;
    }

    @Override
    public boolean isPassivationCapableBean() {
        return true;
    }

    @Override
    public boolean isPassivationCapableDependency() {
        return true;
    }

    @Override
    public boolean isProxyRequired() {
        return proxyRequired;
    }

    @Override
    public Class getType() {
        return type;
    }

    public boolean isDependentContextOptimizationAllowed() {
        // By default, all dependent built-in beans do not have to be stored in a CreationalContext
        return Dependent.class.equals(getScope());
    }

    protected static class BuiltInBeanAttributes extends ImmutableBeanAttributes {

        public BuiltInBeanAttributes(Class type) {
            super(Collections.> emptySet(), false, null, Bindings.DEFAULT_QUALIFIERS, ImmutableSet.of(type, Object.class), Dependent.class);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy