KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > policy > DispatchPolicy


1 package fr.improve.struts.taglib.layout.policy;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 import javax.servlet.jsp.PageContext JavaDoc;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 /**
11  * Implementation of AbstractPolicy that will dispatch the create/edit/inspect call to a policy method.
12  * The policy method must have the following signature:
13  * public short policy(String name, String property, PageContext pageContext);
14  * @author: JeanNoŽl Ribette
15  */

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 JavaDoc in_policy,
21         String JavaDoc in_name,
22         String JavaDoc in_property,
23         PageContext JavaDoc in_pageContext) {
24         try {
25             Class JavaDoc[] lc_parameters = new Class JavaDoc[3];
26             lc_parameters[0] = String JavaDoc.class;
27             lc_parameters[1] = String JavaDoc.class;
28             lc_parameters[2] = PageContext JavaDoc.class;
29             Method JavaDoc lc_method = getClass().getDeclaredMethod(in_policy, lc_parameters);
30             Object JavaDoc[] l_args = { in_name, in_property, in_pageContext };
31             Object JavaDoc lc_result = lc_method.invoke(this, l_args);
32             return ((Short JavaDoc) lc_result).shortValue();
33         } catch (NoSuchMethodException JavaDoc 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 JavaDoc("Policy " + in_policy + " is not supported");
36         } catch (IllegalAccessException JavaDoc iae) {
37             LOG.error("Policy error", iae);
38             throw new RuntimeException JavaDoc("Accessing policy " + in_policy + " is not allowed");
39         } catch (java.lang.reflect.InvocationTargetException JavaDoc ite) {
40             LOG.error("Policy error", ite.getTargetException());
41             throw new RuntimeException JavaDoc("Apply of policy " + in_policy + " failed: " + ite.getTargetException());
42         }
43     }
44 }
Popular Tags