KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > config > FlowSystemDefaults


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.config;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.springframework.core.style.ToStringCreator;
21 import org.springframework.webflow.core.collection.LocalAttributeMap;
22 import org.springframework.webflow.core.collection.MutableAttributeMap;
23 import org.springframework.webflow.engine.support.ApplicationViewSelector;
24
25 /**
26  * Encapsulates overall flow system configuration defaults. Allows for
27  * centralized application of, and if necessary, overridding of system-wide
28  * default values.
29  *
30  * @author Keith Donald
31  */

32 public class FlowSystemDefaults implements Serializable JavaDoc {
33
34     /**
35      * The default 'alwaysRedirectOnPause' execution attribute value.
36      */

37     private boolean alwaysRedirectOnPause = true;
38
39     /**
40      * The default flow execution repository type.
41      */

42     private RepositoryType repositoryType = RepositoryType.CONTINUATION;
43
44     /**
45      * Overrides the alwaysRedirectOnPause execution attribute default. Defaults
46      * to "true".
47      * @param alwaysRedirectOnPause the new default value
48      * @see ApplicationViewSelector#ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE
49      */

50     public void setAlwaysRedirectOnPause(boolean alwaysRedirectOnPause) {
51         this.alwaysRedirectOnPause = alwaysRedirectOnPause;
52     }
53
54     /**
55      * Overrides the default repository type.
56      * @param repositoryType the new default value
57      */

58     public void setRepositoryType(RepositoryType repositoryType) {
59         this.repositoryType = repositoryType;
60     }
61
62     /**
63      * Applies default execution attributes if necessary. Defaults will only
64      * apply in the case where the user did not configure a value, or explicitly
65      * requested the 'default' value.
66      * @param executionAttributes the user-configured execution attribute map
67      * @return the map with defaults applied as appropriate
68      */

69     public MutableAttributeMap applyExecutionAttributes(MutableAttributeMap executionAttributes) {
70         if (executionAttributes == null) {
71             executionAttributes = new LocalAttributeMap(1, 1);
72         }
73         if (!executionAttributes.contains(ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE)) {
74             executionAttributes.put(ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE, Boolean
75                     .valueOf(alwaysRedirectOnPause));
76         }
77         return executionAttributes;
78     }
79
80     /**
81      * Applies the default repository type if requested by the user.
82      * @param selectedType the selected repository type (may be null if no
83      * selection was made)
84      * @return the repository type, with the default applied if necessary
85      */

86     public RepositoryType applyIfNecessary(RepositoryType selectedType) {
87         if (selectedType == null) {
88             return repositoryType;
89         }
90         else {
91             return selectedType;
92         }
93     }
94
95     public String JavaDoc toString() {
96         return new ToStringCreator(this).append("alwaysRedirectOnPause", alwaysRedirectOnPause).append(
97                 "repositoryType", repositoryType).toString();
98     }
99 }
Popular Tags