What I am doing now and which makes all tests pass locally again is:
GenericBeanAspectFactory:
| protected Object doCreate(Advisor advisor, InstanceAdvisor instanceAdvisor,
Joinpoint jp)
| {
| try
| {
| log.debug("Creating advice " + name);
|
| Object object = null;
| final ClassLoader loader = getCreatingClassLoader(advisor);
| if (loader == null)
| {
| object = factory.createBean();
| }
| else
| {
| if (context == null)
| {
| throw new IllegalStateException("Attempting to create aspects in
an undeployed factory");
| }
| KernelConfigurator configurator = context.getKernel().getConfigurator();
| ClassLoaderAwareGenericBeanFactory factoryWrapper = new
ClassLoaderAwareGenericBeanFactory(configurator, loader, (GenericBeanFactory)factory);
| object = factoryWrapper.createBean();
| }
|
|
| if (object instanceof XmlLoadable)
| {
| ((XmlLoadable)object).importXml(element);
| }
| configureInstance(object, advisor, instanceAdvisor, jp);
| return object;
| }
| catch (Throwable throwable)
| {
| throw new RuntimeException(throwable);
| }
| }
|
| private ClassLoader getCreatingClassLoader(Advisor advisor)
| {
| if (advisor == null)
| {
| return getLoader();
| }
| return SecurityActions.getClassLoader(advisor.getClass());
| }
|
The createBean() and invokeLifecycle() methods are modified copies of the GBF and
AbstractBeanFactory equivalents
| public class ClassLoaderAwareGenericBeanFactory implements BeanFactory
| {
| ClassLoader loader;
| GenericBeanFactory delegate;
| KernelConfigurator configurator;
|
| public ClassLoaderAwareGenericBeanFactory(KernelConfigurator configurator,
ClassLoader loader, GenericBeanFactory factory)
| {
| this.configurator = configurator;
| this.loader = loader;
| this.delegate = factory;
| }
|
| public Object createBean() throws Throwable
| {
| if (loader == null)
| {
| return delegate.createBean();
| }
| else
| {
| BeanInfo info = null;
| if (delegate.getBean() != null)
| info = configurator.getBeanInfo(delegate.getBean(), loader,
delegate.getAccessMode());
|
| Joinpoint joinpoint = configurator.getConstructorJoinPoint(info,
delegate.getConstructor(), null);
| Object result = joinpoint.dispatch();
| if (info == null && result != null)
| info =
configurator.getBeanInfo(result.getClass(),delegate.getAccessMode());
|
| if (delegate.getProperties() != null &&
delegate.getProperties().size() > 0)
| {
| for (Map.Entry<String, ValueMetaData> entry :
delegate.getProperties().entrySet())
| {
| String property = entry.getKey();
| ValueMetaData vmd = entry.getValue();
| PropertyInfo pi = info.getProperty(property);
| pi.set(result, vmd.getValue(pi.getType(), loader));
| }
| }
| invokeLifecycle("create", delegate.getCreate(), info, loader,
result);
| invokeLifecycle("start", delegate.getStart(), info, loader,
result);
| return result;
|
| }
| }
|
| protected void invokeLifecycle(String methodName, LifecycleMetaData lifecycle,
BeanInfo info, ClassLoader cl, Object target) throws Throwable
| {
| if (lifecycle == null || lifecycle.isIgnored() == false)
| {
| String method = methodName;
| if (lifecycle != null && lifecycle.getMethodName() != null)
| method = lifecycle.getMethodName();
| List<ParameterMetaData> parameters = null;
| if (lifecycle != null)
| parameters = lifecycle.getParameters();
| MethodJoinpoint joinpoint;
| try
| {
| joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters,
false, true);
| }
| catch (JoinpointException ignored)
| {
| return;
| }
| joinpoint.setTarget(target);
| joinpoint.dispatch();
| }
| }
|
| }
|
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193032#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...