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

org.jboss.weld.injection.producer.DefaultInstantiator Maven / Gradle / Ivy

There is a newer version: 3.0.0.Alpha1
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012, 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.injection.producer;

import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;

import javax.enterprise.inject.spi.Bean;

import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedConstructor;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.injection.ConstructorInjectionPoint;
import org.jboss.weld.injection.InjectionPointFactory;
import org.jboss.weld.injection.ParameterInjectionPoint;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Beans;

/**
 * Creates a new Java object by calling its class constructor. This class is thread-safe.
 *
 * @author Jozef Hartinger
 *
 * @param 
 */
public class DefaultInstantiator extends AbstractInstantiator {

    private final ConstructorInjectionPoint constructor;

    public DefaultInstantiator(EnhancedAnnotatedType type, Bean bean, BeanManagerImpl manager) {
        EnhancedAnnotatedConstructor constructor = Beans.getBeanConstructor(type);
        this.constructor = InjectionPointFactory.instance().createConstructorInjectionPoint(bean, type.getJavaClass(), constructor, manager);
    }

    @Override
    public ConstructorInjectionPoint getConstructorInjectionPoint() {
        return constructor;
    }

    @Override
    public Constructor getConstructor() {
        if (constructor == null) { // TODO: isolate this into a special non-producible instantiator
            return null;
        }
        return constructor.getAnnotated().getJavaMember();
    }

    public List> getParameterInjectionPoints() {
        if (constructor == null) {
            return Collections.emptyList();
        }
        return constructor.getParameterInjectionPoints();
    }

    @Override
    public String toString() {
        return "SimpleInstantiator [constructor=" + constructor.getMember() + "]";
    }

    @Override
    public boolean hasInterceptorSupport() {
        return false;
    }

    @Override
    public boolean hasDecoratorSupport() {
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy