midletinstallerimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 476 行 · 第 1/2 页
JAVA
476 行
/* * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.midp.jump.installer;import com.sun.jump.common.JUMPApplication;import com.sun.jump.module.download.JUMPDownloadDescriptor;import com.sun.jump.common.JUMPContent;import com.sun.jump.module.installer.JUMPInstallerModule;import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStreamReader;import java.net.URL;import java.util.ArrayList;import java.util.Map;import java.util.Properties;import com.sun.midp.installer.InvalidJadException;import com.sun.midp.jump.MIDletApplication;import com.sun.midp.jump.JumpInit;import com.sun.midp.jump.midletsuite.MIDletSuiteStorageAccessor;/** * <code>JUMPInstallerModule</code> provides the ability to install * content. * Installers have to implement this interface. They can optionally derive from * {@link com.sun.jump.module.contentstore.JUMPContentStore} in their * implementation for flexible storage options and abstractions. */public class MIDLETInstallerImpl implements JUMPInstallerModule { JUMPInstallerInterface installer = null; StorageAccessInterface suiteStore = null; private static String midpHomeKey = "sun.midp.home.path"; public void unload() { } public void load(Map map) { String homeDir = (String) map.get(midpHomeKey); JumpInit.init(homeDir); installer = new JUMPFileInstaller(); suiteStore = new MIDletSuiteStorageAccessor(); } /** * Install content specified by the given descriptor and location. * @return the installed content */ public JUMPContent[] install(URL location, JUMPDownloadDescriptor desc) { return installOrUpdate(location, desc, false); } /** * Update content from given location */ public void update(JUMPContent content, URL location, JUMPDownloadDescriptor desc) { installOrUpdate(location, desc, true); } private JUMPContent[] installOrUpdate(URL location, JUMPDownloadDescriptor desc, boolean isUpdate) { String path = location.getPath().toLowerCase(); // below for more details. String bundleName = desc.getName(); if (bundleName != null) { // We need to replace spaces because apparently java doesn't like // jarfiles with spaces in the name. Any further string // substitutions should be done here. bundleName = bundleName.replace(' ', '_'); } String localJadFile = null; String localJarFile = null; try { Properties prop = desc.getApplications()[0]; localJadFile = prop.getProperty("JUMPApplication_localJadUrl"); localJarFile = location.getPath(); int suiteId = 0; if (localJadFile != null) { suiteId = installer.verifyAndStoreSuite(desc.getObjectURI(), null, localJadFile, localJarFile, isUpdate); } else if (path.endsWith(".jar")) { suiteId = installer .verifyAndStoreSuite(desc.getObjectURI(), localJarFile, bundleName, isUpdate); } else { System.err.println("install() failed, path not a jar file: " + location); return null; } // Install succeeded. Gather the installed midlet suite's info // from suitestore and convert them to a list of JUMPContents. JUMPContent[] installed = suiteStore .convertToMIDletApplications(suiteId); return installed; } catch (Throwable ex) { handleInstallerException(ex); } finally { // File localJad = new File(localJadFile); // if (localJad.exists()) { // localJad.delete(); // } // File localJar = new File(localJarFile); // if (localJar.exists()) { // localJar.delete(); // } } return null; } /** * Uninstall content */ public void uninstall(JUMPContent content) { MIDletApplication midlet = (MIDletApplication) content; JUMPContent midlets[] = suiteStore .convertToMIDletApplications(midlet.getMIDletSuiteID()); if (midlets.length > 1) { System.out.println("MIDLET suite: " + midlet.getTitle() + " contains the following midlets."); System.out.print(" "); for (int i = 0; i < midlets.length; i++) { JUMPApplication app = (JUMPApplication)midlets[i]; System.out.print(app.getTitle()); if (i < (midlets.length - 1)) { System.out.print(", "); } } System.out.println(""); System.out.println("Deleting this suite will remove all" + " of the midlets."); // while ( true ) { // System.out.println("Do you wish to proceed: [y/n]"); // BufferedReader in = // new BufferedReader( new InputStreamReader( System.in ) ); // String answer; // // try { // answer = in.readLine(); // } catch ( java.io.IOException ioe ) { // continue; // } // // if (answer.toLowerCase().equals("y")) { // break; // } else if (answer.toLowerCase().equals("n")){ // return; // } else { // System.out.println("ERROR: Illegal response."); // } // } } suiteStore.remove(midlet.getMIDletSuiteID()); } /** * Get all installed content */ public JUMPContent[] getInstalled() { ArrayList appslist = new ArrayList(); JUMPContent[] apps; int[] suiteIds = suiteStore.getInstalledMIDletSuiteIds(); for (int i = 0; i < suiteIds.length; i++) { apps = suiteStore.convertToMIDletApplications(suiteIds[i]); for (int j = 0; j < apps.length; j++) { appslist.add(apps[j]); } } return (JUMPContent[])appslist.toArray(new JUMPContent[] {}); } /** * Converts a pair suite id and midlet class name into * <code>MIDletApplication</code>. * * @param midletSuiteId <code>MIDlet</code> suite ID * @param midletClassName name of <code>MIDlet</code> class * * @return instance of <code>MIDletApplication</code> or <code>null</code> * if there is no matching instance */ public MIDletApplication getMIDletApplication( final int midletSuiteId, final String midletClassName) { final MIDletApplication [] apps = (MIDletApplication []) suiteStore.convertToMIDletApplications(midletSuiteId);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?