[jboss-cvs] JBossAS SVN: r66579 - in trunk/aspects/src: main/org/jboss/aspects and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Oct 30 13:56:30 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-10-30 13:56:30 -0400 (Tue, 30 Oct 2007)
New Revision: 66579

Added:
   trunk/aspects/src/main/org/jboss/aspects/library/
   trunk/aspects/src/main/org/jboss/aspects/library/JBossAspectLibrary.java
   trunk/aspects/src/main/org/jboss/aspects/library/SecurityActions.java
Modified:
   trunk/aspects/src/etc/META-INF/jboss-aspect-library-beans.xml
Log:
[JBAOP-107]  Move the AspectLibrary bean into aspects/ from the aop source tree and use the correct classloader to deploy the base-aspects.xml file

Modified: trunk/aspects/src/etc/META-INF/jboss-aspect-library-beans.xml
===================================================================
--- trunk/aspects/src/etc/META-INF/jboss-aspect-library-beans.xml	2007-10-30 17:34:58 UTC (rev 66578)
+++ trunk/aspects/src/etc/META-INF/jboss-aspect-library-beans.xml	2007-10-30 17:56:30 UTC (rev 66579)
@@ -6,7 +6,7 @@
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
 
    <!-- Aspect Library -->
-   <bean name="AspectLibrary" class="org.jboss.aop.deployers.JBossAspectLibrary">
+   <bean name="AspectLibrary" class="org.jboss.aspects.library.JBossAspectLibrary">
       <property name="aspectManager"><inject bean="AspectManager"/></property>
    </bean>
 

Added: trunk/aspects/src/main/org/jboss/aspects/library/JBossAspectLibrary.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aspects/library/JBossAspectLibrary.java	                        (rev 0)
+++ trunk/aspects/src/main/org/jboss/aspects/library/JBossAspectLibrary.java	2007-10-30 17:56:30 UTC (rev 66579)
@@ -0,0 +1,69 @@
+/*
+* 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.aspects.library;
+
+import java.net.URL;
+
+import org.jboss.aop.deployers.AbstractAspectManager;
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossAspectLibrary
+{
+   private static final Logger log = Logger.getLogger(JBossAspectLibrary.class);
+   AbstractAspectManager aspectManager;
+
+   public AbstractAspectManager getAspectManager()
+   {
+      return aspectManager;
+   }
+
+   public void setAspectManager(AbstractAspectManager aspectManagerBean)
+   {
+      this.aspectManager = aspectManagerBean;
+   }
+   
+   /**
+    * @throws Exception
+    * @see org.jboss.system.ServiceMBeanSupport#start()
+    */
+   public void start() throws Exception
+   {
+      //Use the loader of this class so that we can find base-aspects.xml in the resources
+      //using the new loaders
+      ClassLoader tcl = SecurityActions.getThreadContextClassLoader();
+      try
+      {
+         ClassLoader mycl = SecurityActions.getClassLoader(this.getClass());
+         SecurityActions.setThreadContextClassLoader(mycl);
+         aspectManager.deployBaseAspects();
+      }
+      finally
+      {
+         SecurityActions.setThreadContextClassLoader(tcl);
+      }
+   }
+}

Added: trunk/aspects/src/main/org/jboss/aspects/library/SecurityActions.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aspects/library/SecurityActions.java	                        (rev 0)
+++ trunk/aspects/src/main/org/jboss/aspects/library/SecurityActions.java	2007-10-30 17:56:30 UTC (rev 66579)
@@ -0,0 +1,148 @@
+/*
+* 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.aspects.library;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+   interface SetTcl
+   {
+      void setContextClassLoader(ClassLoader loader);
+      
+      SetTcl PRIVILEGED = new SetTcl() {
+
+         public void setContextClassLoader(final ClassLoader loader)
+         {
+            AccessController.doPrivileged(new PrivilegedAction() {
+
+               public Object run()
+               {
+                  Thread.currentThread().setContextClassLoader(loader);
+                  return null;
+               }});
+         }
+      };
+
+      SetTcl NON_PRIVILEGED = new SetTcl() {
+
+         public void setContextClassLoader(ClassLoader loader)
+         {
+            Thread.currentThread().setContextClassLoader(loader);
+         }
+      };
+   }
+   
+   interface GetTcl
+   {
+      ClassLoader getContextClassLoader();
+      
+      GetTcl PRIVILEGED = new GetTcl() {
+
+         public ClassLoader getContextClassLoader()
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return Thread.currentThread().getContextClassLoader();
+               }});
+         }
+      };
+
+      GetTcl NON_PRIVILEGED = new GetTcl() {
+
+         public ClassLoader getContextClassLoader()
+         {
+            return Thread.currentThread().getContextClassLoader();
+         }
+      };
+   }
+   
+   interface GetClassLoader
+   {
+      ClassLoader getClassLoader(Class clazz);
+      
+      GetClassLoader PRIVILEGED = new GetClassLoader() {
+
+         public ClassLoader getClassLoader(final Class clazz)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return clazz.getClassLoader();
+               }});
+         }
+      };
+
+      GetClassLoader NON_PRIVILEGED = new GetClassLoader() {
+
+         public ClassLoader getClassLoader(Class clazz)
+         {
+            return clazz.getClassLoader();
+         }
+      };
+   }
+   
+   public static void setThreadContextClassLoader(ClassLoader loader)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         SetTcl.NON_PRIVILEGED.setContextClassLoader(loader);
+      }
+      else
+      {
+         SetTcl.PRIVILEGED.setContextClassLoader(loader);
+      }
+   }
+   
+   public static ClassLoader getThreadContextClassLoader()
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetTcl.NON_PRIVILEGED.getContextClassLoader();
+      }
+      else
+      {
+         return GetTcl.PRIVILEGED.getContextClassLoader();
+      }
+   }
+   
+   public static ClassLoader getClassLoader(Class clazz)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetClassLoader.NON_PRIVILEGED.getClassLoader(clazz);
+      }
+      else
+      {
+         return GetClassLoader.PRIVILEGED.getClassLoader(clazz);
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list