1 25 package org.objectweb.jonas.security.lib.wrapper; 26 27 import java.io.Reader ; 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 31 import org.objectweb.jonas.security.JResources; 32 import org.objectweb.jonas.security.SecurityServiceException; 33 import org.objectweb.jonas.server.LoaderManager; 34 35 38 public class JResourceManagerWrapper { 39 40 43 private static Object managerInstance = null; 44 45 48 private static Method addResourcesMethod = null; 49 50 53 private JResourceManagerWrapper() { 54 } 55 56 64 public static void addResources(JResources jres, Reader reader, String xml) throws SecurityServiceException { 65 if (managerInstance == null) { 66 managerInstance = getJResourceManagerInstance(); 67 } 68 69 if (addResourcesMethod == null) { 70 addResourcesMethod = getJResourceManagerMethod(); 71 } 72 73 try { 74 addResourcesMethod.invoke(managerInstance, new Object [] {jres, reader, xml}); 75 } catch (InvocationTargetException e) { 76 Throwable t = e.getTargetException(); 77 if (t instanceof SecurityServiceException) { 78 throw (SecurityServiceException) t; 79 } else if (t instanceof Error ) { 80 throw (Error ) t; 81 } 82 throw new SecurityServiceException("Exception during JResourcesManager.addResources invocation", e); 83 } catch (Exception e) { 84 throw new SecurityServiceException("Exception during JResourcesManager.addResources invocation", e); 85 } 86 } 87 88 92 private static Method getJResourceManagerMethod() throws SecurityServiceException { 93 try { 94 return managerInstance.getClass().getMethod("addResources", 95 new Class [] {JResources.class, Reader .class, String .class}); 96 } catch (Exception e) { 97 throw new SecurityServiceException("Cannot get JResourcesManager.addResources method", e); 98 } 99 } 100 101 105 private static Object getJResourceManagerInstance() throws SecurityServiceException { 106 107 LoaderManager lm = LoaderManager.getInstance(); 108 try { 109 ClassLoader tools = lm.getToolsLoader(); 110 111 Class jrmClass = tools.loadClass("org.objectweb.jonas.security.lib.JResourceManager"); 112 Method m = jrmClass.getMethod("getInstance", new Class [] {}); 113 return m.invoke(null, new Object [] {}); 114 } catch (InvocationTargetException e) { 115 Throwable t = e.getTargetException(); 116 if (t instanceof SecurityServiceException) { 117 throw (SecurityServiceException) t; 118 } else if (t instanceof Error ) { 119 throw (Error ) t; 120 } 121 throw new SecurityServiceException("InvocationTargetException during JResourcesManager.getInstance invocation : " + e.getMessage(), e); 122 } catch (Exception e) { 123 throw new SecurityServiceException("Exception during JResourcesManager.getInstance invocation : " + e.getMessage(), e); 124 } 125 } 126 127 } | Popular Tags |