Source Code Cross Referenced for SerialApp.java in  » Ajax » NextApp-Echo2 » nextapp » echo2 » testapp » serial » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » NextApp Echo2 » nextapp.echo2.testapp.serial 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003:         * Copyright (C) 2002-2005 NextApp, Inc.
004:         *
005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version
008:         * 1.1 (the "License"); you may not use this file except in compliance with
009:         * the License. You may obtain a copy of the License at
010:         * http://www.mozilla.org/MPL/
011:         *
012:         * Software distributed under the License is distributed on an "AS IS" basis,
013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014:         * for the specific language governing rights and limitations under the
015:         * License.
016:         *
017:         * Alternatively, the contents of this file may be used under the terms of
018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020:         * in which case the provisions of the GPL or the LGPL are applicable instead
021:         * of those above. If you wish to allow use of your version of this file only
022:         * under the terms of either the GPL or the LGPL, and not to allow others to
023:         * use your version of this file under the terms of the MPL, indicate your
024:         * decision by deleting the provisions above and replace them with the notice
025:         * and other provisions required by the GPL or the LGPL. If you do not delete
026:         * the provisions above, a recipient may use your version of this file under
027:         * the terms of any one of the MPL, the GPL or the LGPL.
028:         */
029:
030:        package nextapp.echo2.testapp.serial;
031:
032:        import java.io.FileInputStream;
033:        import java.io.FileOutputStream;
034:        import java.io.IOException;
035:        import java.io.ObjectInputStream;
036:        import java.io.ObjectOutputStream;
037:        import java.util.Enumeration;
038:
039:        import javax.servlet.http.HttpSession;
040:
041:        import nextapp.echo2.app.ApplicationInstance;
042:        import nextapp.echo2.app.Border;
043:        import nextapp.echo2.app.Button;
044:        import nextapp.echo2.app.Color;
045:        import nextapp.echo2.app.Column;
046:        import nextapp.echo2.app.ContentPane;
047:        import nextapp.echo2.app.Extent;
048:        import nextapp.echo2.app.Insets;
049:        import nextapp.echo2.app.Label;
050:        import nextapp.echo2.app.ListBox;
051:        import nextapp.echo2.app.Window;
052:        import nextapp.echo2.app.WindowPane;
053:        import nextapp.echo2.app.event.ActionEvent;
054:        import nextapp.echo2.app.event.ActionListener;
055:        import nextapp.echo2.app.list.DefaultListModel;
056:        import nextapp.echo2.testapp.interactive.InteractiveApp;
057:        import nextapp.echo2.webcontainer.ContainerContext;
058:        import nextapp.echo2.webrender.UserInstance;
059:
060:        public class SerialApp extends ApplicationInstance {
061:
062:            private ListBox listBox;
063:            private Window mainWindow;
064:
065:            private void doLoad() {
066:                try {
067:                    String fileName = "session.data";
068:                    FileInputStream fis = new FileInputStream(fileName);
069:                    ObjectInputStream ois = new ObjectInputStream(fis);
070:                    String sessionKey = (String) ois.readObject();
071:                    UserInstance userInstance = (UserInstance) ois.readObject();
072:                    getSession().setAttribute(sessionKey, userInstance);
073:                    ois.close();
074:                    fis.close();
075:                    showDialog(false, sessionKey + " loaded successfully.");
076:                } catch (ClassNotFoundException ex) {
077:                    showDialog(true, "Exception occurred: " + ex);
078:                    ex.printStackTrace();
079:                } catch (IOException ex) {
080:                    showDialog(true, "Exception occurred: " + ex);
081:                    ex.printStackTrace();
082:                }
083:            }
084:
085:            private void doRefresh() {
086:                DefaultListModel listModel = (DefaultListModel) listBox
087:                        .getModel();
088:                listModel.removeAll();
089:                Enumeration enumeration = getSession().getAttributeNames();
090:                while (enumeration.hasMoreElements()) {
091:                    String sessionKey = (String) enumeration.nextElement();
092:                    listModel.add(sessionKey);
093:                }
094:            }
095:
096:            private void doStore() {
097:                String sessionKey = (String) listBox.getSelectedValue();
098:                UserInstance userInstance = (UserInstance) getSession()
099:                        .getAttribute(sessionKey);
100:                if (userInstance == null) {
101:                    showDialog(true, "No instance selected.");
102:                    return;
103:                }
104:                try {
105:                    String fileName = "session.data";
106:                    FileOutputStream fos = new FileOutputStream(fileName);
107:                    ObjectOutputStream oos = new ObjectOutputStream(fos);
108:                    oos.writeObject(sessionKey);
109:                    oos.writeObject(userInstance);
110:                    oos.flush();
111:                    oos.close();
112:                    fos.close();
113:                    showDialog(false, sessionKey + " serialized successfully.");
114:                } catch (IOException ex) {
115:                    showDialog(true, "Exception occurred: " + ex);
116:                    ex.printStackTrace();
117:                }
118:
119:            }
120:
121:            private HttpSession getSession() {
122:                ContainerContext containerContext = (ContainerContext) getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME);
123:                return containerContext.getSession();
124:            }
125:
126:            /**
127:             * @see nextapp.echo2.app.ApplicationInstance#init()
128:             */
129:            public Window init() {
130:                if (InteractiveApp.LIVE_DEMO_SERVER) {
131:                    throw new RuntimeException(
132:                            "Serialization test disabled on live demo server.");
133:                }
134:
135:                mainWindow = new Window();
136:                mainWindow
137:                        .setTitle("NextApp Echo2 Serialization Test Application");
138:
139:                ContentPane content = new ContentPane();
140:                mainWindow.setContent(content);
141:
142:                Column mainColumn = new Column();
143:                mainColumn.setBorder(new Border(new Extent(4), Color.BLUE,
144:                        Border.STYLE_OUTSET));
145:                mainColumn.setInsets(new Insets(40));
146:                mainColumn.setCellSpacing(new Extent(20));
147:                content.add(mainColumn);
148:
149:                Column serializeColumn = new Column();
150:                mainColumn.add(serializeColumn);
151:
152:                Button button;
153:
154:                serializeColumn.add(new Label("Available Applications:"));
155:
156:                listBox = new ListBox();
157:                listBox.setWidth(new Extent(100, Extent.PERCENT));
158:                serializeColumn.add(listBox);
159:
160:                button = new Button("[ Refresh ]");
161:                button.addActionListener(new ActionListener() {
162:
163:                    /**
164:                     * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
165:                     */
166:                    public void actionPerformed(ActionEvent e) {
167:                        doRefresh();
168:                    }
169:                });
170:                serializeColumn.add(button);
171:
172:                button = new Button("[ Serialize ]");
173:                button.addActionListener(new ActionListener() {
174:
175:                    /**
176:                     * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
177:                     */
178:                    public void actionPerformed(ActionEvent e) {
179:                        doStore();
180:                    }
181:                });
182:                serializeColumn.add(button);
183:
184:                button = new Button("[ Load Serialized Application ]");
185:                button.addActionListener(new ActionListener() {
186:
187:                    /**
188:                     * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
189:                     */
190:                    public void actionPerformed(ActionEvent e) {
191:                        doLoad();
192:                    }
193:                });
194:                mainColumn.add(button);
195:
196:                return mainWindow;
197:            }
198:
199:            private void showDialog(boolean error, String message) {
200:                WindowPane windowPane = new WindowPane();
201:                windowPane.setModal(true);
202:                windowPane.setTitle(error ? "Error" : "Status");
203:                windowPane.setTitleBackground(error ? Color.RED : Color.GREEN);
204:                windowPane.setInsets(new Insets(20));
205:                windowPane.add(new Label(message));
206:                mainWindow.getContent().add(windowPane);
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.