001: /*
002: * %W% %E%
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: package com.sun.jumpimpl.executive;
028:
029: import com.sun.jump.module.presentation.JUMPPresentationModule;
030: import com.sun.jump.module.presentation.JUMPPresentationModuleFactory;
031: import com.sun.jump.executive.JUMPExecutive;
032: import com.sun.jump.executive.JUMPUserInputManager;
033: import com.sun.jump.executive.JUMPIsolateFactory;
034: import com.sun.jump.executive.JUMPIsolateProxy;
035: import com.sun.jump.executive.JUMPApplicationProxy;
036: import com.sun.jump.message.JUMPMessagingService;
037: import com.sun.jump.message.JUMPMessageDispatcher;
038: import com.sun.jump.message.JUMPOutgoingMessage;
039: import com.sun.jump.message.JUMPMessage;
040: import com.sun.jump.common.JUMPAppModel;
041:
042: import com.sun.jumpimpl.process.JUMPProcessProxyImpl;
043: import com.sun.jumpimpl.process.JUMPModulesConfig;
044:
045: import com.sun.jump.os.JUMPOSInterface;
046:
047: import com.sun.jump.common.JUMPContent;
048: import com.sun.jump.common.JUMPApplication;
049: import com.sun.jump.module.installer.JUMPInstallerModuleFactory;
050: import com.sun.jump.module.installer.JUMPInstallerModule;
051:
052: import java.util.Properties;
053: import java.io.IOException;
054: import java.io.InputStream;
055: import java.io.FileInputStream;
056: import java.io.BufferedInputStream;
057:
058: public class JUMPExecutiveImpl extends JUMPExecutive {
059: private JUMPProcessProxyImpl pp;
060: private JUMPOSInterface os;
061: private JUMPIsolateFactory isolateFactory = null;
062:
063: // name of a propoerty which points to name of a propoerty file which
064: // overrides default modules configuration
065: private final static String PROPERTY_FILE_NAME_PROP = "runtime-properties-file";
066:
067: private void handleCommandLine(String[] args) {
068: // remove default value (if any)
069: JUMPModulesConfig.getProperties().remove(
070: PROPERTY_FILE_NAME_PROP);
071:
072: for (int i = 0; i < args.length; ++i) {
073: if ("--config-file".equals(args[i])) {
074: if (!(++i < args.length) || args[i] == null) {
075: throw new IllegalArgumentException(
076: "configuration file not specified");
077: }
078: JUMPModulesConfig.overrideDefaultConfig(args[i]);
079:
080: // put name of a property file overriding default properties
081: // in the configuration map hopeing JUMPIsolateManagerModule
082: // implementation will hook it up
083: JUMPModulesConfig.getProperties().put(
084: PROPERTY_FILE_NAME_PROP, args[i]);
085: }
086: }
087: }
088:
089: public JUMPExecutiveImpl() {
090: super ();
091: }
092:
093: /*
094: * Main entry point to the executive
095: */
096: public static void main(String[] args) {
097: JUMPExecutiveImpl jei = new JUMPExecutiveImpl();
098:
099: jei.handleCommandLine(args);
100:
101: // Initialize os interface
102: new com.sun.jumpimpl.os.JUMPOSInterfaceImpl();
103:
104: // Get critical objects
105: jei.os = JUMPOSInterface.getInstance();
106: jei.pp = JUMPProcessProxyImpl.createProcessProxyImpl(jei.os
107: .getProcessID());
108:
109: JUMPFactories.init(JUMPModulesConfig.getProperties());
110:
111: if (false) {
112: // Sample code to create blank isolate upon startup
113: JUMPIsolateFactory factory = jei.getIsolateFactory();
114:
115: JUMPIsolateProxy ip = factory.newIsolate(JUMPAppModel.XLET);
116: System.err.println("New isolate created=" + ip);
117:
118: JUMPInstallerModuleFactory imf = JUMPInstallerModuleFactory
119: .getInstance();
120: JUMPInstallerModule xletInstaller = imf
121: .getModule(JUMPAppModel.XLET);
122: JUMPContent[] content = xletInstaller.getInstalled();
123: if (content != null) {
124: for (int i = 0; i < content.length; i++) {
125: JUMPApplication app = (JUMPApplication) content[i];
126: System.err.println("App[" + i + "] = " + app);
127: }
128: JUMPApplicationProxy appProxy = ip.startApp(
129: (JUMPApplication) content[0], null);
130: System.err.println("Executive started app=" + appProxy);
131: } else {
132: System.err.println("No content available");
133: System.exit(1);
134: }
135: }
136:
137: // Take it away, someone -- presentation mode?
138: try {
139: JUMPPresentationModule pm = getPresentation();
140: if (pm != null) {
141: pm.start();
142: } else {
143: System.err
144: .println("A JUMP presentation module will not be run.");
145: }
146: } catch (Throwable e) {
147: e.printStackTrace();
148: }
149: }
150:
151: public static JUMPPresentationModule getPresentation() {
152: String presentationMode = (String) JUMPModulesConfig
153: .getProperties().get("jump.presentation");
154: JUMPPresentationModuleFactory pmf = JUMPPresentationModuleFactory
155: .getInstance();
156: if (pmf != null) {
157: return pmf.getModule(presentationMode);
158: } else {
159: return null;
160: }
161: }
162:
163: public int getProcessId() {
164: return os.getProcessID();
165: }
166:
167: public JUMPMessageDispatcher getMessageDispatcher() {
168: return pp.getMessageDispatcher();
169: }
170:
171: public JUMPOutgoingMessage newOutgoingMessage(String mesgType) {
172: return pp.newOutgoingMessage(mesgType);
173: }
174:
175: public JUMPOutgoingMessage newOutgoingMessage(
176: JUMPMessage requestMessage) {
177: return pp.newOutgoingMessage(requestMessage);
178: }
179:
180: public JUMPMessage newMessage(byte[] rawData) {
181: return pp.newMessage(rawData);
182: }
183:
184: public JUMPUserInputManager getUserInputManager() {
185: return null;
186: }
187:
188: public synchronized JUMPIsolateFactory getIsolateFactory() {
189: if (isolateFactory == null)
190: isolateFactory = new IsolateFactoryImpl();
191:
192: return isolateFactory;
193: }
194: }
|