[jboss-cvs] JBossAS SVN: r81893 - in projects/microcontainer/branches/Branch_2_0/aop-mc-int/src: main/java/org/jboss/aop/microcontainer/beans and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 1 07:50:40 EST 2008
Author: alesj
Date: 2008-12-01 07:50:40 -0500 (Mon, 01 Dec 2008)
New Revision: 81893
Added:
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/ClassLoaderAwareGenericBeanFactory.java
Removed:
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java
Modified:
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/GenericBeanAspectFactory.java
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/SecurityActions.java
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/metadata/AspectBeanMetaDataFactory.java
projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/test/java/org/jboss/test/microcontainer/test/OverriddenClassLoaderTestCase.java
Log:
Port changes.
Deleted: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java 2008-12-01 11:53:11 UTC (rev 81892)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -1,38 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.aop.microcontainer.aspects.jmx;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Mark getter as ObjectName creator.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
- at Retention(RetentionPolicy.RUNTIME)
- at Target({ElementType.TYPE, ElementType.METHOD})
-public @interface JMXObjectName
-{
-}
Copied: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java (from rev 81892, projects/microcontainer/trunk/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java)
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java (rev 0)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/aspects/jmx/JMXObjectName.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.microcontainer.aspects.jmx;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Mark getter as ObjectName creator.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE, ElementType.METHOD})
+public @interface JMXObjectName
+{
+}
\ No newline at end of file
Copied: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/ClassLoaderAwareGenericBeanFactory.java (from rev 81892, projects/microcontainer/trunk/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/ClassLoaderAwareGenericBeanFactory.java)
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/ClassLoaderAwareGenericBeanFactory.java (rev 0)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/ClassLoaderAwareGenericBeanFactory.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.microcontainer.beans;
+
+import org.jboss.beans.metadata.plugins.factory.GenericBeanFactory;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+
+/**
+ * CL aware GBF.
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderAwareGenericBeanFactory extends GenericBeanFactory
+{
+ private ThreadLocal<ClassLoader> pushedLoader = new ThreadLocal<ClassLoader>();
+
+ public ClassLoaderAwareGenericBeanFactory(KernelConfigurator configurator)
+ {
+ super(configurator);
+ }
+
+ /**
+ * Push classloader into thread local.
+ *
+ * @param loader the loader
+ */
+ public void pushLoader(ClassLoader loader)
+ {
+ pushedLoader.set(loader);
+ }
+
+ /**
+ * Pop loader from thread local.
+ */
+ public void popLoader()
+ {
+ pushedLoader.set(null);
+ }
+
+ @Override
+ public Object createBean() throws Throwable
+ {
+ ClassLoader loader = pushedLoader.get();
+ if (loader == null)
+ {
+ return super.createBean();
+ }
+ else
+ {
+ return super.createBean(loader);
+ }
+ }
+}
Modified: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/GenericBeanAspectFactory.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/GenericBeanAspectFactory.java 2008-12-01 11:53:11 UTC (rev 81892)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/GenericBeanAspectFactory.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -56,7 +56,7 @@
protected KernelControllerContext context;
- public GenericBeanAspectFactory(String name, GenericBeanFactory factory, Element element)
+ public GenericBeanAspectFactory(String name, BeanFactory factory, Element element)
{
super(null, element);
this.name = name;
@@ -64,11 +64,11 @@
setBeanFactory(factory);
}
- public void setBeanFactory(GenericBeanFactory factory)
+ public void setBeanFactory(BeanFactory factory)
{
- if (factory != null)
+ if (factory != null && factory instanceof GenericBeanFactory)
{
- classname = factory.getBean();
+ classname = ((GenericBeanFactory)factory).getBean();
}
this.factory = factory;
}
@@ -130,34 +130,14 @@
{
try
{
- log.debug("Creating advice " + name);
-
-
- PushedClassLoaderMetaData pcmd = null;
- if (((GenericBeanFactory)factory).getClassLoader() == null)
+ final ClassLoader loader = getCreatingClassLoader(advisor);
+ log.debug("Creating advice " + name + " with loader " + loader);
+ if (factory instanceof ClassLoaderAwareGenericBeanFactory)
{
- pcmd = new PushedClassLoaderMetaData();
- ((GenericBeanFactory)factory).setClassLoader(pcmd);
+ ((ClassLoaderAwareGenericBeanFactory)factory).pushLoader(loader);
}
- Object object = null;
- try
- {
- //Try without looking at the context first which is what shold be used when running scoped in AS
- object = factory.createBean();
- }
- catch(Throwable t)
- {
- if (pcmd != null)
- {
- pcmd.setLookAtContext(true);
- }
- else
- {
- throw new RuntimeException(t);
- }
- object = factory.createBean();
- }
+ Object object = factory.createBean();
if (object instanceof XmlLoadable)
{
@@ -170,59 +150,21 @@
{
throw new RuntimeException(throwable);
}
+ finally
+ {
+ if (factory instanceof ClassLoaderAwareGenericBeanFactory)
+ {
+ ((ClassLoaderAwareGenericBeanFactory)factory).popLoader();
+ }
+ }
}
- /**
- * Gets any classloaders for the thread
- */
- private class PushedClassLoaderMetaData extends AbstractClassLoaderMetaData
+ private ClassLoader getCreatingClassLoader(Advisor advisor)
{
- /** The serialVersionUID */
- private static final long serialVersionUID = 1L;
-
- boolean lookAtContext;
-
- void setLookAtContext(boolean look)
+ if (advisor == null)
{
- lookAtContext = look;
+ return getLoader();
}
-
- @Override
- public ValueMetaData getClassLoader()
- {
- ClassLoader loader = GenericBeanAspectFactory.this.getLoader();
- //GenericBeanAspectFactory.this.peekScopedClassLoader();
- if (loader == null)
- {
- if (lookAtContext && context != null)
- {
- try
- {
- loader = context.getClassLoader();
- }
- catch (Throwable t)
- {
- log.trace("Unable to retrieve classloader from " + context);
- }
-
- if (loader == null)
- {
- try
- {
- loader = Configurator.getClassLoader(((GenericBeanFactory)factory).getClassLoader());
- }
- catch (Throwable e)
- {
- log.trace("Unable to retrieve classloader from " + factory);
- }
- }
- }
- return loader != null ? new AbstractValueMetaData(loader) : null;
- }
- else
- {
- return new AbstractValueMetaData(loader);
- }
- }
+ return SecurityActions.getClassLoader(advisor.getClass());
}
}
Modified: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/SecurityActions.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/SecurityActions.java 2008-12-01 11:53:11 UTC (rev 81892)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/SecurityActions.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -25,7 +25,8 @@
import java.security.PrivilegedAction;
/**
- *
+ * CL security actions.
+ *
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
@@ -69,4 +70,43 @@
return GetContextClassLoaderAction.PRIVILEGED.getContextClassLoader();
}
}
+
+ private interface GetClassLoaderAction
+ {
+ ClassLoader getClassLoader(Class<?> clazz);
+
+ GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction(){
+
+ public ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+ };
+
+ GetClassLoaderAction NOT_PRIVILEGED = new GetClassLoaderAction(){
+
+ public ClassLoader getClassLoader(Class<?> clazz)
+ {
+ return clazz.getClassLoader();
+ }
+ };
+ }
+
+ public static ClassLoader getClassLoader(Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetClassLoaderAction.NOT_PRIVILEGED.getClassLoader(clazz);
+ }
+ else
+ {
+ return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+ }
+ }
}
Modified: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/metadata/AspectBeanMetaDataFactory.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/metadata/AspectBeanMetaDataFactory.java 2008-12-01 11:53:11 UTC (rev 81892)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/main/java/org/jboss/aop/microcontainer/beans/metadata/AspectBeanMetaDataFactory.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -32,6 +32,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import org.jboss.aop.microcontainer.beans.Aspect;
+import org.jboss.aop.microcontainer.beans.ClassLoaderAwareGenericBeanFactory;
import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
@@ -138,6 +139,7 @@
}
BeanMetaData factory = beans.get(0);
BeanMetaDataBuilder factoryBuilder = BeanMetaDataBuilder.createBuilder(factory);
+ factoryBuilder.setBean(ClassLoaderAwareGenericBeanFactory.class.getName());
result.add(factory);
//Add the Aspect
Modified: projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/test/java/org/jboss/test/microcontainer/test/OverriddenClassLoaderTestCase.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/test/java/org/jboss/test/microcontainer/test/OverriddenClassLoaderTestCase.java 2008-12-01 11:53:11 UTC (rev 81892)
+++ projects/microcontainer/branches/Branch_2_0/aop-mc-int/src/test/java/org/jboss/test/microcontainer/test/OverriddenClassLoaderTestCase.java 2008-12-01 12:50:40 UTC (rev 81893)
@@ -67,23 +67,20 @@
assertNotSame(TestAspect.class, clazz);
assertSame(loader, clazz.getClassLoader());
- Aspect aspect = (Aspect)getBean("Aspect");
- assertNotNull(aspect);
-
+ Aspect aspect = assertInstanceOf(getBean("Aspect"), Aspect.class, false);
AspectDefinition def = aspect.getDefinition();
AspectFactory factory = def.getFactory();
Object global = factory.createPerVM();
- assertSame(this.getClass().getClassLoader(), global.getClass().getClassLoader());
-
- assertInstanceOf(factory, AspectFactoryWithClassLoader.class);
- AspectFactoryWithClassLoader factoryCl = (AspectFactoryWithClassLoader)factory;
-
+ assertSame(getClass().getClassLoader(), global.getClass().getClassLoader());
+
+ AspectFactoryWithClassLoader factoryCl = assertInstanceOf(factory, AspectFactoryWithClassLoader.class);
factoryCl.pushScopedClassLoader(loader);
try
{
Object scoped = factory.createPerVM();
- assertSame(loader, scoped.getClass().getClassLoader());
+ ClassLoader scopedLoader = scoped.getClass().getClassLoader();
+ assertSame(loader, scopedLoader);
}
finally
{
@@ -96,13 +93,14 @@
File jarFile = createJar();
URL jarUrl = jarFile.toURL();
- return new ParentLastURLClassLoader(new URL[] {jarUrl}, this.getClass().getClassLoader());
+ return new ParentLastURLClassLoader(new URL[] {jarUrl}, getClass().getClassLoader());
}
private File createJar() throws Exception
{
String resource = TestAspect.class.getName().replace('.', '/') + ".class";
- URL url = this.getClass().getClassLoader().getResource(resource);
+ URL url = getClass().getClassLoader().getResource(resource);
+ assertNotNull(resource + " not found.", url);
File classFile = new File(url.toURI());
// File jarFile = new File("test-overridden-classloader.jar");
@@ -111,7 +109,7 @@
if (jarFile.exists())
{
- jarFile.delete();
+ assertTrue(jarFile.delete());
}
JarOutputStream out = null;
try
@@ -150,7 +148,7 @@
private File createTempFile(final String prefix, final String suffix) throws Exception
{
if (System.getSecurityManager() == null)
- return File.createTempFile("test-overridden-classloader", "jar");
+ return File.createTempFile(prefix, suffix);
else
{
try
@@ -159,7 +157,7 @@
{
public File run() throws Exception
{
- return File.createTempFile("test-overridden-classloader", "jar");
+ return File.createTempFile(prefix, suffix);
}
});
}
More information about the jboss-cvs-commits
mailing list