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.example.main.message;
16:
17: import java.io.Serializable;
18: import org.araneaframework.Component;
19: import org.araneaframework.Message;
20: import org.araneaframework.Widget;
21: import org.araneaframework.core.util.ExceptionUtil;
22: import org.araneaframework.example.main.web.RootWidget;
23: import org.araneaframework.framework.FlowContext;
24: import org.araneaframework.framework.RootFlowContext;
25: import org.araneaframework.uilib.core.PopupFlowWidget.MessageFactory;
26:
27: /**
28: * Wrapper around the flow that is started from new session-thread. It pretends
29: * to be {@link org.araneaframework.framework.FlowContext} for wrapped flows and proxies
30: * method calls current <emphasis>real</emphasis> {@link org.araneaframework.framework.FlowContext}
31: * and to {@link org.araneaframework.framework.FlowContext} that requested starting of wrapped flow.
32: *
33: * @author Taimo Peelo (taimo@araneaframework.org)
34: */
35: public class PopupMessageFactory implements MessageFactory,
36: Serializable {
37: private static final long serialVersionUID = 1L;
38:
39: public Message buildMessage(Widget widget) {
40: return new MainExampleMessage(widget);
41: }
42:
43: public static class MainExampleMessage implements Message {
44: private static final long serialVersionUID = 1L;
45: Widget flow;
46:
47: public MainExampleMessage(Widget flow) {
48: this .flow = flow;
49: }
50:
51: public final void send(Object id, Component component) {
52: if (!(component instanceof RootFlowContext)) {
53: component._getComponent().propagate(this );
54: } else {
55: try {
56: this .execute(component);
57: } catch (Exception e) {
58: throw ExceptionUtil.uncheckException(e);
59: }
60: }
61: }
62:
63: protected void execute(Component component) throws Exception {
64: FlowContext fCtx = (FlowContext) component;
65: fCtx.start(new RootWidget(flow));
66: }
67: }
68: }
|