Search in sources :

Example 1 with ConfigInjector

use of org.jvnet.hk2.config.ConfigInjector in project Payara by payara.

the class ConfigModularityUtils method getAnnotatedConfigBeans.

public List<Class> getAnnotatedConfigBeans(Class annotationType) {
    List<Class> prox = new ArrayList<Class>();
    List<ActiveDescriptor<?>> descriptor = serviceLocator.getDescriptors(BuilderHelper.createContractFilter(ConfigInjector.class.getName()));
    Class<?> clz = null;
    for (ActiveDescriptor desc : descriptor) {
        if (desc.getName() == null) {
            continue;
        }
        ConfigInjector injector = serviceLocator.getService(ConfigInjector.class, desc.getName());
        if (injector != null) {
            String clzName = injector.getClass().getName().substring(0, injector.getClass().getName().length() - 8);
            if (clzName == null) {
                continue;
            }
            try {
                clz = injector.getClass().getClassLoader().loadClass(clzName);
                if (clz == null) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.log(Level.FINE, "Cannot find the class mapping to:  " + clzName);
                    }
                    continue;
                }
            } catch (Throwable e) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE, "Cannot load the class", e);
                }
                continue;
            }
        }
        if (clz != null) {
            if (clz.isAnnotationPresent(annotationType)) {
                prox.add(clz);
            }
        }
    }
    return prox;
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) ArrayList(java.util.ArrayList) ConfigInjector(org.jvnet.hk2.config.ConfigInjector)

Example 2 with ConfigInjector

use of org.jvnet.hk2.config.ConfigInjector in project Payara by payara.

the class ConfigModularityUtils method getClassForFullName.

public Class getClassForFullName(String configBeanClassName) {
    ActiveDescriptor<?> descriptor = serviceLocator.getBestDescriptor(BuilderHelper.createContractFilter(configBeanClassName));
    if (descriptor != null) {
        if (!descriptor.isReified()) {
            descriptor = serviceLocator.reifyDescriptor(descriptor);
        }
        return getClassFromDescriptor(descriptor);
    } else {
        descriptor = serviceLocator.getBestDescriptor(BuilderHelper.createContractFilter(configBeanClassName + "Injector"));
        if (!descriptor.isReified()) {
            descriptor = serviceLocator.reifyDescriptor(descriptor);
        }
        ConfigInjector injector = (ConfigInjector) serviceLocator.getServiceHandle(descriptor).getService();
        return getClassFromInjector(injector);
    }
}
Also used : ConfigInjector(org.jvnet.hk2.config.ConfigInjector)

Example 3 with ConfigInjector

use of org.jvnet.hk2.config.ConfigInjector in project Payara by payara.

the class ConfigModularityUtils method getClassFor.

public Class getClassFor(String serviceName) {
    serviceName = getServiceTypeNameIfNamedComponent(serviceName);
    ConfigInjector injector = serviceLocator.getService(ConfigInjector.class, serviceName.toLowerCase(Locale.getDefault()));
    return getClassFromInjector(injector);
}
Also used : ConfigInjector(org.jvnet.hk2.config.ConfigInjector)

Aggregations

ConfigInjector (org.jvnet.hk2.config.ConfigInjector)3 ArrayList (java.util.ArrayList)1 ActiveDescriptor (org.glassfish.hk2.api.ActiveDescriptor)1