@Override public Object getInstance(ForeignDescriptor foreignDescriptor) { return getServiceLocator().getServiceHandle((ActiveDescriptor<?>) foreignDescriptor.get()).getService(); }
@Override public Object getInstance(ForeignDescriptor foreignDescriptor) { return getServiceLocator().getServiceHandle((ActiveDescriptor<?>) foreignDescriptor.get()).getService(); }
@Override public Injectee apply(CacheKey cacheKey) { Injectee injectee = cacheKey.getInjectee(); if (injectee.getParent() != null) { if (Field.class.isAssignableFrom(injectee.getParent().getClass())) { Field f = (Field) injectee.getParent(); if (foreignRequestScopedComponents.get().contains(f.getDeclaringClass())) { final Class<?> clazz = f.getType(); if (serviceLocator.getServiceHandle(clazz).getActiveDescriptor().getScopeAnnotation() == RequestScoped.class) { final AbstractActiveDescriptor<Object> descriptor = BuilderHelper.activeLink(clazz) .to(clazz) .in(RequestScoped.class) .build(); return new DescriptorOverridingInjectee(injectee, descriptor); } } } } return injectee; } });
@Override public Injectee apply(CacheKey cacheKey) { Injectee injectee = cacheKey.getInjectee(); if (injectee.getParent() != null) { if (Field.class.isAssignableFrom(injectee.getParent().getClass())) { Field f = (Field) injectee.getParent(); if (foreignRequestScopedComponents.get().contains(f.getDeclaringClass())) { final Class<?> clazz = f.getType(); if (serviceLocator.getServiceHandle(clazz).getActiveDescriptor().getScopeAnnotation() == RequestScoped.class) { final AbstractActiveDescriptor<Object> descriptor = BuilderHelper.activeLink(clazz) .to(clazz) .in(RequestScoped.class) .build(); return new DescriptorOverridingInjectee(injectee, descriptor); } } } } return injectee; } });
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { Type requiredType = injectee.getRequiredType(); boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class); Injectee newInjectee; if (isHk2Factory) { newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0)); } else { newInjectee = foreignRequestScopedInjecteeCache.apply(new CacheKey(injectee)); } ActiveDescriptor<?> ad = descriptorCache.apply(new CacheKey(newInjectee)); if (ad != null) { final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee); if (isHk2Factory) { return asFactory(handle); } else { return handle.getService(); } } return null; }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { Type requiredType = injectee.getRequiredType(); boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class); Injectee newInjectee; if (isHk2Factory) { newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0)); } else { newInjectee = foreignRequestScopedInjecteeCache.apply(new CacheKey(injectee)); } ActiveDescriptor<?> ad = descriptorCache.apply(new CacheKey(newInjectee)); if (ad != null) { final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee); if (isHk2Factory) { return asFactory(handle); } else { return handle.getService(); } } return null; }
public void testGenericContainerInjector() { ServiceHandle sh = habitat.getServiceHandle(ConfigInjector.class, "generic-container"); assert(sh != null); }
public void testLookupOfInjectorAndCheckIfActive() { ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); ServiceHandle inhabitant2 = habitat.getServiceHandle(ConfigInjector.class, "ejb-container-availability"); assert(inhabitant1 != null && inhabitant2 != null && inhabitant1.isActive() == false && inhabitant2.isActive() == false); }
public void lookupConnectorServiceAndEnsureNotActive() { SimpleConnector sc = habitat.getService(SimpleConnector.class); System.out.println("[lookupConnectorService] Got sc : " + sc.getClass().getName()); ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); assert(sc != null && !inhabitant1.isActive()); }
public void lookupInjectorByName() { ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); ServiceHandle inhabitant2 = habitat.getServiceHandle(ConfigInjector.class, "ejb-container-availability"); assert(inhabitant1 != null && inhabitant2 != null && inhabitant1.getActiveDescriptor().getImplementation().equals(SimpleConnectorInjector.class.getName()) && inhabitant2.getActiveDescriptor().getImplementation().equals(EjbContainerAvailabilityInjector.class.getName())); }
public void getConnectorServiceAndCheckIfActive() { SimpleConnector sc = habitat.getService(SimpleConnector.class); String port = sc.getPort(); ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); assert(port.equals("8080")); // && inhabitant1.isActive()); }
serviceHandle = getHabitat().getServiceHandle(domDescriptor);
@Override public <T> ServiceHandle<T> getServiceHandle(Class<T> contractOrImpl, String name, Annotation... qualifiers) throws MultiException { return delegate.getServiceHandle(contractOrImpl, name, qualifiers); }
@SuppressWarnings("unchecked") private ServiceHandle<Factory<T>> getFactoryHandle() { try { return (ServiceHandle<Factory<T>>) locator.getServiceHandle(factoryDescriptor); } catch (Throwable th) { throw new MultiException(th); } }
private AnnotationHandler getHandler() { if (handler != null) return handler; handler = locator.getServiceHandle(descriptor).getService(); return handler; }
@SuppressWarnings("unchecked") private ServiceHandle<Factory<T>> getFactoryHandle() { try { return (ServiceHandle<Factory<T>>) locator.getServiceHandle(factoryDescriptor); } catch (Throwable th) { throw new MultiException(th); } }
private synchronized ServiceHandle<?> getServiceFromName(String id) { if (locator == null) throw new IllegalStateException( "ServiceLocator must be set"); ActiveDescriptor<?> best = locator.getBestDescriptor(BuilderHelper.createTokenizedFilter(id)); if (best == null) return null; return locator.getServiceHandle(best); }
@Override public T create(ServiceHandle<?> root) { ensureInitialized(); return locator.getServiceHandle(descriptor).getService(); }
@SuppressWarnings("unchecked") public Archivist getArchivist(String archiveType) { ActiveDescriptor<Archivist> best = (ActiveDescriptor<Archivist>) habitat.getBestDescriptor(new ArchivistFilter(archiveType, ARCHIVE_TYPE, Archivist.class)); if (best == null) return null; return habitat.getServiceHandle(best).getService(); }
public void getConnectorServiceAndCheckIfActive() { SimpleConnector sc = habitat.getService(SimpleConnector.class); String port = sc.getPort(); ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); assert(port.equals("8080")); // && inhabitant1.isActive()); }