[jboss-cvs] JBossAS SVN: r66020 - in projects/aop/trunk: aop/src/main/org/jboss/aop/advice and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 11 06:41:29 EDT 2007
Author: kabir.khan at jboss.com
Date: 2007-10-11 06:41:28 -0400 (Thu, 11 Oct 2007)
New Revision: 66020
Added:
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ExtraClassPoolFactoryParameters.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPool.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPoolFactory.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainInitializer.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainRegistry.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderScopingPolicy.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderDomainIntializer.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderScopingPolicy.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedJBoss5ClassPool.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedNewClassLoaderDomain.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedRepositoryClassLoaderHelper.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedClassLoaderDomain.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedRepositoryClassLoaderDomain.java
Removed:
projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelper.java
projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelperBridge.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossScopedClassLoaderHelper.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedClassLoaderDomain.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericAspectFactory.java
projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassLoaderScopingPolicy.java
projects/aop/trunk/asintegration/.classpath
projects/aop/trunk/asintegration/build.xml
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AbstractAspectManager.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AspectDeployer.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/JBossAspectLibrary.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5Integration.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectDeployer.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectManagerService.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBoss4Integration.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java
Log:
[JBAOP-409] Refactor AOP scoping to work with either both the old (UnifiedClassLoader) and new (BaseClassLoader) jboss classloaders.
The BaseClassLoader version still has some tests failing:
org.jboss.test.aop.test.ScopedExtenderBaseLoadedScopedNoParentDelegationTestCase
org.jboss.test.aop.test.ScopedExtenderBaseLoadedScopedParentDelegationTestCase
org.jboss.test.aop.test.ScopedExtenderBaseNotLoadedScopedNoParentDelegationTestCase
org.jboss.test.aop.test.ScopedExtenderBaseNotLoadedScopedParentDelegationTestCase
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -57,7 +57,6 @@
import org.jboss.aop.advice.Scope;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
import org.jboss.aop.classpool.AOPClassPoolRepository;
-import org.jboss.aop.classpool.AOPScopedClassLoaderHelper;
import org.jboss.aop.instrument.GeneratedAdvisorInstrumentor;
import org.jboss.aop.instrument.Instrumentor;
import org.jboss.aop.instrument.InstrumentorFactory;
@@ -174,9 +173,6 @@
// indicates that the transformation process has begun
protected boolean transformationStarted = false;
- @Deprecated // replaced by the temporary AOPClassLoaderScopingPolicy - no longer referenced
- protected static AOPScopedClassLoaderHelper scopedCLHelper;
-
/** The classloader scoping policy */
// This shouldn't really be static (artifact of singleton and self-bootstrap design)
private static AOPClassLoaderScopingPolicy classLoaderScopingPolicy;
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericAspectFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericAspectFactory.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericAspectFactory.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -96,6 +96,10 @@
this.element = element;
}
+ @Deprecated
+ /**
+ * @deprecated Not public API
+ */
public Class getClazz()
{
try
@@ -107,12 +111,39 @@
throw new RuntimeException(e);
}
}
+
+ private Class getClazz(Advisor advisor)
+ {
+ try
+ {
+ ClassLoader cl = null;
+ if (advisor != null)
+ {
+ //Get the correct classloader based on the class of the advisor
+ Class clazz = advisor.getClazz();
+ cl = (clazz != null) ? clazz.getClassLoader() : advisor.getClass().getClassLoader();
+ }
+ if (cl != null)
+ {
+ pushScopedClassLoader(cl);
+ }
+ return loadClass(classname);
+ }
+ catch(ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ popScopedClassLoader();
+ }
+ }
public Object createPerVM()
{
try
{
- Object aspect = getClazz().newInstance();
+ Object aspect = getClazz(null).newInstance();
configureInstance(aspect, null, null, null);
return aspect;
}
@@ -127,7 +158,7 @@
{
try
{
- Object aspect = getClazz().newInstance();
+ Object aspect = getClazz(advisor).newInstance();
configureInstance(aspect, advisor, null, null);
return aspect;
}
@@ -142,7 +173,7 @@
{
try
{
- Object aspect = getClazz().newInstance();
+ Object aspect = getClazz(advisor).newInstance();
configureInstance(aspect, advisor, instanceAdvisor, null);
return aspect;
}
@@ -157,7 +188,7 @@
{
try
{
- Object aspect = getClazz().newInstance();
+ Object aspect = getClazz(advisor).newInstance();
configureInstance(aspect, advisor, null, jp);
return aspect;
}
@@ -172,7 +203,7 @@
{
try
{
- Object aspect = getClazz().newInstance();
+ Object aspect = getClazz(advisor).newInstance();
configureInstance(aspect, advisor, instanceAdvisor, jp);
return aspect;
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassLoaderScopingPolicy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassLoaderScopingPolicy.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassLoaderScopingPolicy.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -36,16 +36,16 @@
*/
public interface AOPClassLoaderScopingPolicy
{
+// /**
+// * Is the classloader scoped?
+// *
+// * TODO Move ClassPool construction policy into here and remove this
+// * @param classLoader the classLoader
+// * @return true when scoped
+// */
+// boolean isScoped(T classLoader);
+//
/**
- * Is the classloader scoped?
- *
- * TODO Move ClassPool construction policy into here and remove this
- * @param classLoader the classLoader
- * @return true when scoped
- */
- boolean isScoped(ClassLoader classLoader);
-
- /**
* Get the domain for classloader
*
* @param classLoader the classloader
Deleted: projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelper.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelper.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelper.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -1,61 +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.classpool;
-
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Domain;
-
-/**
- * Helper to determine if we are running within a scoped classloader.
- *
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision$
- */
-public interface AOPScopedClassLoaderHelper
-{
- /**
- * Checks if passed in ClassLoader is a scoped JBoss classloader
- * @param loader The loader to check
- * @return The nearest parent (or self) in the hierarchy that is scoped, or null if not scoped
- */
- ClassLoader ifScopedDeploymentGetScopedParentUclForCL(ClassLoader loader);
-
- /**
- * Returns the top-level JBoss classloader
- */
- ClassLoader getTopLevelJBossClassLoader();
-
- /**
- * Creates a new domain for the passed in classloader with the passed in AspectManager as the parent
- * @param loader A scoped classloader
- * @param parent The AspectManager to create the domain under
- * @return The created domain for the scoped classloader
- */
- Domain getScopedClassLoaderDomain(ClassLoader cl, AspectManager parent);
-
- /**
- * Gets the loader repository for the passed in scoped JBossClassLoader
- * @param loader The classloader to get the loader repository for
- * @return The LoaderRepository for the scopedc ClassLoader, or null if ClassLoader is not scoped
- */
- Object getLoaderRepository(ClassLoader loader);
-}
Deleted: projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelperBridge.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelperBridge.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPScopedClassLoaderHelperBridge.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -1,108 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, 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.classpool;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Domain;
-import org.jboss.logging.Logger;
-
-/**
- * AOPScopedClassLoaderHelperBridge.<p>
- *
- * A bridged from the old scoped classloader helper to the temporary
- * AOPClassLoaderScopingPolicy
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class AOPScopedClassLoaderHelperBridge implements AOPClassLoaderScopingPolicy
-{
- /** The log */
- private static final Logger log = Logger.getLogger(AOPScopedClassLoaderHelper.class);
-
- /** The delegate */
- private AOPScopedClassLoaderHelper delegate;
-
- /** A map of domains by loader repository, maintaned by the top level AspectManager */
- private Map<Object, Domain> scopedClassLoaderDomains = new WeakHashMap<Object, Domain>();
-
- /**
- * Create a new AOPScopedClassLoaderHelperBridge.
- *
- * @param delegate the delegate helper
- * @throws IllegalArgumentException for a null delegate
- */
- public AOPScopedClassLoaderHelperBridge(AOPScopedClassLoaderHelper delegate)
- {
- if (delegate == null)
- throw new IllegalArgumentException("Null delegate");
- this.delegate = delegate;
- }
-
- public boolean isScoped(ClassLoader classLoader)
- {
- return delegate.ifScopedDeploymentGetScopedParentUclForCL(classLoader) != null;
- }
-
- public synchronized Domain getDomain(ClassLoader classLoader, AspectManager parent)
- {
- ClassLoader scopedClassLoader = delegate.ifScopedDeploymentGetScopedParentUclForCL(classLoader);
- if (scopedClassLoader != null)
- {
- Domain scopedManager = null;
- synchronized (AOPClassPoolRepository.getInstance().getRegisteredCLs())
- {
- Object loaderRepository = delegate.getLoaderRepository(classLoader);
- scopedManager = scopedClassLoaderDomains.get(loaderRepository);
-
- // FIXME: JBAOP-107 REMOVE THIS HACK
- if (scopedManager != null && scopedManager.isValid() == false)
- {
- scopedClassLoaderDomains.remove(loaderRepository);
- scopedManager = null;
- }
-
- if (scopedManager == null)
- {
- scopedManager = delegate.getScopedClassLoaderDomain(scopedClassLoader, parent);
- log.debug("Created domain " + scopedManager + " for scoped deployment on: " +
- classLoader + "; identifying scoped ucl: " + scopedClassLoader);
- scopedManager.setInheritsBindings(true);
- scopedManager.setInheritsDeclarations(true);
-
- scopedClassLoaderDomains.put(loaderRepository, scopedManager);
- }
- return scopedManager;
- }
- }
- return null;
- }
-
- public Domain getTopLevelDomain(AspectManager parent)
- {
- ClassLoader classLoader = delegate.getTopLevelJBossClassLoader();
- return getDomain(classLoader, parent);
- }
-}
Modified: projects/aop/trunk/asintegration/.classpath
===================================================================
--- projects/aop/trunk/asintegration/.classpath 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/.classpath 2007-10-11 10:41:28 UTC (rev 66020)
@@ -24,5 +24,6 @@
<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-container-metadata-spi.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-container-sources.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-deployers-client-spi.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-container-metadata.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-deployers-impl.jar"/>
<classpathentry kind="output" path="output/eclipse-classes"/>
</classpath>
Modified: projects/aop/trunk/asintegration/build.xml
===================================================================
--- projects/aop/trunk/asintegration/build.xml 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/build.xml 2007-10-11 10:41:28 UTC (rev 66020)
@@ -217,6 +217,7 @@
<fileset dir="${build.classes}">
<!-- Include everything else -->
<include name="org/jboss/aop/deploy*/**"/>
+ <include name="org/jboss/aop/domain/**"/>
</fileset>
<fileset file ="${project.root}/aop/src/etc/jbossorg-eula.txt"/>
</jar>
@@ -227,6 +228,7 @@
<fileset dir="${build.classes}">
<!-- Include everything else -->
<include name="org/jboss/aop/deploy*/**"/>
+ <include name="org/jboss/aop/domain/**"/>
<exclude name="org/jboss/aop/deployers/*.class"/>
</fileset>
<fileset file ="${project.root}/aop/src/etc/jbossorg-eula.txt"/>
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AbstractAspectManager.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AbstractAspectManager.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AbstractAspectManager.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -38,6 +38,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
import org.jboss.aop.deployment.AspectManagerService;
+import org.jboss.aop.deployment.JBossIntegration;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.logging.Logger;
import org.w3c.dom.Document;
@@ -641,4 +642,22 @@
{
return delegate.toString();
}
+
+ /**
+ * @return
+ * @see org.jboss.aop.deployment.AspectManagerService#getJBossIntegration()
+ */
+ public JBossIntegration getJbossIntegration()
+ {
+ return delegate.getJBossIntegration();
+ }
+
+ /**
+ * @param integration
+ * @see org.jboss.aop.deployment.AspectManagerService#setJBossIntegration(org.jboss.aop.deployment.JBossIntegration)
+ */
+ public void setJbossIntegration(JBossIntegration integration)
+ {
+ delegate.setJBossIntegration(integration);
+ }
}
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AspectDeployer.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AspectDeployer.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/AspectDeployer.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -33,15 +33,15 @@
import org.jboss.aop.AspectAnnotationLoader;
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
+import org.jboss.aop.Domain;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
-import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.aop.deployers.temp.NewClassLoaderDomainInitializer;
+import org.jboss.aop.deployers.temp.RepositoryClassLoaderDomainIntializer;
+import org.jboss.deployers.plugins.classloading.Module;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metadata.spi.MutableMetaData;
-import org.jboss.metadata.spi.scope.ScopeKey;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.VisitorAttributes;
@@ -104,22 +104,22 @@
public void deploy(VFSDeploymentUnit unit) throws DeploymentException
{
-// dumpDeploymentUnitStuffForTesting(unit);
+ AspectManager manager = getCorrectManager(unit);
List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
if (isAopArchiveOrFolder(unit))
{
- deployAnnotations(unit);
+ deployAnnotations(manager, unit);
}
if (files.size() > 0)
{
- deployXml(unit, files);
+ deployXml(manager, unit, files);
}
}
-// public void dumpDeploymentUnitStuffForTesting(VFSDeploymentUnit unit)
+// private void dumpDeploymentUnitStuffForTesting(VFSDeploymentUnit unit)
// {
// ScopeKey scope = unit.getScope();
// ScopeKey mutable = unit.getMutableScope();
@@ -128,39 +128,36 @@
// MutableMetaData mutableMetaData = unit.getMutableMetaData();
// System.out.println("====> SCOPE: " + scope + "\n\tMUTABLE_SCOPE: " + mutable + "\n\tMETADATA: " + metaData + "\n\tMUTABLE_METADATA: " + mutableMetaData);
//
-// //Need to get information about the classloader
-// ClassLoader loader = unit.getClassLoader();
-// if (loader instanceof BaseClassLoader)
+// if (metaData == null)
// {
-// BaseClassLoader bcl = (BaseClassLoader)loader;
-//// bcl.get
+// System.out.println("Null metadata");
+// return;
// }
-//
+// Module module = metaData.getMetaData(Module.class);
+// System.out.println("MetaData module " + module);
+// module = unit.getAttachment(Module.class);
+// System.out.println("Attached module " + module);
// }
public void undeploy(VFSDeploymentUnit unit)
{
+ AspectManager manager = getCorrectManager(unit);
List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
if (isAopArchiveOrFolder(unit))
{
- undeployAnnotations(unit);
+ undeployAnnotations(manager, unit);
}
if (files.size() > 0)
{
- undeployXml(unit, files);
+ undeployXml(manager, unit, files);
}
}
- private void deployXml(VFSDeploymentUnit unit, List<VirtualFile> files) throws DeploymentException
+ private void deployXml(AspectManager manager, VFSDeploymentUnit unit, List<VirtualFile> files) throws DeploymentException
{
- ClassLoader scl = getScopedClassLoader(unit);
-
- if (scl != null)
- {
- log.info("AOP deployment is scoped using classloader " + scl);
- }
+ log.info("Deploying xml into " + manager + " for " + unit.getClassLoader());
ArrayList<VirtualFile> deployedFiles = new ArrayList<VirtualFile>(files.size());
for (VirtualFile vf : files)
@@ -168,23 +165,16 @@
deployedFiles.add(vf);
try
{
- log.debug("deploying: " + vf.toURL());
+ log.debug("deploying: " + vf.toURL() + " into " + manager);
InputStream is = vf.openStream();
try
{
Document doc = AspectXmlLoader.loadDocument(is);
AspectXmlLoader loader = new AspectXmlLoader();
- if (scl != null)
- {
- loader.setManager(AspectManager.instance(scl));
- loader.setClassLoader(scl);
- }
- else
- {
- loader.setManager(AspectManager.instance());
- }
- loader.deployXML(doc, vf.toURL(), scl);
+ loader.setManager(manager);
+ loader.setClassLoader(unit.getClassLoader());
+ loader.deployXML(doc, vf.toURL(), unit.getClassLoader());
}
finally
{
@@ -196,39 +186,36 @@
//Unwind things already installed, in the reverse order
for (int i = deployedFiles.size() - 1 ; i >= 0 ; i--)
{
- undeployXml(scl, deployedFiles.get(i));
+ undeployXml(manager, deployedFiles.get(i));
}
- throw DeploymentException.rethrowAsDeploymentException("Error deploying xml " + vf.getName(), e);
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying xml " + vf.getName() + " into " + manager, e);
}
}
}
- private void undeployXml(VFSDeploymentUnit unit, List<VirtualFile> files)
+ private void undeployXml(AspectManager manager, VFSDeploymentUnit unit, List<VirtualFile> files)
{
- ClassLoader scl = getScopedClassLoader(unit);
-
for (VirtualFile vf : files)
{
- undeployXml(scl, vf);
+ undeployXml(manager, vf);
}
+ //FIXME isn't this a bit too early?
aspectManager.unregisterClassLoader(unit.getClassLoader());
}
- private void undeployXml(ClassLoader scl, VirtualFile vf)
+ private void undeployXml(AspectManager manager, VirtualFile vf)
{
try
{
- log.debug("undeploying: " + vf.toURL());
+ log.debug("undeploying: " + vf.toURL() + " from " + manager);
InputStream is = vf.openStream();
try
{
Document doc = AspectXmlLoader.loadDocument(is);
AspectXmlLoader loader = new AspectXmlLoader();
- AspectManager manager = (scl != null) ? AspectManager.instance(scl) : aspectManager;
-
loader.setManager(manager);
loader.undeployXML(doc, vf.toURL());
}
@@ -245,20 +232,15 @@
}
catch (Exception e)
{
- log.warn("Error undeploying xml " + vf.getName(), e);
+ log.warn("Error undeploying xml " + vf.getName() + " from " + manager, e);
}
}
- private void deployAnnotations(VFSDeploymentUnit unit) throws DeploymentException
+ private void deployAnnotations(AspectManager manager, VFSDeploymentUnit unit) throws DeploymentException
{
- ClassLoader scl = getScopedClassLoader(unit);
+ log.info("Deploying AOP annotations into " + manager + " for " + unit.getClassLoader());
- if (scl != null)
- {
- log.info("AOP deployment is scoped using classloader " + scl);
- }
-
- AspectAnnotationLoader loader = getAnnotationLoader(scl);
+ AspectAnnotationLoader loader = getAnnotationLoader(manager, unit);
List<VirtualFile> files = getClasses(unit);
ArrayList<VirtualFile> deployedFiles = new ArrayList<VirtualFile>(files.size());
for(VirtualFile file : files)
@@ -266,7 +248,7 @@
try
{
ClassFile cf = loadClassFile(file);
- log.debug("Deploying possibly annotated class " + cf.getName());
+ log.debug("Deploying possibly annotated class " + cf.getName() + " into " + manager);
loader.deployClassFile(cf);
}
catch (Exception e)
@@ -276,15 +258,14 @@
{
undeployAnnotation(loader, deployedFiles.get(i));
}
- throw new DeploymentException("Error reading annotations for " + file, e);
+ throw new DeploymentException("Error reading annotations for " + file + " during deployment into " + manager, e);
}
}
}
- private void undeployAnnotations(VFSDeploymentUnit unit)
+ private void undeployAnnotations(AspectManager manager, VFSDeploymentUnit unit)
{
- ClassLoader scl = getScopedClassLoader(unit);
- AspectAnnotationLoader loader = getAnnotationLoader(scl);
+ AspectAnnotationLoader loader = getAnnotationLoader(manager, unit);
List<VirtualFile> files = getClasses(unit);
for(VirtualFile file : files)
{
@@ -306,11 +287,10 @@
}
}
- private AspectAnnotationLoader getAnnotationLoader(ClassLoader scl)
+ private AspectAnnotationLoader getAnnotationLoader(AspectManager manager, VFSDeploymentUnit unit)
{
- AspectManager manager = (scl != null) ? AspectManager.instance(scl) : AspectManager.instance();
AspectAnnotationLoader loader = new AspectAnnotationLoader(manager);
- loader.setClassLoader(scl);
+ loader.setClassLoader(unit.getClassLoader());
return loader;
}
@@ -385,21 +365,40 @@
return (realName.endsWith(AOP_JAR_SUFFIX));
}
- private ClassLoader getScopedClassLoader(VFSDeploymentUnit unit)
+ private AspectManager getCorrectManager(VFSDeploymentUnit unit)
{
//Scoped AOP deployments are only available when deployed as part of a scoped sar, ear etc.
//It can contain an aop.xml file, or it can be part of a .aop file
//Linking a standalone -aop.xml file onto a scoped deployment is not possible at the moment
- AOPClassLoaderScopingPolicy policy = AspectManager.instance().getClassLoaderScopingPolicy();
+ AOPClassLoaderScopingPolicy policy = AspectManager.getClassLoaderScopingPolicy();
+
ClassLoader cl = unit.getClassLoader();
- if (policy != null && policy.isScoped(cl))
+ Module module = unit.getTopLevel().getAttachment(Module.class);
+ Domain domain = null;
+ if (policy != null)
{
- return unit.getClassLoader();
+ if (policy instanceof NewClassLoaderDomainInitializer)
+ {
+ domain = ((NewClassLoaderDomainInitializer)policy).initScopedDomain(cl, module);
+ }
+ else if (policy instanceof RepositoryClassLoaderDomainIntializer)
+ {
+ domain = ((RepositoryClassLoaderDomainIntializer)policy).initScopedDomain(cl);
+ }
+ else
+ {
+ throw new RuntimeException("No domain intitialiser could be found");
+ }
}
- return null;
+ if (domain != null)
+ {
+ return domain;
+ }
+
+ return aspectManager;
}
-
+
private static class ClassFileFilter implements VirtualFileFilter
{
public boolean accepts(VirtualFile file)
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/JBossAspectLibrary.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/JBossAspectLibrary.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/JBossAspectLibrary.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -51,6 +51,10 @@
*/
public void start() throws Exception
{
+ System.out.println("***************************");
+ System.out.println("TCL " + Thread.currentThread().getContextClassLoader() + " - " + Thread.currentThread().getContextClassLoader());
+ System.out.println("MyCl " + this.getClass().getClassLoader() + " - " + this.getClass().getClassLoader());
+
aspectManager.deployBaseAspects();
}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ExtraClassPoolFactoryParameters.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ExtraClassPoolFactoryParameters.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ExtraClassPoolFactoryParameters.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,53 @@
+/*
+* 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.deployers.temp;
+
+import java.util.Map;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExtraClassPoolFactoryParameters
+{
+ /** A map of properties that can be used to configure the classpool factories further */
+ private static ThreadLocal<Map> properties = new ThreadLocal<Map>();
+
+ public static void pushThreadProperties(Map props)
+ {
+ properties.set(props);
+ }
+
+ public static Map peekThreadProperties()
+ {
+ return properties.get();
+ }
+
+ public static Map popThreadProperties()
+ {
+ Map props = properties.get();
+ properties.remove();
+ return props;
+ }
+
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPool.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPool.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPool.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,138 @@
+/*
+* 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.deployers.temp;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.aop.classpool.AOPClassPool;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBoss5ClassPool extends AOPClassPool
+{
+ /**
+ * Used for dynamically created classes (see loadClass(String, byte[]), ClassLoader)
+ */
+ protected File tempdir = null;
+ protected URL tempURL = null;
+ // For loadClass tmpdir creation for UCL
+ protected final Object tmplock = new Object();
+
+ protected JBoss5ClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+ {
+ super(cl, src, repository);
+ tempdir = tmp;
+ tempURL = tmpURL;
+ }
+
+ protected JBoss5ClassPool(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(src, repository);
+ }
+
+ public boolean isUnloadedClassLoader()
+ {
+ if (getClassLoader() instanceof RepositoryClassLoader)
+ {
+ RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
+ return rcl.getLoaderRepository() == null;
+ }
+ return false;
+ }
+
+ public Class toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain)
+ throws CannotCompileException
+ {
+ ClassLoader useLoader = getClassLoader() == null ? loader : getClassLoader();
+ return super.toClass(cc, useLoader, domain);
+// lockInCache(cc);
+// if (getClassLoader() == null || tempdir == null)
+// {
+// return super.toClass(cc, loader, domain);
+// }
+// Class dynClass = null;
+// try
+// {
+// File classFile = null;
+// String classFileName = getResourceName(cc.getName());
+// // Write the clas file to the tmpdir
+// synchronized (tmplock)
+// {
+// classFile = new File(tempdir, classFileName);
+// File pkgDirs = classFile.getParentFile();
+// pkgDirs.mkdirs();
+// FileOutputStream stream = new FileOutputStream(classFile);
+// stream.write(cc.toBytecode());
+// stream.flush();
+// stream.close();
+// classFile.deleteOnExit();
+// }
+// // We have to clear Blacklist caches or the class will never
+// // be found
+// //((UnifiedClassLoader)dcl).clearBlacklists();
+// // To be backward compatible
+// RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
+// rcl.clearClassBlackList();
+// rcl.clearResourceBlackList();
+//
+// // Now load the class through the cl
+// dynClass = getClassLoader().loadClass(cc.getName());
+// }
+// catch (Exception ex)
+// {
+// ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
+// cfe.initCause(ex);
+// throw cfe;
+// }
+//
+// return dynClass;
+ }
+
+ protected boolean isLocalResource(String resourceName)
+ {
+ if (super.isLocalResource(resourceName))
+ {
+ return true;
+ }
+
+ File file = new File(tempdir, resourceName);
+ if (file.exists())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPoolFactory.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPoolFactory.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5ClassPoolFactory.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,113 @@
+/*
+* 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.deployers.temp;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
+import org.jboss.aop.classpool.AOPClassPool;
+import org.jboss.aop.deployment.JBossClassPool;
+import org.jboss.aop.deployment.JBossClassPoolFactory;
+import org.jboss.aop.deployment.ScopedJBossClassPool;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.deployers.plugins.classloading.Module;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ * Comment
+ *
+ * @deprecated TODO JBAOP-107 Need a different version for the JBoss5 classloader
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 64815 $
+ **/
+ at Deprecated
+public class JBoss5ClassPoolFactory extends JBossClassPoolFactory implements ScopedClassPoolFactory
+{
+ public JBoss5ClassPoolFactory(File tmpClassesDir) throws IOException
+ {
+ super(tmpClassesDir);
+ }
+
+ static ThreadLocal<Boolean> reentry = new ThreadLocal<Boolean>();
+ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+
+ ClassPool parent = getCreateParentClassPools(cl, src, repository);
+ if (cl instanceof BaseClassLoader)
+ {
+ Map props = ExtraClassPoolFactoryParameters.peekThreadProperties();
+ Module module = (Module)props.get(Module.class);
+
+ File tempdir = getTempDirectory(cl);
+
+ //Do we need a way to add urls to the repository
+ URL tmpCP;
+ try
+ {
+ tmpCP = createURLAndAddToLoader(cl, tempdir);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ if (module != null && module.getParentDomain() != null)
+ {
+ //It is scoped
+ ClassLoaderSystem sys = ClassLoaderSystem.getInstance();
+ ClassLoaderDomain domain = sys.getDomain(module.getDomainName());
+ boolean parentFirst = module.getMetadata().isJ2seClassLoadingCompliance();
+
+ return new ScopedJBoss5ClassPool(cl, parent, repository, tempdir, tmpCP, parentFirst, domain);
+ }
+ return new JBoss5ClassPool(cl, parent, repository, tempdir, tmpCP);
+ }
+ return new AOPClassPool(cl, parent, repository);
+ }
+
+ private URL createURLAndAddToLoader(ClassLoader cl, File tempdir) throws IOException
+ {
+ URL tmpURL = tempdir.toURL();
+ URL tmpCP = new URL(tmpURL, "?dynamic=true");
+
+ //FIXME IS this needed
+// RepositoryClassLoader ucl = (RepositoryClassLoader) cl;
+//
+// // We may be undeploying.
+// if (ucl.getLoaderRepository() != null)
+// {
+// ucl.addURL(tmpCP);
+// }
+
+ return tmpCP;
+ }
+}
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5Integration.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5Integration.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/JBoss5Integration.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -23,40 +23,73 @@
import java.io.File;
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+import org.jboss.aop.AspectManager;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
import org.jboss.aop.deployment.JBossIntegration;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.mx.loading.RepositoryClassLoader;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
-public class JBoss5Integration implements JBossIntegration
+public class JBoss5Integration implements JBossIntegration, ScopedClassPoolFactory
{
+ /** The delegate classpool factory */
+ private ScopedClassPoolFactory delegateClassPoolFactory;
+ private AOPClassLoaderScopingPolicy policy;
+
+ public boolean isValidClassLoader(ClassLoader loader)
+ {
+ if (!(loader instanceof RepositoryClassLoader)) return false;
+ return ((RepositoryClassLoader) loader).getLoaderRepository() != null;
+ }
- public void attachDeprecatedTranslator()
+ public void setScopingPolicy(AOPClassLoaderScopingPolicy policy)
{
+ this.policy = policy;
}
-
+
+ public AOPClassLoaderScopingPolicy getScopingPolicy()
+ {
+ return policy;
+ }
+
public AOPClassLoaderScopingPolicy createAOPClassLoaderScopingPolicy()
{
- return null;
+ return policy;
}
public ScopedClassPoolFactory createScopedClassPoolFactory(File tmpDir) throws Exception
{
- return null;
+ delegateClassPoolFactory = new JBoss5ClassPoolFactory(tmpDir);
+ return this;
}
+
+ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return delegateClassPoolFactory.create(cl, src, repository);
+ }
- public void detachDeprecatedTranslator()
+ public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
{
+ return delegateClassPoolFactory.create(src, repository);
}
+
+ public void attachDeprecatedTranslator()
+ {
+ AspectManager mgr = AspectManager.instance();
+ ClassLoaderSystem.getInstance().setTranslator(mgr);
+ }
- public boolean isValidClassLoader(ClassLoader loader)
+ public void detachDeprecatedTranslator()
{
- return false;
+ ClassLoaderSystem.getInstance().setTranslator(null);
}
-
}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainInitializer.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainInitializer.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainInitializer.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,36 @@
+/*
+* 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.deployers.temp;
+
+import org.jboss.aop.Domain;
+import org.jboss.deployers.plugins.classloading.Module;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface NewClassLoaderDomainInitializer
+{
+ Domain initScopedDomain(ClassLoader loader, Module module);
+
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainRegistry.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainRegistry.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderDomainRegistry.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,92 @@
+/*
+* 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.deployers.temp;
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.aop.Domain;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.deployers.plugins.classloading.Module;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class NewClassLoaderDomainRegistry
+{
+ final static ClassLoaderDomain domain = new ClassLoaderDomain("NOT_USED_PLACEHOLDER");
+
+ /** classloader domains by their classloaders */
+ private Map<ClassLoader, WeakReference<ClassLoaderDomain>> classLoaderDomainsByLoader = new WeakHashMap<ClassLoader, WeakReference<ClassLoaderDomain>>();
+
+ /** aopDomains by classloader domain */
+ private Map<ClassLoaderDomain, ScopedNewClassLoaderDomain> aopDomainsByClassLoaderDomain = new WeakHashMap<ClassLoaderDomain, ScopedNewClassLoaderDomain>();
+
+ synchronized void initMapsForLoader(ClassLoader loader, Module module, ScopedNewClassLoaderDomain domain)
+ {
+ ClassLoaderSystem system = ClassLoaderSystem.getInstance();
+
+ String domainName = module.getDomainName();
+ ClassLoaderDomain clDomain = system.getDomain(domainName);
+ classLoaderDomainsByLoader.put(loader, new WeakReference<ClassLoaderDomain>(clDomain));
+
+ if (domain != null)
+ {
+ aopDomainsByClassLoaderDomain.put(clDomain, domain);
+ }
+ }
+
+ synchronized Domain getRegisteredDomain(ClassLoader cl)
+ {
+ ClassLoaderDomain clDomain = getClassLoaderDomainForLoader(cl);
+ if (clDomain != null)
+ {
+ return aopDomainsByClassLoaderDomain.get(clDomain);
+ }
+ return null;
+ }
+
+ synchronized ClassLoaderDomain getClassLoaderDomainForLoader(ClassLoader cl)
+ {
+ WeakReference<ClassLoaderDomain> clDomainRef = classLoaderDomainsByLoader.get(cl);
+ if (clDomainRef != null)
+ {
+ return clDomainRef.get();
+ }
+
+ ClassLoader parent = cl.getParent();
+ if (parent != null)
+ {
+ ClassLoaderDomain domain = getClassLoaderDomainForLoader(parent);
+ if (domain != null)
+ {
+ classLoaderDomainsByLoader.put(parent, new WeakReference<ClassLoaderDomain>(domain));
+ return domain;
+ }
+ }
+ return null;
+ }
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderScopingPolicy.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderScopingPolicy.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/NewClassLoaderScopingPolicy.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,124 @@
+/*
+* 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.deployers.temp;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.deployers.plugins.classloading.Module;
+import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
+import org.jboss.logging.Logger;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class NewClassLoaderScopingPolicy implements AOPClassLoaderScopingPolicy, NewClassLoaderDomainInitializer
+{
+ static Logger log = Logger.getLogger(NewClassLoaderScopingPolicy.class);
+ NewClassLoaderDomainRegistry registry = new NewClassLoaderDomainRegistry();
+
+ public Domain initScopedDomain(ClassLoader loader, Module module)
+ {
+ ScopedNewClassLoaderDomain scopedDomain = (ScopedNewClassLoaderDomain)registry.getRegisteredDomain(loader);
+ if (scopedDomain == null)
+ {
+ if (module.getParentDomain() != null/* && module.getParentDomain().equals(ClassLoaderSystem.DEFAULT_DOMAIN_NAME)*/)
+ {
+ ClassLoaderSystem system = ClassLoaderSystem.getInstance();
+ String domainName = module.getDomainName();
+ ClassLoaderDomain domain = system.getDomain(domainName);
+
+ ClassLoaderMetaData cmd = module.getMetadata();
+ boolean parentDelegation = cmd.isJ2seClassLoadingCompliance();
+ String name = String.valueOf(System.identityHashCode(loader));
+
+ scopedDomain = new ScopedNewClassLoaderDomain(loader, name, parentDelegation, AspectManager.getTopLevelAspectManager(), false, domain, registry);
+ }
+
+ registry.initMapsForLoader(loader, module, scopedDomain);
+
+ //Need to pass some data through to the classpoolfactory here
+ Map properties = new HashMap();
+ //The module is needed by the JBoss5ClassPoolFactory, the legacy JBossClassPoolFactory will ignore this
+ properties.put(Module.class, module);
+ ExtraClassPoolFactoryParameters.pushThreadProperties(properties);
+ try
+ {
+ AspectManager.instance().registerClassLoader(loader); //Ends up in classpool factory create method
+ }
+ finally
+ {
+ ExtraClassPoolFactoryParameters.popThreadProperties();
+ }
+ }
+ return scopedDomain;
+ }
+
+ public Domain getDomain(ClassLoader classLoader, AspectManager parent)
+ {
+ //Check the stored domains
+ Domain domain = registry.getRegisteredDomain(classLoader);
+ if (domain != null)
+ {
+ return domain;
+ }
+
+ return null;
+ }
+
+ public Domain getTopLevelDomain(AspectManager parent)
+ {
+ Thread.currentThread().getContextClassLoader();
+ return null;
+ }
+
+// public boolean isScoped(Module module)
+// {
+// String domainName = module.getDomainName();
+// ClassLoaderMetaData cmd = module.getMetadata();
+//// boolean parentDelegation = cmd.isJ2seClassLoadingCompliance();
+//
+// System.out.println("****** DomainName: " + domainName + " parentDomain: " + module.getParentDomain());
+//
+//
+// //FIXME There seems to be no way to navigate the tree of domains
+//
+// if (module.getParentDomain() != null && module.getParentDomain().equals(ClassLoaderSystem.DEFAULT_DOMAIN_NAME))
+// {
+// //Should probably check for more levels?
+// return true;
+// }
+// return false;
+// }
+
+
+}
+
\ No newline at end of file
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderDomainIntializer.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderDomainIntializer.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderDomainIntializer.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,34 @@
+/*
+* 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.deployers.temp;
+
+import org.jboss.aop.Domain;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface RepositoryClassLoaderDomainIntializer
+{
+ Domain initScopedDomain(ClassLoader loader);
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderScopingPolicy.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderScopingPolicy.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/RepositoryClassLoaderScopingPolicy.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,158 @@
+/*
+* 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.deployers.temp;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
+import org.jboss.aop.classpool.AOPClassPoolRepository;
+import org.jboss.aop.deployment.ScopedRepositoryClassLoaderHelper;
+import org.jboss.aop.domain.ScopedRepositoryClassLoaderDomain;
+import org.jboss.logging.Logger;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class RepositoryClassLoaderScopingPolicy implements AOPClassLoaderScopingPolicy, RepositoryClassLoaderDomainIntializer
+{
+ Logger log = Logger.getLogger(RepositoryClassLoaderScopingPolicy.class);
+
+ /** A map of domains by loader repository, maintaned by the top level AspectManager */
+ private Map<Object, Domain> scopedClassLoaderDomains = new WeakHashMap<Object, Domain>();
+
+
+ public Domain initScopedDomain(ClassLoader loader)
+ {
+ Domain domain = getDomain(loader, AspectManager.getTopLevelAspectManager());
+
+ AspectManager.instance().registerClassLoader(loader); //Ends up in classpool factory create method
+
+ return domain;
+ }
+
+ public synchronized Domain getDomain(ClassLoader classLoader, AspectManager parent)
+ {
+ ClassLoader scopedClassLoader = ifScopedDeploymentGetScopedParentUclForCL(classLoader);
+ if (scopedClassLoader != null)
+ {
+ Domain scopedManager = null;
+ synchronized (AOPClassPoolRepository.getInstance().getRegisteredCLs())
+ {
+ Object loaderRepository = getLoaderRepository(classLoader);
+ scopedManager = scopedClassLoaderDomains.get(loaderRepository);
+
+ // FIXME: JBAOP-107 REMOVE THIS HACK
+ if (scopedManager != null && scopedManager.isValid() == false)
+ {
+ scopedClassLoaderDomains.remove(loaderRepository);
+ scopedManager = null;
+ }
+
+ if (scopedManager == null)
+ {
+ scopedManager = getScopedClassLoaderDomain(scopedClassLoader, parent);
+ log.debug("Created domain " + scopedManager + " for scoped deployment on: " +
+ classLoader + "; identifying scoped ucl: " + scopedClassLoader);
+ scopedManager.setInheritsBindings(true);
+ scopedManager.setInheritsDeclarations(true);
+
+ scopedClassLoaderDomains.put(loaderRepository, scopedManager);
+ }
+ return scopedManager;
+ }
+ }
+ return null;
+ }
+
+ public Domain getTopLevelDomain(AspectManager parent)
+ {
+ ClassLoader classLoader = getTopLevelJBossClassLoader();
+ return getDomain(classLoader, parent);
+ }
+
+//////////
+
+ private ClassLoader ifScopedDeploymentGetScopedParentUclForCL(ClassLoader loader)
+ {
+ ClassLoader parent = loader;
+ //The web classloader will be a child of the unified classloader - find out if that is scoped
+ while (parent != null)
+ {
+ if (ScopedRepositoryClassLoaderHelper.isScopedClassLoader(parent))
+ {
+ return parent;
+ }
+ if (parent instanceof RepositoryClassLoader)
+ {
+ //We were a repository classloader, but not scoped - ignore the parents like a sulky teenager
+ return null;
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ private ClassLoader getTopLevelJBossClassLoader()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ RepositoryClassLoader topRcl = null;
+ while (loader != null)
+ {
+ if (loader instanceof RepositoryClassLoader)
+ {
+ topRcl = (RepositoryClassLoader)loader;
+ }
+ loader = loader.getParent();
+ }
+ return topRcl;
+ }
+
+ private Domain getScopedClassLoaderDomain(ClassLoader cl, AspectManager parent)
+ {
+ boolean parentDelegation = true;
+ if (cl instanceof RepositoryClassLoader)
+ {
+ HeirarchicalLoaderRepository3 repository = (HeirarchicalLoaderRepository3)((RepositoryClassLoader)cl).getLoaderRepository();
+ parentDelegation = repository.getUseParentFirst();
+ }
+ String name = String.valueOf(System.identityHashCode(cl));
+ return new ScopedRepositoryClassLoaderDomain(cl, name, parentDelegation, parent, false);
+ }
+
+ private Object getLoaderRepository(ClassLoader loader)
+ {
+ ClassLoader cl = ifScopedDeploymentGetScopedParentUclForCL(loader);
+ if (cl != null)
+ {
+ return ((RepositoryClassLoader)cl).getLoaderRepository();
+ }
+ return null;
+ }
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedJBoss5ClassPool.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedJBoss5ClassPool.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedJBoss5ClassPool.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,284 @@
+/*
+* 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.deployers.temp;
+
+import java.io.File;
+import java.lang.ref.WeakReference;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.classpool.AOPClassPool;
+import org.jboss.aop.classpool.AOPClassPoolRepository;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScopedJBoss5ClassPool extends JBoss5ClassPool
+{
+// final static LoaderRepositoryUrlUtil LOADER_REPOSITORY_UTIL = new LoaderRepositoryUrlUtil();
+//
+// WeakReference repository = null;
+// UrlInfo urlInfo;
+ ThreadLocal lastPool = new ThreadLocal();
+ WeakReference<ClassLoaderDomain> domainRef;
+
+ public ScopedJBoss5ClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp,
+ URL tmpURL, boolean parentFirst, ClassLoaderDomain domain)
+ {
+ super(cl, src, repository, tmp, tmpURL);
+ super.childFirstLookup = !parentFirst;
+ this.domainRef = new WeakReference(domain);
+ }
+
+
+
+// public ScopedJBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+// {
+// super(cl, src, repository, tmp, tmpURL);
+//
+// boolean parentFirst = false;
+// LoaderRepository loaderRepository = null;
+// ClassLoader prnt = cl;
+// while (prnt != null)
+// {
+// if (prnt instanceof RepositoryClassLoader)
+// {
+// loaderRepository = ((RepositoryClassLoader)prnt).getLoaderRepository();
+// if (loaderRepository instanceof HeirarchicalLoaderRepository3)
+// {
+// parentFirst = ((HeirarchicalLoaderRepository3)loaderRepository).getUseParentFirst();
+// }
+// break;
+// }
+// prnt = SecurityActions.getParent(cl);
+// }
+//
+// super.childFirstLookup = !parentFirst;
+// }
+
+
+// private HeirarchicalLoaderRepository3 getRepository()
+// {
+// ClassLoader cl = getClassLoader0();
+// if (cl != null)
+// {
+// return (HeirarchicalLoaderRepository3)((RepositoryClassLoader)cl).getLoaderRepository();
+// }
+// return null;
+// }
+
+ private URL getResourceUrlForClass(String resourcename)
+ {
+// HeirarchicalLoaderRepository3 repo = getRepository();
+// return repo.getResource(resourcename, super.getClassLoader());
+ ClassLoaderDomain domain = domainRef.get();
+ return domain.getResource(resourcename);
+ }
+
+ private boolean isMine(URL url)
+ {
+// HeirarchicalLoaderRepository3 repo = getRepository();
+// if (repo != null)
+// {
+// //The URL of the class loaded with my scoped classloader
+// if (url != null)
+// {
+// urlInfo = LOADER_REPOSITORY_UTIL.getURLInfo(getRepository(), urlInfo);
+//
+// URL[] myUrls = urlInfo.getLocalUrls();
+// String resource = url.toString();
+// for (int i = 0 ; i < myUrls.length ; i++)
+// {
+// if (resource.indexOf(myUrls[i].toString()) >= 0)
+// {
+// return true;
+// }
+// }
+// return false;
+// }
+// }
+ return true;
+ }
+
+ public CtClass getCached(String classname)
+ {
+ if (classname == null)
+ {
+ return null;
+ }
+ if (isUnloadedClassLoader())
+ {
+ return null;
+ }
+
+ if (generatedClasses.get(classname) != null)
+ {
+ //It is a new class, and this callback is probably coming from the frozen check when creating a new nested class
+ return super.getCached(classname);
+ }
+
+ //Is this from the scoped classloader itself of from the parent?
+ String resourcename = getResourceName(classname);
+ URL url = getResourceUrlForClass(resourcename);
+ boolean isMine = isMine(url);
+
+ if (isMine)
+ {
+ if (super.childFirstLookup)
+ {
+ //Parent delegation is false, attempt to get this class out of ourselves
+ CtClass clazz = super.getCachedLocally(classname);
+ if (clazz == null)
+ {
+ clazz = createCtClass(classname, false);
+ if (clazz != null)
+ {
+ lockInCache(clazz);
+ }
+ }
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ return super.getCached(classname);
+ }
+
+
+ try
+ {
+ ClassPool pool = getCorrectPoolForResource(classname, url);
+ if (pool != lastPool.get())
+ {
+ lastPool.set(pool);
+ return pool.get(classname);
+ }
+ }
+ catch (NotFoundException e)
+ {
+ }
+ catch(StackOverflowError e)
+ {
+ throw e;
+ }
+ finally
+ {
+ lastPool.set(null);
+ }
+
+ return null;
+ }
+
+ private ClassPool getCorrectPoolForResource(String classname, URL url)
+ {
+ synchronized(AspectManager.getRegisteredCLs())
+ {
+ //JBoss 5 has an extra NoAnnotationURLCLassLoader that is not on the default path, make sure that that is checked at the end
+ //FIXME This needs revisiting/removing once the
+ ArrayList noAnnotationURLClassLoaderPools = null;
+ String resource = url.toString();
+ for(Iterator it = AspectManager.getRegisteredCLs().values().iterator() ; it.hasNext() ; )
+ {
+ AOPClassPool candidate = (AOPClassPool)it.next();
+ if (candidate.isUnloadedClassLoader())
+ {
+ AspectManager.instance().unregisterClassLoader(candidate.getClassLoader());
+ continue;
+ }
+
+ if (candidate.getClassLoader() instanceof BaseClassLoader)
+ {
+ //Sometimes the ClassLoader is a proxy for MBeanProxyExt?!
+ RepositoryClassLoader rcl = (RepositoryClassLoader)candidate.getClassLoader();
+ URL[] urls = rcl.getClasspath();
+
+ for (int i = 0 ; i < urls.length ; i++)
+ {
+ if (resource.indexOf(urls[i].getFile()) >= 0)
+ {
+ return candidate;
+ }
+ }
+ }
+ //FIXME Remove once we have the JBoss 5 version of pool
+ else if (isInstanceOfNoAnnotationURLClassLoader(candidate.getClassLoader()))
+ {
+ if (noAnnotationURLClassLoaderPools == null)
+ {
+ noAnnotationURLClassLoaderPools = new ArrayList();
+ }
+ noAnnotationURLClassLoaderPools.add(candidate);
+ }
+ }
+
+ //FIXME Remove once we have the JBoss 5 version of pool
+ if (noAnnotationURLClassLoaderPools != null)
+ {
+ for (Iterator it = noAnnotationURLClassLoaderPools.iterator() ; it.hasNext() ; )
+ {
+ ClassPool pool = (ClassPool)it.next();
+
+ try
+ {
+ pool.get(classname);
+ return pool;
+ }
+ catch(NotFoundException ignoreTryNext)
+ {
+ }
+ }
+ }
+ }
+
+ return AOPClassPool.createAOPClassPool(ClassPool.getDefault(), AOPClassPoolRepository.getInstance());
+ }
+
+ /**
+ * NoAnnotationURLCLassLoader lives in different packages in JBoss 4 and 5
+ */
+ private boolean isInstanceOfNoAnnotationURLClassLoader(ClassLoader loader)
+ {
+ Class parent = loader.getClass();
+ while (parent != null)
+ {
+ if ("NoAnnotationURLClassLoader".equals(parent.getSimpleName()))
+ {
+ return true;
+ }
+ parent = parent.getSuperclass();
+ }
+ return false;
+ }
+
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedNewClassLoaderDomain.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedNewClassLoaderDomain.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployers/temp/ScopedNewClassLoaderDomain.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,151 @@
+/*
+* 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.deployers.temp;
+
+
+import java.lang.ref.WeakReference;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.domain.ScopedClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+
+/**
+ * A domain that is used for scoped classloaders with the new JBoss 5 classloaders
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 1.1 $
+ */
+public class ScopedNewClassLoaderDomain extends ScopedClassLoaderDomain
+{
+ WeakReference<ClassLoaderDomain> classLoaderDomainRef;
+ NewClassLoaderDomainRegistry registry;
+
+ public ScopedNewClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, AspectManager manager, boolean parentFirst,
+ ClassLoaderDomain classLoaderDomain, NewClassLoaderDomainRegistry registry)
+ {
+ super(loader, name, parentDelegation, manager, parentFirst);
+ classLoaderDomainRef = new WeakReference<ClassLoaderDomain>(classLoaderDomain);
+ this.registry = registry;
+ }
+
+ private ClassLoaderDomain getClassLoaderDomain()
+ {
+ if (classLoaderDomainRef != null)
+ {
+ return classLoaderDomainRef.get();
+ }
+ return null;
+ }
+
+ // FIXME: JBAOP-107 REMOVE THIS HACK
+ public boolean isValid()
+ {
+ ClassLoader cl = getClassLoader();
+ if (cl == null)
+ return false;
+
+ ClassLoaderDomain domain = getClassLoaderDomain();
+ if (domain == null)
+ return false;
+
+ if (domain.hasClassLoaders())
+ {
+ return true;
+ }
+
+ return false;
+// return cl.getLoaderRepository() != null;
+ }
+
+ protected Object getPerVmAspectWithNoParentDelegation(String def)
+ {
+ Object aspect = myPerVMAspects.get(def);
+ if (aspect != null)
+ {
+ return aspect;
+ }
+
+ aspect = super.getSuperPerVmAspect(def);
+ if (aspect != null)
+ {
+ ClassLoaderDomain loadingDomain = getAspectRepository(aspect);
+// LoaderRepository myRepository = getScopedRepository();
+ ClassLoaderDomain myDomain = getClassLoaderDomain();
+
+ if (loadingDomain == myDomain)
+ {
+ //The parent does not load this class
+ myPerVMAspects.put(def, aspect);
+ }
+ else
+ {
+ //The class has been loaded by a parent domain, find out if we also have a copy
+ Class clazz = myDomain.loadClass(aspect.getClass().getName());
+ if (clazz == aspect.getClass())
+ {
+ notMyPerVMAspects.put(def, Boolean.TRUE);
+ }
+ else
+ {
+ //We have a different version of the class deployed
+ AspectDefinition aspectDefinition = getAspectDefinition(def);
+ //Override the classloader to create the aspect instance
+ aspect = createPerVmAspect(def, aspectDefinition, getClassLoader());
+ myPerVMAspects.put(def, aspect);
+ }
+ }
+ }
+
+ return aspect;
+ }
+
+
+
+ private ClassLoaderDomain getAspectRepository(Object aspect)
+ {
+ ClassLoader cl = aspect.getClass().getClassLoader();
+ ClassLoaderDomain domain = registry.getClassLoaderDomainForLoader(cl);
+ return domain;
+ }
+
+// private HeirarchicalLoaderRepository3 getScopedRepository()
+// {
+// ClassLoader classloader = getClassLoader();
+// if (classloader == null)
+// throw new IllegalStateException("ClassLoader no longer exists: " + classLoaderString);
+// if (classloader instanceof RepositoryClassLoader == false)
+// throw new IllegalStateException("ClassLoader is not an instanceof RepositoryClassLoader " + classLoaderString);
+// RepositoryClassLoader repositoryClassLoader = (RepositoryClassLoader) classloader;
+// LoaderRepository loaderRepository = repositoryClassLoader.getLoaderRepository();
+// if (loaderRepository == null)
+// throw new IllegalStateException("ClassLoader has been undeployed: " + classLoaderString);
+// if (loaderRepository instanceof HeirarchicalLoaderRepository3 == false)
+// throw new IllegalStateException("Repository " + loaderRepository + " for classlaoder " + classLoaderString + " is not an HeirarchicalLoaderRepository3");
+// return (HeirarchicalLoaderRepository3) loaderRepository;
+// }
+}
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectDeployer.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectDeployer.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectDeployer.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -303,7 +303,7 @@
//Scoped AOP deployments are only available when deployed as part of a scoped sar, ear etc.
//It can contain an aop.xml file, or it can be part of a .aop file
//Linking a standalone -aop.xml file onto a scoped deployment is not possible at the moment
- if (JBossScopedClassLoaderHelper.isScopedClassLoader(di.ucl))
+ if (ScopedRepositoryClassLoaderHelper.isScopedClassLoader(di.ucl))
{
return di.ucl;
}
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectManagerService.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectManagerService.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/AspectManagerService.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -45,6 +45,7 @@
import org.jboss.aop.hook.JDK14TransformerManager;
import org.jboss.aop.instrument.InstrumentorFactory;
import org.jboss.aop.instrument.TransformerCommon;
+import org.jboss.logging.Logger;
import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
import org.jboss.mx.server.ServerConstants;
import org.jboss.mx.util.ObjectNameFactory;
@@ -61,6 +62,8 @@
implements AspectManagerServiceMBean, AspectNotificationHandler
{
+ Logger log = Logger.getLogger(AspectManagerService.class);
+
static {
//pre-load necessary classes so that we avoid NoClassDefFoundErrors on JRockit when using the RepositoryClassloader hook
//When AspectManager.translate() is called the first time, these classes have not been loaded yet, and this is what causes
@@ -220,7 +223,7 @@
}
else
{
- System.out.println("Could not find " + xml + " file in the resources of " + cl);
+ log.warn("Could not find " + xml + " file in the resources of " + cl);
}
}
catch (Exception e)
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBoss4Integration.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBoss4Integration.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBoss4Integration.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -38,8 +38,7 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
-import org.jboss.aop.classpool.AOPScopedClassLoaderHelper;
-import org.jboss.aop.classpool.AOPScopedClassLoaderHelperBridge;
+import org.jboss.aop.deployers.temp.RepositoryClassLoaderScopingPolicy;
import org.jboss.mx.loading.RepositoryClassLoader;
import org.jboss.mx.util.MBeanServerLocator;
@@ -52,9 +51,9 @@
* <ul>Related Classes:
* <li> {@link JBossClassPool}
* <li> {@link JBossClassPoolFactory}
- * <li> {@link JBossScopedClassLoaderHelper}
+ * <li> {@link ScopedRepositoryClassLoaderHelper}
* <li> {@link LoaderRepositoryUrlUtil}
- * <li> {@link ScopedClassLoaderDomain}
+ * <li> {@link ScopedRepositoryClassLoaderDomain}
* <li> {@link ScopedJBossClassPool}
* </ul>
*
@@ -78,8 +77,7 @@
public AOPClassLoaderScopingPolicy createAOPClassLoaderScopingPolicy()
{
- AOPScopedClassLoaderHelper helper = new JBossScopedClassLoaderHelper();
- return new AOPScopedClassLoaderHelperBridge(helper);
+ return new RepositoryClassLoaderScopingPolicy();
}
public ScopedClassPoolFactory createScopedClassPoolFactory(File tmpDir) throws Exception
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -24,9 +24,6 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import org.jboss.aop.AspectManager;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
@@ -71,17 +68,17 @@
throw new RuntimeException(e);
}
AOPClassLoaderScopingPolicy policy = AspectManager.getClassLoaderScopingPolicy();
- if (policy != null && policy.isScoped(cl))
+ if (ScopedRepositoryClassLoaderHelper.isScopedClassLoader(cl))
{
//It is scoped
- return new ScopedJBossClassPool(cl, /*src*/parent, repository, tempdir, tmpCP);
+ return new ScopedJBossClassPool(cl, parent, repository, tempdir, tmpCP);
}
- return new JBossClassPool(cl, /*src*/parent, repository, tempdir, tmpCP);
+ return new JBossClassPool(cl, parent, repository, tempdir, tmpCP);
}
- return new AOPClassPool(cl, /*src*/parent, repository);
+ return new AOPClassPool(cl, parent, repository);
}
- private ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ protected ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
{
//Make sure that we get classpools for all the parent classloaders
ClassLoader parent = SecurityActions.getParent(cl);
@@ -93,7 +90,7 @@
return src;
}
- private File getTempDirectory(ClassLoader cl)
+ protected File getTempDirectory(ClassLoader cl)
{
File tempdir = null;
int attempts = 0;
@@ -149,4 +146,5 @@
return tmpCP;
}
+
}
Deleted: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossScopedClassLoaderHelper.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossScopedClassLoaderHelper.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossScopedClassLoaderHelper.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -1,116 +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.deployment;
-
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Domain;
-import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
-import org.jboss.aop.classpool.AOPScopedClassLoaderHelper;
-import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
-import org.jboss.mx.loading.LoaderRepository;
-import org.jboss.mx.loading.RepositoryClassLoader;
-
-/**
- *
- * TODO JBAOP-107 Need a different version for the JBoss5 classloader
- * @deprecated use {@link AOPClassLoaderScopingPolicy}
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @autor adrian at jboss.org
- * @version $Revision$
- */
- at Deprecated
-public class JBossScopedClassLoaderHelper implements AOPScopedClassLoaderHelper
-{
- public ClassLoader ifScopedDeploymentGetScopedParentUclForCL(ClassLoader loader)
- {
- ClassLoader parent = loader;
- //The web classloader will be a child of the unified classloader - find out if that is scoped
- while (parent != null)
- {
- if (isScopedClassLoader(parent))
- {
- return parent;
- }
- if (parent instanceof RepositoryClassLoader)
- {
- //We were a repository classloader, but not scoped - ignore the parents like a sulky teenager
- return null;
- }
- parent = parent.getParent();
- }
- return null;
- }
-
- public static boolean isScopedClassLoader(ClassLoader loader)
- {
- boolean scoped = false;
- if (loader instanceof RepositoryClassLoader)
- {
- LoaderRepository repository = ((RepositoryClassLoader)loader).getLoaderRepository();
- if (repository instanceof HeirarchicalLoaderRepository3)
- {
- scoped = true;
- HeirarchicalLoaderRepository3 hlr = (HeirarchicalLoaderRepository3)repository;
- boolean parentFirst = hlr.getUseParentFirst();
- }
- }
- return scoped;
- }
-
-
- public ClassLoader getTopLevelJBossClassLoader()
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- RepositoryClassLoader topRcl = null;
- while (loader != null)
- {
- if (loader instanceof RepositoryClassLoader)
- {
- topRcl = (RepositoryClassLoader)loader;
- }
- loader = loader.getParent();
- }
- return topRcl;
- }
-
- public Domain getScopedClassLoaderDomain(ClassLoader cl, AspectManager parent)
- {
- boolean parentDelegation = true;
- if (cl instanceof RepositoryClassLoader)
- {
- HeirarchicalLoaderRepository3 repository = (HeirarchicalLoaderRepository3)((RepositoryClassLoader)cl).getLoaderRepository();
- parentDelegation = repository.getUseParentFirst();
- }
- String name = String.valueOf(System.identityHashCode(cl));
- return new ScopedClassLoaderDomain(cl, name, parentDelegation, parent, false);
- }
-
- public Object getLoaderRepository(ClassLoader loader)
- {
- ClassLoader cl = ifScopedDeploymentGetScopedParentUclForCL(loader);
- if (cl != null)
- {
- return ((RepositoryClassLoader)cl).getLoaderRepository();
- }
- return null;
- }
-}
Deleted: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedClassLoaderDomain.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedClassLoaderDomain.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedClassLoaderDomain.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -1,195 +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.deployment;
-
-import java.lang.ref.WeakReference;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Domain;
-import org.jboss.aop.InterceptionMarkers;
-import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
-import org.jboss.mx.loading.LoaderRepository;
-import org.jboss.mx.loading.RepositoryClassLoader;
-
-
-/**
- * A domain that is used for scoped classloaders
- *
- * @deprecated TODO JBAOP-107 Need a different version for the JBoss5 classloader
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @author adrian at jboss.org
- * @version $Revision: 1.1 $
- */
- at Deprecated
-public class ScopedClassLoaderDomain extends Domain
-{
-
- WeakReference<ClassLoader> loader;
- boolean parentDelegation;
- ConcurrentHashMap<String, Object> myPerVMAspects = new ConcurrentHashMap<String, Object>();
- ConcurrentHashMap<String, Boolean> notMyPerVMAspects = new ConcurrentHashMap<String, Boolean>();
- InterceptionMarkers interceptionMarkers = new InterceptionMarkers();
- String classLoaderString;
-
- public ScopedClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, AspectManager manager, boolean parentFirst)
- {
- super(manager, name, parentFirst);
- if (loader == null)
- throw new IllegalArgumentException("Null classloader");
- this.loader = new WeakReference<ClassLoader>(loader);
- this.parentDelegation = parentDelegation;
- classLoaderString = loader.toString();
- }
-
- protected ClassLoader getClassLoader()
- {
- ClassLoader cl = loader.get();
- if (cl != null)
- {
- return cl;
- }
- return null;
- }
-
- // FIXME: JBAOP-107 REMOVE THIS HACK
- public boolean isValid()
- {
- RepositoryClassLoader cl = (RepositoryClassLoader) getClassLoader();
- if (cl == null)
- return false;
- return cl.getLoaderRepository() != null;
- }
-
- public void removeAspectDefinition(String name)
- {
- AspectDefinition def = super.internalRemoveAspectDefintion(name);
- if (def != null)
- {
- myPerVMAspects.remove(name);
- }
- }
-
- public Object getPerVMAspect(AspectDefinition def)
- {
- return getPerVMAspect(def.getName());
- }
-
- @Override
- public InterceptionMarkers getInterceptionMarkers()
- {
- return interceptionMarkers;
- }
-
- public Object getPerVMAspect(String def)
- {
- if (parentDelegation == true)
- {
- //We will alway be loading up the correct class
- Object aspect = super.getPerVMAspect(def);
- return aspect;
- }
- else
- {
- return getPerVmAspectWithNoParentDelegation(def);
- }
- }
-
- private Object getPerVmAspectWithNoParentDelegation(String def)
- {
- Object aspect = myPerVMAspects.get(def);
- if (aspect != null)
- {
- return aspect;
- }
-
- aspect = super.getPerVMAspect(def);
- if (aspect != null)
- {
- LoaderRepository loadingRepository = getAspectRepository(aspect);
- LoaderRepository myRepository = getScopedRepository();
- if (loadingRepository == myRepository)
- {
- //The parent does not load this class
- myPerVMAspects.put(def, aspect);
- }
- else
- {
- //The class has been loaded by a parent classloader, find out if we also have a copy
- try
- {
- Class clazz = myRepository.loadClass(aspect.getClass().getName());
- if (clazz == aspect.getClass())
- {
- notMyPerVMAspects.put(def, Boolean.TRUE);
- }
- else
- {
- //We have a different version of the class deployed
- AspectDefinition aspectDefinition = getAspectDefinition(def);
- //Override the classloader to create the aspect instance
- aspect = createPerVmAspect(def, aspectDefinition, getClassLoader());
- myPerVMAspects.put(def, aspect);
- }
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(e);
- }
- }
- }
-
- return aspect;
- }
-
- private LoaderRepository getAspectRepository(Object aspect)
- {
- ClassLoader cl = aspect.getClass().getClassLoader();
- ClassLoader parent = cl;
- while (parent != null)
- {
- if (parent instanceof RepositoryClassLoader)
- {
- return ((RepositoryClassLoader)parent).getLoaderRepository();
- }
- parent = parent.getParent();
- }
- return null;
- }
-
- private HeirarchicalLoaderRepository3 getScopedRepository()
- {
- ClassLoader classloader = getClassLoader();
- if (classloader == null)
- throw new IllegalStateException("ClassLoader no longer exists: " + classLoaderString);
- if (classloader instanceof RepositoryClassLoader == false)
- throw new IllegalStateException("ClassLoader is not an instanceof RepositoryClassLoader " + classLoaderString);
- RepositoryClassLoader repositoryClassLoader = (RepositoryClassLoader) classloader;
- LoaderRepository loaderRepository = repositoryClassLoader.getLoaderRepository();
- if (loaderRepository == null)
- throw new IllegalStateException("ClassLoader has been undeployed: " + classLoaderString);
- if (loaderRepository instanceof HeirarchicalLoaderRepository3 == false)
- throw new IllegalStateException("Repository " + loaderRepository + " for classlaoder " + classLoaderString + " is not an HeirarchicalLoaderRepository3");
- return (HeirarchicalLoaderRepository3) loaderRepository;
- }
-}
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java 2007-10-11 03:39:35 UTC (rev 66019)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -34,7 +34,6 @@
import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
import org.jboss.mx.loading.LoaderRepository;
import org.jboss.mx.loading.RepositoryClassLoader;
-import org.jboss.system.server.NoAnnotationURLClassLoader;
import javassist.ClassPool;
import javassist.CtClass;
@@ -57,7 +56,7 @@
UrlInfo urlInfo;
ThreadLocal lastPool = new ThreadLocal();
- protected ScopedJBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+ public ScopedJBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
{
super(cl, src, repository, tmp, tmpURL);
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedRepositoryClassLoaderHelper.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedRepositoryClassLoaderHelper.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedRepositoryClassLoaderHelper.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,52 @@
+/*
+* 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.deployment;
+
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ *
+ * TODO JBAOP-107 Need a different version for the JBoss5 classloader
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @autor adrian at jboss.org
+ * @version $Revision$
+ */
+public class ScopedRepositoryClassLoaderHelper
+{
+ public static boolean isScopedClassLoader(ClassLoader loader)
+ {
+ boolean scoped = false;
+ if (loader instanceof RepositoryClassLoader)
+ {
+ LoaderRepository repository = ((RepositoryClassLoader)loader).getLoaderRepository();
+ if (repository instanceof HeirarchicalLoaderRepository3)
+ {
+ scoped = true;
+ HeirarchicalLoaderRepository3 hlr = (HeirarchicalLoaderRepository3)repository;
+ boolean parentFirst = hlr.getUseParentFirst();
+ }
+ }
+ return scoped;
+ }
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedClassLoaderDomain.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedClassLoaderDomain.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedClassLoaderDomain.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,121 @@
+/*
+* 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.domain;
+
+import java.lang.ref.WeakReference;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.InterceptionMarkers;
+import org.jboss.aop.advice.AspectDefinition;
+
+
+/**
+ * A domain that is used for scoped classloaders
+ *
+ * @deprecated TODO JBAOP-107 Need a different version for the JBoss5 classloader
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 1.1 $
+ */
+public abstract class ScopedClassLoaderDomain extends Domain
+{
+
+ private WeakReference<ClassLoader> loader;
+ protected boolean parentDelegation;
+ protected ConcurrentHashMap<String, Object> myPerVMAspects = new ConcurrentHashMap<String, Object>();
+ protected ConcurrentHashMap<String, Boolean> notMyPerVMAspects = new ConcurrentHashMap<String, Boolean>();
+ protected InterceptionMarkers interceptionMarkers = new InterceptionMarkers();
+ protected String classLoaderString;
+
+ public ScopedClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, AspectManager manager, boolean parentFirst)
+ {
+ super(manager, name, parentFirst);
+ if (loader == null)
+ throw new IllegalArgumentException("Null classloader");
+ this.loader = new WeakReference<ClassLoader>(loader);
+ this.parentDelegation = parentDelegation;
+ classLoaderString = loader.toString();
+ super.inheritsBindings = true;
+ super.inheritsDeclarations = true;
+ }
+
+ protected ClassLoader getClassLoader()
+ {
+ ClassLoader cl = loader.get();
+ if (cl != null)
+ {
+ return cl;
+ }
+ return null;
+ }
+
+ // FIXME: JBAOP-107 REMOVE THIS HACK
+ @Override
+ public abstract boolean isValid();
+
+ @Override
+ public void removeAspectDefinition(String name)
+ {
+ AspectDefinition def = super.internalRemoveAspectDefintion(name);
+ if (def != null)
+ {
+ myPerVMAspects.remove(name);
+ }
+ }
+
+ @Override
+ public Object getPerVMAspect(AspectDefinition def)
+ {
+ return getPerVMAspect(def.getName());
+ }
+
+ @Override
+ public InterceptionMarkers getInterceptionMarkers()
+ {
+ return interceptionMarkers;
+ }
+
+ @Override
+ public Object getPerVMAspect(String def)
+ {
+ if (parentDelegation == true)
+ {
+ //We will alway be loading up the correct class
+ Object aspect = super.getPerVMAspect(def);
+ return aspect;
+ }
+ else
+ {
+ return getPerVmAspectWithNoParentDelegation(def);
+ }
+ }
+
+ protected Object getSuperPerVmAspect(String def)
+ {
+ return super.getPerVMAspect(def);
+ }
+
+ protected abstract Object getPerVmAspectWithNoParentDelegation(String def);
+
+}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedRepositoryClassLoaderDomain.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedRepositoryClassLoaderDomain.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/domain/ScopedRepositoryClassLoaderDomain.java 2007-10-11 10:41:28 UTC (rev 66020)
@@ -0,0 +1,136 @@
+/*
+* 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.domain;
+
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+
+/**
+ * A domain that is used for scoped classloaders
+ *
+ * @deprecated TODO JBAOP-107 Need a different version for the JBoss5 classloader
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 1.1 $
+ */
+ at Deprecated
+public class ScopedRepositoryClassLoaderDomain extends ScopedClassLoaderDomain
+{
+ public ScopedRepositoryClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, AspectManager manager, boolean parentFirst)
+ {
+ super(loader, name, parentDelegation, manager, parentFirst);
+ }
+
+ // FIXME: JBAOP-107 REMOVE THIS HACK
+ public boolean isValid()
+ {
+ RepositoryClassLoader cl = (RepositoryClassLoader) getClassLoader();
+ if (cl == null)
+ return false;
+ return cl.getLoaderRepository() != null;
+ }
+
+ protected Object getPerVmAspectWithNoParentDelegation(String def)
+ {
+ Object aspect = myPerVMAspects.get(def);
+ if (aspect != null)
+ {
+ return aspect;
+ }
+
+ aspect = super.getSuperPerVmAspect(def);
+ if (aspect != null)
+ {
+ LoaderRepository loadingRepository = getAspectRepository(aspect);
+ LoaderRepository myRepository = getScopedRepository();
+ if (loadingRepository == myRepository)
+ {
+ //The parent does not load this class
+ myPerVMAspects.put(def, aspect);
+ }
+ else
+ {
+ //The class has been loaded by a parent classloader, find out if we also have a copy
+ try
+ {
+ Class clazz = myRepository.loadClass(aspect.getClass().getName());
+ if (clazz == aspect.getClass())
+ {
+ notMyPerVMAspects.put(def, Boolean.TRUE);
+ }
+ else
+ {
+ //We have a different version of the class deployed
+ AspectDefinition aspectDefinition = getAspectDefinition(def);
+ //Override the classloader to create the aspect instance
+ aspect = createPerVmAspect(def, aspectDefinition, getClassLoader());
+ myPerVMAspects.put(def, aspect);
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ return aspect;
+ }
+
+
+
+ private LoaderRepository getAspectRepository(Object aspect)
+ {
+ ClassLoader cl = aspect.getClass().getClassLoader();
+ ClassLoader parent = cl;
+ while (parent != null)
+ {
+ if (parent instanceof RepositoryClassLoader)
+ {
+ return ((RepositoryClassLoader)parent).getLoaderRepository();
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ private HeirarchicalLoaderRepository3 getScopedRepository()
+ {
+ ClassLoader classloader = getClassLoader();
+ if (classloader == null)
+ throw new IllegalStateException("ClassLoader no longer exists: " + classLoaderString);
+ if (classloader instanceof RepositoryClassLoader == false)
+ throw new IllegalStateException("ClassLoader is not an instanceof RepositoryClassLoader " + classLoaderString);
+ RepositoryClassLoader repositoryClassLoader = (RepositoryClassLoader) classloader;
+ LoaderRepository loaderRepository = repositoryClassLoader.getLoaderRepository();
+ if (loaderRepository == null)
+ throw new IllegalStateException("ClassLoader has been undeployed: " + classLoaderString);
+ if (loaderRepository instanceof HeirarchicalLoaderRepository3 == false)
+ throw new IllegalStateException("Repository " + loaderRepository + " for classlaoder " + classLoaderString + " is not an HeirarchicalLoaderRepository3");
+ return (HeirarchicalLoaderRepository3) loaderRepository;
+ }
+}
More information about the jboss-cvs-commits
mailing list