org.openfact.components.utils.DefaultComponentUtil Maven / Gradle / Ivy
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);
}
}
}