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


001:        /*
002:         * @(#)PXletRunner.java	1.13 06/10/10
003:         *
004:         * Copyright  1990-2006 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:
028:        /*
029:         * A sample class to introduce xlet to the system
030:         *
031:         * Usage: 
032:         * cvm sun.mtask.xlet.PXletRunner -name <XletName> {-path <XletPath> | 
033:         *     -codebase <URL_path>} [-args <arg1> [<arg2>] [<arg3>] ...]
034:         *
035:         * cvm sun.mtask.xlet.PXletRunner -filename <filename>
036:         *
037:         * The xlet should not be found in the classpath and
038:         * <XletPath> is relative to the current directory.
039:         */
040:
041:        package sun.mtask.xlet;
042:
043:        // To read the command line from a file.
044:        import java.io.BufferedReader;
045:        import java.io.FileReader;
046:        import java.io.File;
047:        import java.io.FileNotFoundException;
048:        import java.io.IOException;
049:        import java.util.StringTokenizer;
050:
051:        // Data structure to save the command line options.
052:        import java.util.Vector;
053:
054:        import com.sun.xlet.XletLifecycleHandler;
055:
056:        public class PXletRunner {
057:
058:            private static boolean verbose = (System
059:                    .getProperty("cdcams.verbose") != null)
060:                    && (System.getProperty("cdcams.verbose").toLowerCase()
061:                            .equals("true"));
062:
063:            static String[] flags = { "-name", "-path", "-codebase", "-args",
064:                    "-filename", "-laf", "-lafTheme", "-loadOnly" };
065:
066:            static boolean isKey(String s) {
067:                for (int i = 0; i < flags.length; i++)
068:                    if (s.equals(flags[i]))
069:                        return true;
070:                return false;
071:            }
072:
073:            public static void main(String[] args) {
074:                if (args.length < 2)
075:                    printErrorAndExit();
076:
077:                // Parse the command line options.
078:                if (args[0].equals("-filename")) {
079:                    String filename = args[1];
080:                    try {
081:                        BufferedReader reader = new BufferedReader(
082:                                new FileReader(filename));
083:                        Vector v = new Vector();
084:                        String s;
085:                        while ((s = reader.readLine()) != null) {
086:                            StringTokenizer tok = new StringTokenizer(s, " ");
087:                            while (tok.hasMoreTokens()) {
088:                                v.addElement(tok.nextToken());
089:                            }
090:                        }
091:                        args = new String[v.size()];
092:                        for (int i = 0; i < v.size(); i++) {
093:                            args[i] = (String) v.elementAt(i);
094:                        }
095:                    } catch (FileNotFoundException fnf) {
096:                        if (verbose) {
097:                            System.out.println("Could not find file "
098:                                    + filename);
099:                        }
100:                        System.exit(1);
101:                    } catch (IOException ioe) {
102:                        if (verbose) {
103:                            System.out
104:                                    .println("IOException caught while reading file "
105:                                            + filename);
106:                        }
107:                        System.exit(1);
108:                    }
109:                }
110:
111:                String name = null;
112:                String[] paths = null;
113:                String[] xletArgs = new String[] {};
114:                String laf = null; // L&F, if applicable
115:                String lafTheme = null; // Theme for L&F, if applicable
116:                boolean isLoadOnly = false; // If true, don't init the xlet
117:                for (int i = 0; i < args.length;) {
118:                    try {
119:                        if (args[i].equals("-laf")) {
120:                            laf = args[++i];
121:                        } else if (args[i].equals("-lafTheme")) {
122:                            lafTheme = args[++i];
123:                        } else if (args[i].equals("-name")) {
124:                            name = args[++i];
125:                            if (!(args[++i].equals("-path") || args[i]
126:                                    .equals("-codebase"))) {
127:                                printErrorAndExit();
128:                            }
129:                            Vector v = new Vector();
130:                            if (args[i].equals("-path")) {
131:                                StringTokenizer tok = new StringTokenizer(
132:                                        args[++i], File.pathSeparator);
133:                                while (tok.hasMoreTokens()) {
134:                                    v.addElement(tok.nextToken());
135:                                }
136:                            } else {
137:                                while ((i + 1) < args.length
138:                                        && !args[i + 1].equals("-args")) {
139:                                    v.addElement(args[++i]);
140:                                }
141:                            }
142:                            paths = (String[]) v.toArray(new String[v.size()]);
143:                            if ((i + 1) < args.length
144:                                    && args[++i].equals("-args")) {
145:                                v = new Vector();
146:                                while ((i + 1) < args.length
147:                                        && !isKey(args[++i])) {
148:                                    v.addElement(args[i]);
149:                                }
150:                                xletArgs = (String[]) v.toArray(new String[v
151:                                        .size()]);
152:                            }
153:                        } else if (args[i].equals("-loadOnly")) {
154:                            isLoadOnly = true;
155:                            i++;
156:                        } else {
157:                            i++;
158:                        }
159:                    } catch (Exception e) {
160:                        e.printStackTrace();
161:                        printErrorAndExit();
162:                    }
163:                }
164:                // Parsing is finished. Now start the xlet by calling methods on
165:                // the Xlet Manager.
166:
167:                try {
168:                    if (verbose) {
169:                        System.out.println("@@PXletRunner starting Xlet "
170:                                + name);
171:                    }
172:
173:                    // Get an instance of XletLifecycle from the Xlet Manager,
174:                    // and post a request on the handler.
175:                    PXletManager handler = PXletManager.createXlet(name, laf,
176:                            lafTheme, paths, xletArgs);
177:
178:                    // First, tell the system to recognize us as the
179:                    // singleton xlet.
180:                    //handler.register();
181:
182:                    if (!isLoadOnly) {
183:                        // Call a method so the xlet is initialized. 
184:                        // Xlet.initXlet(XletContext) is invoked on the Xlet Manager.
185:                        handler.postInitXlet();
186:                        // Call a method so the xlet is started.
187:                        // Xlet.startXlet() is invoked on the Xlet Manager.
188:                        handler.postStartXlet();
189:                    }
190:
191:                } catch (Throwable e) {
192:                    // If we can't get this xlet started, there is no need to linger.
193:                    // So go away.
194:                    if (verbose) {
195:                        System.out.println("Error while loading xlet: " + name);
196:                    }
197:                    e.printStackTrace();
198:                    System.exit(1);
199:                }
200:
201:            }
202:
203:            // If there was a problem parsing the command line, call this method, which ultimately exits.
204:            static void printErrorAndExit() {
205:                if (verbose) {
206:                    System.out.println("\n\nPXletRunner Usage: ");
207:                    System.out.println("cvm sun.mtask.xlet.PXletRunner "
208:                            + "-name <xletname> -path <xletpath> ");
209:                    System.out.println("\nOptions");
210:                    System.out
211:                            .println("-filename <filename>                   Reads PXletRunner arguments from a file");
212:                    System.out
213:                            .println("-args <arguments separated by space>   Xlet runtime arguments");
214:                    System.out
215:                            .println("-codebase <URLs separated by space>    Specifies class location in URL format, replaces \"-path\" option");
216:                    System.out
217:                            .println("\nRepeat arguments to run more than one xlets");
218:                }
219:                System.exit(1);
220:            }
221:
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.