@Override public Class<?> getBeanClass() { return binding.getService().getClass(); }
@Override public T create(CreationalContext<T> context) { T service = binding.getService(); this.injectionTarget.inject(service, context); return service; }
@Override @SuppressWarnings("unchecked") public ForeignDescriptor createForeignDescriptor(Binding binding) { Class<?> clazz; if (ClassBinding.class.isAssignableFrom(binding.getClass())) { clazz = ((ClassBinding<?>) binding).getService(); } else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) { clazz = ((InstanceBinding<?>) binding).getService().getClass(); } else { throw new RuntimeException( org.glassfish.jersey.internal.LocalizationMessages .UNKNOWN_DESCRIPTOR_TYPE(binding.getClass().getSimpleName())); } Set<Bean<?>> beans = beanManager.getBeans(clazz); if (beans.isEmpty()) { return null; } Bean bean = beans.iterator().next(); CreationalContext ctx = beanManager.createCreationalContext(bean); return ForeignDescriptor.wrap(bean, instance -> bean.destroy(instance, ctx)); }
} else { InstanceBinding instanceBinding = (InstanceBinding) binding; return instanceBinding.getService();
} else { InstanceBinding instanceBinding = (InstanceBinding) binding; return instanceBinding.getService();
/** * Ignores the classes which are manually added using bindings (through {@link Application} class) and scanned by CDI. * The manual adding is privileged and the beans scanned using CDI are ignored. * <p> * TODO: The method counts with the condition that the all bindings are known before the CDI scanning has been started, * can be changed during the migration from CDI SE to JAVA EE environment. * * @param pat processed type. * @param <T> type of the scanned bean. */ public <T> void ignoreManuallyRegisteredComponents( @Observes @WithAnnotations({ Path.class, Provider.class }) ProcessAnnotatedType<T> pat) { for (Binding binding : bindings.getBindings()) { if (ClassBinding.class.isAssignableFrom(binding.getClass())) { ClassBinding<?> classBinding = (ClassBinding<?>) binding; if (pat.getAnnotatedType().getJavaClass() == classBinding.getService()) { pat.veto(); return; } } else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) { InstanceBinding<?> instanceBinding = (InstanceBinding<?>) binding; if (pat.getAnnotatedType().getJavaClass() == instanceBinding.getService().getClass()) { pat.veto(); return; } } } }
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(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; }
} else { InstanceBinding instanceBinding = (InstanceBinding) binding; return instanceBinding.getService();
} else { InstanceBinding instanceBinding = (InstanceBinding) binding; return instanceBinding.getService();
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(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; }