ConfigProperty configProperty = pip.getInjectionPoint().getAnnotated().getAnnotation(ConfigProperty.class); if (configProperty != null) { InjectionPoint ip = pip.getInjectionPoint(); String fullPath = ip.getMember().getDeclaringClass().getName() + "." + getFieldName(ip); Type type = ip.getType();
protected static void validateResourceInjectionPointType(Class<?> resourceType, InjectionPoint injectionPoint) { Class<?> injectionPointRawType = Reflections.getRawType(injectionPoint.getType()); HierarchyDiscovery discovery = new HierarchyDiscovery(resourceType); for (Type type : discovery.getTypeClosure()) { if (Reflections.getRawType(type).equals(injectionPointRawType)) { return; } } // type autoboxing if (resourceType.isPrimitive() && BOXED_TYPES.get(resourceType).equals(injectionPointRawType)) { return; } else if (injectionPointRawType.isPrimitive() && BOXED_TYPES.get(injectionPointRawType).equals(resourceType)) { return; } throw BeanLogger.LOG.invalidResourceProducerType(injectionPoint.getAnnotated(), resourceType.getName()); }
private String getFieldName(InjectionPoint ip) { Annotated annotated = ip.getAnnotated(); if (annotated instanceof AnnotatedField) { AnnotatedField f = (AnnotatedField) annotated; return f.getJavaMember().getName(); } if (annotated instanceof AnnotatedParameter) { AnnotatedParameter p = (AnnotatedParameter) annotated; Member member = ip.getMember(); if (member instanceof Method) { return member.getName() + "_" + p.getPosition(); } if (member instanceof Constructor) { return "new_" + p.getPosition(); } } return ip.getMember().getName(); }
protected String getEJBResourceName(InjectionPoint injectionPoint, String proposedName) { if (injectionPoint.getType() instanceof Class<?>) { final Class<?> type = (Class<?>) injectionPoint.getType(); final String typeName = type.getName(); if (USER_TRANSACTION_CLASS_NAME.equals(typeName)) { return USER_TRANSACTION_LOCATION; } else if (HANDLE_DELEGATE_CLASS_NAME.equals(typeName)) { WeldLogger.ROOT_LOGGER.injectionTypeNotValue(HANDLE_DELEGATE_CLASS_NAME, injectionPoint.getMember()); return proposedName; } else if (ORB_CLASS_NAME.equals(typeName)) { WeldLogger.ROOT_LOGGER.injectionTypeNotValue(ORB_CLASS_NAME, injectionPoint.getMember()); return proposedName; } else if (TIMER_SERVICE_CLASS_NAME.equals(typeName)) { WeldLogger.ROOT_LOGGER.injectionTypeNotValue(TIMER_SERVICE_CLASS_NAME, injectionPoint.getMember()); return proposedName; } else if (EJB_CONTEXT_CLASS_NAME.equals(typeName) ||
if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) { throw ValidatorLogger.LOG.newWithQualifiers(ij, Formats.formatAsStackTraceElement(ij)); if (ij.getType() instanceof TypeVariable<?>) { throw ValidatorLogger.LOG.injectionPointWithTypeVariable(ij, Formats.formatAsStackTraceElement(ij)); if (!(ij.getMember() instanceof Field) && ij.getAnnotated().isAnnotationPresent(Named.class) && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) { throw ValidatorLogger.LOG.nonFieldInjectionPointCannotUseNamed(ij, Formats.formatAsStackTraceElement(ij)); if (ij.getAnnotated().isAnnotationPresent(Produces.class)) { if (bean != null) { throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), bean); } else { throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), Reflections.<AnnotatedField<?>>cast(ij.getAnnotated()).getDeclaringType()); checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class)); checkFacadeInjectionPoint(ij, Instance.class); checkFacadeInjectionPoint(ij, Event.class); JtaApiAbstraction jtaApi = beanManager.getServices().get(JtaApiAbstraction.class); if (jtaApi.USER_TRANSACTION_CLASS.equals(ij.getType()) && (ij.getQualifiers().isEmpty() || ij.getQualifiers().contains(DefaultLiteral.INSTANCE)) && beanManager.getServices().get(EJBApiAbstraction.class).isSessionBeanWithContainerManagedTransactions(bean)) { throw ValidatorLogger.LOG.userTransactionInjectionIntoBeanWithContainerManagedTransactions(ij, Formats.formatAsStackTraceElement(ij));
public void observeInfo(@Observes @Any Info info, EventMetadata metadata) { InjectionPoint injectionPoint = metadata.getInjectionPoint(); lastBean = injectionPoint.getBean(); lastIsTransient = injectionPoint.isTransient(); lastType = injectionPoint.getType(); lastQualifiers = injectionPoint.getQualifiers(); lastMember = injectionPoint.getMember(); lastAnnotated = injectionPoint.getAnnotated(); }
private static void validatePseudoScopedInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManager, Set<Object> dependencyPath, Set<Bean<?>> validatedBeans) { Set<Bean<?>> resolved = beanManager.getBeans(ij); Bean<?> bean = null; try { bean = beanManager.resolve(resolved); } catch (AmbiguousResolutionException ex) { throw ValidatorLogger.LOG.injectionPointHasAmbiguousDependencies(ij, Formats.formatAnnotations(ij.getQualifiers()), Formats.formatInjectionPointType(ij.getType()), Formats.formatAsStackTraceElement(ij), WeldCollections.toMultiRowString(resolved)); } if (bean != null) { if (!(bean instanceof AbstractBuiltInBean<?>)) { if (!ij.isDelegate()) { boolean normalScoped = beanManager.isNormalScope(bean.getScope()); if (!normalScoped && !(bean instanceof SessionBean)) { reallyValidatePseudoScopedBean(bean, beanManager, dependencyPath, validatedBeans); } } } } }
private boolean isInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager) { if (!Beans.isPassivationCapableDependency(resolvedBean)) { if (((ij.getMember() instanceof Field) && ij.isTransient())) { return true; } if (ij.getAnnotated() instanceof AnnotatedParameter<?> && ij.getAnnotated().isAnnotationPresent(TransientReference.class)) { return true; } return false; } return true; }
public void validateMetadataInjectionPoint(InjectionPoint ij, Bean<?> bean, MessageCallback<DefinitionException> messageCallback) { // metadata injection points if (ij.getType().equals(InjectionPoint.class) && bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(bean.getScope())) { throw ValidatorLogger.LOG.injectionIntoNonDependentBean(ij, Formats.formatAsStackTraceElement(ij)); } Class<?> rawType = Reflections.getRawType(ij.getType()); if (Bean.class.equals(rawType) || Interceptor.class.equals(rawType) || Decorator.class.equals(rawType)) { if (bean == null) { throw messageCallback.construct(ij, Formats.formatAsStackTraceElement(ij)); } if (bean instanceof AbstractClassBean<?>) { checkBeanMetadataInjectionPoint(bean, ij, AnnotatedTypes.getDeclaringAnnotatedType(ij.getAnnotated()).getBaseType()); } if (bean instanceof ProducerMethod<?, ?>) { ProducerMethod<?, ?> producerMethod = Reflections.cast(bean); checkBeanMetadataInjectionPoint(bean, ij, producerMethod.getAnnotated().getBaseType()); } } }
/** * Returns the {@link Gauge} matching the criteria from the injection point. * * @param <T> type of the {@code Gauge} * @param registry metric registry * @param ip injection point being resolved * @return requested gauge */ @Produces @VendorDefined @SuppressWarnings("unchecked") private <T> Gauge<T> produceGauge(MetricRegistry registry, InjectionPoint ip) { Metric metric = ip.getAnnotated().getAnnotation(Metric.class); return (Gauge<T>) registry.getGauges().entrySet().stream() .filter(entry -> entry.getKey().equals(metric.name())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Could not produce Gauge for injection point " + ip.toString())) .getValue(); }
@Override protected <T> ResourceReferenceFactory<T> getResourceReferenceFactory(InjectionPoint injectionPoint, JpaInjectionServices injectionServices, PersistenceApiAbstraction apiAbstraction) { if (!injectionPoint.getType().equals(apiAbstraction.ENTITY_MANAGER_FACTORY_CLASS)) { throw BeanLogger.LOG.invalidResourceProducerType(injectionPoint.getAnnotated(), apiAbstraction.ENTITY_MANAGER_FACTORY_CLASS); } return Reflections.<ResourceReferenceFactory<T>> cast(injectionServices .registerPersistenceUnitInjectionPoint(injectionPoint)); }
protected String getVariableLocalTypedName(InjectionPoint ip) { String variableName = ip.getAnnotated().getAnnotation(ProcessVariableLocalTyped.class).value(); if (variableName.length() == 0) { variableName = ip.getMember().getName(); } return variableName; }
public static <T, X> FieldInjectionPointAttributes<T, X> of(InjectionPoint ip) { if (ip instanceof FieldInjectionPointAttributes<?, ?>) { return Reflections.cast(ip); } if (!(ip.getAnnotated() instanceof AnnotatedField<?>) || !(ip.getMember() instanceof Field)) { throw BeanLogger.LOG.invalidInjectionPointType(ForwardingFieldInjectionPointAttributes.class, ip.getAnnotated()); } return new ForwardingFieldInjectionPointAttributes<T, X>(ip); }
void captureTypes(@Observes final ProcessBean<?> bean) { for (final InjectionPoint ip : bean.getBean().getInjectionPoints()) { final Component component = ip.getAnnotated().getAnnotation(Component.class); if (component != null) { beans.add(new ComponentBean(component, ip.getType())); } } }
private static boolean isInjectionPointSatisfied(InjectionPoint ij, Set<?> resolvedBeans, BeanManagerImpl beanManager) { if (ij.getBean() instanceof Decorator<?>) { if (beanManager.getEnabled().isDecoratorEnabled(ij.getBean().getBeanClass())) { return resolvedBeans.size() > 0; } else { return true; } } else { return resolvedBeans.size() > 0; } }
public void validateEventMetadataInjectionPoint(InjectionPoint ip) { if (EventMetadata.class.equals(ip.getType()) && ip.getQualifiers().contains(Default.Literal.INSTANCE)) { throw ValidatorLogger.LOG.eventMetadataInjectedOutsideOfObserver(ip, Formats.formatAsStackTraceElement(ip)); } }
@Test @SpecAssertions({ @SpecAssertion(section = PROCESS_INJECTION_POINT, id = "bba") }) public void configuratorInitializedWithOriginalInjectionPoint() { InjectionPoint configuredOne = getUniqueBean(Helicopter.class).getInjectionPoints().iterator().next(); InjectionPoint originalOne = getCurrentManager().getExtension(ProcessInjectionPointObserver.class).getEngineIP(); assertEquals(configuredOne.getType(), originalOne.getType()); assertEquals(configuredOne.getQualifiers(), originalOne.getQualifiers()); assertEquals(configuredOne.getAnnotated(), originalOne.getAnnotated()); assertEquals(configuredOne.getBean(), originalOne.getBean()); } }
@Override protected InterceptionFactory<?> newInstance(InjectionPoint ip, CreationalContext<InterceptionFactory<?>> creationalContext) { AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ip.getAnnotated(); ParameterizedType parameterizedType = (ParameterizedType) annotatedParameter.getBaseType(); AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(Reflections.getRawType(parameterizedType.getActualTypeArguments()[0])); return InterceptionFactoryImpl.of(beanManager, creationalContext, annotatedType); }
public static String getResourceName(InjectionPoint injectionPoint) { Resource resource = getResourceAnnotated(injectionPoint).getAnnotation(Resource.class); String mappedName = resource.mappedName(); if (!mappedName.equals("")) { if (injectionPoint.getMember() instanceof Field) { propertyName = injectionPoint.getMember().getName(); } else if (injectionPoint.getMember() instanceof Method) { propertyName = getPropertyName((Method) injectionPoint.getMember()); if (propertyName == null) { throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) injectionPoint.getMember()); String className = injectionPoint.getMember().getDeclaringClass().getName(); return RESOURCE_LOOKUP_PREFIX + "/" + className + "/" + propertyName;
if (ij.isDelegate()) { return; // do not validate delegate injection points as these are special Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getBeans(ij)); if (!isInjectionPointSatisfied(ij, resolvedBeans, beanManager)) { throw ValidatorLogger.LOG.injectionPointHasUnsatisfiedDependencies( ij, Formats.formatAnnotations(ij.getQualifiers()), Formats.formatInjectionPointType(ij.getType()), Formats.formatAsStackTraceElement(ij), InjectionPoints.getUnsatisfiedDependenciesAdditionalInfo(ij, beanManager)); throw ValidatorLogger.LOG.injectionPointHasAmbiguousDependencies( ij, Formats.formatAnnotations(ij.getQualifiers()), Formats.formatInjectionPointType(ij.getType()), Formats.formatAsStackTraceElement(ij), WeldCollections.toMultiRowString(resolvedBeans)); if (beanManager.isNormalScope(resolvedBean.getScope())) { UnproxyableResolutionException ue = Proxies.getUnproxyableTypeException(ij.getType(), resolvedBean, beanManager.getServices()); if (ue != null) { throw ValidatorLogger.LOG.injectionPointHasNonProxyableDependencies(ij, Formats.formatAsStackTraceElement(ij), ue); validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);