1 package fr.improve.struts.taglib.layout.policy; 2 3 import java.lang.reflect.Method ; 4 5 import javax.servlet.jsp.PageContext ; 6 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 10 16 public abstract class DispatchPolicy extends AbstractPolicy { 17 private static final Log LOG = LogFactory.getLog(DispatchPolicy.class); 18 19 public final short getAuthorizedDisplayMode( 20 String in_policy, 21 String in_name, 22 String in_property, 23 PageContext in_pageContext) { 24 try { 25 Class [] lc_parameters = new Class [3]; 26 lc_parameters[0] = String .class; 27 lc_parameters[1] = String .class; 28 lc_parameters[2] = PageContext .class; 29 Method lc_method = getClass().getDeclaredMethod(in_policy, lc_parameters); 30 Object [] l_args = { in_name, in_property, in_pageContext }; 31 Object lc_result = lc_method.invoke(this, l_args); 32 return ((Short ) lc_result).shortValue(); 33 } catch (NoSuchMethodException nsme) { 34 LOG.error("Policy error : The method " + in_policy + "(String,String,PageContext) can not be found in the class " + getClass().getName(), nsme); 35 throw new RuntimeException ("Policy " + in_policy + " is not supported"); 36 } catch (IllegalAccessException iae) { 37 LOG.error("Policy error", iae); 38 throw new RuntimeException ("Accessing policy " + in_policy + " is not allowed"); 39 } catch (java.lang.reflect.InvocationTargetException ite) { 40 LOG.error("Policy error", ite.getTargetException()); 41 throw new RuntimeException ("Apply of policy " + in_policy + " failed: " + ite.getTargetException()); 42 } 43 } 44 } | Popular Tags |