001: /*
002: * Copyright 1990-2006 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.jumpimpl.presentation.installer;
026:
027: import com.sun.jump.module.presentation.JUMPPresentationModule;
028: import com.sun.jumpimpl.module.installer.JUMPInstallerTool;
029: import java.util.Map;
030:
031: /**
032: * This JUMP Presentation mode contains support for installing,
033: * uninstalling, and listing installed content.
034: */
035: public class InstallerTool implements JUMPPresentationModule {
036:
037: static private boolean verbose;
038: private String installToolArgs[] = null;
039:
040: /**
041: * Create an instance of InstallerTool
042: */
043: public InstallerTool() {
044: }
045:
046: /**
047: * This method converts the executive properties into
048: * application arguments that the JUMPInstallerTool recognizes.
049: */
050: private String[] parseToolProperties(Map map) {
051: String str[] = null;
052:
053: String arg1 = (String) map
054: .get("jump.presentation.installer.arg1");
055: String arg2 = (String) map
056: .get("jump.presentation.installer.arg2");
057: String arg3 = (String) map
058: .get("jump.presentation.installer.arg3");
059: String verbose = (String) map.get("jump.installer.verbose");
060:
061: trace("********************************");
062: trace("parseToolProperties() arg1: " + arg1);
063: trace("parseToolProperties() arg2: " + arg2);
064: trace("parseToolProperties() arg3: " + arg3);
065: trace("********************************");
066:
067: String command = arg1;
068: if (command.equals("install")) {
069: if (arg2 != null) {
070: str = new String[4];
071: str[0] = "-command";
072: str[1] = command;
073: str[2] = "-DescriptorURI";
074: str[3] = arg2;
075: } else {
076: System.err
077: .println("ERROR: A content descriptor file has not been specified.");
078: return null;
079: }
080: } else if (command.equals("install_all")) {
081: str = new String[6];
082: str[0] = "-command";
083: str[1] = command;
084: str[2] = "-DescriptorURI";
085: str[3] = arg2;
086: str[4] = "-ProvisioningServerURL";
087: str[5] = (String) map.get("jump.installer.provisionURL");
088: } else if (command.equals("uninstall")) {
089: str = new String[6];
090: str[0] = "-command";
091: str[1] = command;
092: str[2] = "-type";
093: str[3] = arg2;
094: str[4] = "-id";
095: str[5] = arg3;
096: } else if (command.equals("info") || command.equals("list")
097: || command.equals("uninstall_all")) {
098: str = new String[2];
099: str[0] = "-command";
100: str[1] = command;
101: } else {
102: System.err.println("ERROR: Unknown command given: "
103: + command);
104: return null;
105: }
106:
107: // Append the -verbose option if needed.
108: String newStr[] = null;
109: if (verbose != null && verbose.toLowerCase().equals("true")) {
110: newStr = new String[str.length + 1];
111: System.arraycopy(str, 0, newStr, 0, str.length);
112: newStr[str.length] = "-verbose";
113: return newStr;
114: }
115:
116: return str;
117: }
118:
119: /**
120: * load the presentation module
121: * @param map the configuration data required for loading this module.
122: */
123: public void load(Map map) {
124: // check if verbose mode is used
125: String verboseStr = System
126: .getProperty("jump.presentation.verbose");
127: if (verboseStr == null && map != null) {
128: verboseStr = (String) map.get("jump.presentation.verbose");
129: }
130: if (verboseStr != null
131: && verboseStr.toLowerCase().equals("true")) {
132: verbose = true;
133: }
134:
135: // convert the properties into application arguments for the tool
136: installToolArgs = parseToolProperties(map);
137: }
138:
139: /**
140: * Stop this Presentation Mode from running.
141: */
142: public void stop() {
143: }
144:
145: /**
146: * Unload this module
147: */
148: public void unload() {
149: }
150:
151: static void trace(String str) {
152: if (verbose) {
153: System.out.println(str);
154: }
155: }
156:
157: /**
158: * Implementation of the interface's start() method.
159: */
160: public void start() {
161: System.out.println("*** Starting InstallerTool ***");
162: new JUMPInstallerTool(installToolArgs);
163: // shut down the server
164: new com.sun.jumpimpl.os.JUMPOSInterfaceImpl().shutdownServer();
165: System.exit(0);
166: }
167: }
|