1 5 package com.opensymphony.webwork.util; 6 7 import com.opensymphony.xwork.ActionContext; 8 import com.opensymphony.xwork.ActionInvocation; 9 import com.opensymphony.xwork.util.OgnlValueStack; 10 11 import java.io.Serializable ; 12 import java.util.HashMap ; 13 import java.util.Map ; 14 15 16 22 public class InvocationSessionStore { 23 25 private static final String INVOCATION_MAP_KEY = "com.opensymphony.webwork.util.InvocationSessionStore.invocationMap"; 26 27 29 private InvocationSessionStore() { 30 } 31 32 34 43 public static ActionInvocation loadInvocation(String key, String token) { 44 InvocationContext invocationContext = (InvocationContext) getInvocationMap().get(key); 45 46 if ((invocationContext == null) || !invocationContext.token.equals(token)) { 47 return null; 48 } 49 50 OgnlValueStack stack = invocationContext.invocation.getStack(); 51 ActionContext.getContext().setValueStack(stack); 52 53 return invocationContext.invocation; 54 } 55 56 63 public static void storeInvocation(String key, String token, ActionInvocation invocation) { 64 InvocationContext invocationContext = new InvocationContext(invocation, token); 65 Map invocationMap = getInvocationMap(); 66 invocationMap.put(key, invocationContext); 67 setInvocationMap(invocationMap); 68 } 69 70 static void setInvocationMap(Map invocationMap) { 71 Map session = ActionContext.getContext().getSession(); 72 73 if (session == null) { 74 throw new IllegalStateException ("Unable to access the session."); 75 } 76 77 session.put(INVOCATION_MAP_KEY, invocationMap); 78 } 79 80 static Map getInvocationMap() { 81 Map session = ActionContext.getContext().getSession(); 82 83 if (session == null) { 84 throw new IllegalStateException ("Unable to access the session."); 85 } 86 87 Map invocationMap = (Map ) session.get(INVOCATION_MAP_KEY); 88 89 if (invocationMap == null) { 90 invocationMap = new HashMap (); 91 setInvocationMap(invocationMap); 92 } 93 94 return invocationMap; 95 } 96 97 99 private static class InvocationContext implements Serializable { 100 ActionInvocation invocation; 101 String token; 102 103 public InvocationContext(ActionInvocation invocation, String token) { 104 this.invocation = invocation; 105 this.token = token; 106 } 107 } 108 } 109 | Popular Tags |