1 /* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2006, JBoss Inc., and individual contributors as indicated 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 package org.jboss.system.microcontainer; 23 24 import java.security.AccessController; 25 import java.security.PrivilegedAction; 26 import java.security.PrivilegedActionException; 27 import java.security.PrivilegedExceptionAction; 28 29 import org.jboss.dependency.plugins.spi.action.ControllerContextAction; 30 import org.jboss.dependency.spi.ControllerContext; 31 import org.jboss.logging.Logger; 32 33 /** 34 * ServiceControllerContextAction. 35 * 36 * @author <a HREF="adrian@jboss.com">Adrian Brock</a> 37 * @version $Revision: 1.1 $ 38 */ 39 public class ServiceControllerContextAction implements ControllerContextAction 40 { 41 protected Logger log = Logger.getLogger(getClass()); 42 43 public void install(final ControllerContext context) throws Throwable 44 { 45 if (System.getSecurityManager() == null || context instanceof ServiceControllerContext == false) 46 installAction((ServiceControllerContext) context); 47 else 48 { 49 PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>() 50 { 51 public Object run() throws Exception 52 { 53 try 54 { 55 installAction((ServiceControllerContext) context); 56 return null; 57 } 58 catch (RuntimeException e) 59 { 60 throw e; 61 } 62 catch (Exception e) 63 { 64 throw e; 65 } 66 catch (Error e) 67 { 68 throw e; 69 } 70 catch (Throwable t) 71 { 72 throw new RuntimeException(t); 73 } 74 } 75 }; 76 try 77 { 78 AccessController.doPrivileged(action); 79 } 80 catch (PrivilegedActionException e) 81 { 82 throw e.getCause(); 83 } 84 } 85 } 86 87 public void uninstall(final ControllerContext context) 88 { 89 if (System.getSecurityManager() == null || context instanceof ServiceControllerContext == false) 90 uninstallAction((ServiceControllerContext) context); 91 else 92 { 93 PrivilegedAction<Object> action = new PrivilegedAction<Object>() 94 { 95 public Object run() 96 { 97 uninstallAction((ServiceControllerContext) context); 98 return null; 99 } 100 }; 101 AccessController.doPrivileged(action); 102 } 103 } 104 105 public void installAction(ServiceControllerContext context) throws Throwable 106 { 107 } 108 109 public void uninstallAction(ServiceControllerContext context) 110 { 111 } 112 } 113