<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { final AnnotatedType<T> annotatedType = pat.getAnnotatedType(); if (annotatedType.getJavaClass().equals(testClass)) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType).addToClass(APPLICATIONSCOPED); pat.setAnnotatedType(builder.create()); } }
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { final AnnotatedType<T> annotatedType = pat.getAnnotatedType(); if (annotatedType.getJavaClass().equals(testClass)) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType).addToClass(APPLICATIONSCOPED); pat.setAnnotatedType(builder.create()); } }
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { final AnnotatedType<T> annotatedType = pat.getAnnotatedType(); if (annotatedType.getJavaClass().equals(testClass)) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType).addToClass(APPLICATIONSCOPED); pat.setAnnotatedType(builder.create()); } }
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { final AnnotatedType<T> annotatedType = pat.getAnnotatedType(); if (annotatedType.getJavaClass().equals(testClass)) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType).addToClass(APPLICATIONSCOPED); pat.setAnnotatedType(builder.create()); } }
public AnnotatedType<T> invoke() { if (ReflectionsUtils.isPossibleCdiBean(delegate.getJavaClass())) { final AnnotatedTypeBuilder<T> typeBuilder = new AnnotatedTypeBuilder<>(); typeBuilder.readFromType(delegate); for (Map.Entry<Class<? extends Annotation>, Annotation> replacement : replacementMap.entrySet()) { final Class<? extends Annotation> toReplace = replacement.getKey(); if (delegate.isAnnotationPresent(toReplace)) { typeBuilder.addToClass(replacement.getValue()); } } return typeBuilder.create(); } else { return delegate; } } }
private <X> void copyAnnotation(final ProcessAnnotatedType<X> annotatedType, final Class<?> anInterface, final Method method, final Class<? extends Annotation> annotation) { final Annotation methodAnnotation = method.getAnnotation(annotation); final Annotation typeAnnotation = anInterface.getAnnotation(annotation); if (methodAnnotation != null || typeAnnotation != null) { AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(annotatedType.getAnnotatedType()); if (typeAnnotation != null) { builder = builder.addToClass(typeAnnotation); } if (methodAnnotation != null) { builder = builder.addToMethod(getMethod(annotatedType, method.getName()), methodAnnotation); } annotatedType.setAnnotatedType(builder.create()); } }
@SuppressWarnings("serial") public <T> void processAnnotatedType( @Observes @WithAnnotations(Path.class) ProcessAnnotatedType<T> processAnnotatedType) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>() .readFromType(processAnnotatedType.getAnnotatedType()) .addToClass(new AnnotationLiteral<Exceptionable>() {}); processAnnotatedType.setAnnotatedType(builder.create()); }
public <T> void processAuthenticationServiceTypes(@Observes final ProcessAnnotatedType<T> processedAnnotatedType) { final Class<T> type = processedAnnotatedType.getAnnotatedType().getJavaClass(); if (isNonKeycloakAuthenticationService(type)) { processedAnnotatedType.setAnnotatedType(new AnnotatedTypeBuilder<T>() .readFromType(processedAnnotatedType.getAnnotatedType()).removeFromClass(Default.class) .addToClass(wrapped).create()); } }
/** * Add an annotation to the class represented by pat. * * @param pat ProcessAnnotatedType for bean. * @param annotation annotation literal to add to the type. * @param <X> any type. */ public static <X> void addClassAnnotation(ProcessAnnotatedType<X> pat, Annotation annotation) { AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<>(); builder.readFromType(pat.getAnnotatedType()); pat.setAnnotatedType(builder.addToClass(annotation).create()); } }
void invoke() { ActivatableTestImplementation implementation = type.getAnnotation(ActivatableTestImplementation.class); if (implementation.value().length == 0) { guessReplacableTypes(); } builder.addToClass(new TypedLiteral() { @Override public Class<?>[] value() { return new Class[]{javaClass}; } }); pat.setAnnotatedType(builder.create()); }
public <T> void onAnnotatedType(@Observes @WithAnnotations(Transactional.class) ProcessAnnotatedType<T> annotatedType) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>() .readFromType(annotatedType.getAnnotatedType()) .addToClass(AnnotationInstanceProvider.of(org.apache.deltaspike.jpa.api.transaction.Transactional.class)); annotatedType.setAnnotatedType(builder.create()); }
@Test public void buildValidAnnotationAnnotatedType() { final AnnotatedTypeBuilder<Small> builder = new AnnotatedTypeBuilder<Small>(); builder.readFromType(Small.class); final AnnotatedType<Small> smallAnnotatedType = builder.create(); assertThat(smallAnnotatedType.getMethods().size(), is(1)); assertThat(smallAnnotatedType.getConstructors().size(), is(0)); assertThat(smallAnnotatedType.getFields().size(), is(0)); }
public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { boolean modified = false; AnnotatedType<T> annotatedType = pat.getAnnotatedType(); AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType); for (AnnotatedField field : annotatedType.getFields()) { Context context = field.getAnnotation(Context.class); if (context != null) { builder.addToField(field, new AnnotationLiteral<Inject>() {}); builder.addToField(field, new AnnotationLiteral<JaxRsQualifier>() {}); modified = true; } } if (modified) { pat.setAnnotatedType(builder.create()); } }
public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { boolean modified = false; AnnotatedType<T> annotatedType = pat.getAnnotatedType(); AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType); for (AnnotatedField field : annotatedType.getFields()) { Context context = field.getAnnotation(Context.class); if (context != null) { builder.addToField(field, new AnnotationLiteral<Inject>() { }); builder.addToField(field, new AnnotationLiteral<JaxRsQualifier>() { }); modified = true; } } if (modified) { pat.setAnnotatedType(builder.create()); } }
protected <T> Bean<T> createBean(Class<T> beanClass, BeanManager beanManager) { Class<? extends InvocationHandler> invocationHandlerClass = Converter.class.isAssignableFrom(beanClass) ? ConverterInvocationHandler.class : ValidatorInvocationHandler.class; AnnotatedType<T> annotatedType = new AnnotatedTypeBuilder<T>().readFromType(beanClass).create(); DeltaSpikeProxyContextualLifecycle lifecycle = new DeltaSpikeProxyContextualLifecycle(beanClass, invocationHandlerClass, ConverterAndValidatorProxyFactory.getInstance(), beanManager); BeanBuilder<T> beanBuilder = new BeanBuilder<T>(beanManager) .readFromType(annotatedType) .passivationCapable(true) .beanLifecycle(lifecycle); return beanBuilder.create(); } }
protected <T> Bean<T> createBean(Class<T> beanClass, BeanManager beanManager) { Class<? extends InvocationHandler> invocationHandlerClass = Converter.class.isAssignableFrom(beanClass) ? ConverterInvocationHandler.class : ValidatorInvocationHandler.class; AnnotatedType<T> annotatedType = new AnnotatedTypeBuilder<T>().readFromType(beanClass).create(); DeltaSpikeProxyContextualLifecycle lifecycle = new DeltaSpikeProxyContextualLifecycle(beanClass, invocationHandlerClass, ConverterAndValidatorProxyFactory.getInstance(), beanManager); BeanBuilder<T> beanBuilder = new BeanBuilder<T>(beanManager) .readFromType(annotatedType) .passivationCapable(true) .beanLifecycle(lifecycle); return beanBuilder.create(); } }
private <X> void createEJBWrapper(ProcessAnnotatedType<X> pat, final AnnotatedType<X> at) { EjbAsynchronous ejbAsynchronous = AnnotationInstanceProvider.of(EjbAsynchronous.class); EjbTransactional transactionalAnnotation = AnnotationInstanceProvider.of(EjbTransactional.class); AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(at); builder.addToClass(transactionalAnnotation); if (possiblyAsynchronous(at)) { builder.addToClass(ejbAsynchronous); } // by annotating let CDI set Wrapper to this Bean pat.setAnnotatedType(builder.create()); }
@Test public void testCtWithMultipleParams() { final AnnotatedTypeBuilder<TypeWithParamsInCt> builder = new AnnotatedTypeBuilder<TypeWithParamsInCt>(); builder.readFromType(TypeWithParamsInCt.class); builder.addToClass(new AnnotationLiteral<Default>() {}); AnnotatedType<TypeWithParamsInCt> newAt = builder.create(); assertNotNull(newAt); }
@Test public void testAdditionOfAnnotation() { final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>(); builder.readFromType(Cat.class, true); builder.addToClass(new TypedLiteral()); final AnnotatedType<Cat> catAnnotatedType = builder.create(); assertThat(catAnnotatedType.isAnnotationPresent(Typed.class), is(true)); }
@Test public void testEnumWithParam() { final AnnotatedTypeBuilder<EnumWithParams> builder = new AnnotatedTypeBuilder<EnumWithParams>(); builder.readFromType(EnumWithParams.class); builder.addToClass(new AnnotationLiteral<Default>() {}); AnnotatedType<EnumWithParams> newAt = builder.create(); assertNotNull(newAt); }