001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.pageflow.config;
020:
021: import org.apache.struts.config.ModuleConfig;
022: import org.apache.struts.config.ExceptionConfig;
023: import org.apache.struts.config.ActionConfig;
024: import org.apache.beehive.netui.pageflow.internal.InternalUtils;
025:
026: import javax.servlet.ServletContext;
027:
028: /**
029: * A Struts ExceptionConfig object that delegates to an ExceptionConfig in a different module.
030: */
031: public class DelegatingExceptionConfig extends PageFlowExceptionConfig {
032: private ExceptionConfig _delegate;
033: private String _delegateModulePath;
034: private String _delegateActionPath;
035: private boolean _inheritLocalPaths;
036:
037: /**
038: * Set the path prefix for the module where the delegate ExceptionConfig lives.
039: */
040: public void setDelegateModulePath(String delegateModulePath) {
041: _delegateModulePath = delegateModulePath;
042: }
043:
044: /**
045: * Set the path for the action where the delegate ExceptionConfig lives. This will be <code>null</code> if the
046: * delegate ExceptionConfig lives at the module level.
047: */
048: public void setDelegateActionPath(String delegateActionPath) {
049: _delegateActionPath = delegateActionPath;
050: }
051:
052: /**
053: * Get the ModuleConfig where the delegate ExceptionConfig lives.
054: */
055: public ModuleConfig getDelegateModuleConfig(
056: ServletContext servletContext) {
057: return InternalUtils.ensureModuleConfig(_delegateModulePath,
058: servletContext);
059: }
060:
061: public void init(ServletContext servletContext) {
062: ModuleConfig moduleConfig = getDelegateModuleConfig(servletContext);
063: assert moduleConfig != null : "No ModuleConfig found for path "
064: + _delegateModulePath;
065:
066: if (_delegateActionPath != null) {
067: ActionConfig actionConfig = moduleConfig
068: .findActionConfig(_delegateActionPath);
069: assert actionConfig != null : "No action config found for path "
070: + _delegateActionPath;
071: _delegate = actionConfig.findExceptionConfig(getType());
072: assert _delegate != null : "No ExceptionConfig with type "
073: + getType() + " on action " + _delegateActionPath
074: + " in module " + _delegateModulePath;
075: } else {
076: _delegate = moduleConfig.findExceptionConfig(getType());
077: assert _delegate != null : "No ExceptionConfig with type "
078: + getType() + " in module " + _delegateModulePath;
079: }
080: }
081:
082: public String toString() {
083: return "[delegate to " + _delegate + ']';
084: }
085:
086: /**
087: * Get the prefix directory path that local paths in Forwards should be relative to. This is only enabled if we're
088: * inheriting local paths from a base page flow.
089: */
090: public String getLocalPathsRelativeTo() {
091: return _inheritLocalPaths ? _delegateModulePath : null;
092: }
093:
094: /**
095: * Tell whether local paths should be inherited from the base class. This affects the value of
096: * {@link #getLocalPathsRelativeTo()}.
097: */
098: public void setInheritLocalPaths(boolean inheritLocalPaths) {
099: _inheritLocalPaths = inheritLocalPaths;
100: }
101:
102: //
103: // Everything below this point is simple delegation.
104: //
105:
106: public boolean isHandlerMethod() {
107: return _delegate instanceof PageFlowExceptionConfig
108: && ((PageFlowExceptionConfig) _delegate)
109: .isHandlerMethod();
110: }
111:
112: public String getDefaultMessage() {
113: return _delegate instanceof PageFlowExceptionConfig ? ((PageFlowExceptionConfig) _delegate)
114: .getDefaultMessage()
115: : null;
116: }
117:
118: public boolean isPathContextRelative() {
119: return _delegate instanceof PageFlowExceptionConfig
120: && ((PageFlowExceptionConfig) _delegate)
121: .isPathContextRelative();
122: }
123:
124: public boolean isReadonly() {
125: return _delegate instanceof PageFlowExceptionConfig
126: && ((PageFlowExceptionConfig) _delegate).isReadonly();
127: }
128:
129: public String getBundle() {
130: return _delegate.getBundle();
131: }
132:
133: public String getHandler() {
134: return _delegate.getHandler();
135: }
136:
137: public String getKey() {
138: return _delegate.getKey();
139: }
140:
141: public String getPath() {
142: return _delegate.getPath();
143: }
144:
145: public String getScope() {
146: return _delegate.getScope();
147: }
148: }
|