View Javadoc

1   package org.weda.action.impl;
2   
3   import java.util.ArrayList;
4   import java.util.HashMap;
5   import java.util.List;
6   import java.util.Map;
7   import org.weda.action.ActionContainer;
8   import org.weda.action.ActionDescriptor;
9   import org.weda.action.ActionExecutionContext;
10  import org.weda.action.ActionExecutionContextException;
11  import org.weda.action.ActionParameter;
12  import org.weda.action.Parameter.Direction;
13  
14  /**
15   *
16   * @author tim
17   */
18  public class ActionExecutionContextImpl implements ActionExecutionContext {
19      private ActionDescriptor actionDescriptor;
20      private ActionContainer targetObject;
21      private Map<String, Object> actionParameters = 
22              new HashMap<String, Object>();
23      private Map objectState;
24      
25      public ActionDescriptor getActionDescriptor() {
26          return actionDescriptor;
27      }
28  
29      public void setActionDescriptor(ActionDescriptor actionDescriptor) {
30          this.actionDescriptor = actionDescriptor;
31      }
32  
33      public ActionContainer getTargetObject() {
34          return targetObject;
35      }
36  
37      public void setTargetObject(ActionContainer targetObject) {
38          this.targetObject = targetObject;
39      }
40  
41      public Map<String, Object> getActionParameters() {
42          return actionParameters;
43      }
44  
45      public void setActionParameterValue(String parameterName, Object value)
46          throws ActionExecutionContextException
47      {
48          try{
49              ActionParameter parameter = 
50                      actionDescriptor.getActionParameter(parameterName);
51              if (   parameter.getDirection() == Direction.READ_WRITE
52                  || parameter.getDirection() == Direction.WRITE)
53              {
54                  actionParameters.put(parameterName, value);
55              }else
56                  throw new ActionExecutionContextException(
57                          String.format(
58                              "Can't set parameter value " +
59                              "because of it's READ ONLY"));
60          }catch(Exception e){
61              throw new ActionExecutionContextException(
62                      String.format(
63                          "Error while setting value of parameter (%s) for " +
64                          "action (%s)"
65                          , parameterName
66                          , actionDescriptor.getActionClass().getName())
67                      , e);
68          }
69      }
70  
71      public Map getObjectState() {
72          return objectState;
73      }
74  
75      public void setObjectState(Map objectState) {
76          this.objectState = objectState;
77      }
78  
79  }