harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r660326 [12/17] - in /harmony/enhanced/microemulator: ./ microemu-android/ microemu-android/src/ microemu-android/src/org/ microemu-android/src/org/microemu/ microemu-android/src/org/microemu/android/ microemu-android/src/org/microemu/andro...
Date Mon, 26 May 2008 22:21:57 GMT
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletSystemProperties.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletSystemProperties.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletSystemProperties.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletSystemProperties.java Mon May 26 15:20:19 2008
@@ -0,0 +1,216 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import org.microemu.device.Device;
+import org.microemu.log.Logger;
+
+/**
+ * @author vlads
+ * 
+ * This class is called by MIDlet to access System Property. Call injection is
+ * made by MIDlet ClassLoaded
+ * 
+ */
+public class MIDletSystemProperties {
+
+	/**
+	 * This may be a configuration option. But not for applet and Web Start.
+	 */
+	public static boolean applyToJavaSystemProperties = true;
+
+	/**
+	 * Permits null values.
+	 */
+	private static final Map props = new HashMap();
+
+	private static Map systemPropertiesPreserve;
+
+	private static List systemPropertiesDevice;
+
+	private static boolean wanrOnce = true;
+
+	private static boolean initialized = false;
+
+	/* The context to be used when starting MicroEmulator */
+	private static AccessControlContext acc;
+
+	private static void initOnce() {
+		// Can't use static initializer because of applyToJavaSystemProperties
+		// in applet
+		if (initialized) {
+			return;
+		}
+		initialized = true;
+		// This are set in Config
+		// setProperty("microedition.configuration", "CLDC-1.1");
+		// setProperty("microedition.profiles", "MIDP-2.0");
+		setProperty("microedition.platform", "MicroEmulator");
+		setProperty("microedition.encoding", getSystemProperty("file.encoding"));
+	}
+
+	/**
+	 * Allow Access to system properties from MIDlet
+	 */
+	public static void initContext() {
+		acc = AccessController.getContext();
+	}
+
+	/**
+	 * Gets the system property indicated by the specified key. The only
+	 * function called by MIDlet
+	 * 
+	 * @param key
+	 *            the name of the system property
+	 * @return
+	 */
+	public static String getProperty(String key) {
+		initOnce();
+		if (props.containsKey(key)) {
+			return (String) props.get(key);
+		}
+		String v = getDynamicProperty(key);
+		if (v != null) {
+			return v;
+		}
+		try {
+			return getSystemProperty(key);
+		} catch (SecurityException e) {
+			return null;
+		}
+	}
+
+	public static String getSystemProperty(String key) {
+		try {
+			if (acc != null) {
+				return getSystemPropertySecure(key);
+			} else {
+				return System.getProperty(key);
+			}
+		} catch (SecurityException e) {
+			return null;
+		}
+	}
+
+	private static String getSystemPropertySecure(final String key) {
+		try {
+			return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
+				public Object run() {
+					return System.getProperty(key);
+				}
+			}, acc);
+		} catch (Throwable e) {
+			return null;
+		}
+	}
+
+	private static String getDynamicProperty(String key) {
+		if (key.equals("microedition.locale")) {
+			return Locale.getDefault().getLanguage();
+		}
+		return null;
+	}
+
+	public static Set getPropertiesSet() {
+		initOnce();
+		return props.entrySet();
+	}
+
+	public static String setProperty(String key, String value) {
+		initOnce();
+		if (applyToJavaSystemProperties) {
+			try {
+				if (value == null) {
+					System.getProperties().remove(key);
+				} else {
+					System.setProperty(key, value);
+				}
+			} catch (SecurityException e) {
+				if (wanrOnce) {
+					wanrOnce = false;
+					Logger.error("Cannot update Java System.Properties", e);
+					Logger.debug("Continue ME2 operations with no updates to system Properties");
+				}
+			}
+		}
+		return (String) props.put(key, value);
+	}
+
+	public static String clearProperty(String key) {
+		if (applyToJavaSystemProperties) {
+			try {
+				System.getProperties().remove(key);
+			} catch (SecurityException e) {
+				if (wanrOnce) {
+					wanrOnce = false;
+					Logger.error("Cannot update Java System.Properties", e);
+				}
+			}
+		}
+		return (String) props.remove(key);
+	}
+
+	public static void setProperties(Map properties) {
+		initOnce();
+		for (Iterator i = properties.entrySet().iterator(); i.hasNext();) {
+			Map.Entry e = (Map.Entry) i.next();
+			setProperty((String) e.getKey(), (String) e.getValue());
+		}
+	}
+
+	public static void setDevice(Device newDevice) {
+		initOnce();
+		// Restore System Properties from previous device activation.
+		if (systemPropertiesDevice != null) {
+			for (Iterator iter = systemPropertiesDevice.iterator(); iter.hasNext();) {
+				clearProperty((String) iter.next());
+			}
+		}
+		if (systemPropertiesPreserve != null) {
+			for (Iterator i = systemPropertiesPreserve.entrySet().iterator(); i.hasNext();) {
+				Map.Entry e = (Map.Entry) i.next();
+				setProperty((String) e.getKey(), (String) e.getValue());
+			}
+		}
+		systemPropertiesDevice = new Vector();
+		systemPropertiesPreserve = new HashMap();
+		for (Iterator i = newDevice.getSystemProperties().entrySet().iterator(); i.hasNext();) {
+			Map.Entry e = (Map.Entry) i.next();
+			String key = (String) e.getKey();
+			if (props.containsKey(key)) {
+				systemPropertiesPreserve.put(key, props.get(key));
+			} else {
+				systemPropertiesDevice.add(key);
+			}
+			setProperty(key, (String) e.getValue());
+		}
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletSystemProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletThread.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletThread.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletThread.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletThread.java Mon May 26 15:20:19 2008
@@ -0,0 +1,159 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.microemu.MIDletBridge;
+import org.microemu.MIDletContext;
+import org.microemu.log.Logger;
+import org.microemu.util.ThreadUtils;
+
+/**
+ * MIDletContext is used to hold keys to running Threads created by  MIDlet  
+ * 
+ * @author vlads
+ */
+public class MIDletThread extends Thread {
+
+	public static int graceTerminationPeriod = 5000;
+	
+	private static final String THREAD_NAME_PREFIX = "MIDletThread-";
+	
+	private static boolean terminator = false;
+	
+	private static Map midlets = new WeakHashMap();
+	
+    private static int threadInitNumber;
+    
+    private String callLocation;
+    
+    private static synchronized int nextThreadNum() {
+    	return threadInitNumber++;
+    }
+    
+	public MIDletThread() {
+		super(THREAD_NAME_PREFIX + nextThreadNum());
+		register(this);
+	}
+	
+	public MIDletThread(Runnable target) {
+		super(target, THREAD_NAME_PREFIX + nextThreadNum());
+		register(this);
+	}
+	
+	public MIDletThread(Runnable target, String name) {
+		super(target, THREAD_NAME_PREFIX + name);
+		register(this);
+	}
+	
+	public MIDletThread(String name) {
+		super(THREAD_NAME_PREFIX + name);
+		register(this);
+	}
+	
+	private static void register(MIDletThread thread) {
+		MIDletContext midletContext = MIDletBridge.getMIDletContext();
+		if (midletContext == null) {
+			Logger.error("Creating thread with no MIDlet context", new Throwable());
+			return;
+		}
+		thread.callLocation  = ThreadUtils.getCallLocation(MIDletThread.class.getName());
+		Map threads = (Map)midlets.get(midletContext);
+		if (threads == null) {
+			threads = new WeakHashMap();
+			midlets.put(midletContext, threads);
+		}
+		threads.put(thread, midletContext);
+	}
+	
+	//TODO overrite run() in user Threads using ASM
+	public void run() {
+		 try {
+			super.run();
+		} catch (Throwable e) {
+			Logger.debug("MIDletThread throw", e);
+		}
+		//Logger.debug("thread ends, created from " + callLocation);	
+	 }
+	
+	/**
+	 * Terminate all Threads created by MIDlet
+	 * @param previousMidletAccess
+	 */
+	public static void contextDestroyed(final MIDletContext midletContext) {
+		if (midletContext == null) {
+			return;
+		}
+		final Map threads = (Map)midlets.remove(midletContext);
+		if ((threads != null) && (threads.size() != 0)) {
+			terminator = true;
+			Thread terminator = new Thread("MIDletThreadsTerminator") {
+				public void run() {
+					terminateThreads(threads);
+				}
+			};
+			terminator.start();
+		}
+		MIDletTimer.contextDestroyed(midletContext);
+	}
+	
+	public static boolean hasRunningThreads(MIDletContext midletContext) {
+		//return (midlets.get(midletContext) != null);
+		return terminator;
+	}
+	
+	private static void terminateThreads(Map threads) {
+		long endTime = System.currentTimeMillis() + graceTerminationPeriod;
+		for (Iterator iter = threads.keySet().iterator(); iter.hasNext();) {
+			Object o = iter.next();
+			if (o == null) {
+				continue;
+			}
+			if (o instanceof MIDletThread) {
+				MIDletThread t = (MIDletThread) o;
+				if (t.isAlive()) {
+					Logger.info("wait thread [" + t.getName() + "] end");
+					while ((endTime > System.currentTimeMillis()) && (t.isAlive())) {
+						try {
+							t.join(700);
+						} catch (InterruptedException e) {
+							break;
+						}
+					}
+					if (t.isAlive()) {
+						Logger.warn("MIDlet thread [" + t.getName() + "] still running" + ThreadUtils.getTreadStackTrace(t));
+						if (t.callLocation != null) {
+							Logger.info("this thread [" + t.getName() + "] was created from " + t.callLocation);
+						}
+						t.interrupt();
+					}
+				}
+			} else {
+				Logger.debug("unrecognized Object [" + o.getClass().getName() + "]");
+			}
+		};
+		Logger.debug("all "+ threads.size() + " thread(s) finished");
+		terminator = false;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletThread.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletTimer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletTimer.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletTimer.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletTimer.java Mon May 26 15:20:19 2008
@@ -0,0 +1,168 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.WeakHashMap;
+
+import org.microemu.MIDletBridge;
+import org.microemu.MIDletContext;
+import org.microemu.log.Logger;
+
+/**
+ * Terminate all timers on MIDlet exit.
+ * TODO Name all the timer Threads created by MIDlet in Java 5  
+ * @author vlads
+ */
+public class MIDletTimer extends Timer {
+
+	private static Map midlets = new WeakHashMap();
+	
+	private class OneTimeTimerTaskWrapper extends TimerTask {
+
+		TimerTask task;
+		
+		OneTimeTimerTaskWrapper(TimerTask task) {
+			this.task = task;
+		}
+		
+		public void run() {
+			unregister(MIDletTimer.this);
+			task.run();
+		}
+		
+	}
+	
+	private String name;
+	
+	private MIDletContext midletContext;
+	
+	public MIDletTimer() {
+		super();
+		StackTraceElement[] ste = new Throwable().getStackTrace();
+		name = ste[1].getClassName() + "." + ste[1].getMethodName(); 
+	}
+	
+	public void schedule(TimerTask task, Date time) {
+		register(this);
+		super.schedule(new OneTimeTimerTaskWrapper(task), time);
+	}
+	
+	public void schedule(TimerTask task, Date firstTime, long period) {
+		register(this);
+		super.schedule(task, firstTime, period);
+	}
+	
+	public void schedule(TimerTask task, long delay) {
+		register(this);
+		super.schedule(new OneTimeTimerTaskWrapper(task), delay);
+	}
+	
+	public void schedule(TimerTask task, long delay, long period) {
+		register(this);
+		super.schedule(task, delay, period);
+	}
+	
+	public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period) {
+		register(this);
+		super.schedule(task, firstTime, period);
+	}
+	
+	public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
+		register(this);
+		super.scheduleAtFixedRate(task, delay, period);
+	}
+	
+	public void cancel() {
+    	unregister(this);
+		super.cancel();
+	}
+
+	private void terminate() {
+		super.cancel();
+	}
+	
+	private static void register(MIDletTimer timer) {
+		if (timer.midletContext == null) {
+			timer.midletContext = MIDletBridge.getMIDletContext();
+		}
+		if (timer.midletContext == null) {
+			Logger.error("Creating Timer with no MIDlet context", new Throwable());
+			return;
+		}
+		Map timers = (Map)midlets.get(timer.midletContext);
+		if (timers == null) {
+			// Can't use WeakHashMap Timers are disposed by JVM
+			timers = new HashMap();
+			midlets.put(timer.midletContext, timers);
+		}
+		//Logger.debug("Register timer created from [" + timer.name + "]");
+		timers.put(timer, timer.midletContext);
+	}
+	
+	private static void unregister(MIDletTimer timer) {
+		if (timer.midletContext == null) {
+			Logger.error("Timer with no MIDlet context", new Throwable());
+			return;
+		}
+		Map timers = (Map)midlets.get(timer.midletContext);
+		if (timers == null) {
+			return;
+		}
+		//Logger.debug("Unregister timer created from [" + timer.name + "]");
+		timers.remove(timer);
+	}
+	
+	/**
+	 * Termnate all Threads created by MIDlet
+	 */
+	public static void contextDestroyed(MIDletContext midletContext) {
+		if (midletContext == null) {
+			return;
+		}
+		Map timers = (Map)midlets.get(midletContext);
+		if (timers != null) {
+			terminateTimers(timers);
+			midlets.remove(midletContext);
+		}
+	}
+	
+	private static void terminateTimers(Map timers) {
+		for (Iterator iter = timers.keySet().iterator(); iter.hasNext();) {
+			Object o = iter.next();
+			if (o == null) {
+				continue;
+			}
+			if (o instanceof MIDletTimer) {
+				MIDletTimer tm = (MIDletTimer)o;
+				Logger.warn("MIDlet timer created from [" + tm.name + "] still running");
+				tm.terminate();
+			} else {
+				Logger.debug("unrecognized Object [" + o.getClass().getName() + "]");
+			}
+		};
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MIDletTimer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUList.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUList.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUList.java Mon May 26 15:20:19 2008
@@ -0,0 +1,137 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.Stack;
+
+import nanoxml.XMLElement;
+
+/**
+ * 
+ * Most Recently Used (MRU) list
+ * 
+ * @author vlads
+ */
+public class MRUList implements XMLItem {
+
+	private static final long serialVersionUID = 1L;
+	
+	protected int maxCapacity;
+
+	private Stack items = new Stack/*<XMLItem>*/(); 
+	
+	private String itemsName;
+	
+	private Class classXMLItem;
+	
+	private MRUListListener listener;
+	
+	private boolean modified = true;
+	
+	public MRUList(Class classXMLItem, String itemsName) {
+		this.classXMLItem = classXMLItem;
+		this.itemsName = itemsName;
+	}
+	
+	public Object push(Object item) {
+		if (!(item instanceof XMLItem)) {
+			throw new ClassCastException(item.getClass().getName());
+		}
+		modified = true;
+		if (items.size() > maxCapacity) {
+			items.pop();
+		}
+		items.remove(item);
+		if (items.empty()) {
+			items.add(item);
+		} else {
+			items.insertElementAt(item, 0);
+		}
+		fireListener(item);
+		return item;
+	}
+
+	private void fireListener(Object item) {
+		if (this.listener != null) {
+			this.listener.listItemChanged(item);
+		}
+	
+	}
+	
+	public void setListener(MRUListListener l) {
+		if (this.listener != null) {
+			throw new IllegalArgumentException();
+		}
+		this.listener = l;
+	}
+	
+	public int getMaxCapacity() {
+		return maxCapacity;
+	}
+
+	public void setMaxCapacity(int maxCapacity) {
+		this.maxCapacity = maxCapacity;
+	}
+
+	public void save(XMLElement xml) {
+		if (!modified) {
+			return;
+		}
+		xml.removeChildren();
+		xml.setAttribute("maxCapacity", String.valueOf(maxCapacity));
+		for (Iterator iter = items.iterator(); iter.hasNext();) {
+			XMLItem element = (XMLItem) iter.next();
+			element.save(xml.addChild(itemsName));
+		}
+		modified = false;
+	}
+	
+	public void read(XMLElement xml) {
+		modified = false;
+		items.removeAllElements();
+		this.maxCapacity = xml.getIntAttribute("maxCapacity", 10);
+		for (Enumeration en = xml.enumerateChildren(); en.hasMoreElements(); ) {
+            XMLElement xmlChild = (XMLElement) en.nextElement();
+            if (xmlChild.getName().equals(itemsName)) {
+				try {
+					XMLItem element = (XMLItem)classXMLItem.newInstance();
+					element.read(xmlChild);
+					items.add(element);
+				} catch (InstantiationException e) {
+					throw new RuntimeException(e);
+				} catch (IllegalAccessException e) {
+					throw new RuntimeException(e);
+				}
+            }
+        }
+		
+		if (!items.empty()) {
+			// Fire Listener in reverse order
+			for (ListIterator iter = items.listIterator(items.size()); iter.hasPrevious();) {
+				XMLItem element = (XMLItem) iter.previous();
+				fireListener(element);
+			}
+		}
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUListListener.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUListListener.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUListListener.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUListListener.java Mon May 26 15:20:19 2008
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+/**
+ * @author vlads
+ *
+ */
+public interface MRUListListener {
+
+	public void listItemChanged(Object item);
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MRUListListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MidletURLReference.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MidletURLReference.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MidletURLReference.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MidletURLReference.java Mon May 26 15:20:19 2008
@@ -0,0 +1,126 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+
+import org.microemu.log.Logger;
+
+/**
+ * @author vlads
+ *
+ */
+public class MidletURLReference implements XMLItem {
+
+
+	private String name;
+	
+	private String url;
+
+	public MidletURLReference() {
+		super();
+	}
+	
+	/**
+	 * @param name MIDlet name
+	 * @param url  URL to locate this URL
+	 */
+	public MidletURLReference(String name, String url) {
+		super();
+		this.name = name;
+		this.url = url;
+	}
+
+	public boolean equals(Object obj) {
+		 if (!(obj instanceof MidletURLReference)) {
+			 return false;
+		 }
+		 return ((MidletURLReference)obj).url.equals(url); 
+	}
+	 
+	public String toString() {
+		// make the text presentation shorter.
+		URL u;
+		try {
+			u = new URL(url);
+		} catch (MalformedURLException e) {
+			Logger.error(e);
+			return url;
+		}
+		StringBuffer b = new StringBuffer();
+		
+		String scheme = u.getProtocol();
+		if (scheme.equals("file") || scheme.startsWith("http")) {
+			b.append(scheme).append("://");
+			if (u.getHost() != null) {
+				b.append(u.getHost());
+			}
+			Vector pathComponents = new Vector();
+			final String pathSeparator = "/";
+			StringTokenizer st = new StringTokenizer(u.getPath(), pathSeparator);
+			while (st.hasMoreTokens()) {
+				pathComponents.add(st.nextToken());
+			}
+			if (pathComponents.size() > 3) {
+				b.append(pathSeparator);
+				b.append(pathComponents.get(0));
+				b.append(pathSeparator).append("...").append(pathSeparator);
+				b.append(pathComponents.get(pathComponents.size()-2));
+				b.append(pathSeparator);
+				b.append(pathComponents.get(pathComponents.size()-1));
+			} else {
+				b.append(u.getPath());
+			}
+			
+		} else {
+			b.append(url);
+		}
+		if (name != null) {
+			b.append(" - ");
+			b.append(name);
+		}
+		return b.toString();
+	}
+	
+	public void read(XMLElement xml) {
+		name = xml.getChildString("name", "");
+		url = xml.getChildString("url", "");
+	}
+
+	public void save(XMLElement xml) {
+		xml.removeChildren();
+		xml.addChild("name", name);
+		xml.addChild("url", url);
+	}
+
+	public String getName() {
+		return this.name;
+	}
+
+	public String getUrl() {
+		return this.url;
+	}
+	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/MidletURLReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLConnection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLConnection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLConnection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Hashtable;
+
+public class ResURLConnection extends URLConnection {
+	
+	private static final String PREFIX = "res:";
+
+	private Hashtable entries;
+	
+	protected ResURLConnection(URL url, Hashtable entries) {
+		super(url);
+		
+		this.entries = entries;
+	}
+
+	public void connect() throws IOException {
+	}
+
+	public InputStream getInputStream() throws IOException {
+		String location = url.toString();
+		int idx = location.indexOf(PREFIX);
+		if (idx == -1) {
+			throw new IOException();
+		}
+		location = location.substring(idx + PREFIX.length());
+		byte[] data = (byte[]) entries.get(location);
+		if (data == null) {
+			throw new IOException();
+		}
+		return new ByteArrayInputStream(data);
+	}
+	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLStreamHandler.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLStreamHandler.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLStreamHandler.java Mon May 26 15:20:19 2008
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.Hashtable;
+
+
+
+public class ResURLStreamHandler extends URLStreamHandler {
+
+	private Hashtable entries;
+	
+	public ResURLStreamHandler(Hashtable entries)
+	{
+		this.entries = entries;
+	}
+	
+	protected URLConnection openConnection(URL url) throws IOException {
+		return new ResURLConnection(url, entries);
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/ResURLStreamHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/SystemClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/SystemClassLoader.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/SystemClassLoader.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/SystemClassLoader.java Mon May 26 15:20:19 2008
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import java.net.URL;
+
+/**
+ * 
+ * @deprecated use MIDletClassLoader 
+ */
+public class SystemClassLoader /*extends ClassLoader*/ {
+	
+//	private static MIDletClassLoader childClassLoader = null; 
+//	
+//	public SystemClassLoader(ClassLoader parent) {
+//		super(parent);
+//		
+//		if (this instanceof MIDletClassLoader) {
+//			childClassLoader = (MIDletClassLoader) this;
+//		}
+//	}
+//
+//	protected URL findResource(String name) {
+//		URL result = null;
+//		
+//		if (childClassLoader != null) {
+//			result = childClassLoader.findResource(name);
+//		}
+//		
+//		return result;
+//	}
+//	
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/SystemClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/XMLItem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/XMLItem.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/XMLItem.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/XMLItem.java Mon May 26 15:20:19 2008
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.app.util;
+
+import nanoxml.XMLElement;
+
+public interface XMLItem {
+
+	public void save(XMLElement xml);
+	
+	public void read(XMLElement xml);
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/util/XMLItem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/CertificateImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/CertificateImpl.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/CertificateImpl.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/CertificateImpl.java Mon May 26 15:20:19 2008
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc;
+
+import java.security.cert.X509Certificate;
+
+import javax.microedition.pki.Certificate;
+
+public class CertificateImpl implements Certificate {
+	
+	private X509Certificate cert;
+
+	public CertificateImpl(X509Certificate cert) {
+		this.cert = cert;
+	}
+
+	public String getIssuer() {
+		return cert.getIssuerDN().getName();
+	}
+
+	public long getNotAfter() {
+		return cert.getNotAfter().getTime();
+	}
+
+	public long getNotBefore() {
+		return cert.getNotBefore().getTime();
+	}
+
+	public String getSerialNumber() {
+		return cert.getSerialNumber().toString();
+	}
+
+	public String getSigAlgName() {
+		return cert.getSigAlgName();
+	}
+
+	public String getSubject() {
+		return cert.getSubjectDN().getName();
+	}
+
+	public String getType() {
+		return cert.getType();
+	}
+
+	public String getVersion() {
+		return Integer.toString(cert.getVersion());
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/CertificateImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/SecurityInfoImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/SecurityInfoImpl.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/SecurityInfoImpl.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/SecurityInfoImpl.java Mon May 26 15:20:19 2008
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc;
+
+import javax.microedition.io.SecurityInfo;
+import javax.microedition.pki.Certificate;
+import org.microemu.log.Logger;
+
+public class SecurityInfoImpl implements SecurityInfo {
+
+	private String cipherSuite;
+	private String protocolName;
+	private Certificate certificate;
+
+	public SecurityInfoImpl(String cipherSuite, String protocolName, Certificate certificate) {
+		this.cipherSuite = cipherSuite;
+		this.protocolName = protocolName;
+		this.certificate = certificate;
+	}
+
+	public String getCipherSuite() {
+		return cipherSuite;
+	}
+
+	public String getProtocolName() {
+		if (protocolName.startsWith("TLS")) {
+			return "TLS";
+		} else if (protocolName.startsWith("SSL")) {
+			return "SSL";
+		} else {
+			// TODO Auto-generated method stub
+			try {
+				throw new RuntimeException();
+			} catch (RuntimeException ex) {
+				Logger.error(ex);
+				throw ex;
+			}
+		}
+	}
+
+	public String getProtocolVersion() {
+		if (protocolName.startsWith("TLS")) {
+			return "3.1";
+		} else if (getProtocolName().equals("SSL")) {
+			return "3.0";
+		} else {
+			// TODO Auto-generated method stub
+			try {
+				throw new RuntimeException();
+			} catch (RuntimeException ex) {
+				Logger.error(ex);
+				throw ex;
+			}
+		}
+	}
+
+	public Certificate getServerCertificate() {
+		return certificate;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/SecurityInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/http/Connection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/http/Connection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/http/Connection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/http/Connection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,359 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc.http;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.microedition.io.HttpConnection;
+
+import org.microemu.microedition.io.ConnectionImplementation;
+
+public class Connection implements HttpConnection, ConnectionImplementation {
+	
+	protected URLConnection cn;
+
+	protected boolean connected = false;
+	
+	protected static boolean allowNetworkConnection = true;
+
+	public javax.microedition.io.Connection openConnection(String name, int mode, boolean timeouts) throws IOException {
+		if (!isAllowNetworkConnection()) {
+			throw new IOException("No network");
+		}
+		URL url;
+		try {
+			url = new URL(name);
+		} catch (MalformedURLException ex) {
+			throw new IOException(ex.toString());
+		}
+		cn = url.openConnection();
+		cn.setDoOutput(true);
+
+		return this;
+	}
+
+	public void close() throws IOException {
+		if (cn == null) {
+			return;
+		}
+
+		if (cn instanceof HttpURLConnection) {
+			((HttpURLConnection) cn).disconnect();
+		}
+
+		cn = null;
+	}
+
+	public String getURL() {
+		if (cn == null) {
+			return null;
+		}
+
+		return cn.getURL().toString();
+	}
+
+	public String getProtocol() {
+		return "http";
+	}
+
+	public String getHost() {
+		if (cn == null) {
+			return null;
+		}
+
+		return cn.getURL().getHost();
+	}
+
+	public String getFile() {
+		if (cn == null) {
+			return null;
+		}
+
+		return cn.getURL().getFile();
+	}
+
+	public String getRef() {
+		if (cn == null) {
+			return null;
+		}
+
+		return cn.getURL().getRef();
+	}
+
+	public String getQuery() {
+		if (cn == null) {
+			return null;
+		}
+
+		//    return cn.getURL().getQuery();
+		return null;
+	}
+
+	public int getPort() {
+		if (cn == null) {
+			return -1;
+		}
+
+		int port = cn.getURL().getPort();
+		if (port == -1) {
+			return 80;
+		}
+		return port;
+	}
+
+	public String getRequestMethod() {
+		if (cn == null) {
+			return null;
+		}
+
+		if (cn instanceof HttpURLConnection) {
+			return ((HttpURLConnection) cn).getRequestMethod();
+		} else {
+			return null;
+		}
+	}
+
+	public void setRequestMethod(String method) throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+
+		if (method.equals(HttpConnection.POST)) {
+			cn.setDoOutput(true);
+		}
+
+		if (cn instanceof HttpURLConnection) {
+			((HttpURLConnection) cn).setRequestMethod(method);
+		}
+	}
+
+	public String getRequestProperty(String key) {
+		if (cn == null) {
+			return null;
+		}
+
+		return cn.getRequestProperty(key);
+	}
+
+	public void setRequestProperty(String key, String value) throws IOException {
+		if (cn == null || connected) {
+			throw new IOException();
+		}
+
+		cn.setRequestProperty(key, value);
+	}
+
+	public int getResponseCode() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		if (cn instanceof HttpURLConnection) {
+			return ((HttpURLConnection) cn).getResponseCode();
+		} else {
+			return -1;
+		}
+	}
+
+	public String getResponseMessage() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		if (cn instanceof HttpURLConnection) {
+			return ((HttpURLConnection) cn).getResponseMessage();
+		} else {
+			return null;
+		}
+	}
+
+	public long getExpiration() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getExpiration();
+	}
+
+	public long getDate() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getDate();
+	}
+
+	public long getLastModified() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getLastModified();
+	}
+
+	public String getHeaderField(String name) throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getHeaderField(name);
+	}
+
+	public int getHeaderFieldInt(String name, int def) throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getHeaderFieldInt(name, def);
+	}
+
+	public long getHeaderFieldDate(String name, long def) throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getHeaderFieldDate(name, def);
+	}
+
+	public String getHeaderField(int n) throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getHeaderField(n);
+	}
+
+	public String getHeaderFieldKey(int n) throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+		if (!connected) {
+			cn.connect();
+			connected = true;
+		}
+
+		return cn.getHeaderFieldKey(n);
+	}
+
+	public InputStream openInputStream() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+
+		connected = true;
+
+		return cn.getInputStream();
+	}
+
+	public DataInputStream openDataInputStream() throws IOException {
+		return new DataInputStream(openInputStream());
+	}
+
+	public OutputStream openOutputStream() throws IOException {
+		if (cn == null) {
+			throw new IOException();
+		}
+
+		connected = true;
+
+		return cn.getOutputStream();
+	}
+
+	public DataOutputStream openDataOutputStream() throws IOException {
+		return new DataOutputStream(openOutputStream());
+	}
+
+	public String getType() {
+		try {
+			return getHeaderField("content-type");
+		} catch (IOException ex) {
+			return null;
+		}
+	}
+
+	public String getEncoding() {
+		try {
+			return getHeaderField("content-encoding");
+		} catch (IOException ex) {
+			return null;
+		}
+	}
+
+	public long getLength() {
+		try {
+			return getHeaderFieldInt("content-length", -1);
+		} catch (IOException ex) {
+			return -1;
+		}
+	}
+
+	public static boolean isAllowNetworkConnection() {
+		return allowNetworkConnection;
+	}
+
+	public static void setAllowNetworkConnection(boolean allowNetworkConnection) {
+		Connection.allowNetworkConnection = allowNetworkConnection;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/http/Connection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/https/Connection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/https/Connection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/https/Connection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/https/Connection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,97 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc.https;
+
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+
+import javax.microedition.io.HttpsConnection;
+import javax.microedition.io.SecurityInfo;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+
+import org.microemu.cldc.CertificateImpl;
+import org.microemu.cldc.SecurityInfoImpl;
+import org.microemu.log.Logger;
+
+public class Connection extends org.microemu.cldc.http.Connection implements HttpsConnection {
+
+	private SSLContext sslContext;
+
+	private SecurityInfo securityInfo;
+
+	public Connection() {
+	    try {
+			sslContext = SSLContext.getInstance("SSL");
+		} catch (NoSuchAlgorithmException ex) {
+			Logger.error(ex);
+		}
+
+		securityInfo = null;
+	}
+
+	public SecurityInfo getSecurityInfo() throws IOException {
+		if (securityInfo == null) {
+		    if (cn == null) {
+				throw new IOException();
+			}
+			if (!connected) {
+				cn.connect();
+				connected = true;
+			}
+			HttpsURLConnection https = (HttpsURLConnection) cn;
+
+			Certificate[] certs = https.getServerCertificates();
+			if (certs.length == 0) {
+				throw new IOException();
+			}
+			securityInfo = new SecurityInfoImpl(
+					https.getCipherSuite(),
+					sslContext.getProtocol(),
+					new CertificateImpl((X509Certificate) certs[0]));
+		}
+
+		return securityInfo;
+	}
+
+	public String getProtocol() {
+		return "https";
+	}
+
+
+    /**
+     * Returns the network port number of the URL for this HttpsConnection
+     *
+     * @return  the network port number of the URL for this HttpsConnection. The default HTTPS port number (443) is returned if there was no port number in the string passed to Connector.open.
+     */
+	public int getPort() {
+		if (cn == null) {
+			return -1;
+		}
+		int port = cn.getURL().getPort();
+		if (port == -1) {
+			return 443;
+		}
+		return port;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/https/Connection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/Connection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/Connection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/Connection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/Connection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc.socket;
+
+import java.io.IOException;
+
+import org.microemu.cldc.ClosedConnection;
+
+public class Connection implements ClosedConnection {
+
+	public javax.microedition.io.Connection open(String name) throws IOException {
+
+		if (!org.microemu.cldc.http.Connection.isAllowNetworkConnection()) {
+			throw new IOException("No network");
+		}
+
+		int portSepIndex = name.lastIndexOf(':');
+		int port = Integer.parseInt(name.substring(portSepIndex + 1));
+		String host = name.substring("socket://".length(), portSepIndex);
+
+		if (host.length() > 0) {
+			return new SocketConnection(host, port);
+		} else {
+			return new ServerSocketConnection(port);
+		}
+	}
+
+	public void close() throws IOException {
+		// Implemented in SocketConnection or ServerSocketConnection
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/Connection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/ServerSocketConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/ServerSocketConnection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/ServerSocketConnection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/ServerSocketConnection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+package org.microemu.cldc.socket;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+
+import javax.microedition.io.StreamConnection;
+
+public class ServerSocketConnection implements
+		javax.microedition.io.ServerSocketConnection {
+	
+	private ServerSocket serverSocket;
+	
+	public ServerSocketConnection(int port) throws IOException {
+		serverSocket = new ServerSocket(port);
+	}
+
+	public String getLocalAddress() throws IOException {
+		InetAddress localHost = InetAddress.getLocalHost();
+		return localHost.getHostAddress();
+	}
+
+	public int getLocalPort() throws IOException {
+		return serverSocket.getLocalPort();
+	}
+
+	public StreamConnection acceptAndOpen() throws IOException {
+		return new SocketConnection(serverSocket.accept());
+	}
+
+	public void close() throws IOException {
+		serverSocket.close();
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/ServerSocketConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/SocketConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/SocketConnection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/SocketConnection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/SocketConnection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,179 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc.socket;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+public class SocketConnection implements javax.microedition.io.SocketConnection {
+
+	protected Socket socket;
+	
+	public SocketConnection() {		
+	}
+
+	public SocketConnection(String host, int port) throws IOException {
+		this.socket = new Socket(host, port);
+	}
+	
+	public SocketConnection(Socket socket) {
+		this.socket = socket;
+	}
+
+	public String getAddress() throws IOException {
+		if (socket == null || socket.isClosed()) {
+			throw new IOException();
+		}
+
+		return socket.getInetAddress().toString();
+	}
+
+	public String getLocalAddress() throws IOException {
+		if (socket == null || socket.isClosed()) {
+			throw new IOException();
+		}
+
+		return socket.getLocalAddress().toString();
+	}
+
+	public int getLocalPort() throws IOException {
+		if (socket == null || socket.isClosed()) {
+			throw new IOException();
+		}
+
+		return socket.getLocalPort();
+	}
+
+	public int getPort() throws IOException {
+		if (socket == null || socket.isClosed()) {
+			throw new IOException();
+		}
+
+		return socket.getPort();
+	}
+
+	public int getSocketOption(byte option) throws IllegalArgumentException,
+			IOException {
+		if (socket != null && socket.isClosed()) {
+			throw new IOException();
+		}
+		switch (option) {
+		case DELAY:
+			if (socket.getTcpNoDelay()) {
+				return 1;
+			} else {
+				return 0;
+			}
+		case LINGER:
+			int value = socket.getSoLinger();
+			if (value == -1) {
+				return 0;
+			} else {
+				return value;
+			}
+		case KEEPALIVE:
+			if (socket.getKeepAlive()) {
+				return 1;
+			} else {
+				return 0;
+			}
+		case RCVBUF:
+			return socket.getReceiveBufferSize();
+		case SNDBUF:
+			return socket.getSendBufferSize();
+		default:
+			throw new IllegalArgumentException();
+		}
+	}
+
+	public void setSocketOption(byte option, int value)
+			throws IllegalArgumentException, IOException {
+		if (socket.isClosed()) {
+			throw new IOException();
+		}
+		switch (option) {
+		case DELAY:
+			int delay;
+			if (value == 0) {
+				delay = 0;
+			} else {
+				delay = 1;
+			}
+			socket.setTcpNoDelay(delay == 0 ? false : true);
+			break;
+		case LINGER:
+			if (value < 0) {
+				throw new IllegalArgumentException();
+			}
+			socket.setSoLinger(value == 0 ? false : true, value);
+			break;
+		case KEEPALIVE:
+			int keepalive;
+			if (value == 0) {
+				keepalive = 0;
+			} else {
+				keepalive = 1;
+			}
+			socket.setKeepAlive(keepalive == 0 ? false : true);
+			break;
+		case RCVBUF:
+			if (value <= 0) {
+				throw new IllegalArgumentException();
+			}
+			socket.setReceiveBufferSize(value);
+			break;
+		case SNDBUF:
+			if (value <= 0) {
+				throw new IllegalArgumentException();
+			}
+			socket.setSendBufferSize(value);
+			break;
+		default:
+			throw new IllegalArgumentException();
+		}
+	}
+
+	public void close() throws IOException {
+		// TODO fix differences between Java ME and Java SE
+		
+		socket.close();
+	}
+
+	public InputStream openInputStream() throws IOException {
+		return socket.getInputStream();
+	}
+
+	public DataInputStream openDataInputStream() throws IOException {
+		return new DataInputStream(openInputStream());
+	}
+
+	public OutputStream openOutputStream() throws IOException {
+		return socket.getOutputStream();
+	}
+
+	public DataOutputStream openDataOutputStream() throws IOException {
+		return new DataOutputStream(openOutputStream());
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/socket/SocketConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/ssl/Connection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/ssl/Connection.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/ssl/Connection.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/ssl/Connection.java Mon May 26 15:20:19 2008
@@ -0,0 +1,113 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.cldc.ssl;
+
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+
+import javax.microedition.io.SecureConnection;
+import javax.microedition.io.SecurityInfo;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.microemu.cldc.CertificateImpl;
+import org.microemu.cldc.ClosedConnection;
+import org.microemu.cldc.SecurityInfoImpl;
+
+public class Connection extends org.microemu.cldc.socket.SocketConnection implements SecureConnection, ClosedConnection {
+	
+	private SecurityInfo securityInfo;
+	
+	public Connection() {
+		securityInfo = null;
+	}
+
+	public javax.microedition.io.Connection open(String name) throws IOException {
+		
+		if (!org.microemu.cldc.http.Connection.isAllowNetworkConnection()) {
+			throw new IOException("No network");
+		}
+		
+		int portSepIndex = name.lastIndexOf(':');
+		int port = Integer.parseInt(name.substring(portSepIndex + 1));
+		String host = name.substring("ssl://".length(), portSepIndex);
+		
+		// TODO validate certificate chains
+	    TrustManager[] trustAllCerts = new TrustManager[]{
+	        new X509TrustManager() {
+	            public X509Certificate[] getAcceptedIssuers() {
+	                return null;
+	            }
+	            public void checkClientTrusted(
+	                X509Certificate[] certs, String authType) {
+	            }
+	            public void checkServerTrusted(
+	                X509Certificate[] certs, String authType) {
+	            }
+	        }
+	    };
+		
+		try {
+			SSLContext sc = SSLContext.getInstance("SSL");			
+			sc.init(null, trustAllCerts, new SecureRandom());
+			SSLSocketFactory factory = sc.getSocketFactory();
+			socket = factory.createSocket(host, port);
+		} catch (NoSuchAlgorithmException ex) {
+			throw new IOException(ex.toString());
+		} catch (KeyManagementException ex) {
+			throw new IOException(ex.toString());
+		}
+		
+		return this;
+	}
+
+	public void close() throws IOException {
+		// TODO fix differences between Java ME and Java SE
+		
+		socket.close();
+	}
+
+	public SecurityInfo getSecurityInfo() throws IOException {
+		if (securityInfo == null) {
+			SSLSession session = ((SSLSocket) socket).getSession();
+			
+			Certificate[] certs = session.getPeerCertificates();
+			if (certs.length == 0) {
+				throw new IOException();
+			}
+			
+			securityInfo = new SecurityInfoImpl(
+					session.getCipherSuite(),
+					session.getProtocol(),
+					new CertificateImpl((X509Certificate) certs[0]));
+		}
+
+		return securityInfo;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/cldc/ssl/Connection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Button.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Button.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Button.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Button.java Mon May 26 15:20:19 2008
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+public interface Button {
+
+	public static final int NAME_RIMARY_SINCE_SKIN_VERSION = 20002;
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Button.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonDetaultDeviceKeyCodes.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonDetaultDeviceKeyCodes.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonDetaultDeviceKeyCodes.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonDetaultDeviceKeyCodes.java Mon May 26 15:20:19 2008
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.microedition.lcdui.Canvas;
+
+/**
+ * 
+ * This class defines default device key codes and game actions for buttons.
+ * 
+ * Key code is reported to MIDP application by Canvas.keyPressed()
+ * 
+ * Game action is reported to MIDP application by Canvas.getGameAction()
+ * 
+ * Use 'device.xml' to redefine codes for your device if required.
+ * 
+ * @author vlads
+ * 
+ */
+public abstract class ButtonDetaultDeviceKeyCodes {
+
+	private static Map codes = new HashMap();
+
+	private static Map gameActions = new HashMap();
+
+	public static int getKeyCode(ButtonName name) {
+		Integer code = (Integer) codes.get(name);
+		if (code != null) {
+			return code.intValue();
+		}
+		return 0;
+	}
+
+	public static int getGameAction(ButtonName name) {
+		Integer code = (Integer) gameActions.get(name);
+		if (code != null) {
+			return code.intValue();
+		}
+		return 0;
+	}
+
+	public static ButtonName getButtonNameByGameAction(int gameAction) {
+		Integer value = new Integer(gameAction);
+		if (gameActions.containsValue(value)) {
+			for (Iterator iterator = gameActions.entrySet().iterator(); iterator.hasNext();) {
+				Map.Entry v = (Map.Entry) iterator.next();
+				if (v.getValue().equals(value)) {
+					return (ButtonName) v.getKey();
+				}
+			}
+		}
+		throw new IllegalArgumentException("Illegal action " + gameAction);
+	}
+
+	static {
+		code(ButtonName.SOFT1, -6);
+		code(ButtonName.SOFT2, -7);
+		code(ButtonName.SELECT, -5, Canvas.FIRE);
+		code(ButtonName.UP, -1, Canvas.UP);
+		code(ButtonName.DOWN, -2, Canvas.DOWN);
+		code(ButtonName.LEFT, -3, Canvas.LEFT);
+		code(ButtonName.RIGHT, -4, Canvas.RIGHT);
+
+		code(ButtonName.KEY_NUM0, Canvas.KEY_NUM0);
+		code(ButtonName.KEY_NUM1, Canvas.KEY_NUM1, Canvas.GAME_A);
+		code(ButtonName.KEY_NUM2, Canvas.KEY_NUM2);
+		code(ButtonName.KEY_NUM3, Canvas.KEY_NUM3, Canvas.GAME_B);
+		code(ButtonName.KEY_NUM4, Canvas.KEY_NUM4);
+		code(ButtonName.KEY_NUM5, Canvas.KEY_NUM5);
+		code(ButtonName.KEY_NUM6, Canvas.KEY_NUM6);
+		code(ButtonName.KEY_NUM7, Canvas.KEY_NUM7, Canvas.GAME_C);
+		code(ButtonName.KEY_NUM8, Canvas.KEY_NUM8);
+		code(ButtonName.KEY_NUM9, Canvas.KEY_NUM9, Canvas.GAME_D);
+		code(ButtonName.KEY_STAR, Canvas.KEY_STAR);
+		code(ButtonName.KEY_POUND, Canvas.KEY_POUND);
+	}
+
+	private static void code(ButtonName name, int code) {
+		codes.put(name, new Integer(code));
+	}
+
+	private static void code(ButtonName name, int code, int gameAction) {
+		code(name, code);
+		gameActions.put(name, new Integer(gameAction));
+	}
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonDetaultDeviceKeyCodes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonName.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonName.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonName.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonName.java Mon May 26 15:20:19 2008
@@ -0,0 +1,145 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 
+ * This class defines Buttons available on Device
+ * 
+ * Implementation is Java 5 enum in java 1.4
+ * 
+ * @author vlads
+ * 
+ */
+public final class ButtonName {
+
+	private static Map altNames = new HashMap();
+
+	public static final ButtonName SOFT1 = new ButtonName();
+
+	public static final ButtonName SOFT2 = new ButtonName();
+
+	public static final ButtonName SOFT3 = new ButtonName();
+
+	public static final ButtonName SELECT = new ButtonName("SEL");
+
+	public static final ButtonName UP = new ButtonName("U");
+
+	public static final ButtonName DOWN = new ButtonName("D");
+
+	public static final ButtonName LEFT = new ButtonName("L");
+
+	public static final ButtonName RIGHT = new ButtonName("R");
+
+	// public static final ButtonName BACK = new ButtonName();
+
+	public static final ButtonName BACK_SPACE = new ButtonName();
+
+	public static final ButtonName DELETE = new ButtonName();
+
+	// public static final ButtonName CLEAR = DELETE;
+
+	public static final ButtonName KEY_NUM0 = new ButtonName("0");
+
+	public static final ButtonName KEY_NUM1 = new ButtonName("1");
+
+	public static final ButtonName KEY_NUM2 = new ButtonName("2");
+
+	public static final ButtonName KEY_NUM3 = new ButtonName("3");
+
+	public static final ButtonName KEY_NUM4 = new ButtonName("4");
+
+	public static final ButtonName KEY_NUM5 = new ButtonName("5");
+
+	public static final ButtonName KEY_NUM6 = new ButtonName("6");
+
+	public static final ButtonName KEY_NUM7 = new ButtonName("7");
+
+	public static final ButtonName KEY_NUM8 = new ButtonName("8");
+
+	public static final ButtonName KEY_NUM9 = new ButtonName("9");
+
+	public static final ButtonName KEY_STAR = new ButtonName(new String[] { "*", "STAR", "ASTERISK" });
+
+	public static final ButtonName KEY_POUND = new ButtonName(new String[] { "#", "POUND" });
+
+	private String name = "n/a";
+
+	public static ButtonName getButtonName(String functionName) {
+		String name = functionName.toUpperCase();
+		try {
+			Field field = ButtonName.class.getField(name);
+			if (field.getType() == ButtonName.class) {
+				return (ButtonName) field.get(null);
+			}
+		} catch (NoSuchFieldException e) {
+		} catch (IllegalAccessException e) {
+		}
+		ButtonName btn = (ButtonName) altNames.get(name);
+		if (btn == null) {
+			// User defined button
+			btn = new ButtonName();
+			btn.name = functionName;
+		}
+
+		return btn;
+	}
+
+	static {
+		// Name all the Buttons by filed name
+		Field[] fields = ButtonName.class.getDeclaredFields();
+		for (int i = 0; i < fields.length; i++) {
+			if (fields[i].getType() == ButtonName.class) {
+				try {
+					((ButtonName) fields[i].get(null)).name = fields[i].getName();
+				} catch (IllegalAccessException e) {
+
+				}
+			}
+		}
+	}
+
+	private ButtonName() {
+
+	}
+
+	private ButtonName(String name) {
+		altNames.put(name, this);
+	}
+
+	private ButtonName(String[] names) {
+		for (int i = 0; i < names.length; i++) {
+			altNames.put(names[i], this);
+		}
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String toString() {
+		return name;
+	}
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/ButtonName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Color.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Color.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Color.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Color.java Mon May 26 15:20:19 2008
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+public class Color
+{
+    private int value;
+    
+    
+    public Color(int value)
+    {
+        this.value = value;
+    }
+    
+
+    public int getRed()
+    {
+        return (value >> 16) & 0xff;
+    }
+    
+    
+    public int getGreen()
+    {
+        return (value >> 8) & 0xff;
+    }
+
+    
+    public int getBlue()
+    {
+        return value & 0xff;
+    }
+    
+    
+    public int getRGB()
+    {
+        return value;
+    }
+    
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/Color.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceDisplayImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceDisplayImpl.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceDisplayImpl.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceDisplayImpl.java Mon May 26 15:20:19 2008
@@ -0,0 +1,118 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.microemu.device.impl;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Font;
+import javax.microedition.lcdui.Image;
+
+import org.microemu.device.DeviceDisplay;
+
+public interface DeviceDisplayImpl extends DeviceDisplay {
+
+	Image createSystemImage(URL url) throws IOException;
+
+	/**
+	 * @param name
+	 * @param shape
+	 * @param keyCode -
+	 *            Integer.MIN_VALUE when unspecified
+	 * @param keyboardKeys
+	 * @param keyboardChars
+	 * @param chars
+	 * @param modeChange
+	 * @return
+	 */
+	Button createButton(int skinVersion, String name, Shape shape, int keyCode, String keyboardKeys,
+			String keyboardChars, Hashtable inputToChars, boolean modeChange);
+
+	/**
+	 * @param name
+	 * @param rectangle
+	 * @param keyCode -
+	 *            Integer.MIN_VALUE when unspecified
+	 * @param keyName
+	 * @param paintable
+	 * @param alignmentName
+	 * @param commands
+	 * @param font
+	 * @return
+	 */
+	SoftButton createSoftButton(int skinVersion, String name, Shape shape, int keyCode, String keyName,
+			Rectangle paintable, String alignmentName, Vector commands, Font font);
+
+	SoftButton createSoftButton(int skinVersion, String name, Rectangle paintable, Image normalImage, Image pressedImage);
+
+	/**
+	 * @param i
+	 */
+	void setNumColors(int i);
+
+	/**
+	 * @param b
+	 */
+	void setIsColor(boolean b);
+
+	void setNumAlphaLevels(int i);
+
+	/**
+	 * @param color
+	 */
+	void setBackgroundColor(Color color);
+
+	/**
+	 * @param color
+	 */
+	void setForegroundColor(Color color);
+
+	/**
+	 * @param rectangle
+	 */
+	void setDisplayRectangle(Rectangle rectangle);
+
+	/**
+	 * @param rectangle
+	 */
+	void setDisplayPaintable(Rectangle rectangle);
+
+	/**
+	 * @param object
+	 */
+	void setMode123Image(PositionedImage object);
+
+	/**
+	 * @param object
+	 */
+	void setModeAbcLowerImage(PositionedImage object);
+
+	/**
+	 * @param object
+	 */
+	void setModeAbcUpperImage(PositionedImage object);
+
+	boolean isResizable();
+
+	void setResizable(boolean state);
+
+}

Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/device/impl/DeviceDisplayImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message