Source Code Cross Referenced for NamsManager.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:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.main;
028:
029:        import javax.microedition.midlet.MIDlet;
030:        import javax.microedition.midlet.MIDletStateChangeException;
031:        import javax.microedition.lcdui.Display;
032:
033:        import javax.microedition.lcdui.Form;
034:        import javax.microedition.lcdui.Command;
035:        import javax.microedition.lcdui.CommandListener;
036:        import javax.microedition.lcdui.Displayable;
037:
038:        import com.sun.midp.midlet.MIDletSuite;
039:        import com.sun.midp.events.EventTypes;
040:        import com.sun.midp.events.EventQueue;
041:        import com.sun.midp.events.EventCopyStorage;
042:
043:        import com.sun.midp.log.Logging;
044:        import com.sun.midp.log.LogChannels;
045:
046:        /**
047:         * Works as a simple (display) manager to test NAMS.
048:         */
049:        public class NamsManager extends MIDlet implements  CommandListener {
050:
051:            /** stores event copies for native events being tracked */
052:            static private EventCopyStorage eventCopyStorage = new EventCopyStorage();
053:
054:            /** array if IDs for dummy midlets */
055:            private int dummyId[];
056:
057:            private Command cmdExit;
058:            private Command cmdHide;
059:            private Command cmdRefresh;
060:            private Command cmdStart[];
061:            private Command cmdActivate[];
062:            private Command cmdPause[];
063:            private Command cmdDestroy[];
064:            private Command cmdI3Framework;
065:
066:            /** MIDlet's screen */
067:            private Form form;
068:
069:            /** reference to MIdlet's Display */
070:            private Display display;
071:
072:            /**
073:             * public constructor
074:             */
075:            public NamsManager() {
076:
077:                int i, j;
078:                EventQueue eventQueue;
079:
080:                // appId = 0 is reserved for NamsManager itself
081:                initNamsManager(MIDletSuiteUtils.getIsolateId());
082:
083:                dummyId = new int[3];
084:
085:                cmdExit = new Command("Destroy", Command.EXIT, 0);
086:                cmdHide = new Command("Hide", Command.SCREEN, 0);
087:                cmdRefresh = new Command("Refresh MIDlet status",
088:                        Command.SCREEN, 0);
089:
090:                cmdStart = new Command[3];
091:                cmdActivate = new Command[3];
092:                cmdPause = new Command[3];
093:                cmdDestroy = new Command[3];
094:
095:                for (i = 0; i < 3; ++i) {
096:                    dummyId[i] = 0;
097:                    cmdStart[i] = new Command("Start Dummy#" + (i + 1),
098:                            Command.SCREEN, 0);
099:                    cmdActivate[i] = new Command("Activate Dummy#" + (i + 1),
100:                            Command.SCREEN, 0);
101:                    cmdPause[i] = new Command("Pause Dummy#" + (i + 1),
102:                            Command.SCREEN, 0);
103:                    cmdDestroy[i] = new Command("Destroy Dummy#" + (i + 1),
104:                            Command.SCREEN, 0);
105:                }
106:                cmdI3Framework = new Command("Start I3 Nams Framework",
107:                        Command.SCREEN, 0);
108:
109:                form = new Form("NAMS Manager screen");
110:
111:                form.addCommand(cmdRefresh);
112:                form.addCommand(cmdExit);
113:                form.addCommand(cmdHide);
114:                for (i = 0; i < 3; ++i) {
115:                    form.addCommand(cmdStart[i]);
116:                    form.addCommand(cmdActivate[i]);
117:                    form.addCommand(cmdPause[i]);
118:                    form.addCommand(cmdDestroy[i]);
119:                }
120:                form.addCommand(cmdI3Framework);
121:
122:                form.setCommandListener(this );
123:
124:                display = Display.getDisplay(this );
125:                display.setCurrent(form);
126:            }
127:
128:            private native void initNamsManager(int isolateId);
129:
130:            protected void startApp() throws MIDletStateChangeException {
131:                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
132:                        "NamsManager MIDlet: entered active state ...");
133:
134:                display.setCurrent(form);
135:            };
136:
137:            protected void pauseApp() {
138:                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
139:                        "NamsManager MIDlet: entered paused state ...");
140:
141:                resumeRequest();
142:            }
143:
144:            protected void destroyApp(boolean unconditional)
145:                    throws MIDletStateChangeException {
146:                /* if (unconditional) */{
147:                    Logging.report(Logging.WARNING, LogChannels.LC_CORE,
148:                            "NamsManager MIDlet: entered destroyed state ...");
149:                    notifyDestroyed();
150:                    MIDletProxyList list = MIDletProxyList.getMIDletProxyList();
151:                    if (list != null)
152:                        list.shutdown();
153:                    else {
154:                        Logging.report(Logging.WARNING, LogChannels.LC_CORE,
155:                                "NamsManager MIDlet: Proxy List is NULL !!!");
156:                    }
157:                }
158:                /* else {
159:                    throw new MIDletStateChangeException(
160:                            "NAMS Manager: I DO NOT want to be destroyed !");
161:                } */
162:            }
163:
164:            public void commandAction(Command c, Displayable s) {
165:
166:                if (c == cmdRefresh) {
167:                    refresh();
168:                } else if (c == cmdExit) {
169:                    try {
170:                        destroyApp(true);
171:                    } catch (MIDletStateChangeException e) {
172:                    }
173:                    ;
174:                } else if (c == cmdHide) {
175:                    midletSetForeground(findNextForegroundMIDlet(0));
176:                } else if (c == cmdI3Framework) {
177:                    startInternalMidlet("com.sun.midp.i3test.NamsFramework",
178:                    /* null, null, null */
179:                    false, false);
180:                } else {
181:                    int i;
182:                    for (i = 0; i < 3; ++i) {
183:                        if (c == cmdStart[i]) {
184:                            dummyId[i] = startInternalMidlet(
185:                                    "com.sun.midp.main.DummyNamsMIDlet"
186:                                            + (i + 1),
187:                                    /* null, null, null */
188:                                    false, false);
189:                        } else if (c == cmdActivate[i]) {
190:                            if (dummyId[i] != 0) {
191:                                midletResume(dummyId[i]);
192:                            }
193:                        } else if (c == cmdPause[i]) {
194:                            if (dummyId[i] != 0) {
195:                                midletPause(dummyId[i]);
196:                            }
197:                        } else if (c == cmdDestroy[i]) {
198:                            if (dummyId[i] != 0) {
199:                                midletDestroy(dummyId[i]);
200:                            }
201:                            dummyId[i] = 0;
202:                        }
203:                    }
204:                }
205:            }
206:
207:            static public void midletCreateStart(int suiteId, String className,
208:            /*
209:            String displayName,
210:            String arg0,
211:            String arg1,
212:            String arg2,
213:             */
214:            int appId) {
215:
216:                if (NamsStorage.getMIDletStateTrack(appId)) {
217:                    eventCopyStorage.putTail(
218:                            EventTypes.NATIVE_MIDLET_EXECUTE_REQUEST, appId,
219:                            suiteId, 0, 0, className, null,
220:                            /* displayName, arg0, arg1, arg2 */
221:                            null, null, null, null);
222:                }
223:
224:                NamsAPIWrapper.midletCreateStart(suiteId, className,
225:                /* displayName, arg0, arg1, arg2, */
226:                appId);
227:            }
228:
229:            static public void midletResume(int appId) {
230:                if (NamsStorage.getMIDletStateTrack(appId)) {
231:                    eventCopyStorage.putTail(
232:                            EventTypes.NATIVE_MIDLET_RESUME_REQUEST, appId, 0,
233:                            0, 0, null, null, null, null, null, null);
234:                }
235:
236:                NamsAPIWrapper.midletResume(appId);
237:            }
238:
239:            static public void midletPause(int appId) {
240:                if (NamsStorage.getMIDletStateTrack(appId)) {
241:                    eventCopyStorage.putTail(
242:                            EventTypes.NATIVE_MIDLET_PAUSE_REQUEST, appId, 0,
243:                            0, 0, null, null, null, null, null, null);
244:                }
245:
246:                NamsAPIWrapper.midletPause(appId);
247:            }
248:
249:            static public void midletDestroy(int appId) {
250:                if (NamsStorage.getMIDletStateTrack(appId)) {
251:                    eventCopyStorage.putTail(
252:                            EventTypes.NATIVE_MIDLET_DESTROY_REQUEST, appId,
253:                            -1, 0, 0, null, null, null, null, null, null);
254:                }
255:
256:                NamsAPIWrapper.midletDestroy(appId);
257:            }
258:
259:            static public void midletSetForeground(int appId) {
260:                if (NamsStorage.getDisplayStatusTrack(appId)) {
261:                    eventCopyStorage.putTail(
262:                            EventTypes.NATIVE_SET_FOREGROUND_REQUEST, appId, 0,
263:                            0, 0, null, null, null, null, null, null);
264:                }
265:
266:                NamsAPIWrapper.midletSetForeground(appId);
267:            }
268:
269:            static public void midletSetBackground() {
270:                int appId = getForegroundAppId();
271:                int nextFgAppId = findNextForegroundMIDlet(appId);
272:                if (nextFgAppId == appId)
273:                    nextFgAppId = 0;
274:
275:                midletSetForeground(nextFgAppId);
276:            }
277:
278:            static int startInternalMidlet(String className,
279:            /* String arg0, String arg1, String arg2, */
280:            boolean midlet_state_track, boolean display_status_track) {
281:                int appId = findNextEmptyMIDlet(getForegroundAppId());
282:
283:                if (appId == 0) {
284:                    Logging
285:                            .report(
286:                                    Logging.ERROR,
287:                                    LogChannels.LC_CORE,
288:                                    "NamsManager MIDlet: "
289:                                            + "Failed to start MIDlet: no IDs available ...");
290:                } else {
291:                    NamsStorage.setMIDletStateTrack(appId, midlet_state_track);
292:                    NamsStorage.setDisplayStatusTrack(appId,
293:                            display_status_track);
294:                    midletCreateStart(MIDletSuite.INTERNAL_SUITE_ID, className,
295:                    /* "Display#" + appId, arg0, arg1, arg2, */
296:                    appId);
297:                }
298:                return appId;
299:            }
300:
301:            static native int findNextEmptyMIDlet(int appId);
302:
303:            static native int findNextForegroundMIDlet(int appId);
304:
305:            static native int getForegroundAppId();
306:
307:            private String getMIDletStateString(int state) {
308:                switch (state) {
309:                case NamsStorage.NAMS_STATE_NO:
310:                    return "NO";
311:                case NamsStorage.NAMS_STATE_ACTIVE:
312:                    return "ACTIVE";
313:                case NamsStorage.NAMS_STATE_PAUSED:
314:                    return "PAUSED";
315:                case NamsStorage.NAMS_STATE_DESTROYED:
316:                    return "DESTROYED";
317:                case NamsStorage.NAMS_STATE_ERROR:
318:                    return "ERROR";
319:                case NamsStorage.NAMS_STATE_RESERVED:
320:                    return "RESERVED";
321:                default:
322:                    return "INVALID";
323:                }
324:            }
325:
326:            private void refresh() {
327:                int i;
328:                int midlet_state;
329:                boolean display_status;
330:
331:                form.deleteAll();
332:
333:                for (i = 0; i < NamsStorage.NAMS_STORAGE_SIZE; ++i) {
334:                    midlet_state = NamsStorage.getMIDletState(i);
335:                    display_status = NamsStorage.getDisplayStatus(i);
336:
337:                    if (midlet_state != NamsStorage.NAMS_STATE_NO
338:                            || display_status) {
339:
340:                        form.append("#" + i + " state="
341:                                + getMIDletStateString(midlet_state)
342:                                + " display="
343:                                + ((display_status) ? "FG" : "BG"));
344:                    }
345:                }
346:            }
347:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.