01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
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: */
16: package org.romaframework.aspect.view.echo2;
17:
18: import javax.servlet.ServletConfig;
19:
20: import nextapp.echo2.app.ApplicationInstance;
21: import nextapp.echo2.app.Window;
22: import nextapp.echo2.webcontainer.ContainerContext;
23:
24: import org.romaframework.aspect.i18n.I18NAspect;
25: import org.romaframework.aspect.view.echo2.message.CustomDelayMessage;
26: import org.romaframework.aspect.view.echo2.screen.BasicScreen;
27: import org.romaframework.aspect.view.echo2.screen.Echo2ScreenContainer;
28: import org.romaframework.aspect.view.form.FormViewer;
29: import org.romaframework.aspect.view.screen.ScreenContainer;
30: import org.romaframework.core.config.ApplicationConfiguration;
31: import org.romaframework.core.flow.Controller;
32: import org.romaframework.core.flow.ObjectContext;
33:
34: /**
35: * Echo2ApplicationContext instance implementation.
36: */
37: public class Echo2ApplicationContext extends ApplicationInstance {
38:
39: public Echo2ApplicationContext() {
40: }
41:
42: public Echo2ApplicationContext(ServletConfig iServletContext) {
43: // SAVE SERVLET CONTEXT FOR DIRECT ACCESS TO J2EE SERVLET APIs
44: servletConfig = iServletContext;
45: }
46:
47: /**
48: * Returns the active <code>ApplicationInstance</code> cast to the appropriate type.
49: *
50: * @return the active <code>ApplicationInstance</code>
51: */
52: public static Echo2ApplicationContext getApp() {
53: return (Echo2ApplicationContext) getActive();
54: }
55:
56: /**
57: * @see nextapp.echo2.app.ApplicationInstance#init()
58: */
59: @Override
60: public Window init() {
61: // log.info("[Echo2ApplicationContext.init] Setting ROMA ClassLoader...");
62: // Thread.currentThread().setContextClassLoader(new RomaClassLoader());
63:
64: ContainerContext containerContext = (ContainerContext) getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME);
65:
66: // LOAD MESSAGE FROM I18N
67: String msg = ObjectContext.getInstance().getComponent(
68: I18NAspect.class).resolveString(
69: "$CustomDelayMessage.message.label");
70: containerContext.setServerDelayMessage(new CustomDelayMessage(
71: containerContext, msg));
72:
73: config = ObjectContext.getInstance().getComponent(
74: ApplicationConfiguration.class);
75:
76: mainWindow = new Window();
77: ScreenContainer deskContainer = new Echo2ScreenContainer(
78: mainWindow);
79: FormViewer.getInstance().setScreenContainer(deskContainer);
80: FormViewer.getInstance().setScreen(new BasicScreen());
81:
82: Controller.getInstance().createContext();
83:
84: config.startUserSession();
85:
86: return mainWindow;
87: }
88:
89: public ServletConfig getServletConfig() {
90: return servletConfig;
91: }
92:
93: /**
94: * Main window of user interface.
95: */
96: private Window mainWindow;
97: private ServletConfig servletConfig;
98: private ApplicationConfiguration config;
99: }
|