1 22 package org.jboss.kernel.plugins.dependency; 23 24 import java.security.*; 25 26 import org.jboss.beans.metadata.spi.BeanMetaData; 27 import org.jboss.dependency.plugins.spi.action.ControllerContextAction; 28 import org.jboss.dependency.spi.ControllerContext; 29 import org.jboss.joinpoint.spi.Joinpoint; 30 import org.jboss.kernel.plugins.config.Configurator; 31 import org.jboss.kernel.spi.dependency.KernelControllerContext; 32 import org.jboss.logging.Logger; 33 34 40 public class KernelControllerContextAction implements ControllerContextAction 41 { 42 protected Logger log = Logger.getLogger(getClass()); 43 44 52 protected static Object dispatchJoinPoint(final KernelControllerContext context, final Joinpoint joinpoint) throws Throwable 53 { 54 BeanMetaData metaData = context.getBeanMetaData(); 55 ClassLoader cl = Configurator.getClassLoader(metaData); 56 AccessControlContext access = null; 57 if (context instanceof AbstractKernelControllerContext) 58 { 59 AbstractKernelControllerContext theContext = (AbstractKernelControllerContext) context; 60 access = theContext.getAccessControlContext(); 61 } 62 63 ClassLoader tcl = Thread.currentThread().getContextClassLoader(); 65 try 66 { 67 if( cl != null && access == null ) 68 Thread.currentThread().setContextClassLoader(cl); 69 if (access == null) 70 { 71 return joinpoint.dispatch(); 72 } 73 else 74 { 75 DispatchJoinPoint action = new DispatchJoinPoint(joinpoint); 76 try 77 { 78 return AccessController.doPrivileged(action, access); 79 } 80 catch (PrivilegedActionException e) 81 { 82 throw e.getCause(); 83 } 84 } 85 } 86 finally 87 { 88 if( cl != null && access == null ) 89 Thread.currentThread().setContextClassLoader(tcl); 90 } 91 } 92 93 public void install(final ControllerContext context) throws Throwable 94 { 95 if (System.getSecurityManager() == null || context instanceof AbstractKernelControllerContext == false) 96 installAction((KernelControllerContext) context); 97 else 98 { 99 PrivilegedExceptionAction<Object > action = new PrivilegedExceptionAction<Object >() 100 { 101 public Object run() throws Exception 102 { 103 try 104 { 105 installAction((KernelControllerContext) context); 106 return null; 107 } 108 catch (RuntimeException e) 109 { 110 throw e; 111 } 112 catch (Exception e) 113 { 114 throw e; 115 } 116 catch (Error e) 117 { 118 throw e; 119 } 120 catch (Throwable t) 121 { 122 throw new RuntimeException (t); 123 } 124 } 125 }; 126 try 127 { 128 AccessController.doPrivileged(action); 129 } 130 catch (PrivilegedActionException e) 131 { 132 throw e.getCause(); 133 } 134 } 135 } 136 137 public void uninstall(final ControllerContext context) 138 { 139 if (System.getSecurityManager() == null || context instanceof AbstractKernelControllerContext == false) 140 uninstallAction((KernelControllerContext) context); 141 else 142 { 143 PrivilegedAction<Object > action = new PrivilegedAction<Object >() 144 { 145 public Object run() 146 { 147 uninstallAction((KernelControllerContext) context); 148 return null; 149 } 150 }; 151 AccessController.doPrivileged(action); 152 } 153 } 154 155 public void installAction(KernelControllerContext context) throws Throwable 156 { 157 } 158 159 public void uninstallAction(KernelControllerContext context) 160 { 161 } 162 } | Popular Tags |