use of org.glassfish.hk2.utilities.DescriptorBuilder in project Payara by payara.
the class ConfigModule method bindInjector.
private void bindInjector(DynamicConfiguration configurator, String elementName, Class contract, final Class clz) {
DescriptorBuilder db = BuilderHelper.link(clz).to(ConfigInjector.class).to(InjectionTarget.class).to(contract).in(Singleton.class.getName()).qualifiedBy(clz.getAnnotation(InjectionTarget.class)).named(elementName).andLoadWith(new MyHk2Loader(clz.getClassLoader()));
String metaData = ((Service) clz.getAnnotation(Service.class)).metadata();
Map<String, List<String>> metaMap = new HashMap<String, List<String>>();
for (StringTokenizer st = new StringTokenizer(metaData, ","); st.hasMoreTokens(); ) {
String tok = st.nextToken();
int index = tok.indexOf('=');
if (index > 0) {
String key = tok.substring(0, index);
String value = tok.substring(index + 1);
List<String> lst = metaMap.get(key);
if (lst == null) {
lst = new LinkedList<String>();
metaMap.put(key, lst);
}
lst.add(value);
// System.out.println("** Added Metadata: " + tok.substring(0, index) + " : " + tok.substring(index+1));
}
// db.andLoadWith(new MyHk2Loader(clz.getClassLoader()));
}
for (String key : metaMap.keySet()) {
db.has(key, metaMap.get(key));
}
ActiveDescriptor desc = configurator.bind(db.build());
configurator.bind(new AliasDescriptor(serviceLocator, desc, InjectionTarget.class.getName(), contract.getName()));
System.out.println("**Successfully bound an alias descriptor for: " + elementName);
}
use of org.glassfish.hk2.utilities.DescriptorBuilder in project Payara by payara.
the class AppServerStartupTest method bindService.
private void bindService(DynamicConfiguration configurator, Class<?> service) {
final DescriptorBuilder descriptorBuilder = BuilderHelper.link(service);
final RunLevel rla = service.getAnnotation(RunLevel.class);
if (rla != null) {
descriptorBuilder.to(RunLevel.class).has(RunLevel.RUNLEVEL_VAL_META_TAG, Collections.singletonList(((Integer) rla.value()).toString())).has(RunLevel.RUNLEVEL_MODE_META_TAG, Collections.singletonList(((Integer) rla.mode()).toString()));
descriptorBuilder.in(RunLevel.class);
}
Class clazz = service;
while (clazz != null) {
Class<?>[] interfaces = clazz.getInterfaces();
for (int j = 0; j < interfaces.length; j++) {
descriptorBuilder.to(interfaces[j]);
}
clazz = clazz.getSuperclass();
}
final Named named = service.getAnnotation(Named.class);
if (named != null) {
descriptorBuilder.named(named.value());
}
configurator.bind(descriptorBuilder.build());
}
Aggregations