static ActiveDescriptor<?> translateToActiveDescriptor(ClassBinding<?> desc) { ActiveDescriptorBuilder binding = BuilderHelper.activeLink(desc.getService()).named(desc.getName()) .analyzeWith(desc.getAnalyzer()); if (desc.getScope() != null) { binding.in(transformScope(desc.getScope())); } if (desc.getRank() != null) { binding.ofRank(desc.getRank()); } for (Annotation annotation : desc.getQualifiers()) { binding.qualifiedBy(annotation); } for (Type contract : desc.getContracts()) { binding.to(contract); } if (desc.isProxiable() != null) { binding.proxy(desc.isProxiable()); } if (desc.isProxiedForSameScope() != null) { binding.proxyForSameScope(desc.isProxiedForSameScope()); } if (desc.getImplementationType() != null) { binding.asType(desc.getImplementationType()); } return binding.build(); }
static ActiveDescriptor<?> translateToActiveDescriptor(InstanceBinding<?> desc, Type... contracts) { AbstractActiveDescriptor<?> binding; if (contracts.length == 0) { binding = BuilderHelper.createConstantDescriptor(desc.getService()); } else { binding = BuilderHelper.createConstantDescriptor(desc.getService(), null, contracts); } binding.setName(desc.getName()); binding.setClassAnalysisName(desc.getAnalyzer()); if (desc.getScope() != null) { binding.setScope(desc.getScope().getName()); } if (desc.getRank() != null) { binding.setRanking(desc.getRank()); } for (Annotation annotation : desc.getQualifiers()) { binding.addQualifierAnnotation(annotation); } for (Type contract : desc.getContracts()) { binding.addContractType(contract); } if (desc.isProxiable() != null) { binding.setProxiable(desc.isProxiable()); } if (desc.isProxiedForSameScope() != null) { binding.setProxyForSameScope(desc.isProxiedForSameScope()); } return binding; }
AbstractActiveDescriptor<? extends Supplier<?>> supplierBuilder = BuilderHelper.createConstantDescriptor(supplier); binding.getContracts().forEach(contract -> { supplierBuilder.addContractType(new ParameterizedTypeImpl(Supplier.class, contract)); if (disposable) { supplierBuilder.addContractType(new ParameterizedTypeImpl(DisposableSupplier.class, contract)); supplierBuilder.setName(binding.getName()); binding.getQualifiers().forEach(supplierBuilder::addQualifierAnnotation); binder.bind(supplierBuilder); ServiceBindingBuilder<?> builder = binder.bindFactory(new InstanceSupplierFactoryBridge<>(supplier, disposable)); setupSupplierFactoryBridge(binding, builder); }; ServiceLocatorUtilities.bind(locator, createBinder(bindConsumer));
private static ActiveDescriptor<?> translateToActiveDescriptor(InjectionResolverBinding<?> desc) { ParameterizedTypeImpl parameterizedType = new ParameterizedTypeImpl( org.glassfish.jersey.internal.inject.InjectionResolver.class, desc.getResolver().getAnnotation()); return BuilderHelper.createConstantDescriptor(desc.getResolver(), null, parameterizedType); }
@Override public void completeRegistration() throws IllegalStateException { Hk2Helper.bind(this, bindings); ServiceLocatorUtilities.bind(getServiceLocator(), providers.toArray(new org.glassfish.hk2.utilities.Binder[]{})); completed = true; } }
@Override public ForeignDescriptor createForeignDescriptor(Binding binding) { ForeignDescriptor foreignDescriptor = createAndTranslateForeignDescriptor(binding); ActiveDescriptor<Object> activeDescriptor = ServiceLocatorUtilities .addOneDescriptor(getServiceLocator(), (Descriptor) foreignDescriptor.get(), false); return ForeignDescriptor.wrap(activeDescriptor, activeDescriptor::dispose); }
private static InjecteeImpl toInjecteeImpl(org.glassfish.jersey.internal.inject.Injectee injectee) { InjecteeImpl hk2injectee = new InjecteeImpl() { @Override public Class<?> getInjecteeClass() { return injectee.getInjecteeClass(); } }; hk2injectee.setRequiredType(injectee.getRequiredType()); hk2injectee.setRequiredQualifiers(injectee.getRequiredQualifiers()); hk2injectee.setParent(injectee.getParent()); if (injectee.getInjecteeDescriptor() != null) { hk2injectee.setInjecteeDescriptor((ActiveDescriptor<?>) injectee.getInjecteeDescriptor().get()); } return hk2injectee; }
public ActorBaseTest() { ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance(); serviceLocator = factory.create(UUID.randomUUID().toString()); ServiceLocatorUtilities.addOneConstant(serviceLocator, fakeSync); }
/** * Creates the alias object to a provided descriptor. * * @param locator locator used to create an alias. * @param descriptor descriptor which the alias belongs to. * @param alias source of the alias information. * @return populated alias object, ready to bindBinder using {@link DynamicConfiguration}. */ private static org.glassfish.hk2.utilities.AliasDescriptor<?> createAlias(ServiceLocator locator, ActiveDescriptor<?> descriptor, AliasBinding alias) { org.glassfish.hk2.utilities.AliasDescriptor<?> hk2Alias = new org.glassfish.hk2.utilities.AliasDescriptor<>(locator, descriptor, alias.getContract().getName(), null); alias.getQualifiers().forEach(hk2Alias::addQualifierAnnotation); alias.getScope().ifPresent(hk2Alias::setScope); alias.getRank().ifPresent(hk2Alias::setRanking); return hk2Alias; }
/** * Creates a new {@link ServiceLocator} instance from static {@link ServiceLocatorFactory} and adds the provided parent * locator if the instance is not null. * * @param parentLocator parent locator, can be {@code null}. * @return new instance of injection manager. */ private static ServiceLocator createLocator(ServiceLocator parentLocator) { ServiceLocator result = factory.create(null, parentLocator, null, ServiceLocatorFactory.CreatePolicy.DESTROY); result.setNeutralContextClassLoader(false); ServiceLocatorUtilities.enablePerThreadScope(result); return result; }
AbstractActiveDescriptor<? extends Supplier<?>> supplierBuilder = BuilderHelper.createConstantDescriptor(supplier); binding.getContracts().forEach(contract -> { supplierBuilder.addContractType(new ParameterizedTypeImpl(Supplier.class, contract)); if (disposable) { supplierBuilder.addContractType(new ParameterizedTypeImpl(DisposableSupplier.class, contract)); supplierBuilder.setName(binding.getName()); binding.getQualifiers().forEach(supplierBuilder::addQualifierAnnotation); binder.bind(supplierBuilder); ServiceBindingBuilder<?> builder = binder.bindFactory(new InstanceSupplierFactoryBridge<>(supplier, disposable)); setupSupplierFactoryBridge(binding, builder); }; ServiceLocatorUtilities.bind(locator, createBinder(bindConsumer));
static ActiveDescriptor<?> translateToActiveDescriptor(InstanceBinding<?> desc, Type... contracts) { AbstractActiveDescriptor<?> binding; if (contracts.length == 0) { binding = BuilderHelper.createConstantDescriptor(desc.getService()); } else { binding = BuilderHelper.createConstantDescriptor(desc.getService(), null, contracts); } binding.setName(desc.getName()); binding.setClassAnalysisName(desc.getAnalyzer()); if (desc.getScope() != null) { binding.setScope(desc.getScope().getName()); } if (desc.getRank() != null) { binding.setRanking(desc.getRank()); } for (Annotation annotation : desc.getQualifiers()) { binding.addQualifierAnnotation(annotation); } for (Type contract : desc.getContracts()) { binding.addContractType(contract); } if (desc.isProxiable() != null) { binding.setProxiable(desc.isProxiable()); } if (desc.isProxiedForSameScope() != null) { binding.setProxyForSameScope(desc.isProxiedForSameScope()); } return binding; }
static ActiveDescriptor<?> translateToActiveDescriptor(ClassBinding<?> desc) { ActiveDescriptorBuilder binding = BuilderHelper.activeLink(desc.getService()).named(desc.getName()) .analyzeWith(desc.getAnalyzer()); if (desc.getScope() != null) { binding.in(transformScope(desc.getScope())); } if (desc.getRank() != null) { binding.ofRank(desc.getRank()); } for (Annotation annotation : desc.getQualifiers()) { binding.qualifiedBy(annotation); } for (Type contract : desc.getContracts()) { binding.to(contract); } if (desc.isProxiable() != null) { binding.proxy(desc.isProxiable()); } if (desc.isProxiedForSameScope() != null) { binding.proxyForSameScope(desc.isProxiedForSameScope()); } if (desc.getImplementationType() != null) { binding.asType(desc.getImplementationType()); } return binding.build(); }
private static ActiveDescriptor<?> translateToActiveDescriptor(InjectionResolverBinding<?> desc) { ParameterizedTypeImpl parameterizedType = new ParameterizedTypeImpl( org.glassfish.jersey.internal.inject.InjectionResolver.class, desc.getResolver().getAnnotation()); return BuilderHelper.createConstantDescriptor(desc.getResolver(), null, parameterizedType); }
@Override public void completeRegistration() throws IllegalStateException { Hk2Helper.bind(this, bindings); ServiceLocatorUtilities.bind(getServiceLocator(), providers.toArray(new org.glassfish.hk2.utilities.Binder[]{})); completed = true; } }
@Override public ForeignDescriptor createForeignDescriptor(Binding binding) { ForeignDescriptor foreignDescriptor = createAndTranslateForeignDescriptor(binding); ActiveDescriptor<Object> activeDescriptor = ServiceLocatorUtilities .addOneDescriptor(getServiceLocator(), (Descriptor) foreignDescriptor.get(), false); return ForeignDescriptor.wrap(activeDescriptor, activeDescriptor::dispose); }
private static InjecteeImpl toInjecteeImpl(org.glassfish.jersey.internal.inject.Injectee injectee) { InjecteeImpl hk2injectee = new InjecteeImpl() { @Override public Class<?> getInjecteeClass() { return injectee.getInjecteeClass(); } }; hk2injectee.setRequiredType(injectee.getRequiredType()); hk2injectee.setRequiredQualifiers(injectee.getRequiredQualifiers()); hk2injectee.setParent(injectee.getParent()); if (injectee.getInjecteeDescriptor() != null) { hk2injectee.setInjecteeDescriptor((ActiveDescriptor<?>) injectee.getInjecteeDescriptor().get()); } return hk2injectee; }
/** * Creates a new {@link ServiceLocator} instance from static {@link ServiceLocatorFactory} and adds the provided parent * locator if the instance is not null. * * @param parentLocator parent locator, can be {@code null}. * @return new instance of injection manager. */ private static ServiceLocator createLocator(ServiceLocator parentLocator) { ServiceLocator result = factory.create(null, parentLocator, null, ServiceLocatorFactory.CreatePolicy.DESTROY); result.setNeutralContextClassLoader(false); ServiceLocatorUtilities.enablePerThreadScope(result); return result; }
@Override public void register(Object provider) { if (isRegistrable(provider.getClass())) { ServiceLocatorUtilities.bind(getServiceLocator(), (org.glassfish.hk2.utilities.Binder) provider); } else { throw new IllegalArgumentException(LocalizationMessages.HK_2_PROVIDER_NOT_REGISTRABLE(provider.getClass())); } } }
@Override public void register(Object provider) { if (isRegistrable(provider.getClass())) { ServiceLocatorUtilities.bind(getServiceLocator(), (org.glassfish.hk2.utilities.Binder) provider); } else { throw new IllegalArgumentException(LocalizationMessages.HK_2_PROVIDER_NOT_REGISTRABLE(provider.getClass())); } } }