⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javaemulatordeviceimporter.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2003-2007 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 */
package eclipseme.core.model.impl;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import org.eclipse.core.runtime.IStatus;

import eclipseme.core.importer.IDeviceImporter;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.preverifier.EmbeddedPreverifier;
import eclipseme.core.model.IPreverifier;

/**
 * Provides common support operations for use in emulators that are launched
 * as Java classes.
 * <p />
 * Copyright (c) 2003-2007 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision$
 * <br>
 * $Date$
 * <br>
 * @author Craig Setera
 */
public abstract class JavaEmulatorDeviceImporter implements IDeviceImporter {
	private static final String ATTR_MAIN_CLASS = "Main-Class";

	protected Properties deviceProperties;

	/**
	 * Return a boolean indicating whether the specified JAR file has a
	 * main class attribute of the specified class name.
	 * 
	 * @param file
	 * @param classname
	 * @return
	 * @throws IOException
	 */
	protected boolean hasMainClassAttribute(File file, String classname)
		throws IOException
	{
		JarFile jarFile = new JarFile(file);
		Manifest manifest = jarFile.getManifest();
		Attributes attributes = manifest.getMainAttributes();
		String mainClass = attributes.getValue(ATTR_MAIN_CLASS);
		
		return ((mainClass != null) && mainClass.trim().equals(classname));
	}

	/**
	 * Return a boolean indicating whether this device acts as a debug server.
	 * 
	 * @return
	 */
	protected boolean isDebugServer() {
		return getDeviceProperties().getProperty("debug.server", "false").equalsIgnoreCase("true");
	}

	/**
	 * Return the device definition properties.
	 * 
	 * @return
	 */
	protected Properties getDeviceProperties() {
		if (deviceProperties == null) {
			deviceProperties = readDeviceProperties();
		}
		
		return deviceProperties;
	}

	/**
	 * Return the URL to access the device properties file.
	 * 
	 * @return
	 */
	protected abstract URL getDevicePropertiesURL();

	/**
	 * Read in the device properties
	 * 
	 * @return
	 */
	private Properties readDeviceProperties() {
		// Read the properties the define the device data
		Properties deviceProperties = new Properties();
		
		InputStream propertiesStream = null;
		try {
			URL propsFileURL = getDevicePropertiesURL();
			
			propertiesStream = propsFileURL.openStream();
			if (propertiesStream != null) {
				deviceProperties.load(propertiesStream);
			}
			
		} catch (IOException e) {
			EclipseMECorePlugin.log(IStatus.ERROR, "Error loading device properties", e);
		} finally {
			if (propertiesStream != null) {
				try { propertiesStream.close(); } catch (IOException e) {}
			}
		}
		
		return deviceProperties;
	}

	/**
	 * Return the preverifier to use.
	 * 
	 * @param jarFile
	 * @return
	 */
	protected IPreverifier getPreverifier(File jarFile) {
		return new EmbeddedPreverifier();
	}

	/**
	 * Return the launch command template.
	 * @return
	 */
	protected String getLaunchCommand() {
		return getDeviceProperties().getProperty("launch.command", "");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -