001: /*
002: * Copyright 2004-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.springframework.webflow.config;
017:
018: import java.io.Serializable;
019:
020: import org.springframework.core.style.ToStringCreator;
021: import org.springframework.webflow.core.collection.LocalAttributeMap;
022: import org.springframework.webflow.core.collection.MutableAttributeMap;
023: import org.springframework.webflow.engine.support.ApplicationViewSelector;
024:
025: /**
026: * Encapsulates overall flow system configuration defaults. Allows for
027: * centralized application of, and if necessary, overridding of system-wide
028: * default values.
029: *
030: * @author Keith Donald
031: */
032: public class FlowSystemDefaults implements Serializable {
033:
034: /**
035: * The default 'alwaysRedirectOnPause' execution attribute value.
036: */
037: private boolean alwaysRedirectOnPause = true;
038:
039: /**
040: * The default flow execution repository type.
041: */
042: private RepositoryType repositoryType = RepositoryType.CONTINUATION;
043:
044: /**
045: * Overrides the alwaysRedirectOnPause execution attribute default. Defaults
046: * to "true".
047: * @param alwaysRedirectOnPause the new default value
048: * @see ApplicationViewSelector#ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE
049: */
050: public void setAlwaysRedirectOnPause(boolean alwaysRedirectOnPause) {
051: this .alwaysRedirectOnPause = alwaysRedirectOnPause;
052: }
053:
054: /**
055: * Overrides the default repository type.
056: * @param repositoryType the new default value
057: */
058: public void setRepositoryType(RepositoryType repositoryType) {
059: this .repositoryType = repositoryType;
060: }
061:
062: /**
063: * Applies default execution attributes if necessary. Defaults will only
064: * apply in the case where the user did not configure a value, or explicitly
065: * requested the 'default' value.
066: * @param executionAttributes the user-configured execution attribute map
067: * @return the map with defaults applied as appropriate
068: */
069: public MutableAttributeMap applyExecutionAttributes(
070: MutableAttributeMap executionAttributes) {
071: if (executionAttributes == null) {
072: executionAttributes = new LocalAttributeMap(1, 1);
073: }
074: if (!executionAttributes
075: .contains(ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE)) {
076: executionAttributes
077: .put(
078: ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE,
079: new Boolean(alwaysRedirectOnPause));
080: }
081: return executionAttributes;
082: }
083:
084: /**
085: * Applies the default repository type if requested by the user.
086: * @param selectedType the selected repository type (may be null if no
087: * selection was made)
088: * @return the repository type, with the default applied if necessary
089: */
090: public RepositoryType applyIfNecessary(RepositoryType selectedType) {
091: if (selectedType == null) {
092: return repositoryType;
093: } else {
094: return selectedType;
095: }
096: }
097:
098: public String toString() {
099: return new ToStringCreator(this ).append(
100: "alwaysRedirectOnPause", alwaysRedirectOnPause).append(
101: "repositoryType", repositoryType).toString();
102: }
103: }
|