KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > executor > jsf > JsfExternalContext


1 /*
2  * Copyright 2002-2006 the original author or authors.
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 package org.springframework.webflow.executor.jsf;
17
18 import javax.faces.context.FacesContext;
19
20 import org.springframework.binding.collection.SharedMapDecorator;
21 import org.springframework.core.style.ToStringCreator;
22 import org.springframework.webflow.context.ExternalContext;
23 import org.springframework.webflow.core.collection.LocalAttributeMap;
24 import org.springframework.webflow.core.collection.LocalParameterMap;
25 import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
26 import org.springframework.webflow.core.collection.MutableAttributeMap;
27 import org.springframework.webflow.core.collection.ParameterMap;
28 import org.springframework.webflow.core.collection.SharedAttributeMap;
29
30 /**
31  * Provides contextual information about a JSF environment that has interacted
32  * with SWF.
33  *
34  * @author Keith Donald
35  */

36 public class JsfExternalContext implements ExternalContext {
37
38     /**
39      * The JSF Faces context.
40      */

41     private FacesContext facesContext;
42
43     /**
44      * The id of the action or "command button" that fired.
45      */

46     private String JavaDoc actionId;
47
48     /**
49      * The action outcome.
50      */

51     private String JavaDoc outcome;
52
53     /**
54      * Creates a JSF External Context.
55      * @param facesContext the JSF faces context
56      */

57     public JsfExternalContext(FacesContext facesContext) {
58         this.facesContext = facesContext;
59     }
60
61     /**
62      * Creates a JSF External Context.
63      * @param facesContext the JSF faces context.
64      * @param actionId the action that fired
65      * @param outcome the action outcome
66      */

67     public JsfExternalContext(FacesContext facesContext, String JavaDoc actionId, String JavaDoc outcome) {
68         this.facesContext = facesContext;
69         this.actionId = actionId;
70         this.outcome = outcome;
71     }
72
73     public String JavaDoc getContextPath() {
74         return facesContext.getExternalContext().getRequestContextPath();
75     }
76
77     public String JavaDoc getDispatcherPath() {
78         return facesContext.getExternalContext().getRequestServletPath();
79     }
80
81     public String JavaDoc getRequestPathInfo() {
82         return facesContext.getExternalContext().getRequestPathInfo();
83     }
84
85     public ParameterMap getRequestParameterMap() {
86         return new LocalParameterMap(facesContext.getExternalContext().getRequestParameterMap());
87     }
88
89     public MutableAttributeMap getRequestMap() {
90         return new LocalAttributeMap(facesContext.getExternalContext().getRequestMap());
91     }
92
93     public SharedAttributeMap getSessionMap() {
94         return new LocalSharedAttributeMap(new SessionSharedMap(facesContext));
95     }
96
97     public SharedAttributeMap getGlobalSessionMap() {
98         return getSessionMap();
99     }
100     
101     public SharedAttributeMap getApplicationMap() {
102         return new LocalSharedAttributeMap(new ApplicationSharedMap(facesContext));
103     }
104
105     /**
106      * Returns the JSF FacesContext.
107      */

108     public FacesContext getFacesContext() {
109         return facesContext;
110     }
111
112     /**
113      * Returns the action identifier.
114      */

115     public String JavaDoc getActionId() {
116         return actionId;
117     }
118
119     /**
120      * Returns the action outcome.
121      */

122     public String JavaDoc getOutcome() {
123         return outcome;
124     }
125
126     private static class SessionSharedMap extends SharedMapDecorator {
127
128         private FacesContext facesContext;
129
130         public SessionSharedMap(FacesContext facesContext) {
131             super(facesContext.getExternalContext().getSessionMap());
132             this.facesContext = facesContext;
133         }
134
135         public Object JavaDoc getMutex() {
136             return facesContext.getExternalContext().getSession(false);
137         }
138     }
139
140     private static class ApplicationSharedMap extends SharedMapDecorator {
141
142         private FacesContext facesContext;
143
144         public ApplicationSharedMap(FacesContext facesContext) {
145             super(facesContext.getExternalContext().getApplicationMap());
146             this.facesContext = facesContext;
147         }
148
149         public Object JavaDoc getMutex() {
150             return facesContext.getExternalContext().getContext();
151         }
152     }
153
154     public String JavaDoc toString() {
155         return new ToStringCreator(this).append("actionId", actionId).append("outcome", outcome).append("facesContext",
156                 facesContext).toString();
157     }
158 }
Popular Tags