[jboss-cvs] JBossAS SVN: r74253 - in trunk: aspects/src/main/org/jboss/aop/asintegration/jboss5 and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 6 08:03:49 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-06-06 08:03:48 -0400 (Fri, 06 Jun 2008)
New Revision: 74253
Added:
trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/
trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPDeploymentAopMetaDataDeployer.java
trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPUnregisterAMClassLoaderDeployer.java
trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AbstractAopMetaDataDeployer.java
trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AopMetaDataDeployerOutput.java
trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AspectDeployer.java
Modified:
trunk/aspects/.classpath
trunk/aspects/build.xml
trunk/server/src/etc/conf/default/aop.xml
trunk/server/src/etc/conf/default/deployers.xml
Log:
Add work done so far on the new AspectDeployers. This is neither ready nor enabled yet
Modified: trunk/aspects/.classpath
===================================================================
--- trunk/aspects/.classpath 2008-06-06 12:01:45 UTC (rev 74252)
+++ trunk/aspects/.classpath 2008-06-06 12:03:48 UTC (rev 74253)
@@ -10,7 +10,7 @@
<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/aop/lib/jboss-aop-deployer-jdk50.jar"/>
<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/aop/lib/jboss-aop-jdk50.jar"/>
<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/aop/lib/jboss-aop-jboss4-jdk50.jar"/>
- <classpathentry exported="true" kind="lib" path="/thirdparty/javassist/lib/javassist.jar"/>
+ <classpathentry exported="true" kind="lib" path="/thirdparty/javassist/lib/javassist.jar" sourcepath="/thirdparty/javassist/lib/javassist-sources.jar"/>
<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/common-core/lib/jboss-common-core.jar"/>
<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi.jar"/>
<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/integration/lib/jboss-integration.jar"/>
@@ -39,5 +39,8 @@
<classpathentry exported="true" kind="lib" path="/thirdparty/org/jboss/aspects/lib/jboss-transaction-aspects.jar"/>
<classpathentry kind="lib" path="/thirdparty/sun-jaxb/lib/jaxb-api.jar"/>
<classpathentry kind="lib" path="/thirdparty/org/jboss/ejb3/lib/jboss-ejb3-async.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-aop-mc-int.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-aop-mc-int-sources.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-kernel.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-kernel-sources.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-dependency.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-dependency-sources.jar"/>
<classpathentry kind="output" path="output/eclipse-classes"/>
</classpath>
Modified: trunk/aspects/build.xml
===================================================================
--- trunk/aspects/build.xml 2008-06-06 12:01:45 UTC (rev 74252)
+++ trunk/aspects/build.xml 2008-06-06 12:03:48 UTC (rev 74253)
@@ -78,7 +78,8 @@
<path refid="jboss.jboss.cl.classpath"/>
<path refid="jboss.jboss.deployers.classpath"/>
<path refid="jboss.jboss.man.classpath"/>
- <path refid="jboss.jboss.mdr.classpath"/>
+ <path refid="jboss.jboss.mdr.classpath"/>
+ <path refid="jboss.jbossxb.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
<path refid="jboss.jboss.vfs.classpath"/>
<path refid="jboss.aop.classpath"/>
Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPDeploymentAopMetaDataDeployer.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPDeploymentAopMetaDataDeployer.java (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPDeploymentAopMetaDataDeployer.java 2008-06-06 12:03:48 UTC (rev 74253)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, Red Hat Middleware LLC., 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.asintegration.jboss5.temp;
+
+import java.util.List;
+
+import org.jboss.aop.microcontainer.beans.metadata.AOPDeployment;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+
+/**
+ * Deployer for Aspects
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @author adrian at jboss.org
+ */
+public class AOPDeploymentAopMetaDataDeployer extends AbstractAopMetaDataDeployer<AOPDeployment>
+{
+ public AOPDeploymentAopMetaDataDeployer()
+ {
+ super(AOPDeployment.class);
+ }
+
+ @Override
+ public void deploy(VFSDeploymentUnit unit, AOPDeployment aopDeployment) throws DeploymentException
+ {
+ super.deploy(unit, aopDeployment);
+ }
+
+ @Override
+ public void undeploy(VFSDeploymentUnit unit, AOPDeployment aopDeployment)
+ {
+ super.undeploy(unit, aopDeployment);
+ }
+
+
+ @Override
+ protected List<BeanMetaDataFactory> getFactories(AOPDeployment deployment)
+ {
+ return deployment.getBeanFactories();
+ }
+}
Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPUnregisterAMClassLoaderDeployer.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPUnregisterAMClassLoaderDeployer.java (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AOPUnregisterAMClassLoaderDeployer.java 2008-06-06 12:03:48 UTC (rev 74253)
@@ -0,0 +1,67 @@
+/*
+* 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.asintegration.jboss5.temp;
+
+import org.jboss.aop.AspectManager;
+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;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AOPUnregisterAMClassLoaderDeployer extends AbstractVFSRealDeployer
+{
+ AspectManager aspectManager;
+
+ public AOPUnregisterAMClassLoaderDeployer()
+ {
+ setStage(DeploymentStages.CLASSLOADER);
+ }
+
+ public AspectManager getAspectManager()
+ {
+ return aspectManager;
+ }
+
+ public void setAspectManager(AspectManager aspectManager)
+ {
+ this.aspectManager = aspectManager;
+ }
+
+ @Override
+ public void deploy(VFSDeploymentUnit unit) throws DeploymentException
+ {
+ }
+
+ @Override
+ public void undeploy(VFSDeploymentUnit unit)
+ {
+ if (unit.getTopLevel() == unit)
+ {
+ aspectManager.unregisterClassLoader(unit.getClassLoader());
+ }
+ }
+}
Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AbstractAopMetaDataDeployer.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AbstractAopMetaDataDeployer.java (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AbstractAopMetaDataDeployer.java 2008-06-06 12:03:48 UTC (rev 74253)
@@ -0,0 +1,416 @@
+/*
+* 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.asintegration.jboss5.temp;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
+import org.jboss.aop.domain.DomainInitializer;
+import org.jboss.aop.microcontainer.beans.metadata.AspectManagerAwareBeanMetaDataFactory;
+import org.jboss.beans.metadata.plugins.AbstractClassLoaderMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+
+/**
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractAopMetaDataDeployer<T> extends AbstractSimpleVFSRealDeployer<T>
+{
+ private AspectManager aspectManager;
+ private KernelController controller;
+ private MyBeanMetaDataDeployer beanMetaDataDeployer = new MyBeanMetaDataDeployer();
+ private static int sequence;
+
+
+ public AbstractAopMetaDataDeployer(Class<T> input)
+ {
+ super(input);
+ super.setStage(DeploymentStages.POST_CLASSLOADER);
+ super.setOutput(AopMetaDataDeployerOutput.class);
+ }
+
+ /**
+ * Get the aspectManager.
+ *
+ * @return the aspectManager.
+ */
+ public AspectManager getAspectManager()
+ {
+ return aspectManager;
+ }
+
+ /**
+ * Set the aspectManager.
+ *
+ * @param aspectManager the aspectManager.
+ */
+ public void setAspectManager(AspectManager aspectManager)
+ {
+ this.aspectManager = aspectManager;
+ }
+
+ /**
+ * Set the kernel.
+ *
+ * @param kernel the kernel
+ */
+ public void setKernel(Kernel kernel)
+ {
+ this.controller = kernel.getController();
+ }
+
+ /**
+ * Method for subclasses to call upon deployment
+ */
+ @Override
+ public void deploy(VFSDeploymentUnit unit, T deployment) throws DeploymentException
+ {
+ log.debug("Deploying " + unit + " " + deployment);
+
+ AopMetaDataDeployerOutput output = new AopMetaDataDeployerOutput();
+ unit.getTransientManagedObjects().addAttachment(AopMetaDataDeployerOutput.class, output);
+
+ if (extractAopBeanMetaDataFactories(unit, deployment, output))
+ {
+ AspectManager correctManager = getCorrectManager(unit, output);
+ if (correctManager != aspectManager)
+ {
+ registerScopedManagerBean(unit, correctManager, output);
+ massageScopedDeployment(unit, deployment, output);
+ }
+ }
+
+ try
+ {
+ deployBeans(unit, output);
+ }
+ catch (Throwable t)
+ {
+ unregisterScopedManagerBean(output.getScopedAspectManagerBeanName(), false);
+ if (t instanceof DeploymentException)
+ {
+ throw (DeploymentException)t;
+ }
+ else
+ {
+ throw new DeploymentException(t);
+ }
+ }
+ }
+
+
+ /**
+ * Method for subclasses to call upon undeployment
+ */
+ @Override
+ public void undeploy(VFSDeploymentUnit unit, T deployment)
+ {
+ log.debug("Undeploying " + unit + " " + deployment);
+
+ AopMetaDataDeployerOutput output = unit.getTransientManagedObjects().getAttachment(AopMetaDataDeployerOutput.class);
+
+ undeployBeans(unit, output);
+
+ unregisterScopedManagerBean(output.getScopedAspectManagerBeanName(), true);
+ }
+
+ protected abstract List<BeanMetaDataFactory> getFactories(T deployment);
+
+ private boolean extractAopBeanMetaDataFactories(VFSDeploymentUnit unit, T deployment, AopMetaDataDeployerOutput output)
+ {
+ log.debug("Extracting aop bean metadata factories for " + unit);
+ List<AspectManagerAwareBeanMetaDataFactory> aopFactories = new ArrayList<AspectManagerAwareBeanMetaDataFactory>();
+
+ List<BeanMetaDataFactory> factories = getFactories(deployment);
+ if (factories != null && factories.size() > 0)
+ {
+ for (Iterator<BeanMetaDataFactory> it = factories.iterator() ; it.hasNext() ; )
+ {
+ BeanMetaDataFactory factory = it.next();
+ if (factory instanceof AspectManagerAwareBeanMetaDataFactory)
+ {
+ it.remove();
+ aopFactories.add((AspectManagerAwareBeanMetaDataFactory)factory);
+ }
+ }
+ }
+
+ if (aopFactories.size() > 0)
+ {
+ output.setFactories(aopFactories);
+ return true;
+ }
+ return false;
+ }
+
+ private AspectManager getCorrectManager(VFSDeploymentUnit unit, AopMetaDataDeployerOutput output) throws DeploymentException
+ {
+ //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.getClassLoaderScopingPolicy();
+
+ Domain domain = null;
+ if (policy != null)
+ {
+ if (policy instanceof DomainInitializer == false)
+ {
+ throw new RuntimeException(policy + " must implement DomainInitializer");
+ }
+ DomainInitializer initializer = (DomainInitializer)policy;
+ domain = initializer.initializeDomain(unit);
+ }
+
+ if (domain != null)
+ {
+ log.debug("Deployment is scoped to " + domain);
+ return domain;
+ }
+
+ return aspectManager;
+ }
+
+ private void registerScopedManagerBean(VFSDeploymentUnit unit, AspectManager scopedManager, AopMetaDataDeployerOutput output) throws DeploymentException
+ {
+ String name = "ScopedManager_" + getSequence() + "_" + unit.getName();
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(name, scopedManager.getClass().getName());
+
+ try
+ {
+ controller.install(builder.getBeanMetaData(), scopedManager);
+ output.setScopedAspectManagerBeanName(name);
+ }
+ catch (Throwable e)
+ {
+ unregisterScopedManagerBean(name, false);
+ throw new DeploymentException("Error registering scoped manager" + name + " " + scopedManager, e);
+ }
+ }
+
+ private synchronized int getSequence()
+ {
+ return ++sequence;
+ }
+
+ private void unregisterScopedManagerBean(String name, boolean logError)
+ {
+ if (name == null)
+ {
+ return;
+ }
+
+ try
+ {
+ controller.uninstall(name);
+ }
+ catch(Throwable t)
+ {
+ if (logError)
+ {
+ log.debug("Error unregistering scoped aspect manager " + name, t);
+ }
+ }
+ }
+
+ private void massageScopedDeployment(VFSDeploymentUnit unit, T deployment, AopMetaDataDeployerOutput output) throws DeploymentException
+ {
+ if (output.getScopedAspectManagerBeanName() == null)
+ {
+ return;
+ }
+
+ log.debug("Massaging scoped deployment " + unit);
+ List<AspectManagerAwareBeanMetaDataFactory> aopFactories = output.getFactories();
+
+ if (aopFactories != null && aopFactories.size() > 0)
+ {
+ for (AspectManagerAwareBeanMetaDataFactory factory : aopFactories)
+ {
+ factory.setManagerBean(output.getScopedAspectManagerBeanName());
+ factory.setManagerProperty(null);
+ }
+ }
+ }
+
+ private void deployBeans(VFSDeploymentUnit unit, AopMetaDataDeployerOutput output) throws DeploymentException
+ {
+ List<AspectManagerAwareBeanMetaDataFactory> aopFactories = output.getFactories();
+ List<BeanMetaData> done = new ArrayList<BeanMetaData>();
+ try
+ {
+ if (aopFactories != null && aopFactories.size() > 0)
+ {
+ for (AspectManagerAwareBeanMetaDataFactory factory : aopFactories)
+ {
+ List<BeanMetaData> beans = factory.getBeans();
+ if (beans != null && beans.size() > 0)
+ {
+ for (BeanMetaData bean : beans)
+ {
+ beanMetaDataDeployer.deploy(unit, bean);
+ done.add(bean);
+ }
+ }
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ for (int i = done.size() - 1 ; i >= 0 ; i--)
+ {
+ try
+ {
+ beanMetaDataDeployer.undeploy(unit, done.get(i));
+ controller.uninstall(done.get(i));
+ }
+ catch (Throwable e)
+ {
+ log.debug("Error undeploying " + done.get(i) + " for " + unit);
+ }
+ }
+ throw new DeploymentException(t);
+ }
+ }
+
+ private void undeployBeans(VFSDeploymentUnit unit, AopMetaDataDeployerOutput output)
+ {
+ List<AspectManagerAwareBeanMetaDataFactory> aopFactories = output.getFactories();
+ if (aopFactories != null && aopFactories.size() > 0)
+ {
+ for (int i = aopFactories.size() - 1 ; i >= 0 ; i--)
+ {
+ AspectManagerAwareBeanMetaDataFactory factory = aopFactories.get(i);
+ List<BeanMetaData> beans = factory.getBeans();
+ if (beans != null && beans.size() > 0)
+ {
+ for (int j = beans.size() - 1 ; j >= 0 ; j--)
+ {
+ BeanMetaData bean = beans.get(j);
+ beanMetaDataDeployer.undeploy(unit, bean);
+ }
+ }
+ }
+ }
+ }
+
+ private class MyBeanMetaDataDeployer
+ {
+ /**
+ * Copied from the real org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer
+ */
+ private void deploy(DeploymentUnit unit, BeanMetaData deployment) throws DeploymentException
+ {
+ // No explicit classloader, use the deployment's classloader
+ if (deployment.getClassLoader() == null)
+ {
+ try
+ {
+ // Check the unit has a classloader
+ unit.getClassLoader();
+ // TODO clone the metadata?
+ deployment.setClassLoader(new DeploymentClassLoaderMetaData(unit));
+ }
+ catch (Exception e)
+ {
+ log.debug("Unable to retrieve classloader for deployment: " + unit.getName() + " reason=" + e.toString());
+ }
+ }
+ KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
+ try
+ {
+ controller.install(context);
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment.getName(), t);
+ }
+ }
+
+ /**
+ * Copied from the real org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer
+ */
+ private void undeploy(DeploymentUnit unit, BeanMetaData deployment)
+ {
+ try
+ {
+ controller.uninstall(deployment.getName());
+
+ // Remove any classloader metadata we added (not necessary if we clone above)
+ ClassLoaderMetaData classLoader = deployment.getClassLoader();
+ if (classLoader instanceof DeploymentClassLoaderMetaData)
+ deployment.setClassLoader(null);
+ }
+ catch(Throwable t)
+ {
+ log.info("Error undeploying " + deployment + " for " + unit);
+ }
+ }
+ }
+
+ /**
+ * Copied from BeanMetaDataDeployer
+ */
+ private static class DeploymentClassLoaderMetaData extends AbstractClassLoaderMetaData
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The deployment unit */
+ private DeploymentUnit unit;
+
+ /**
+ * Create a new DeploymentClassLoaderMetaData.
+ *
+ * @param unit the deployment unit
+ */
+ public DeploymentClassLoaderMetaData(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+ this.unit = unit;
+ }
+
+ @Override
+ public ValueMetaData getClassLoader()
+ {
+ return new AbstractValueMetaData(unit.getClassLoader());
+ }
+ }
+}
Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AopMetaDataDeployerOutput.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AopMetaDataDeployerOutput.java (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AopMetaDataDeployerOutput.java 2008-06-06 12:03:48 UTC (rev 74253)
@@ -0,0 +1,62 @@
+/*
+* 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.asintegration.jboss5.temp;
+
+import java.util.List;
+
+import org.jboss.aop.microcontainer.beans.metadata.AspectManagerAwareBeanMetaDataFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AopMetaDataDeployerOutput
+{
+ String scopedAspectManagerBeanName;
+ List<AspectManagerAwareBeanMetaDataFactory> factories;
+
+ public AopMetaDataDeployerOutput()
+ {
+
+ }
+
+ public String getScopedAspectManagerBeanName()
+ {
+ return scopedAspectManagerBeanName;
+ }
+
+ public void setScopedAspectManagerBeanName(String scopedAspectManagerBeanName)
+ {
+ this.scopedAspectManagerBeanName = scopedAspectManagerBeanName;
+ }
+
+ public List<AspectManagerAwareBeanMetaDataFactory> getFactories()
+ {
+ return factories;
+ }
+
+ public void setFactories(List<AspectManagerAwareBeanMetaDataFactory> factories)
+ {
+ this.factories = factories;
+ }
+}
Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AspectDeployer.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AspectDeployer.java (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/temp/AspectDeployer.java 2008-06-06 12:03:48 UTC (rev 74253)
@@ -0,0 +1,396 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, Red Hat Middleware LLC., 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.asintegration.jboss5.temp;
+
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.bytecode.ClassFile;
+
+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.aop.domain.DomainInitializer;
+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.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
+import org.w3c.dom.Document;
+
+/**
+ * Deployer for Aspects
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @author adrian at jboss.org
+ */
+public class AspectDeployer extends AbstractVFSRealDeployer
+{
+ private static final String AOP_JAR_SUFFIX = ".aop";
+ private static final String AOP_DD_SUFFIX = "-aop.xml";
+
+ /** The aspect manager */
+ private AspectManager aspectManager;
+
+ /**
+ * Create a new AspectDeployer.
+ */
+ public AspectDeployer()
+ {
+ setStage(DeploymentStages.POST_CLASSLOADER);
+ }
+
+ /**
+ * Get the aspectManager.
+ *
+ * @return the aspectManager.
+ */
+ public AspectManager getAspectManager()
+ {
+ return aspectManager;
+ }
+
+ /**
+ * Set the aspectManager.
+ *
+ * @param aspectManager the aspectManager.
+ */
+ public void setAspectManager(AspectManager aspectManager)
+ {
+ this.aspectManager = aspectManager;
+ }
+
+ /**
+ * Validate the configuration
+ */
+ public void create()
+ {
+ if (aspectManager == null)
+ throw new IllegalStateException("No aspect manager configured");
+ }
+
+ public void deploy(VFSDeploymentUnit unit) throws DeploymentException
+ {
+ AspectManager manager = getCorrectManager(unit);
+
+ List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
+
+ if (isAopArchiveOrFolder(unit))
+ {
+ deployAnnotations(manager, unit);
+ }
+
+ if (files.size() > 0)
+ {
+ deployXml(manager, unit, files);
+ }
+ }
+
+ public void undeploy(VFSDeploymentUnit unit)
+ {
+ try
+ {
+ AspectManager manager = getCorrectManager(unit);
+ List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
+
+ if (isAopArchiveOrFolder(unit))
+ {
+ undeployAnnotations(manager, unit);
+ }
+
+ if (files.size() > 0)
+ {
+ undeployXml(manager, unit, files);
+ }
+ }
+ finally
+ {
+ if (unit.getTopLevel() == unit)
+ {
+ aspectManager.unregisterClassLoader(unit.getClassLoader());
+ }
+ }
+ }
+
+ private void deployXml(AspectManager manager, VFSDeploymentUnit unit, List<VirtualFile> files) throws DeploymentException
+ {
+ log.info("Deploying xml into " + manager + " for " + unit.getClassLoader());
+
+ ArrayList<VirtualFile> deployedFiles = new ArrayList<VirtualFile>(files.size());
+ for (VirtualFile vf : files)
+ {
+ deployedFiles.add(vf);
+ try
+ {
+ log.debug("deploying: " + vf.toURL() + " into " + manager);
+ InputStream is = vf.openStream();
+ try
+ {
+ Document doc = AspectXmlLoader.loadDocument(is);
+ AspectXmlLoader loader = new AspectXmlLoader();
+
+ loader.setManager(manager);
+ loader.setClassLoader(unit.getClassLoader());
+ loader.deployXML(doc, vf.toURL(), unit.getClassLoader());
+ }
+ finally
+ {
+ is.close();
+ }
+ }
+ catch (Exception e)
+ {
+ //Unwind things already installed, in the reverse order
+ for (int i = deployedFiles.size() - 1 ; i >= 0 ; i--)
+ {
+ undeployXml(manager, deployedFiles.get(i));
+ }
+
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying xml " + vf.getName() + " into " + manager, e);
+ }
+ }
+ }
+
+ private void undeployXml(AspectManager manager, VFSDeploymentUnit unit, List<VirtualFile> files)
+ {
+ for (VirtualFile vf : files)
+ {
+ undeployXml(manager, vf);
+ }
+ }
+
+ private void undeployXml(AspectManager manager, VirtualFile vf)
+ {
+ try
+ {
+ log.debug("undeploying: " + vf.toURL() + " from " + manager);
+ InputStream is = vf.openStream();
+ try
+ {
+ Document doc = AspectXmlLoader.loadDocument(is);
+ AspectXmlLoader loader = new AspectXmlLoader();
+
+ loader.setManager(manager);
+ loader.undeployXML(doc, vf.toURL());
+ }
+ finally
+ {
+ try
+ {
+ is.close();
+ }
+ catch(IOException ignore)
+ {
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Error undeploying xml " + vf.getName() + " from " + manager, e);
+ }
+ }
+
+ private void deployAnnotations(AspectManager manager, VFSDeploymentUnit unit) throws DeploymentException
+ {
+ log.info("Deploying AOP annotations into " + manager + " for " + unit.getClassLoader());
+
+ AspectAnnotationLoader loader = getAnnotationLoader(manager, unit);
+ List<VirtualFile> files = getClasses(unit);
+ ArrayList<VirtualFile> deployedFiles = new ArrayList<VirtualFile>(files.size());
+ for(VirtualFile file : files)
+ {
+ try
+ {
+ ClassFile cf = loadClassFile(file);
+ log.debug("Deploying possibly annotated class " + cf.getName() + " into " + manager);
+ loader.deployClassFile(cf);
+ }
+ catch (Exception e)
+ {
+ //Unwind things already installed, in the reverse order
+ for (int i = deployedFiles.size() ; i >= 0 ; i-- )
+ {
+ undeployAnnotation(loader, deployedFiles.get(i));
+ }
+ throw new DeploymentException("Error reading annotations for " + file + " during deployment into " + manager, e);
+ }
+ }
+ }
+
+ private void undeployAnnotations(AspectManager manager, VFSDeploymentUnit unit)
+ {
+ AspectAnnotationLoader loader = getAnnotationLoader(manager, unit);
+ List<VirtualFile> files = getClasses(unit);
+ for(VirtualFile file : files)
+ {
+ undeployAnnotation(loader, file);
+ }
+ }
+
+ private void undeployAnnotation(AspectAnnotationLoader loader, VirtualFile file)
+ {
+ try
+ {
+ ClassFile cf = loadClassFile(file);
+ log.debug("Undeploying possibly annotated class " + cf.getName());
+ loader.undeployClassFile(cf);
+ }
+ catch (Exception e)
+ {
+ log.warn("Error reading annotations for " + file, e);
+ }
+ }
+
+ private AspectAnnotationLoader getAnnotationLoader(AspectManager manager, VFSDeploymentUnit unit)
+ {
+ AspectAnnotationLoader loader = new AspectAnnotationLoader(manager);
+ loader.setClassLoader(unit.getClassLoader());
+ return loader;
+ }
+
+ private ClassFile loadClassFile(VirtualFile file)
+ {
+ DataInputStream din = null;
+ ClassFile cf = null;
+ try
+ {
+ InputStream in = file.openStream();
+ din = new DataInputStream(new BufferedInputStream(in));
+ cf = new ClassFile(din);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error reading " + file, e);
+ }
+ finally
+ {
+ try
+ {
+ din.close();
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+
+ return cf;
+ }
+
+ private List<VirtualFile> getClasses(VFSDeploymentUnit unit)
+ {
+ VisitorAttributes va = new VisitorAttributes();
+ va.setLeavesOnly(true);
+ ClassFileFilter filter = new ClassFileFilter();
+ SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
+ va.setRecurseFilter(noJars);
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
+
+ for (VirtualFile vf : unit.getClassPath())
+ {
+ try
+ {
+ vf.visit(visitor);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return visitor.getMatched();
+
+ }
+
+ private boolean isAopArchiveOrFolder(VFSDeploymentUnit unit)
+ {
+ String name = unit.getName();
+
+ //If name is of format 'blah-blah.aop!/' get rid of the trailing '!' and '/', and see if it ends with .aop
+ int index = name.length();
+ if (name.charAt(name.length() - 1) == '/')
+ {
+ index--;
+ }
+ if (name.charAt(name.length() - 2) == '!')
+ {
+ index--;
+ }
+ String realName = (index == name.length()) ? name : name.substring(0, index);
+
+ return (realName.endsWith(AOP_JAR_SUFFIX));
+ }
+
+ private AspectManager getCorrectManager(final 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.getClassLoaderScopingPolicy();
+
+ Domain domain = null;
+ if (policy != null)
+ {
+ if (policy instanceof DomainInitializer == false)
+ {
+ throw new RuntimeException(policy + " must implement DomainInitializer");
+ }
+ DomainInitializer initializer = (DomainInitializer)policy;
+ domain = initializer.initializeDomain(unit);
+ }
+
+ if (domain != null)
+ {
+ return domain;
+ }
+
+ return aspectManager;
+ }
+
+ private static class ClassFileFilter implements VirtualFileFilter
+ {
+ public boolean accepts(VirtualFile file)
+ {
+ try
+ {
+ return file.isLeaf() && file.getName().endsWith(".class");
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error visiting file: " + file.getName(), e);
+ }
+ }
+ }
+
+
+
+}
Modified: trunk/server/src/etc/conf/default/aop.xml
===================================================================
--- trunk/server/src/etc/conf/default/aop.xml 2008-06-06 12:01:45 UTC (rev 74252)
+++ trunk/server/src/etc/conf/default/aop.xml 2008-06-06 12:03:48 UTC (rev 74253)
@@ -19,6 +19,14 @@
<property name="scopingPolicy"><inject bean="AOPClassLoaderScopingPolicy"/></property>
</bean>
+ <!-- For use once the aop-mc-int metadata stuff goes live
+ <bean name="DefaultAspectManager" class="org.jboss.aop.microcontainer.beans.metadata.DefaultAspectManager">
+ <property name="managerBean">AspectManager</property>
+ <property name="managerProperty">aspectManager</property>
+ </bean>
+ -->
+
+
<!--
Valid values for the AspectManager bean for use with enableTransformer=true are:
* org.jboss.aop.deployers.AspectManagerJDK5 - works with the -javaagent:pluggable-instrumentor.jar switch
Modified: trunk/server/src/etc/conf/default/deployers.xml
===================================================================
--- trunk/server/src/etc/conf/default/deployers.xml 2008-06-06 12:01:45 UTC (rev 74252)
+++ trunk/server/src/etc/conf/default/deployers.xml 2008-06-06 12:03:48 UTC (rev 74253)
@@ -123,6 +123,22 @@
<property name="aspectManager"><inject bean="AspectManager" property="aspectManager"/></property>
</bean>
+ <!-- Use these instead of AspectDeployer
+ <bean name="AOPMetaDataParser" class="org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer">
+ <constructor>
+ <parameter>org.jboss.aop.microcontainer.beans.metadata.AOPDeployment</parameter>
+ </constructor>
+ <property name="suffix">-aop.xml</property>
+ </bean>
+ <bean name="AOPUnregisterAMClassLoaderDeployer" class="org.jboss.aop.asintegration.jboss5.temp.AOPUnregisterAMClassLoaderDeployer">
+ <property name="aspectManager"><inject bean="AspectManager" property="aspectManager"/></property>
+ </bean>
+ <bean name="AOPDeploymentAopMetaDataDeployer" class="org.jboss.aop.asintegration.jboss5.temp.AOPDeploymentAopMetaDataDeployer">
+ <property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>
+ <property name="aspectManager"><inject bean="AspectManager" property="aspectManager"/></property>
+ </bean>
+ -->
+
<!-- POJO Deployment -->
<bean name="BeanDeployer" class="org.jboss.deployers.vfs.deployer.kernel.BeanDeployer">
<property name="type">beans</property>
More information about the jboss-cvs-commits
mailing list