/** * Returns a proxy (newly created or cached) which is able to call {@link InjectionResolver} with the given {@link Injectee} * to get the value in proper scope. * * @param injectee information about the injection point. * @param resolver dedicated resolver which find the value. * @return created proxy which resolve the value in the proper scope. */ public Object proxy(Injectee injectee, InjectionResolver resolver) { return cachedProxies.computeIfAbsent(injectee.getParent(), type -> createProxy(injectee, resolver)); }
@Override public Object resolve(Injectee injectee) { AnnotatedElement parent = injectee.getParent(); String beanName = null; if (parent != null) { Qualifier an = parent.getAnnotation(Qualifier.class); if (an != null) { beanName = an.value(); } } boolean required = parent != null ? parent.getAnnotation(Autowired.class).required() : false; return getBeanFromSpringContext(beanName, injectee, required); }
@Override public Object resolve(Injectee injectee) { if (!injectee.getRequiredType().equals(EntityManagerFactory.class)) { return null; } final PersistenceUnit annotation = injectee.getParent().getAnnotation(PersistenceUnit.class); final String unitName = annotation.unitName(); if (!persistenceUnits.containsKey(unitName)) { throw new ContainerException(LocalizationMessages.PERSISTENCE_UNIT_NOT_CONFIGURED(unitName)); } return Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] {EntityManagerFactory.class}, new ThreadLocalNamedInvoker<EntityManagerFactory>(persistenceUnits.get(unitName))); }
@Override public Object resolve(Injectee injectee) { if (!injectee.getRequiredType().equals(EntityManagerFactory.class)) { return null; } final PersistenceUnit annotation = injectee.getParent().getAnnotation(PersistenceUnit.class); final String unitName = annotation.unitName(); if (!persistenceUnits.containsKey(unitName)) { throw new ContainerException(LocalizationMessages.PERSISTENCE_UNIT_NOT_CONFIGURED(unitName)); } return Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] {EntityManagerFactory.class}, new ThreadLocalNamedInvoker<EntityManagerFactory>(persistenceUnits.get(unitName))); }
private boolean hasEncodedAnnotation(Injectee injectee) { AnnotatedElement element = injectee.getParent(); final boolean isConstructor = element instanceof Constructor; final boolean isMethod = element instanceof Method; // if injectee is method or constructor, check its parameters if (isConstructor || isMethod) { Annotation[] annotations; if (isMethod) { annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()]; } else { annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()]; } for (Annotation annotation : annotations) { if (annotation.annotationType().equals(Encoded.class)) { return true; } } } // check injectee itself (method, constructor or field) if (element.isAnnotationPresent(Encoded.class)) { return true; } // check class which contains injectee Class<?> clazz = injectee.getInjecteeClass(); return clazz.isAnnotationPresent(Encoded.class); }
private boolean hasEncodedAnnotation(Injectee injectee) { AnnotatedElement element = injectee.getParent(); final boolean isConstructor = element instanceof Constructor; final boolean isMethod = element instanceof Method; // if injectee is method or constructor, check its parameters if (isConstructor || isMethod) { Annotation[] annotations; if (isMethod) { annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()]; } else { annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()]; } for (Annotation annotation : annotations) { if (annotation.annotationType().equals(Encoded.class)) { return true; } } } // check injectee itself (method, constructor or field) if (element.isAnnotationPresent(Encoded.class)) { return true; } // check class which contains injectee Class<?> clazz = injectee.getInjecteeClass(); return clazz.isAnnotationPresent(Encoded.class); }
private DependencyDescriptor createSpringDependencyDescriptor(final Injectee injectee) { AnnotatedElement annotatedElement = injectee.getParent(); if (annotatedElement.getClass().isAssignableFrom(Field.class)) { return new DependencyDescriptor((Field) annotatedElement, !injectee.isOptional()); } else if (annotatedElement.getClass().isAssignableFrom(Method.class)) { return new DependencyDescriptor( new MethodParameter((Method) annotatedElement, injectee.getPosition()), !injectee.isOptional()); } else { return new DependencyDescriptor( new MethodParameter((Constructor) annotatedElement, injectee.getPosition()), !injectee.isOptional()); } }
@Override @SuppressWarnings("unchecked") public Object resolve(Injectee injectee) { AnnotatedElement annotated = injectee.getParent(); Annotation[] annotations; if (annotated.getClass().equals(Constructor.class)) {
@Override @SuppressWarnings("unchecked") public Object resolve(Injectee injectee) { AnnotatedElement annotated = injectee.getParent(); Annotation[] annotations; if (annotated.getClass().equals(Constructor.class)) {
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; }
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; }
private RequiredTypeOverridingInjectee(Injectee injectee, Type requiredType) { setFactory(injectee.isFactory()); setInjecteeClass(injectee.getInjecteeClass()); setInjecteeDescriptor(injectee.getInjecteeDescriptor()); setOptional(injectee.isOptional()); setParent(injectee.getParent()); setPosition(injectee.getPosition()); setRequiredQualifiers(injectee.getRequiredQualifiers()); setRequiredType(requiredType); } }
private boolean hasEncodedAnnotation(Injectee injectee) { AnnotatedElement element = injectee.getParent(); final boolean isConstructor = element instanceof Constructor; final boolean isMethod = element instanceof Method; // if injectee is method or constructor, check its parameters if (isConstructor || isMethod) { Annotation[] annotations; if (isMethod) { annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()]; } else { annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()]; } for (Annotation annotation : annotations) { if (annotation.annotationType().equals(Encoded.class)) { return true; } } } // check injectee itself (method, constructor or field) if (element.isAnnotationPresent(Encoded.class)) { return true; } // check class which contains injectee Class<?> clazz = injectee.getInjecteeClass(); return clazz.isAnnotationPresent(Encoded.class); }
@Override @SuppressWarnings("unchecked") public Object resolve(Injectee injectee) { AnnotatedElement annotated = injectee.getParent(); Annotation[] annotations; if (annotated.getClass().equals(Constructor.class)) {
@Override public Object resolve(Injectee injectee) { AnnotatedElement parent = injectee.getParent(); String beanName = null; if (parent != null) { Qualifier an = parent.getAnnotation(Qualifier.class); if (an != null) { beanName = an.value(); } } boolean required = parent != null ? parent.getAnnotation(Autowired.class).required() : false; return getBeanFromSpringContext(beanName, injectee, required); }
@Override public Object resolve(Injectee injectee) { if (!injectee.getRequiredType().equals(EntityManagerFactory.class)) { return null; } final PersistenceUnit annotation = injectee.getParent().getAnnotation(PersistenceUnit.class); final String unitName = annotation.unitName(); if (!persistenceUnits.containsKey(unitName)) { throw new ContainerException(LocalizationMessages.PERSISTENCE_UNIT_NOT_CONFIGURED(unitName)); } return Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] {EntityManagerFactory.class}, new ThreadLocalNamedInvoker<EntityManagerFactory>(persistenceUnits.get(unitName))); }
private boolean hasEncodedAnnotation(Injectee injectee) { AnnotatedElement element = injectee.getParent(); final boolean isConstructor = element instanceof Constructor; final boolean isMethod = element instanceof Method; // if injectee is method or constructor, check its parameters if (isConstructor || isMethod) { Annotation[] annotations; if (isMethod) { annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()]; } else { annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()]; } for (Annotation annotation : annotations) { if (annotation.annotationType().equals(Encoded.class)) { return true; } } } // check injectee itself (method, constructor or field) if (element.isAnnotationPresent(Encoded.class)) { return true; } // check class which contains injectee Class<?> clazz = injectee.getInjecteeClass(); return clazz.isAnnotationPresent(Encoded.class); }
private DependencyDescriptor createSpringDependencyDescriptor(final Injectee injectee) { AnnotatedElement annotatedElement = injectee.getParent(); if (annotatedElement.getClass().isAssignableFrom(Field.class)) { return new DependencyDescriptor((Field) annotatedElement, !injectee.isOptional()); } else if (annotatedElement.getClass().isAssignableFrom(Method.class)) { return new DependencyDescriptor( new MethodParameter((Method) annotatedElement, injectee.getPosition()), !injectee.isOptional()); } else { return new DependencyDescriptor( new MethodParameter((Constructor) annotatedElement, injectee.getPosition()), !injectee.isOptional()); } }
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; }
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; }