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

io.helidon.integrations.vault.cdi.QualifiedBean Maven / Gradle / Ivy

There is a newer version: 4.1.1
Show newest version
/*
 * Copyright (c) 2021, 2023 Oracle and/or its affiliates.
 *
 * 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 io.helidon.integrations.vault.cdi;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.enterprise.inject.spi.PassivationCapable;

class QualifiedBean implements Bean, PassivationCapable {
    private final Class beanClass;
    private final Class type;
    private final Set qualifiers;
    private final Supplier creator;
    private final Set customQualifiers;

    QualifiedBean(Class beanClass, Class type, Supplier creator) {
        this.beanClass = beanClass;
        this.type = type;
        this.qualifiers = Set.of(Any.Literal.INSTANCE, Default.Literal.INSTANCE);
        this.customQualifiers = Set.of();
        this.creator = creator;
    }

    QualifiedBean(Class beanClass, Class type, Set qualifiers, Supplier creator) {
        this.beanClass = beanClass;
        this.type = type;
        Set finalQualifiers = new HashSet<>(qualifiers);
        finalQualifiers.add(Any.Literal.INSTANCE);
        this.qualifiers = finalQualifiers;
        this.customQualifiers = qualifiers;
        this.creator = creator;
    }

    @Override
    public Class getBeanClass() {
        return beanClass;
    }

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

    @Override
    public T create(CreationalContext creationalContext) {
        return creator.get();
    }

    @Override
    public void destroy(T instance, CreationalContext creationalContext) {
    }

    @Override
    public Set getTypes() {
        return Set.of(type);
    }

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

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

    @Override
    public String getName() {
        return type.getName() + "." + qualifiers;
    }

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

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

    @Override
    public String toString() {
        return "QualifiedBean{"
                + "beanClass=" + beanClass.getSimpleName()
                + ", type=" + type.getSimpleName()
                + ", qualifiers=" + customQualifiers
                + '}';
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy