use of org.apache.aries.blueprint.Interceptor in project aries by apache.
the class BeanRecipe method addInterceptors.
private Object addInterceptors(final Object original, Collection<Class<?>> requiredInterfaces) throws ComponentDefinitionException {
Object intercepted = null;
if (requiredInterfaces.isEmpty())
requiredInterfaces.add(original.getClass());
ComponentDefinitionRegistry reg = blueprintContainer.getComponentDefinitionRegistry();
List<Interceptor> interceptors = reg.getInterceptors(interceptorLookupKey);
if (interceptors != null && interceptors.size() > 0) {
/* BLUEPRINT-NOOSGI
try {
Bundle b = FrameworkUtil.getBundle(original.getClass());
if (b == null) {
// we have a class from the framework parent, so use our bundle for proxying.
b = blueprintContainer.getBundleContext().getBundle();
}
intercepted = blueprintContainer.getProxyManager().createInterceptingProxy(b,
requiredInterfaces, original, new Collaborator(interceptorLookupKey, interceptors));
} catch (org.apache.aries.proxy.UnableToProxyException e) {
Bundle b = blueprintContainer.getBundleContext().getBundle();
throw new ComponentDefinitionException("Unable to create proxy for bean " + name + " in bundle " + b.getSymbolicName() + " version " + b.getVersion(), e);
}
*/
throw new ComponentDefinitionException("Unable to create proxy for bean " + name + ". Not supported in blueprint-noosgi");
} else {
intercepted = original;
}
return intercepted;
}
use of org.apache.aries.blueprint.Interceptor in project aries by apache.
the class Collaborator method preInvoke.
/**
* Invoke the preCall method on the interceptor
*
* @param o
* : The Object being invoked
* @param m
* : method
* @param parameters
* : method paramters
* @throws Throwable
*/
public Object preInvoke(Object o, Method m, Object[] parameters) throws Throwable {
Deque<StackElement> stack = new ArrayDeque<StackElement>(interceptors.size());
if (interceptors != null) {
try {
for (Interceptor im : interceptors) {
Collaborator.StackElement se = new StackElement(im);
// should we do this before or after the preCall ?
stack.push(se);
// allow exceptions to propagate
se.setPreCallToken(im.preCall(cm, m, parameters));
}
} catch (Throwable t) {
postInvokeExceptionalReturn(stack, o, m, t);
throw t;
}
}
return stack;
}
Aggregations