JResourceManagerWrapper.java

00001 
00025 package org.objectweb.jonas.security.lib.wrapper;
00026 
00027 import java.io.Reader;
00028 import java.lang.reflect.InvocationTargetException;
00029 import java.lang.reflect.Method;
00030 
00031 import org.objectweb.jonas.security.JResources;
00032 import org.objectweb.jonas.security.SecurityServiceException;
00033 import org.objectweb.jonas.server.LoaderManager;
00034 
00038 public class JResourceManagerWrapper {
00039 
00043     private static Object managerInstance = null;
00044 
00048     private static Method addResourcesMethod = null;
00049 
00053     private JResourceManagerWrapper() {
00054     }
00055 
00064     public static void addResources(JResources jres, Reader reader, String xml) throws SecurityServiceException {
00065         if (managerInstance == null) {
00066             managerInstance = getJResourceManagerInstance();
00067         }
00068 
00069         if (addResourcesMethod == null) {
00070             addResourcesMethod = getJResourceManagerMethod();
00071         }
00072 
00073         try {
00074             addResourcesMethod.invoke(managerInstance, new Object[] {jres, reader, xml});
00075         } catch (InvocationTargetException e) {
00076             Throwable t = e.getTargetException();
00077             if (t instanceof SecurityServiceException) {
00078                 throw (SecurityServiceException) t;
00079             } else if (t instanceof Error) {
00080                 throw (Error) t;
00081             }
00082             throw new SecurityServiceException("Exception during JResourcesManager.addResources invocation", e);
00083         } catch (Exception e) {
00084             throw new SecurityServiceException("Exception during JResourcesManager.addResources invocation", e);
00085         }
00086     }
00087 
00092     private static Method getJResourceManagerMethod() throws SecurityServiceException {
00093         try {
00094             return managerInstance.getClass().getMethod("addResources",
00095                     new Class[] {JResources.class, Reader.class, String.class});
00096         } catch (Exception e) {
00097             throw new SecurityServiceException("Cannot get JResourcesManager.addResources method", e);
00098         }
00099     }
00100 
00105     private static Object getJResourceManagerInstance() throws SecurityServiceException {
00106 
00107         LoaderManager lm = LoaderManager.getInstance();
00108         try {
00109             ClassLoader tools = lm.getToolsLoader();
00110 
00111             Class jrmClass = tools.loadClass("org.objectweb.jonas.security.lib.JResourceManager");
00112             Method m = jrmClass.getMethod("getInstance", new Class[] {});
00113             return m.invoke(null, new Object[] {});
00114         } catch (InvocationTargetException e) {
00115             Throwable t = e.getTargetException();
00116             if (t instanceof SecurityServiceException) {
00117                 throw (SecurityServiceException) t;
00118             } else if (t instanceof Error) {
00119                 throw (Error) t;
00120             }
00121             throw new SecurityServiceException("InvocationTargetException during JResourcesManager.getInstance invocation : " + e.getMessage(), e);
00122         } catch (Exception e) {
00123             throw new SecurityServiceException("Exception during JResourcesManager.getInstance invocation : " + e.getMessage(), e);
00124         }
00125     }
00126 
00127 }

Generated on Tue Feb 15 15:05:22 2005 for JOnAS by  doxygen 1.3.9.1