[jboss-cvs] JBossAS SVN: r66628 - in trunk: aspects/src/main/org/jboss/aop/asintegration/jboss5 and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 31 16:18:28 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-10-31 16:18:28 -0400 (Wed, 31 Oct 2007)
New Revision: 66628

Added:
   trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectAppParsingDeployer.java
   trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployment.java
   trunk/testsuite/src/main/org/jboss/test/aop/test/ScopedAttachUnitTestCase.java
Modified:
   trunk/aspects/.classpath
   trunk/server/src/etc/conf/default/bootstrap-beans.xml
   trunk/testsuite/src/main/org/jboss/test/aop/scopedattach/ScopedTester.java
Log:
[JBAOP-366] Create AspectAppParsingDeployer to read the loader-repository element of top-level .aop deployment and populate the VFSDeploymentUnit's LoaderRepositoryConfig attachment if required so that the .aop deployment belongs to the same domain as the deployment we want to attach to

Modified: trunk/aspects/.classpath
===================================================================
--- trunk/aspects/.classpath	2007-10-31 19:51:59 UTC (rev 66627)
+++ trunk/aspects/.classpath	2007-10-31 20:18:28 UTC (rev 66628)
@@ -39,5 +39,8 @@
 	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-classloader.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-classloader-sources.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-deployers-impl.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-deployers-impl-sources.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-deployers-structure-spi.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-deployers-structure-spi-sources.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-deployers-vfs-spi.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-deployers-vfs-spi-sources.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-deployers-spi.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-deployers-spi-sources.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-managed.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-managed-sources.jar"/>
 	<classpathentry kind="output" path="output/eclipse-classes"/>
 </classpath>

Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectAppParsingDeployer.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectAppParsingDeployer.java	                        (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectAppParsingDeployer.java	2007-10-31 20:18:28 UTC (rev 66628)
@@ -0,0 +1,77 @@
+/*
+* 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;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.vfs.spi.deployer.JAXPDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.mx.loading.LoaderRepositoryFactory;
+import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
+import org.jboss.virtual.VirtualFile;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Deployer to read the loader-repository config from a .aop/META-INF/jboss-aop.xml
+ * and populate the LoaderRepositoryConfig attachment. The main use-case is when 
+ * deploying a standalone .aop file that we want to attach to a scoped deployment.
+ * 
+ * @deprecated Use the one from the aop project instead once that is released, and delete these from .classpath: jboss-deployers-vfs-spi.jar, jboss-deployers-spi.jar, jboss-managed.jar
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Deprecated
+public class AspectAppParsingDeployer extends JAXPDeployer<AspectDeployment>
+{
+   public AspectAppParsingDeployer()
+   {
+      super(AspectDeployment.class);
+      setSuffix("-aop.xml");
+      setStage(DeploymentStages.DESCRIBE);
+   }
+
+   protected AspectDeployment parse(VFSDeploymentUnit unit, VirtualFile file, Document document) throws Exception
+   {
+      if (unit.getTopLevel() == unit)
+      {
+         // Check for a custom loader-repository for scoping
+         NodeList loaders = document.getElementsByTagName("loader-repository");
+         if( loaders.getLength() > 0 )
+         {
+            Element loader = (Element) loaders.item(0);
+            try
+            {
+               LoaderRepositoryConfig config = LoaderRepositoryFactory.parseRepositoryConfig(loader);
+               unit.addAttachment(LoaderRepositoryConfig.class, config);
+            }
+            catch (Exception e)
+            {
+               throw DeploymentException.rethrowAsDeploymentException("Unable to parse loader repository config", e);
+            }
+         }
+      }
+      return null;
+   }
+
+}

Added: trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployment.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployment.java	                        (rev 0)
+++ trunk/aspects/src/main/org/jboss/aop/asintegration/jboss5/AspectDeployment.java	2007-10-31 20:18:28 UTC (rev 66628)
@@ -0,0 +1,35 @@
+/*
+* 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;
+
+/**
+ * Here so that the AspectAppParsingDeployer can have an "output"
+ * 
+ * @deprecated Use the one from the aop project instead
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Deprecated
+public class AspectDeployment
+{
+
+}

Modified: trunk/server/src/etc/conf/default/bootstrap-beans.xml
===================================================================
--- trunk/server/src/etc/conf/default/bootstrap-beans.xml	2007-10-31 19:51:59 UTC (rev 66627)
+++ trunk/server/src/etc/conf/default/bootstrap-beans.xml	2007-10-31 20:18:28 UTC (rev 66628)
@@ -239,6 +239,8 @@
     </bean>
 
     <!-- AOP deployment -->
+    <!-- FIXME Replace with org.jboss.aop.deployers.AspectAppParsingDeployer once AOP is released -->
+    <bean name="AspectAppParsingDeployer" class="org.jboss.aop.asintegration.jboss5.AspectAppParsingDeployer"/>
     <bean name="AspectDeployer" class="org.jboss.aop.deployers.AspectDeployer">
        <property name="type">aop</property>
        <property name="aspectManager"><inject bean="AspectManager" property="aspectManager"/></property>

Modified: trunk/testsuite/src/main/org/jboss/test/aop/scopedattach/ScopedTester.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/aop/scopedattach/ScopedTester.java	2007-10-31 19:51:59 UTC (rev 66627)
+++ trunk/testsuite/src/main/org/jboss/test/aop/scopedattach/ScopedTester.java	2007-10-31 20:18:28 UTC (rev 66628)
@@ -21,8 +21,6 @@
  */
 package org.jboss.test.aop.scopedattach;
 
-import java.lang.reflect.Method;
-
 import org.jboss.aop.Advised;
 import org.jboss.mx.loading.LoaderRepository;
 import org.jboss.mx.loading.RepositoryClassLoader;
@@ -88,19 +86,21 @@
          System.out.println("SCOPED INTERCEPTOR CLASSLOADER " + ScopedInterceptor.class.getClassLoader());
          System.out.println("POJO CLASSLOADER " + POJO.class.getClassLoader());
    
-         //Check that the classloaders have the same repositories
-         LoaderRepository repository1 = ((RepositoryClassLoader)getClass().getClassLoader()).getLoaderRepository();
-         LoaderRepository repository2 = ((RepositoryClassLoader)ScopedInterceptor.class.getClassLoader()).getLoaderRepository();
-         LoaderRepository repository3 = ((RepositoryClassLoader)POJO.class.getClassLoader()).getLoaderRepository();
-         
-         if (repository1 != repository2)
+         if (getClass().getClassLoader() instanceof RepositoryClassLoader)
          {
-            throw new RuntimeException("Repositories were not the same");
+            //Check that the classloaders have the same repositories
+            LoaderRepository repository1 = ((RepositoryClassLoader)getClass().getClassLoader()).getLoaderRepository();
+            LoaderRepository repository2 = ((RepositoryClassLoader)ScopedInterceptor.class.getClassLoader()).getLoaderRepository();
+            LoaderRepository repository3 = ((RepositoryClassLoader)POJO.class.getClassLoader()).getLoaderRepository();
+            if (repository1 != repository2)
+            {
+               throw new RuntimeException("Repositories were not the same");
+            }
+            if (repository1 != repository3)
+            {
+               throw new RuntimeException("Repositories were not the same");
+            }
          }
-         if (repository1 != repository3)
-         {
-            throw new RuntimeException("Repositories were not the same");
-         }
          
          System.out.println("------- CTOR");
          ScopedAspect.intercepted = 0;

Added: trunk/testsuite/src/main/org/jboss/test/aop/test/ScopedAttachUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/aop/test/ScopedAttachUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/aop/test/ScopedAttachUnitTestCase.java	2007-10-31 20:18:28 UTC (rev 66628)
@@ -0,0 +1,149 @@
+/*
+ * 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.test.aop.test;
+
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Sample client for the jboss container.
+ *
+ * @author <a href="mailto:bill at burkecentral.com">Kabir Khan</a>
+ * @version $Id$
+ */
+public class ScopedAttachUnitTestCase extends JBossTestCase
+{
+   Logger log = getLog();
+
+   static boolean deployed = false;
+   static int test = 0;
+   static AOPClassLoaderHookTestSetup setup;
+
+   public ScopedAttachUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testPOJOAdvised1() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+      ObjectName testerName = new ObjectName("jboss.aop:name=ScopedTester1");
+      Object[] params = {};
+      String[] sig = {};
+      server.invoke(testerName, "checkPOJOAdvised", params, sig);
+   }
+   
+   public void testPOJOAdvised2() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+      ObjectName testerName = new ObjectName("jboss.aop:name=ScopedTester2");
+      Object[] params = {};
+      String[] sig = {};
+      server.invoke(testerName, "checkPOJOAdvised", params, sig);
+   }
+   
+   public void testExpectedValues1() throws Exception
+   {
+      deploy("aop-scopedattachtest1.aop");
+      try
+      {
+         MBeanServerConnection server = getServer();
+         ObjectName testerName = new ObjectName("jboss.aop:name=ScopedTester1");
+         Integer iv = (Integer)server.getAttribute(testerName, "ExpectedInterceptorValue");
+         Integer ia = (Integer)server.getAttribute(testerName, "ExpectedAspectValue");
+         assertEquals(11, iv.intValue());
+         assertEquals(21, ia.intValue());
+      }
+      finally
+      {
+         undeploy("aop-scopedattachtest1.aop");
+      }
+   }
+   
+   public void testExpectedValues2() throws Exception
+   {
+      deploy("aop-scopedattachtest2.aop");
+      try
+      {
+         MBeanServerConnection server = getServer();
+         ObjectName testerName = new ObjectName("jboss.aop:name=ScopedTester2");
+         Integer iv = (Integer)server.getAttribute(testerName, "ExpectedInterceptorValue");
+         Integer ia = (Integer)server.getAttribute(testerName, "ExpectedAspectValue");
+         assertEquals(12, iv.intValue());
+         assertEquals(22, ia.intValue());
+      }
+      finally
+      {
+         undeploy("aop-scopedattachtest2.aop");
+      }
+   }
+   
+   public void testScoped1() throws Exception
+   {
+      deploy("aop-scopedattachtest1.aop");
+      try
+      {
+         MBeanServerConnection server = getServer();
+         ObjectName testerName = new ObjectName("jboss.aop:name=ScopedTester1");
+         Object[] params = {};
+         String[] sig = {};
+         server.invoke(testerName, "testScoped", params, sig);
+      }
+      finally
+      {
+         undeploy("aop-scopedattachtest1.aop");
+      }
+   }
+
+   public void testScoped2() throws Exception
+   {
+      deploy("aop-scopedattachtest2.aop");
+      try
+      {
+         MBeanServerConnection server = getServer();
+         ObjectName testerName = new ObjectName("jboss.aop:name=ScopedTester2");
+         Object[] params = {};
+         String[] sig = {};
+         server.invoke(testerName, "testScoped", params, sig);
+      }
+      finally
+      {
+         undeploy("aop-scopedattachtest2.aop");
+      }
+   }
+   
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new TestSuite(ScopedAttachUnitTestCase.class));
+
+      setup = new AOPClassLoaderHookTestSetup(suite, "aop-scopedattachtest1.sar,aop-scopedattachtest2.sar");
+      return setup;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list