@Override @Deprecated public <T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root) throws MultiException { return getService(activeDescriptor, root, null); }
@Override public <T> ServiceHandle<T> getServiceHandle(Type contractOrImpl, Annotation... qualifiers) throws MultiException { checkState(); ActiveDescriptor<T> ad = internalGetDescriptor(null, contractOrImpl, null, null, false, qualifiers); if (ad == null) return null; return getServiceHandle(ad, new InjecteeImpl(contractOrImpl)); }
@Override public void clearReflectionCache() { locator.clearReflectionCache(); }
@Override public <T> ServiceHandle<T> getServiceHandle(Type contractOrImpl, String name, Annotation... qualifiers) throws MultiException { checkState(); ActiveDescriptor<T> ad = internalGetDescriptor(null, contractOrImpl, name, null, false, qualifiers); if (ad == null) return null; return internalGetServiceHandle(ad, contractOrImpl, null); }
@Override public ActiveDescriptor<?> reifyDescriptor(Descriptor descriptor) throws MultiException { checkState(); return reifyDescriptor(descriptor, null); }
@SuppressWarnings("unchecked") @Override public <T> List<T> getAllServices(Type contractOrImpl, Annotation... qualifiers) throws MultiException { checkState(); List<T> retVal = (List<T>) internalGetAllServiceHandles( contractOrImpl, null, false, false, qualifiers ); return retVal; }
checkData = checkConfiguration(dci); // Does as much preliminary checking as possible removeConfigurationInternal(checkData.getUnbinds()); List<SystemDescriptor<?>> thingsAdded = addConfigurationInternal(dci); reup(thingsAdded, checkData.getInstanceLifecycleModificationsMade(), checkData.getInjectionResolverModificationMade(), getAllChildren(allMyChildren); sli.reupCache(checkData.getAffectedContracts()); callAllConfigurationListeners(allConfigurationListeners);
List<SystemDescriptor<?>> results = getDescriptors(unbindFilter, null, false, false, true); affectedContracts.addAll(getAllContracts(candidate)); for (ValidationService vs : getAllValidators()) { if (!callValidate(vs, new ValidationInformationImpl( Operation.UNBIND, candidate))) { throw new MultiException(new IllegalArgumentException("Descriptor " + affectedContracts.addAll(getAllContracts(sd)); sd.getAdvertisedContracts().contains(InstanceLifecycleListener.class.getName())) { reifyDescriptor(sd); reifyDescriptor(sd); reifyDescriptor(sd); for (ValidationService vs : getAllValidators()) { Validator validator = vs.getValidator(); if (validator == null) { if (!callValidate(vs, new ValidationInformationImpl( Operation.BIND, sd))) { throw new MultiException(new IllegalArgumentException("Descriptor " + sd + " did not pass the BIND validation"));
@Override public List<ActiveDescriptor<?>> getDescriptors(Filter filter) { checkState(); return ReflectionHelper.cast(getDescriptors(filter, null, true, true, true)); }
@SuppressWarnings("unchecked") @Override public <T> List<T> getAllServices(Annotation qualifier, Annotation... qualifiers) throws MultiException { checkState(); List<ServiceHandle<?>> services = getAllServiceHandles(qualifier, qualifiers); List<T> retVal = new LinkedList<T>(); for (ServiceHandle<?> service : services) { retVal.add((T) service.getService()); } return retVal; }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { ActiveDescriptor<?> ad = locator.getInjecteeDescriptor(injectee); if (ad == null) { if (injectee.isOptional()) return null; throw new MultiException(new UnsatisfiedDependencyException(injectee)); } return locator.getService(ad, root, injectee); }
@Override public <T> T create(Class<T> createMe, String strategy) { checkState(); return Utilities.justCreate(createMe, this, strategy); }
private <T> ServiceHandleImpl<T> internalGetServiceHandle( ActiveDescriptor<T> activeDescriptor, Type requestedType, Injectee originalRequest) { if (activeDescriptor == null) throw new IllegalArgumentException(); checkState(); if (requestedType == null) { return getServiceHandleImpl(activeDescriptor, null); } Injectee useInjectee = (originalRequest != null) ? originalRequest : new InjecteeImpl(requestedType) ; return getServiceHandleImpl(activeDescriptor, useInjectee); }
/** * Must be called under lock * * @param descriptor The descriptor to validate * @param onBehalfOf The fella who is being validated (or null) * @return true if every validator returned true */ private boolean validate(SystemDescriptor<?> descriptor, Injectee onBehalfOf, Filter filter) { for (ValidationService vs : getAllValidators()) { if (!descriptor.isValidating(vs)) continue; if (!callValidate(vs, new ValidationInformationImpl( Operation.LOOKUP, descriptor, onBehalfOf, filter))) { return false; } } return true; }
/** * Called by the Generator, and hence must be a public method * * @param name The name of this locator * @param parent The parent of this locator (may be null) */ public ServiceLocatorImpl(String name, ServiceLocatorImpl parent) { locatorName = name; this.parent = parent; if (parent != null) { parent.addChild(this); } id = getAndIncrementLocatorId(); Logger.getLogger().debug("Created ServiceLocator " + this); if (BIND_TRACING_PATTERN != null) { Logger.getLogger().debug("HK2 will trace binds and unbinds of " + BIND_TRACING_PATTERN + " with stacks " + BIND_TRACING_STACKS + " in " + this); } }
private ServiceLocator initialize(final String name, final ServiceLocator parent) { if (parent != null && !(parent instanceof ServiceLocatorImpl)) { throw new AssertionError("parent must be a " + ServiceLocatorImpl.class.getName() + " instead it is a " + parent.getClass().getName()); } final ServiceLocatorImpl sli = new ServiceLocatorImpl(name, (ServiceLocatorImpl) parent); final DynamicConfigurationImpl dci = new DynamicConfigurationImpl(sli); // The service locator itself dci.bind(Utilities.getLocatorDescriptor(sli)); // The injection resolver for three thirty dci.addActiveDescriptor(Utilities.getThreeThirtyDescriptor(sli)); // The dynamic configuration utility dci.bind(BuilderHelper.link(DynamicConfigurationServiceImpl.class, false). to(DynamicConfigurationService.class). in(Singleton.class.getName()). localOnly(). build()); dci.bind(BuilderHelper.createConstantDescriptor( new DefaultClassAnalyzer(sli))); dci.commit(); GuiceBridge.getGuiceBridge().initializeGuiceBridge(sli); GuiceIntoHK2Bridge guiceBridge = sli.getService(GuiceIntoHK2Bridge.class); guiceBridge.bridgeGuiceInjector(GuiceInjectorHolder.getInjector()); return sli; }
ServiceLocatorImpl sli = new ServiceLocatorImpl(name, (ServiceLocatorImpl) parent);
@Override public void commit() throws MultiException { synchronized (lock) { checkState(); committed = true; } locator.addConfiguration(this); }
checkData = checkConfiguration(dci); // Does as much preliminary checking as possible removeConfigurationInternal(checkData.getUnbinds()); List<SystemDescriptor<?>> thingsAdded = addConfigurationInternal(dci); reup(thingsAdded, checkData.getInstanceLifecycleModificationsMade(), checkData.getInjectionResolverModificationMade(), getAllChildren(allMyChildren); sli.reupCache(checkData.getAffectedContracts()); callAllConfigurationListeners(allConfigurationListeners);
List<SystemDescriptor<?>> results = getDescriptors(unbindFilter, null, false, false, true); affectedContracts.addAll(getAllContracts(candidate)); for (ValidationService vs : getAllValidators()) { if (!callValidate(vs, new ValidationInformationImpl( Operation.UNBIND, candidate))) { throw new MultiException(new IllegalArgumentException("Descriptor " + affectedContracts.addAll(getAllContracts(sd)); sd.getAdvertisedContracts().contains(InstanceLifecycleListener.class.getName())) { reifyDescriptor(sd); reifyDescriptor(sd); reifyDescriptor(sd); for (ValidationService vs : getAllValidators()) { Validator validator = vs.getValidator(); if (validator == null) { if (!callValidate(vs, new ValidationInformationImpl( Operation.BIND, sd))) { throw new MultiException(new IllegalArgumentException("Descriptor " + sd + " did not pass the BIND validation"));