01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.execution.support;
17:
18: import java.util.Collections;
19: import java.util.Map;
20:
21: import org.springframework.util.ObjectUtils;
22: import org.springframework.webflow.execution.ViewSelection;
23:
24: /**
25: * Concrete response type that requests the rendering of a local, internal
26: * application view resource such as a JSP, Velocity, or FreeMarker template.
27: * <p>
28: * This is typically the most common type of view selection.
29: *
30: * @author Keith Donald
31: * @author Erwin Vervaet
32: */
33: public final class ApplicationView extends ViewSelection {
34:
35: /**
36: * The name of the view (or page or other response) to render. This name may
37: * identify a <i>logical</i> view resource or may be a <i>physical</i>
38: * path to an internal view template.
39: */
40: private final String viewName;
41:
42: /**
43: * A map of the application data to make available to the view for
44: * rendering.
45: */
46: private final Map model;
47:
48: /**
49: * Creates a new application view.
50: * @param viewName the name (or resource identifier) of the view that should
51: * be rendered
52: * @param model the map of application model data to make available to the
53: * view during rendering; entries consist of model names (Strings) to model
54: * objects (Objects), model entries may not be null, but the model Map may
55: * be null if there is no model data
56: */
57: public ApplicationView(String viewName, Map model) {
58: if (model == null) {
59: model = Collections.EMPTY_MAP;
60: }
61: this .viewName = viewName;
62: this .model = model;
63: }
64:
65: /**
66: * Returns the name of the view to render.
67: */
68: public String getViewName() {
69: return viewName;
70: }
71:
72: /**
73: * Return the view's application model that should be made available during
74: * the rendering process. Never returns null. The returned map is unmodifiable.
75: */
76: public Map getModel() {
77: return Collections.unmodifiableMap(model);
78: }
79:
80: public boolean equals(Object o) {
81: if (!(o instanceof ApplicationView)) {
82: return false;
83: }
84: ApplicationView other = (ApplicationView) o;
85: return ObjectUtils.nullSafeEquals(viewName, other.viewName)
86: && model.equals(other.model);
87: }
88:
89: public int hashCode() {
90: return (viewName != null ? viewName.hashCode() : 0)
91: + model.hashCode();
92: }
93:
94: public String toString() {
95: return "'" + viewName + "' [" + model.keySet() + "]";
96: }
97: }
|