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

org.apache.openejb.cdi.NewCdiEjbBean Maven / Gradle / Ivy

There is a newer version: 10.0.0-M3
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.openejb.cdi;

import org.apache.webbeans.annotation.NewLiteral;
import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.component.NewBean;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.InjectionTargetFactoryImpl;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionTarget;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;

/**
 * @version $Rev$ $Date$
 */
public class NewCdiEjbBean extends CdiEjbBean implements NewBean {
    private static final Set QUALIFIERS = Collections.singleton(Annotation.class.cast(new NewLiteral()));

    private final String id;

    public NewCdiEjbBean(final CdiEjbBean that) {
        super(that.getBeanContext(), that.getWebBeansContext(), that.getBeanContext().getManagedClass(), that.getAnnotatedType(),
                new NewEjbInjectionTargetFactory(that.getAnnotatedType(), that.getWebBeansContext(), that.getInjectionTarget()),
                new BeanAttributesImpl(that));
        this.id = that.getId() + "NewBean";
        initInternals();
    }

    @Override
    public Class getScope() {
        return Dependent.class;
    }

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

    @Override
    public String getName() {
        return null;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public Set getQualifiers() {
        return QUALIFIERS;
    }

    private static final class NewEjbInjectionTargetFactory extends InjectionTargetFactoryImpl {
        private final InjectionTarget injectionTarget;

        public NewEjbInjectionTargetFactory(final AnnotatedType annotatedType, final WebBeansContext webBeansContext, final InjectionTarget it) {
            super(annotatedType, webBeansContext);
            this.injectionTarget = it;
        }

        @Override
        public InjectionTarget createInjectionTarget(final Bean bean) { // avoid to refire it
            return injectionTarget;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy