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

io.helidon.integrations.graal.mp.nativeimage.extension.ProxyBean Maven / Gradle / Ivy

The 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.graal.mp.nativeimage.extension;

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

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;

/**
 * Proxy used to initialize Weld.
 * This class is a top level class so it does not add WeldFeature to the image.
 */
final class ProxyBean implements Bean {
    // this is the bean class (producer class, or the type itself for managed beans)
    private final Class beanClass;
    // the types of the produced bean
    private final Set types;

    ProxyBean(Class beanClass, Set types) {
        this.beanClass = beanClass;

        this.types = types;
    }

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

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

    @Override
    public Object create(CreationalContext creationalContext) {
        throw new IllegalStateException("This bean should not be created");
    }

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

    @Override
    public Set getTypes() {
        return types;
    }

    @Override
    public Set getQualifiers() {
        return Set.of(Any.Literal.INSTANCE, Default.Literal.INSTANCE);
    }

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

    @Override
    public String getName() {
        return beanClass.getName();
    }

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

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