Source Code Cross Referenced for CldcMIDletSuiteLoader.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » main » 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 » 6.0 JDK Modules » j2me » com.sun.midp.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         * 
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         * 
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        package com.sun.midp.main;
026:
027:        import com.sun.midp.midlet.*;
028:        import com.sun.midp.lcdui.*;
029:        import com.sun.midp.midletsuite.*;
030:        import com.sun.midp.configurator.Constants;
031:        import com.sun.midp.i18n.ResourceConstants;
032:        import com.sun.midp.installer.InternalMIDletSuiteImpl;
033:        import com.sun.midp.log.*;
034:
035:        /**
036:         * The class presents abstract MIDlet suite loader with routines to prepare
037:         * runtime environment for CLDC a suite execution.
038:         */
039:        abstract class CldcMIDletSuiteLoader extends AbstractMIDletSuiteLoader {
040:            /** Event producer to send MIDlet state events to the AMS isolate. */
041:            protected MIDletControllerEventProducer midletControllerEventProducer;
042:
043:            /** Listener for MIDlet related events (state changes, etc). */
044:            protected MIDletEventListener midletEventListener;
045:
046:            /**
047:             * Provides interface for display foreground notification,
048:             * functionality that can not be publicly added to a javax package.
049:             */
050:            protected ForegroundEventListener foregroundEventListener;
051:
052:            /** Core initialization of a MIDlet suite loader */
053:            protected void init() {
054:                isolateId = MIDletSuiteUtils.getIsolateId();
055:                amsIsolateId = MIDletSuiteUtils.getAmsIsolateId();
056:
057:                // Hint VM of startup beginning: system init phase
058:                MIDletSuiteUtils.vmBeginStartUp(isolateId);
059:
060:                super .init();
061:            }
062:
063:            /**
064:             * Creates all needed objects of a MIDlet suite environment, but
065:             * only initialization that is done, will be to pass other created objects,
066:             * and the current and AMS isolate IDs. It is mostly event-related
067:             * objects, however subclasses can extend the environment with more
068:             * specific parts
069:             */
070:            protected void createSuiteEnvironment() {
071:                midletControllerEventProducer = new MIDletControllerEventProducer(
072:                        eventQueue, amsIsolateId, isolateId);
073:
074:                foregroundController = new CldcForegroundController(
075:                        midletControllerEventProducer);
076:
077:                // creates display container, needs foregroundController
078:                super .createSuiteEnvironment();
079:
080:                foregroundEventListener = new ForegroundEventListener(
081:                        eventQueue, displayContainer);
082:
083:                midletStateHandler = MIDletStateHandler.getMidletStateHandler();
084:
085:                MIDletStateListener midletStateListener = new CldcMIDletStateListener(
086:                        internalSecurityToken, displayContainer,
087:                        midletControllerEventProducer);
088:
089:                midletStateHandler.initMIDletStateHandler(
090:                        internalSecurityToken, midletStateListener,
091:                        new CldcMIDletLoader(internalSecurityToken),
092:                        new CldcPlatformRequest(internalSecurityToken));
093:
094:                midletEventListener = new MIDletEventListener(
095:                        internalSecurityToken, midletStateHandler, eventQueue);
096:            }
097:
098:            /**
099:             * Does all initialization for already created objects of a MIDlet suite
100:             * environment. Subclasses can also extend the initialization with
101:             * various global system initializations needed for all suites.
102:             */
103:            protected void initSuiteEnvironment() {
104:                super .initSuiteEnvironment();
105:            }
106:
107:            /**
108:             * Starts MIDlet suite in the prepared environment
109:             * Overrides super method to hint VM of system startup
110:             * phase is ended 
111:             *
112:             * @throws Exception can be thrown during execution
113:             */
114:            protected void startSuite() throws Exception {
115:                // Hint VM of startup finish: system init phase 
116:                MIDletSuiteUtils.vmEndStartUp(isolateId);
117:                super .startSuite();
118:            }
119:
120:            /**
121:             * Creates MIDlet suite instance by suite ID
122:             *
123:             * @return MIDlet suite to load
124:             *
125:             * @throws Exception in the case MIDlet suite can not be
126:             *   created because of a security reasons or some problems
127:             *   related to suite storage
128:             */
129:            protected MIDletSuite createMIDletSuite() throws Exception {
130:                MIDletSuiteStorage storage;
131:                MIDletSuite suite = null;
132:
133:                if (suiteId == MIDletSuite.INTERNAL_SUITE_ID) {
134:                    // assume a class name of a MIDlet in the classpath
135:                    suite = InternalMIDletSuiteImpl.create(midletDisplayName,
136:                            suiteId);
137:                } else {
138:                    storage = MIDletSuiteStorage
139:                            .getMIDletSuiteStorage(internalSecurityToken);
140:
141:                    suite = storage.getMIDletSuite(suiteId, false);
142:                    Logging.initLogSettings(suiteId);
143:                }
144:
145:                return suite;
146:            }
147:
148:            protected void closeSuite() {
149:                super .closeSuite();
150:
151:                // shutdown any preempting
152:                if (displayEventHandler != null) {
153:                    displayEventHandler.donePreempting(null);
154:                }
155:            }
156:
157:            /**
158:             * Gets error code by exception type
159:             *
160:             * @param t exception instance
161:             * @return error code
162:             */
163:            static protected int getErrorCode(Throwable t) {
164:                if (t instanceof  ClassNotFoundException) {
165:                    return Constants.MIDLET_CLASS_NOT_FOUND;
166:                } else if (t instanceof  InstantiationException) {
167:                    return Constants.MIDLET_INSTANTIATION_EXCEPTION;
168:                } else if (t instanceof  IllegalAccessException) {
169:                    return Constants.MIDLET_ILLEGAL_ACCESS_EXCEPTION;
170:                } else if (t instanceof  OutOfMemoryError) {
171:                    return Constants.MIDLET_OUT_OF_MEM_ERROR;
172:                } else if (t instanceof  MIDletSuiteLockedException) {
173:                    return Constants.MIDLET_INSTALLER_RUNNING;
174:                } else {
175:                    return Constants.MIDLET_CONSTRUCTOR_FAILED;
176:                }
177:            }
178:
179:            /**
180:             * Gets AMS error message ID by generic error code
181:             *
182:             * @param errorCode generic error code
183:             * @return AMS error ID
184:             */
185:            static protected int getErrorMessageId(int errorCode) {
186:                switch (errorCode) {
187:                case Constants.MIDLET_SUITE_DISABLED:
188:                    return ResourceConstants.AMS_MIDLETSUITELDR_MIDLETSUITE_DISABLED;
189:                case Constants.MIDLET_SUITE_NOT_FOUND:
190:                    return ResourceConstants.AMS_MIDLETSUITELDR_MIDLETSUITE_NOTFOUND;
191:                case Constants.MIDLET_CLASS_NOT_FOUND:
192:                    return ResourceConstants.AMS_MIDLETSUITELDR_CANT_LAUNCH_MISSING_CLASS;
193:                case Constants.MIDLET_INSTANTIATION_EXCEPTION:
194:                    return ResourceConstants.AMS_MIDLETSUITELDR_CANT_LAUNCH_ILL_OPERATION;
195:                case Constants.MIDLET_ILLEGAL_ACCESS_EXCEPTION:
196:                    return ResourceConstants.AMS_MIDLETSUITELDR_CANT_LAUNCH_ILL_OPERATION;
197:                case Constants.MIDLET_OUT_OF_MEM_ERROR:
198:                    return ResourceConstants.AMS_MIDLETSUITELDR_QUIT_OUT_OF_MEMORY;
199:                default:
200:                    return ResourceConstants.AMS_MIDLETSUITELDR_UNEXPECTEDLY_QUIT;
201:                }
202:            }
203:
204:            /**
205:             * Handles exception occurred during MIDlet suite execution.
206:             * @param t exception instance
207:             */
208:            public void handleException(Throwable t) {
209:                t.printStackTrace();
210:                int errorCode = getErrorCode(t);
211:
212:                reportError(errorCode, t.getMessage());
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.