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

org.openfact.components.utils.DefaultComponentUtil Maven / Gradle / Ivy

There is a newer version: 1.1.3.Final
Show newest version
package org.openfact.components.utils;

import org.openfact.keys.qualifiers.RsaKeyType;
import org.openfact.component.ComponentFactory;

import javax.ejb.Stateless;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.lang.annotation.Annotation;
import java.util.Optional;

@Stateless
public class DefaultComponentUtil implements ComponentUtil {

    @Inject
    @Any
    private Instance componentFactories;

    @Override
    public ComponentFactory getComponentFactory(String providerType, String providerId) {
        try {
            Class aClass = Class.forName(providerType);

            Optional op = RsaKeyType.findByProviderId(providerId);
            if (!op.isPresent()) {
                return null;
            }

            Annotation componentProviderLiteral = new ComponentProviderLiteral(aClass);
            Annotation rsaKeyProviderLiteral = new RsaKeyProviderLiteral(op.get());

            return componentFactories.select(ComponentFactory.class, componentProviderLiteral, rsaKeyProviderLiteral).get();
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException("Invalid factory", e);
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy