@Override public Object resolveResource(InjectionPoint injectionPoint) { final Member member = injectionPoint.getMember(); AnnotatedMember<?> annotatedMember; if (injectionPoint.getAnnotated() instanceof AnnotatedField) { annotatedMember = (AnnotatedField<?>) injectionPoint.getAnnotated(); } else { annotatedMember = ((AnnotatedParameter<?>) injectionPoint.getAnnotated()).getDeclaringCallable(); } if (!annotatedMember.isAnnotationPresent(Resource.class)) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(Resource.class, member); } if (member instanceof Method && ((Method) member).getParameterTypes().length != 1) { throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) member); } String name = getResourceName(injectionPoint); for (ResourceInjectionResolver resolver : resourceResolvers) { Object result = resolver.resolve(name); if (result != null) { return result; } } try { return context.lookup(name); } catch (NamingException e) { throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, injectionPoint.getMember().toString(), e); } }
@Override public <T> ResourceReferenceFactory<T> registerWebServiceRefInjectionPoint(final InjectionPoint injectionPoint) { WebServiceRef annotation = getResourceAnnotated(injectionPoint).getAnnotation(WebServiceRef.class); if (annotation == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(WebServiceRef.class, injectionPoint.getMember()); } validateWebServiceRefInjectionPoint(injectionPoint, annotation); try { ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(deploymentUnit, classNameFromType(injectionPoint.getType()), new WSRefAnnotationWrapper(annotation), (AnnotatedElement) injectionPoint.getMember(), getBindingName(injectionPoint, annotation)); return new ManagedReferenceFactoryToResourceReferenceFactoryAdapter<>(factory); } catch (DeploymentUnitProcessingException e) { throw new RuntimeException(e); } }
EJB ejb = ResourceInjectionUtilities.getResourceAnnotated(injectionPoint).getAnnotation(EJB.class); if (ejb == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(EJB.class, injectionPoint.getMember());
@Override public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(final InjectionPoint injectionPoint) { //TODO: cache this stuff final PersistenceUnit context = getResourceAnnotated(injectionPoint).getAnnotation(PersistenceUnit.class); if (context == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(PersistenceUnit.class, injectionPoint.getMember()); } final String scopedPuName = getScopedPUName(deploymentUnit, context.unitName(), injectionPoint.getMember()); final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName); final ServiceController<?> serviceController = deploymentUnit.getServiceRegistry().getRequiredService(persistenceUnitServiceName); //now we have the service controller, as this method is only called at runtime the service should //always be up final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue(); return new ImmediateResourceReferenceFactory<EntityManagerFactory>(persistenceUnitService.getEntityManagerFactory()); }
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint(final InjectionPoint injectionPoint) { //TODO: cache this stuff final PersistenceContext context = getResourceAnnotated(injectionPoint).getAnnotation(PersistenceContext.class); if (context == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(PersistenceContext.class, injectionPoint.getMember()); } final String scopedPuName = getScopedPUName(deploymentUnit, context.unitName(), injectionPoint.getMember()); final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName); final ServiceController<?> serviceController = deploymentUnit.getServiceRegistry().getRequiredService(persistenceUnitServiceName); //now we have the service controller, as this method is only called at runtime the service should //always be up final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue(); return new EntityManagerResourceReferenceFactory(scopedPuName, persistenceUnitService.getEntityManagerFactory(), context, deploymentUnit.getAttachment(JpaAttachments.TRANSACTION_SYNCHRONIZATION_REGISTRY), ContextTransactionManager.getInstance()); }