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.beehive.netui.pageflow.internal.InternalUtils;
022: import org.apache.struts.config.ModuleConfig;
023: import org.apache.struts.config.ExceptionConfig;
024: import org.apache.struts.config.ForwardConfig;
025: import org.apache.struts.action.ActionForward;
026: import org.apache.struts.action.ActionMapping;
027:
028: import javax.servlet.ServletContext;
029: import java.util.Map;
030:
031: /**
032: * A Struts ActionMapping object that delegates to an ActionMapping in a different module.
033: */
034: public class DelegatingActionMapping extends PageFlowActionMapping {
035: private ActionMapping _delegate;
036: private String _delegateModulePath;
037: private boolean _inheritLocalPaths;
038:
039: // values from the module config to override the delegate properties.
040: private boolean _loginRequiredSet = false;
041: private boolean _readonlySet = false;
042:
043: /**
044: * Set the path prefix for the module where the delegate ActionMapping lives.
045: */
046: public void setDelegateModulePath(String delegateModulePath) {
047: _delegateModulePath = delegateModulePath;
048: }
049:
050: public void init(ServletContext servletContext) {
051: ModuleConfig moduleConfig = InternalUtils.ensureModuleConfig(
052: _delegateModulePath, servletContext);
053: assert moduleConfig != null : "No ModuleConfig found for path "
054: + _delegateModulePath;
055: _delegate = (ActionMapping) moduleConfig
056: .findActionConfig(getPath());
057:
058: // It's possible that an overloaded action method in the derived class has the
059: // same unqualified action path, causing the path to be reset to a disambiguated
060: // path that includes the form bean class type. However, in the base class module
061: // config, the action path does not include the form bean class type. If the
062: // action path didn't match any in the delegate, try the unqualified path.
063: if (_delegate == null) {
064: _delegate = (ActionMapping) moduleConfig
065: .findActionConfig(super .getUnqualifiedActionPath());
066: }
067: assert _delegate != null : "No ActionMapping with path "
068: + getPath() + " in module " + _delegateModulePath;
069: }
070:
071: /**
072: * Get the prefix directory path that local paths in Forwards should be relative to. This is only enabled if we're
073: * inheriting local paths from a base page flow.
074: */
075: public String getLocalPathsRelativeTo() {
076: return _inheritLocalPaths ? _delegateModulePath : null;
077: }
078:
079: public String toString() {
080: return "[delegate to " + _delegate + ']';
081: }
082:
083: public void freeze() {
084: configured = true;
085: }
086:
087: /**
088: * Tell whether local paths should be inherited from the base class. This affects the value of
089: * {@link #getLocalPathsRelativeTo()}.
090: */
091: public void setInheritLocalPaths(boolean inheritLocalPaths) {
092: _inheritLocalPaths = inheritLocalPaths;
093: }
094:
095: //
096: // Attributes that may have been set to override the delegate
097: //
098:
099: public String getRoles() {
100: if (roles != null) {
101: return roles;
102: }
103: return _delegate.getRoles();
104: }
105:
106: //
107: // Properties that may have been set to override the delegate
108: //
109:
110: public boolean isLoginRequired() {
111: if (_loginRequiredSet) {
112: return super .isLoginRequired();
113: }
114: return _delegate instanceof PageFlowActionMapping
115: && ((PageFlowActionMapping) _delegate)
116: .isLoginRequired();
117: }
118:
119: public void setLoginRequired(boolean loginRequired) {
120: _loginRequiredSet = true;
121: super .setLoginRequired(loginRequired);
122: }
123:
124: public boolean isReadonly() {
125: if (_readonlySet) {
126: return super .isReadonly();
127: }
128: return _delegate instanceof PageFlowActionMapping
129: && ((PageFlowActionMapping) _delegate).isReadonly();
130: }
131:
132: public void setReadonly(boolean readonly) {
133: _readonlySet = true;
134: super .setReadonly(readonly);
135: }
136:
137: // If an action level forward does not exist for the delegate then
138: // look for a global forward of the module config for this action
139: // mapping. Then, if still not found, look in the module config of
140: // the delegate.
141: public ActionForward findForward(String forwardName) {
142: ForwardConfig config = _delegate.findForwardConfig(forwardName);
143: if (config == null) {
144: config = getModuleConfig().findForwardConfig(forwardName);
145: }
146: if (config == null) {
147: config = _delegate.getModuleConfig().findForwardConfig(
148: forwardName);
149: }
150: return (ActionForward) config;
151: }
152:
153: //
154: // Everything below this point is simple delegation.
155: //
156:
157: public String getUnqualifiedActionPath() {
158: return _delegate instanceof PageFlowActionMapping ? ((PageFlowActionMapping) _delegate)
159: .getUnqualifiedActionPath()
160: : null;
161: }
162:
163: public String getUnqualifiedActionName() {
164: return _delegate instanceof PageFlowActionMapping ? ((PageFlowActionMapping) _delegate)
165: .getUnqualifiedActionName()
166: : null;
167: }
168:
169: public boolean isPreventDoubleSubmit() {
170: return _delegate instanceof PageFlowActionMapping
171: && ((PageFlowActionMapping) _delegate)
172: .isPreventDoubleSubmit();
173: }
174:
175: public boolean isSimpleAction() {
176: return _delegate instanceof PageFlowActionMapping
177: && ((PageFlowActionMapping) _delegate).isSimpleAction();
178: }
179:
180: public boolean isOverloaded() {
181: return _delegate instanceof PageFlowActionMapping
182: && ((PageFlowActionMapping) _delegate).isOverloaded();
183: }
184:
185: public Map getConditionalForwardsMap() {
186: return _delegate instanceof PageFlowActionMapping ? ((PageFlowActionMapping) _delegate)
187: .getConditionalForwardsMap()
188: : null;
189: }
190:
191: public String getFormBeanMessageResourcesKey() {
192: return _delegate instanceof PageFlowActionMapping ? ((PageFlowActionMapping) _delegate)
193: .getFormBeanMessageResourcesKey()
194: : null;
195: }
196:
197: public String getDefaultForward() {
198: return _delegate instanceof PageFlowActionMapping ? ((PageFlowActionMapping) _delegate)
199: .getDefaultForward()
200: : null;
201: }
202:
203: public String[] findForwards() {
204: return _delegate.findForwards();
205: }
206:
207: public ActionForward getInputForward() {
208: return _delegate.getInputForward();
209: }
210:
211: public String getForward() {
212: return _delegate.getForward();
213: }
214:
215: public String getInclude() {
216: return _delegate.getInclude();
217: }
218:
219: public String getInput() {
220: return _delegate.getInput();
221: }
222:
223: public String getMultipartClass() {
224: return _delegate.getMultipartClass();
225: }
226:
227: public String getPrefix() {
228: return _delegate.getPrefix();
229: }
230:
231: public String[] getRoleNames() {
232: return _delegate.getRoleNames();
233: }
234:
235: public String getScope() {
236: return _delegate.getScope();
237: }
238:
239: public String getSuffix() {
240: return _delegate.getSuffix();
241: }
242:
243: public String getType() {
244: return _delegate.getType();
245: }
246:
247: public boolean getUnknown() {
248: return _delegate.getUnknown();
249: }
250:
251: public boolean getValidate() {
252: return _delegate.getValidate();
253: }
254:
255: public ExceptionConfig findExceptionConfig(String type) {
256: return _delegate.findExceptionConfig(type);
257: }
258:
259: public ExceptionConfig[] findExceptionConfigs() {
260: return _delegate.findExceptionConfigs();
261: }
262:
263: public ExceptionConfig findException(Class type) {
264: return _delegate.findException(type);
265: }
266:
267: public ForwardConfig findForwardConfig(String name) {
268: return _delegate.findForwardConfig(name);
269: }
270:
271: public ForwardConfig[] findForwardConfigs() {
272: return _delegate.findForwardConfigs();
273: }
274:
275: }
|