KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > script > el > NetUIUpdateVariableResolver


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.script.el;
19
20 import javax.servlet.ServletRequest JavaDoc;
21 import javax.servlet.ServletResponse JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.jsp.el.VariableResolver JavaDoc;
24
25 import org.apache.beehive.netui.script.IllegalExpressionException;
26 import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
27 import org.apache.beehive.netui.script.el.util.RequestAttributeMap;
28 import org.apache.beehive.netui.script.el.util.SessionAttributeMap;
29 import org.apache.beehive.netui.util.logging.Logger;
30 import org.apache.beehive.netui.pageflow.SharedFlowController;
31 import org.apache.beehive.netui.pageflow.PageFlowController;
32 import org.apache.beehive.netui.pageflow.GlobalApp;
33
34 import java.util.Map JavaDoc;
35
36 /**
37  *
38  */

39 public class NetUIUpdateVariableResolver
40     extends NetUIVariableResolver {
41
42     private static final Logger LOGGER = Logger.getInstance(NetUIVariableResolver.class);
43
44     private boolean _requestParameter = true;
45     private Object JavaDoc _form = null;
46     private ServletRequest JavaDoc _request = null;
47     private ServletResponse JavaDoc _response = null;
48
49     public NetUIUpdateVariableResolver(Object JavaDoc form, ServletRequest JavaDoc request, ServletResponse JavaDoc response, boolean requestParameter) {
50         super();
51
52         _requestParameter = requestParameter;
53         _form = form;
54         _request = request;
55         _response = response;
56     }
57
58     public Object JavaDoc resolveVariable(String JavaDoc name) {
59         if(name.equals("actionForm"))
60             return _form;
61         else if(name.equals("pageFlow"))
62             return getPageFlow(_request, _response);
63         else if(name.equals("globalApp"))
64             return getGlobalApp(_request, _response);
65         else if(name.equals("sharedFlow"))
66             return getSharedFlow(_request, _response);
67         else if(name.equals("requestScope")) {
68             if(_requestParameter == false)
69                 return new RequestAttributeMap(_request);
70             else
71                 throw new IllegalExpressionException("The request data binding context can not be updated from a request parameter.");
72         } else if(name.equals("sessionScope")) {
73             if(_requestParameter == false)
74                 return new SessionAttributeMap(((HttpServletRequest JavaDoc)_request).getSession());
75             else
76                 throw new IllegalExpressionException("The session data binding context can not be updated from a request parameter.");
77         }
78         // @bug: need to get the ServletContext from somewhere
79
else if(name.equals("applicationScope")) {
80             if(_requestParameter == false)
81                 return null;
82             else
83                 throw new IllegalExpressionException("The application data binding context can not be updated from a request parameter.");
84         } else {
85             String JavaDoc msg = "Could not resolve variable named \"" + name + "\" for an expression update.";
86             if(LOGGER.isErrorEnabled())
87                 LOGGER.error(msg);
88
89             throw new IllegalExpressionException(msg);
90         }
91     }
92
93     public String JavaDoc[] getAvailableVariables() {
94         if(_requestParameter)
95             return new String JavaDoc[]{"actionForm", "pageFlow", "globalApp"};
96         else
97             return new String JavaDoc[]{"actionForm", "pageFlow", "globalApp", "request", "session", "application"};
98     }
99
100     private static final Map/*<String, SharedFlowController>*/ getSharedFlow(ServletRequest JavaDoc request, ServletResponse JavaDoc response) {
101         return ImplicitObjectUtil.getSharedFlow(request);
102     }
103
104     private static final PageFlowController getPageFlow(ServletRequest JavaDoc request, ServletResponse JavaDoc response) {
105         return ImplicitObjectUtil.getPageFlow(request, response);
106     }
107
108     private static final GlobalApp getGlobalApp(ServletRequest JavaDoc request, ServletResponse JavaDoc response) {
109         return ImplicitObjectUtil.getGlobalApp(request, response);
110     }
111 }
112
Popular Tags