use of org.jboss.weld.bean.NewBean in project core by weld.
the class Validator method validateRIBean.
/**
* Validate an RIBean. This includes validating whether two beans specialize
* the same bean
*
* @param bean the bean to validate
* @param beanManager the current manager
* @param specializedBeans the existing specialized beans
*/
protected void validateRIBean(CommonBean<?> bean, BeanManagerImpl beanManager, Collection<CommonBean<?>> specializedBeans) {
validateGeneralBean(bean, beanManager);
if (bean instanceof NewBean) {
return;
}
if (bean instanceof DecorableBean) {
validateDecorators(beanManager, (DecorableBean<?>) bean);
}
if ((bean instanceof AbstractClassBean<?>)) {
AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
// validate CDI-defined interceptors
if (classBean.hasInterceptors()) {
validateInterceptors(beanManager, classBean);
}
}
// for each producer bean validate its disposer method
if (bean instanceof AbstractProducerBean<?, ?, ?>) {
AbstractProducerBean<?, ?, ?> producerBean = Reflections.<AbstractProducerBean<?, ?, ?>>cast(bean);
if (producerBean.getProducer() instanceof AbstractMemberProducer<?, ?>) {
AbstractMemberProducer<?, ?> producer = Reflections.<AbstractMemberProducer<?, ?>>cast(producerBean.getProducer());
if (producer.getDisposalMethod() != null) {
for (InjectionPoint ip : producer.getDisposalMethod().getInjectionPoints()) {
// pass the producer bean instead of the disposal method bean
validateInjectionPointForDefinitionErrors(ip, null, beanManager);
validateMetadataInjectionPoint(ip, null, ValidatorLogger.INJECTION_INTO_DISPOSER_METHOD);
validateEventMetadataInjectionPoint(ip);
validateInjectionPointForDeploymentProblems(ip, null, beanManager);
}
}
}
}
}
use of org.jboss.weld.bean.NewBean in project core by weld.
the class Validator method validateInjectionPointForDefinitionErrors.
/**
* Checks for definition errors associated with a given {@link InjectionPoint}
*/
public void validateInjectionPointForDefinitionErrors(InjectionPoint ij, Bean<?> bean, BeanManagerImpl beanManager) {
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));
}
// WELD-1739
if (ij.getMember() instanceof Executable && ij.getAnnotated().isAnnotationPresent(Named.class) && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) {
Executable executable = (Executable) ij.getMember();
AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ij.getAnnotated();
if (!executable.getParameters()[annotatedParameter.getPosition()].isNamePresent()) {
// No parameters info available
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());
}
}
boolean newBean = (bean instanceof NewBean);
if (!newBean) {
checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class));
}
checkFacadeInjectionPoint(ij, Instance.class);
checkFacadeInjectionPoint(ij, Event.class);
if (InterceptionFactory.class.equals(Reflections.getRawType(ij.getType())) && !(bean instanceof ProducerMethod<?, ?>)) {
throw ValidatorLogger.LOG.invalidInterceptionFactoryInjectionPoint(ij, Formats.formatAsStackTraceElement(ij));
}
for (PlugableValidator validator : plugableValidators) {
validator.validateInjectionPointForDefinitionErrors(ij, bean, beanManager);
}
}
use of org.jboss.weld.bean.NewBean in project core by weld.
the class Validator method validateEnabledAlternativeClasses.
private void validateEnabledAlternativeClasses(BeanManagerImpl beanManager, BeanDeployment deployment) {
BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml();
if (beansXml != null && !beansXml.getEnabledAlternativeClasses().isEmpty()) {
// prepare lookup structure
Map<String, Class<?>> loadedClasses = buildClassNameMap(beanManager.getEnabled().getAlternativeClasses());
// lookup structure for validation of alternatives
Multimap<Class<?>, Bean<?>> beansByClass = SetMultimap.newSetMultimap();
for (Bean<?> bean : beanManager.getDynamicAccessibleBeans()) {
if (!(bean instanceof NewBean)) {
beansByClass.put(bean.getBeanClass(), bean);
}
}
for (Metadata<String> definition : beansXml.getEnabledAlternativeClasses()) {
Class<?> enabledClass = loadedClasses.get(definition.getValue());
if (enabledClass.isAnnotation() || enabledClass.isInterface()) {
throw ValidatorLogger.LOG.alternativeBeanClassNotClass(definition);
} else {
if (!isAlternativeBean(enabledClass, beansByClass) && !isAlternativeCandidate(enabledClass, beanManager)) {
throw ValidatorLogger.LOG.alternativeBeanClassNotAnnotated(definition.getValue(), definition.getLocation());
}
}
}
}
}
Aggregations