01: /**
02: * Copyright 2006 Webmedia Group Ltd.
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: **/package org.araneaframework.framework.message;
16:
17: import org.araneaframework.Component;
18: import org.araneaframework.Environment;
19: import org.araneaframework.EnvironmentAwareCallback;
20: import org.araneaframework.Message;
21: import org.araneaframework.Widget;
22: import org.araneaframework.core.Assert;
23: import org.araneaframework.core.util.ExceptionUtil;
24: import org.araneaframework.framework.FlowContext;
25:
26: /**
27: * Message that:
28: * <ul>
29: * <li>resets the first encountered {@link org.araneaframework.framework.FlowContext}</li>
30: * <li>starts a specified flow in it</li>
31: * </ul>
32: * @author Taimo Peelo (taimo@araneaframework.org)
33: */
34: public class StandardFlowContextResettingMessage implements Message {
35: private Widget flow;
36:
37: public StandardFlowContextResettingMessage(Widget flow) {
38: Assert.notNullParam(flow, "flow");
39:
40: this .flow = flow;
41: }
42:
43: public final void send(Object id, Component component) {
44: if (!(component instanceof FlowContext)) {
45: component._getComponent().propagate(this );
46: } else {
47: try {
48: this .execute(component);
49: } catch (Exception e) {
50: throw ExceptionUtil.uncheckException(e);
51: }
52: }
53: }
54:
55: protected void execute(Component component) throws Exception {
56: final FlowContext fCtx = (FlowContext) component;
57:
58: fCtx.reset(new EnvironmentAwareCallback() {
59: public void call(Environment env) throws Exception {
60: FlowContext f = (FlowContext) env
61: .getEntry(FlowContext.class);
62: if (flow != null)
63: f.start(flow);
64: }
65: });
66: }
67: }
|