use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.
the class EjbSupportImpl method createNewSessionBeans.
@Override
public void createNewSessionBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager) {
final SlimAnnotatedTypeStore store = manager.getServices().get(SlimAnnotatedTypeStore.class);
final ClassTransformer classTransformer = manager.getServices().get(ClassTransformer.class);
for (Type type : environment.getNewBeanTypes()) {
Class<?> clazz = Reflections.getRawType(type);
if (isEjb(clazz)) {
EnhancedAnnotatedType<?> enhancedType = classTransformer.getEnhancedAnnotatedType(clazz, type, manager.getId());
InternalEjbDescriptor<?> descriptor = ejbDescriptors.getUnique(clazz);
environment.addSessionBean(createNewSessionBean(enhancedType, descriptor, manager, store));
}
}
}
use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.
the class Decorators method checkAbstractMethods.
/**
* Check all abstract methods are declared by the decorated types.
*
* @param type
* @param beanManager
* @param delegateType
* @throws DefinitionException If any of the abstract methods is not declared by the decorated types
*/
public static <T> void checkAbstractMethods(Set<Type> decoratedTypes, EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) {
if (decoratedTypes == null) {
decoratedTypes = new HashSet<Type>(type.getInterfaceClosure());
decoratedTypes.remove(Serializable.class);
}
Set<MethodSignature> signatures = new HashSet<MethodSignature>();
for (Type decoratedType : decoratedTypes) {
for (EnhancedAnnotatedMethod<?, ?> method : ClassTransformer.instance(beanManager).getEnhancedAnnotatedType(Reflections.getRawType(decoratedType), beanManager.getId()).getEnhancedMethods()) {
signatures.add(method.getSignature());
}
}
for (EnhancedAnnotatedMethod<?, ?> method : type.getEnhancedMethods()) {
if (Reflections.isAbstract(((AnnotatedMethod<?>) method).getJavaMember())) {
MethodSignature methodSignature = method.getSignature();
if (!signatures.contains(methodSignature)) {
throw BeanLogger.LOG.abstractMethodMustMatchDecoratedType(method, Formats.formatAsStackTraceElement(method.getJavaMember()));
}
}
}
}
use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.
the class Validator method validateDecorator.
protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) {
if (decorator.getDecoratedTypes().isEmpty()) {
throw ValidatorLogger.LOG.noDecoratedTypes(decorator);
}
if (!decorator.getScope().equals(Dependent.class)) {
throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator);
}
Decorators.checkDelegateType(decorator);
/*
* Validate decorators of facade built-in beans
*/
Type delegateType = decorator.getDelegateType();
if (delegateType instanceof ParameterizedType) {
ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType;
if (!Decorators.isPassivationCapable(decorator)) {
if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) {
throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName());
}
if (Event.class.equals(parameterizedDelegateType.getRawType())) {
throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Event.class.getName());
}
}
}
if (decorator instanceof WeldDecorator<?>) {
EnhancedAnnotatedType<?> annotated = ((WeldDecorator<?>) decorator).getEnhancedAnnotated();
if (decorator instanceof DecoratorImpl<?>) {
// Discovered decorator bean - abstract methods and delegate injection point are validated during bean initialization
validateRIBean((CommonBean<?>) decorator, manager, specializedBeans);
// Following checks are not legal for custom decorator beans as we cannot rely on decorator bean class methods
if (!BeanMethods.getObserverMethods(annotated).isEmpty() || !BeanMethods.getAsyncObserverMethods(annotated).isEmpty()) {
throw ValidatorLogger.LOG.decoratorsCannotHaveObserverMethods(decorator);
}
while (annotated != null && annotated.getJavaClass() != Object.class) {
if (!annotated.getDeclaredEnhancedMethods(Produces.class).isEmpty()) {
throw ValidatorLogger.LOG.decoratorsCannotHaveProducerMethods(decorator);
}
if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) {
throw ValidatorLogger.LOG.decoratorsCannotHaveProducerFields(decorator);
}
if (!annotated.getDeclaredEnhancedMethodsWithAnnotatedParameters(Disposes.class).isEmpty()) {
throw ValidatorLogger.LOG.decoratorsCannotHaveDisposerMethods(decorator);
}
annotated = annotated.getEnhancedSuperclass();
}
} else {
// Custom decorator bean
validateGeneralBean(decorator, manager);
Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
}
}
}
use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project core by weld.
the class SubclassedComponentInstantiator method createEnhancedSubclass.
protected Class<T> createEnhancedSubclass(EnhancedAnnotatedType<T> type, Bean<?> bean, BeanManagerImpl manager) {
Set<InterceptionModel> models = getInterceptionModelsForType(type, manager, bean);
Set<MethodSignature> enhancedMethodSignatures = new HashSet<MethodSignature>();
Set<MethodSignature> interceptedMethodSignatures = (models == null) ? enhancedMethodSignatures : new HashSet<MethodSignature>();
for (AnnotatedMethod<?> method : Beans.getInterceptableMethods(type)) {
enhancedMethodSignatures.add(MethodSignatureImpl.of(method));
if (models != null) {
for (InterceptionModel model : models) {
if (!model.getInterceptors(InterceptionType.AROUND_INVOKE, method.getJavaMember()).isEmpty()) {
interceptedMethodSignatures.add(MethodSignatureImpl.of(method));
break;
}
}
}
}
Set<Type> types = null;
if (bean == null) {
types = Collections.<Type>singleton(type.getJavaClass());
} else {
types = bean.getTypes();
}
return new InterceptedSubclassFactory<T>(manager.getContextId(), type.getJavaClass(), types, bean, enhancedMethodSignatures, interceptedMethodSignatures).getProxyClass();
}
use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project HotswapAgent by HotswapProjects.
the class BeanReloadExecutor method doDefineNewManagedBean.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void doDefineNewManagedBean(BeanManagerImpl beanManager, String bdaId, Class<?> beanClass) {
try {
ClassTransformer classTransformer = getClassTransformer();
SlimAnnotatedType<?> annotatedType = classTransformer.getBackedAnnotatedType(beanClass, bdaId);
boolean managedBeanOrDecorator = Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType);
if (managedBeanOrDecorator) {
EnhancedAnnotatedType eat = EnhancedAnnotatedTypeImpl.of(annotatedType, classTransformer);
BeanAttributes attributes = BeanAttributesFactory.forBean(eat, beanManager);
ManagedBean<?> bean = ManagedBean.of(attributes, eat, beanManager);
ReflectionHelper.set(beanManager, beanManager.getClass(), "beanSet", Collections.synchronizedSet(new HashSet<Bean<?>>()));
beanManager.addBean(bean);
beanManager.getBeanResolver().clear();
bean.initializeAfterBeanDiscovery();
LOGGER.debug("Bean defined '{}'", beanClass.getName());
} else {
// TODO : define session bean
LOGGER.warning("Bean NOT? defined '{}', session bean?", beanClass.getName());
}
} catch (Exception e) {
LOGGER.debug("Bean definition failed.", e);
}
}
Aggregations