use of javax.interceptor.AroundConstruct in project javaee7-samples by javaee-samples.
the class MyInterceptor method onConstruct.
@AroundConstruct
public Object onConstruct(InvocationContext context) throws Exception {
// null before the InvocationContext.proceed() returns
Object target = context.getTarget();
isNull(target);
// null in case of AroundConstruct
Method method = context.getMethod();
isNull(method);
// NOT null in case of AroundConstruct
Constructor ctor = context.getConstructor();
isNotNull(ctor);
// perform the constructor injection
Object result = context.proceed();
isNull(result);
// NOT null after the InvocationContext.proceed() completes
target = context.getTarget();
isNotNull(target);
// a constructor should have been called
GreetingBean bean = (GreetingBean) target;
isBoolean(bean.isConstructed(), true);
isBoolean(bean.isInitialized(), false);
// constructor injection should have been done
isNotNull(bean.getParam());
return null;
}
use of javax.interceptor.AroundConstruct in project Payara by payara.
the class MetricsInterceptor method constructorInvocation.
@AroundConstruct
private Object constructorInvocation(InvocationContext context) throws Exception {
Object target;
MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
if (metricsService.isMetricsEnabled()) {
Class<?> beanClass = bean.getBeanClass();
registerMetrics(beanClass, context.getConstructor(), context.getTarget());
target = context.proceed();
Class<?> type = beanClass;
do {
for (Method method : type.getDeclaredMethods()) {
if (!method.isSynthetic() && !Modifier.isPrivate(method.getModifiers())) {
registerMetrics(beanClass, method, context.getTarget());
}
}
type = type.getSuperclass();
} while (!Object.class.equals(type));
} else {
target = context.proceed();
}
return target;
}
use of javax.interceptor.AroundConstruct in project Payara by payara.
the class SystemInterceptorProxy method setDelegate.
public void setDelegate(Object d) {
Class delegateClass = d.getClass();
try {
for (Method m : delegateClass.getDeclaredMethods()) {
if (m.getAnnotation(PostConstruct.class) != null) {
postConstruct = m;
prepareMethod(m);
} else if (m.getAnnotation(PreDestroy.class) != null) {
preDestroy = m;
prepareMethod(m);
} else if (m.getAnnotation(AroundInvoke.class) != null) {
aroundInvoke = m;
prepareMethod(m);
} else if (m.getAnnotation(AroundTimeout.class) != null) {
aroundTimeout = m;
prepareMethod(m);
} else if (m.getAnnotation(AroundConstruct.class) != null) {
aroundConstruct = m;
prepareMethod(m);
}
}
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
delegate = d;
}
Aggregations