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


001:        /*
002:         * @(#)XletRunner.java	1.26 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 com.sun.xlet.XletRunner -name <XletName> {-path <XletPath> | 
033:         *     -codebase <URL_path>} [-args <arg1> [<arg2>] [<arg3>] ...]
034:         *
035:         * cvm com.sun.xlet.XletRunner -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 com.sun.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:        public class XletRunner {
055:            static String[] flags = { "-name", "-path", "-codebase", "-args",
056:                    "-filename" };
057:
058:            static boolean isKey(String s) {
059:                for (int i = 0; i < flags.length; i++)
060:                    if (s.equals(flags[i]))
061:                        return true;
062:                return false;
063:            }
064:
065:            public static void main(String[] args) {
066:                if (args.length < 2)
067:                    printErrorAndExit();
068:
069:                // Parse the command line options.
070:                if (args[0].equals("-filename")) {
071:                    String filename = args[1];
072:                    try {
073:                        BufferedReader reader = new BufferedReader(
074:                                new FileReader(filename));
075:                        Vector v = new Vector();
076:                        String s;
077:                        while ((s = reader.readLine()) != null) {
078:                            StringTokenizer tok = new StringTokenizer(s, " ");
079:                            while (tok.hasMoreTokens()) {
080:                                v.addElement(tok.nextToken());
081:                            }
082:                        }
083:                        args = new String[v.size()];
084:                        for (int i = 0; i < v.size(); i++) {
085:                            args[i] = (String) v.elementAt(i);
086:                        }
087:                    } catch (FileNotFoundException fnf) {
088:                        System.out.println("Could not find file " + filename);
089:                        System.exit(1);
090:                    } catch (IOException ioe) {
091:                        System.out
092:                                .println("IOException caught while reading file "
093:                                        + filename);
094:                        System.exit(1);
095:                    }
096:                }
097:
098:                String name = null;
099:                String[] paths;
100:                String[] xletArgs = new String[] {};
101:                for (int i = 0; i < args.length;) {
102:                    try {
103:                        if (args[i].equals("-name")) {
104:                            if (i + 1 == args.length) {
105:                                System.err.println("Name not specified");
106:                                printErrorAndExit();
107:                            }
108:                            name = args[++i];
109:                            if (++i == args.length
110:                                    || !(args[i].equals("-path") || args[i]
111:                                            .equals("-codebase"))) {
112:                                System.err.println("Missing path arguments");
113:                                printErrorAndExit();
114:                            }
115:                            Vector v = new Vector();
116:                            if (args[i].equals("-path")) {
117:                                if (++i == args.length) {
118:                                    System.err.println("Path not specified");
119:                                    printErrorAndExit();
120:                                }
121:                                StringTokenizer tok = new StringTokenizer(
122:                                        args[i], File.pathSeparator);
123:                                while (tok.hasMoreTokens()) {
124:                                    v.addElement(tok.nextToken());
125:                                }
126:                            } else {
127:                                while ((i + 1) < args.length
128:                                        && !args[i + 1].equals("-args")) {
129:                                    v.addElement(args[++i]);
130:                                }
131:                            }
132:                            paths = (String[]) v.toArray(new String[v.size()]);
133:                            if ((i + 1) < args.length
134:                                    && args[++i].equals("-args")) {
135:                                v = new Vector();
136:                                while ((i + 1) < args.length
137:                                        && !isKey(args[++i])) {
138:                                    v.addElement(args[i]);
139:                                }
140:                                xletArgs = (String[]) v.toArray(new String[v
141:                                        .size()]);
142:                            }
143:
144:                            // Parsing is finished. Now start the xlet by calling methods on
145:                            // the Xlet Manager.
146:
147:                            System.out.println("@@XletRunner starting Xlet "
148:                                    + name);
149:                            try {
150:                                // Get an instance of XletLifecycle from the Xlet Manager,
151:                                // and post a request on the handler.
152:                                XletLifecycleHandler handler = XletManager
153:                                        .createXlet(name, paths, xletArgs);
154:                                // Call a method so the xlet is initialized. 
155:                                // Xlet.initXlet(XletContext) is invoked on the Xlet Manager.
156:                                handler.postInitXlet();
157:                                // Call a method so the xlet is started.
158:                                // Xlet.startXlet() is invoked on the Xlet Manager.
159:                                handler.postStartXlet();
160:                            } catch (Exception e) {
161:                                System.out.println("Error while loading xlet: "
162:                                        + name);
163:                                e.printStackTrace();
164:                                System.exit(1);
165:                            }
166:                            xletArgs = new String[] {};
167:                        } else {
168:                            i++;
169:                        }
170:                    } catch (Exception e) {
171:                        e.printStackTrace();
172:                        printErrorAndExit();
173:                    }
174:                }
175:                if (name == null) {
176:                    System.err.println("Missing name arguments");
177:                    printErrorAndExit();
178:                }
179:            }
180:
181:            // If there was a problem parsing the command line, call this method, which ultimately exits.
182:            static void printErrorAndExit() {
183:                System.err.println("XletRunner Usage: ");
184:                System.err.println("cvm com.sun.xlet.XletRunner "
185:                        + "-name <xletname> -path <xletpath> ");
186:                System.err.println("\nOptions");
187:                System.err
188:                        .println("-filename <filename>                   Reads XletRunner arguments from a file");
189:                System.err
190:                        .println("-args <arguments separated by space>   Xlet runtime arguments");
191:                System.err
192:                        .println("-codebase <URLs separated by space>    Specifies class location in URL format, replaces \"-path\" option");
193:                System.err
194:                        .println("\nRepeat arguments to run more than one xlets");
195:                System.exit(1);
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.