use of javax.enterprise.inject.spi.AnnotatedType in project jersey by jersey.
the class CdiComponentProvider method processAnnotatedType.
@SuppressWarnings("unused")
private void processAnnotatedType(@Observes final // PathParam.class})
ProcessAnnotatedType processAnnotatedType) {
final AnnotatedType<?> annotatedType = processAnnotatedType.getAnnotatedType();
// if one of the JAX-RS annotations is present in the currently seen class, add it to the "whitelist"
if (containsJaxRsConstructorInjection(annotatedType) || containsJaxRsFieldInjection(annotatedType) || containsJaxRsMethodInjection(annotatedType)) {
jaxrsInjectableTypes.add(annotatedType.getBaseType());
}
if (customHk2TypesProvider != null) {
final Type baseType = annotatedType.getBaseType();
if (customHk2TypesProvider.getHk2Types().contains(baseType)) {
processAnnotatedType.veto();
jerseyVetoedTypes.add(baseType);
}
}
if (containsJaxRsParameterizedCtor(annotatedType)) {
processAnnotatedType.setAnnotatedType(new AnnotatedType() {
@Override
public Class getJavaClass() {
return annotatedType.getJavaClass();
}
@Override
public Set<AnnotatedConstructor> getConstructors() {
final Set<AnnotatedConstructor> result = new HashSet<>();
for (final AnnotatedConstructor c : annotatedType.getConstructors()) {
result.add(enrichedConstructor(c));
}
return result;
}
@Override
public Set getMethods() {
return annotatedType.getMethods();
}
@Override
public Set getFields() {
return annotatedType.getFields();
}
@Override
public Type getBaseType() {
return annotatedType.getBaseType();
}
@Override
public Set<Type> getTypeClosure() {
return annotatedType.getTypeClosure();
}
@Override
public <T extends Annotation> T getAnnotation(final Class<T> annotationType) {
return annotatedType.getAnnotation(annotationType);
}
@Override
public Set<Annotation> getAnnotations() {
return annotatedType.getAnnotations();
}
@Override
public boolean isAnnotationPresent(final Class<? extends Annotation> annotationType) {
return annotatedType.isAnnotationPresent(annotationType);
}
});
}
}
use of javax.enterprise.inject.spi.AnnotatedType in project core by weld.
the class GlueDecoratorExtension method registerDecorator.
void registerDecorator(@Observes AfterBeanDiscovery event, BeanManager manager) {
AnnotatedType<GlueDecorator> annotatedType = manager.createAnnotatedType(GlueDecorator.class);
final BeanAttributes<GlueDecorator> attributes = manager.createBeanAttributes(annotatedType);
final InjectionPoint delegateInjectionPoint = manager.createInjectionPoint(annotatedType.getConstructors().iterator().next().getParameters().get(0));
Decorator<GlueDecorator> decorator = new DecoratorImpl<GlueDecorator>() {
@Override
public Type getDelegateType() {
return Glue.class;
}
@Override
public Set<Annotation> getDelegateQualifiers() {
return Collections.<Annotation>singleton(Any.Literal.INSTANCE);
}
@Override
public Set<Type> getDecoratedTypes() {
return Collections.emptySet();
}
@Override
public Class<?> getBeanClass() {
return GlueDecorator.class;
}
@Override
public Set<InjectionPoint> getInjectionPoints() {
final Decorator<GlueDecorator> decorator = this;
InjectionPoint wrappedInjectionPoint = new ForwardingInjectionPoint() {
@Override
public Bean<?> getBean() {
return decorator;
}
@Override
protected InjectionPoint delegate() {
return delegateInjectionPoint;
}
};
return Collections.singleton(wrappedInjectionPoint);
}
@Override
public GlueDecorator create(CreationalContext<GlueDecorator> creationalContext) {
return new GlueDecorator(null);
}
@Override
public void destroy(GlueDecorator instance, CreationalContext<GlueDecorator> creationalContext) {
creationalContext.release();
}
@Override
protected BeanAttributes<GlueDecorator> attributes() {
return attributes;
}
};
event.addBean(decorator);
}
use of javax.enterprise.inject.spi.AnnotatedType in project HotswapAgent by HotswapProjects.
the class BeanClassRefreshAgent method doDefineNewBean.
private static void doDefineNewBean(BeanManagerImpl beanManager, Class<?> beanClass) {
WebBeansContext wbc = beanManager.getWebBeansContext();
AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory();
// Clear AnnotatedElementFactory caches (is it necessary for definition ?)
annotatedElementFactory.clear();
// Injection resolver cache must be cleared before / after definition
beanManager.getInjectionResolver().clearCaches();
AnnotatedType<?> annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
BeanAttributesImpl<?> attributes = BeanAttributesBuilder.forContext(wbc).newBeanAttibutes(annotatedType).build();
HashMap<AnnotatedType<?>, ExtendedBeanAttributes<?>> annotatedTypes = new HashMap<>();
BeansDeployer beansDeployer = new BeansDeployer(wbc);
try {
ReflectionHelper.invoke(beansDeployer, BeansDeployer.class, "defineManagedBean", new Class[] { javax.enterprise.inject.spi.AnnotatedType.class, javax.enterprise.inject.spi.BeanAttributes.class, java.util.Map.class }, annotatedType, attributes, annotatedTypes);
} catch (Exception e) {
LOGGER.error("Bean '{}' definition failed", beanClass.getName(), e);
}
}
use of javax.enterprise.inject.spi.AnnotatedType in project dolphin-platform by canoo.
the class CdiManagedBeanFactory method createDependentInstance.
@Override
public <T> T createDependentInstance(Class<T> cls) {
Assert.requireNonNull(cls, "cls");
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
AnnotatedType annotatedType = bm.createAnnotatedType(cls);
final InjectionTarget<T> injectionTarget = bm.createInjectionTarget(annotatedType);
final Bean<T> bean = new BeanBuilder<T>(bm).beanClass(cls).name(UUID.randomUUID().toString()).scope(Dependent.class).beanLifecycle(new DelegatingContextualLifecycle<T>(injectionTarget)).create();
Class<?> beanClass = bean.getBeanClass();
CreationalContext<T> creationalContext = bm.createCreationalContext(bean);
T instance = (T) bm.getReference(bean, beanClass, creationalContext);
contextMap.put(instance, creationalContext);
beanMap.put(instance, bean);
return instance;
}
use of javax.enterprise.inject.spi.AnnotatedType in project wildfly-swarm by wildfly-swarm.
the class HealthExtension method afterDeploymentValidation.
/**
* Instantiates <em>unmanaged instances</em> of HealthCheckProcedure and
* handle manually their CDI creation lifecycle.
* Add them to the {@link Monitor}.
*/
private void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
try {
for (AnnotatedType delegate : delegates) {
Unmanaged<HealthCheck> unmanagedHealthCheck = new Unmanaged<HealthCheck>(beanManager, delegate.getJavaClass());
Unmanaged.UnmanagedInstance<HealthCheck> healthCheckInstance = unmanagedHealthCheck.newInstance();
HealthCheck healthCheck = healthCheckInstance.produce().inject().postConstruct().get();
healthChecks.add(healthCheck);
healthCheckInstances.add(healthCheckInstance);
monitor.registerHealthBean(healthCheck);
log.info(">> Added health bean impl " + healthCheck);
}
// we don't need the references anymore
delegates.clear();
} catch (Exception e) {
throw new RuntimeException("Failed to register health bean", e);
}
}
Aggregations