Search in sources :

Example 71 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class CDISecondChanceResolver method justInTimeResolution.

/* (non-Javadoc)
     * @see org.glassfish.hk2.api.JustInTimeInjectionResolver#justInTimeResolution(org.glassfish.hk2.api.Injectee)
     */
@SuppressWarnings({ "unchecked" })
@Override
public boolean justInTimeResolution(Injectee failedInjectionPoint) {
    Type requiredType = failedInjectionPoint.getRequiredType();
    Set<Annotation> setQualifiers = failedInjectionPoint.getRequiredQualifiers();
    Annotation[] qualifiers = setQualifiers.toArray(new Annotation[setQualifiers.size()]);
    BeanManager manager = getCurrentBeanManager();
    if (manager == null)
        return false;
    Set<Bean<?>> beans = manager.getBeans(requiredType, qualifiers);
    if (beans == null || beans.isEmpty()) {
        return false;
    }
    DynamicConfiguration config = ServiceLocatorUtilities.createDynamicConfiguration(locator);
    for (Bean<?> bean : beans) {
        // Add a bean to the service locator
        CDIHK2Descriptor<Object> descriptor = new CDIHK2Descriptor<Object>(manager, (Bean<Object>) bean, requiredType);
        config.addActiveDescriptor(descriptor);
    }
    config.commit();
    return true;
}
Also used : Type(java.lang.reflect.Type) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) BeanManager(javax.enterprise.inject.spi.BeanManager) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean)

Aggregations

ServiceLocator (org.glassfish.hk2.api.ServiceLocator)21 ActionReport (org.glassfish.api.ActionReport)19 List (java.util.List)17 MultiException (org.glassfish.hk2.api.MultiException)16 IOException (java.io.IOException)13 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 ParameterMap (org.glassfish.api.admin.ParameterMap)10 Types (org.glassfish.hk2.classmodel.reflect.Types)10 Logger (java.util.logging.Logger)9 File (java.io.File)8 Inject (javax.inject.Inject)7 PropertyVetoException (java.beans.PropertyVetoException)6 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Type (org.glassfish.hk2.classmodel.reflect.Type)6 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)5 Sniffer (org.glassfish.api.container.Sniffer)5