You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/05/27 00:21:57 UTC
svn commit: r660326 [10/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...
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSoftButton.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSoftButton.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSoftButton.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSoftButton.java Mon May 26 15:20:19 2008
@@ -0,0 +1,237 @@
+/*
+ * 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.swt;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Font;
+import javax.microedition.lcdui.Image;
+
+import org.eclipse.swt.graphics.RGB;
+import org.microemu.app.ui.swt.SwtGraphics;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.impl.Rectangle;
+import org.microemu.device.impl.Shape;
+import org.microemu.device.impl.SoftButton;
+
+public class SwtSoftButton extends SwtButton implements SoftButton {
+
+ public static int LEFT = 1;
+ public static int RIGHT = 2;
+
+ private int type;
+
+ private Image normalImage;
+ private Image pressedImage;
+
+ private Vector commandTypes = new Vector();
+
+ private Command command = null;
+
+ private Rectangle paintable;
+
+ private int alignment;
+
+ private boolean visible;
+
+ private boolean pressed;
+
+ private Font font;
+
+ /**
+ * @param name
+ * @param rectangle
+ * @param keyCode - Integer.MIN_VALUE when unspecified
+ * @param keyName
+ * @param paintable
+ * @param alignmentName
+ * @param commands
+ * @param font
+ */
+ public SwtSoftButton(String name, Shape shape, int keyCode, String keyName,
+ Rectangle paintable, String alignmentName, Vector commands, Font font) {
+ super(name, shape, keyCode, keyName, new Hashtable());
+
+ this.type = TYPE_COMMAND;
+
+ this.paintable = paintable;
+ this.visible = true;
+ this.pressed = false;
+ this.font = font;
+
+ if (alignmentName != null) {
+ try {
+ alignment = SwtSoftButton.class.getField(alignmentName).getInt(null);
+ } catch (Exception ex) {
+ System.err.println(ex);
+ }
+ }
+
+ for (Enumeration e = commands.elements(); e.hasMoreElements();) {
+ String tmp = (String) e.nextElement();
+ try {
+ addCommandType(Command.class.getField(tmp).getInt(null));
+ } catch (Exception ex) {
+ System.err.println("a3" + ex);
+ }
+ }
+ }
+
+ public SwtSoftButton(String name, Rectangle paintable, Image normalImage, Image pressedImage) {
+ super(name, null, Integer.MIN_VALUE, null, null);
+
+ this.type = TYPE_ICON;
+
+ this.paintable = paintable;
+ this.normalImage = normalImage;
+ this.pressedImage = pressedImage;
+
+ this.visible = true;
+ this.pressed = false;
+ }
+
+
+ public int getType() {
+ return type;
+ }
+
+ /**
+ * Sets the command attribute of the SoftButton object
+ *
+ * @param cmd
+ * The new command value
+ */
+ public void setCommand(Command cmd) {
+ synchronized (this) {
+ command = cmd;
+ }
+ }
+
+ /**
+ * Gets the command attribute of the SoftButton object
+ *
+ * @return The command value
+ */
+ public Command getCommand() {
+ return command;
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ public void setVisible(boolean state) {
+ visible = state;
+ }
+
+ public boolean isPressed() {
+ return pressed;
+ }
+
+ public void setPressed(boolean state) {
+ pressed = state;
+ }
+
+ public Rectangle getPaintable() {
+ return paintable;
+ }
+
+ public void paint(SwtGraphics g) {
+ if (!visible || paintable == null) {
+ return;
+ }
+
+ org.eclipse.swt.graphics.Rectangle clip = g.getClipping();
+
+ g.setClipping(paintable.x, paintable.y, paintable.width, paintable.height);
+ if (type == TYPE_COMMAND) {
+ int xoffset = 0;
+ Device device = DeviceFactory.getDevice();
+ SwtDeviceDisplay deviceDisplay = (SwtDeviceDisplay) device.getDeviceDisplay();
+ if (pressed) {
+ g.setForeground(g.getColor(new RGB(deviceDisplay
+ .getForegroundColor().getRed(), deviceDisplay
+ .getForegroundColor().getGreen(), deviceDisplay
+ .getForegroundColor().getBlue())));
+ } else {
+ g.setBackground(g.getColor(new RGB(deviceDisplay
+ .getBackgroundColor().getRed(), deviceDisplay
+ .getBackgroundColor().getGreen(), deviceDisplay
+ .getBackgroundColor().getBlue())));
+ }
+ g.fillRectangle(paintable.x, paintable.y, paintable.width,
+ paintable.height);
+ synchronized (this) {
+ if (command != null) {
+ if (font != null) {
+ SwtFontManager fontManager = (SwtFontManager) device.getFontManager();
+ SwtFont buttonFont = (SwtFont) fontManager.getFont(font);
+ g.setFont(buttonFont.getFont());
+ }
+ if (alignment == RIGHT) {
+ xoffset = paintable.width
+ - g.stringWidth(command.getLabel());
+ }
+ if (pressed) {
+ g.setBackground(g.getColor(new RGB(deviceDisplay
+ .getBackgroundColor().getRed(), deviceDisplay
+ .getBackgroundColor().getGreen(), deviceDisplay
+ .getBackgroundColor().getBlue())));
+ } else {
+ g.setForeground(g.getColor(new RGB(deviceDisplay
+ .getForegroundColor().getRed(), deviceDisplay
+ .getForegroundColor().getGreen(), deviceDisplay
+ .getForegroundColor().getBlue())));
+ }
+ g.drawString(command.getLabel(), paintable.x + xoffset,
+ paintable.y
+ + (paintable.height - g.getFontMetrics()
+ .getHeight()), true);
+ }
+ }
+ } else if (type == TYPE_ICON) {
+ if (pressed) {
+ g.drawImage(((SwtImmutableImage) pressedImage).getImage(), paintable.x, paintable.y);
+ } else {
+ g.drawImage(((SwtImmutableImage) normalImage).getImage(), paintable.x, paintable.y);
+ }
+ }
+
+ g.setClipping(clip);
+ }
+
+ public boolean preferredCommandType(Command cmd) {
+ for (Enumeration ct = commandTypes.elements(); ct.hasMoreElements();) {
+ if (cmd.getCommandType() == ((Integer) ct.nextElement()).intValue()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void addCommandType(int commandType) {
+ commandTypes.addElement(new Integer(commandType));
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSoftButton.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSystemFont.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSystemFont.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSystemFont.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSystemFont.java Mon May 26 15:20:19 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.swt;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.microemu.app.ui.swt.SwtDeviceComponent;
+
+public class SwtSystemFont implements SwtFont {
+
+ private String name;
+
+ private String style;
+
+ private int size;
+
+ private boolean antialiasing;
+
+ private boolean initialized;
+
+ private Font font;
+
+ public SwtSystemFont(String name, String style, int size, boolean antialiasing) {
+ this.name = name;
+ this.style = style.toLowerCase();
+ this.size = size;
+ this.antialiasing = antialiasing;
+
+ this.initialized = false;
+ }
+
+ public void setAntialiasing(boolean antialiasing) {
+ if (this.antialiasing != antialiasing) {
+ this.antialiasing = antialiasing;
+ initialized = false;
+ }
+ }
+
+ public Font getFont() {
+ checkInitialized();
+
+ return font;
+ }
+
+ private synchronized void checkInitialized() {
+ if (!initialized) {
+ int swtStyle = 0;
+ if (style.indexOf("plain") != -1) {
+ swtStyle |= SWT.NORMAL;
+ }
+ if (style.indexOf("bold") != -1) {
+ swtStyle |= SWT.BOLD;
+ }
+ if (style.indexOf("italic") != -1) {
+ swtStyle |= SWT.ITALIC;
+ }
+ if (style.indexOf("underlined") != -1) {
+ // TODO underlined style not implemented
+ }
+ font = SwtDeviceComponent.getFont(name, size, swtStyle, antialiasing);
+ initialized = true;
+ }
+ }
+
+ public int charWidth(char ch) {
+ return charsWidth(new char[] {ch}, 0, 1);
+ }
+
+ public int charsWidth(char[] ch, int offset, int length) {
+ checkInitialized();
+
+ return SwtDeviceComponent.stringWidth(font, new String(ch, offset, length));
+ }
+
+ public int getBaselinePosition() {
+ checkInitialized();
+
+ return SwtDeviceComponent.getFontMetrics(font).getAscent();
+ }
+
+ public int getHeight() {
+ checkInitialized();
+
+ return SwtDeviceComponent.getFontMetrics(font).getHeight();
+ }
+
+ public int stringWidth(String str) {
+ checkInitialized();
+
+ return SwtDeviceComponent.stringWidth(font, str);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtSystemFont.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtTrueTypeFont.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtTrueTypeFont.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtTrueTypeFont.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtTrueTypeFont.java Mon May 26 15:20:19 2008
@@ -0,0 +1,135 @@
+/*
+ * 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.swt;
+
+import java.net.URL;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+
+public class SwtTrueTypeFont implements SwtFont {
+
+ private URL url;
+
+ private String style;
+
+ private int size;
+
+ private boolean antialiasing;
+
+ private boolean initialized;
+
+ private Font font;
+
+ public SwtTrueTypeFont(URL url, String style, int size, boolean antialiasing) {
+ this.url = url;
+ this.style = style.toLowerCase();
+ this.size = size;
+ this.antialiasing = antialiasing;
+
+ this.initialized = false;
+ }
+
+ public void setAntialiasing(boolean antialiasing) {
+ if (this.antialiasing != antialiasing) {
+ this.antialiasing = antialiasing;
+ initialized = false;
+ }
+ }
+
+ public Font getFont() {
+ checkInitialized();
+
+ return font;
+ }
+
+ private synchronized void checkInitialized() {
+ if (!initialized) {
+ int swtStyle = 0;
+ if (style.indexOf("plain") != -1) {
+ swtStyle |= SWT.NORMAL;
+ }
+ if (style.indexOf("bold") != -1) {
+ swtStyle |= SWT.BOLD;
+ }
+ if (style.indexOf("italic") != -1) {
+ swtStyle |= SWT.ITALIC;
+ }
+ if (style.indexOf("underlined") != -1) {
+ // TODO underlined style not implemented
+ }
+
+// font = SwtDeviceComponent.getFont(name, size, swtStyle, antialiasing);
+ initialized = true;
+ try {
+ throw new RuntimeException("not implemented");
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+ }
+
+ public int charWidth(char ch) {
+ try {
+ throw new RuntimeException("not implemented");
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+ public int charsWidth(char[] ch, int offset, int length) {
+ try {
+ throw new RuntimeException("not implemented");
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+ public int getBaselinePosition() {
+ try {
+ throw new RuntimeException("not implemented");
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+ public int getHeight() {
+ try {
+ throw new RuntimeException("not implemented");
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+ public int stringWidth(String str) {
+ try {
+ throw new RuntimeException("not implemented");
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/SwtTrueTypeFont.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtCanvasUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtCanvasUI.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtCanvasUI.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtCanvasUI.java Mon May 26 15:20:19 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.swt.ui;
+
+import javax.microedition.lcdui.Canvas;
+
+import org.microemu.device.impl.ui.DisplayableImplUI;
+import org.microemu.device.ui.CanvasUI;
+
+public class SwtCanvasUI extends DisplayableImplUI implements CanvasUI {
+
+ public SwtCanvasUI(Canvas canvas) {
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtCanvasUI.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtListUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtListUI.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtListUI.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtListUI.java Mon May 26 15:20:19 2008
@@ -0,0 +1,53 @@
+/*
+ * 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.swt.ui;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Image;
+import javax.microedition.lcdui.List;
+
+import org.microemu.device.impl.ui.DisplayableImplUI;
+import org.microemu.device.ui.ListUI;
+
+public class SwtListUI extends DisplayableImplUI implements ListUI {
+
+ public SwtListUI(List list) {
+ }
+
+ public int append(String stringPart, Image imagePart) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public void setSelectCommand(Command command) {
+ // TODO Auto-generated method stub
+ }
+
+ public int getSelectedIndex() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getString(int elementNum) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtListUI.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtTextBoxUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtTextBoxUI.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtTextBoxUI.java (added)
+++ harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtTextBoxUI.java Mon May 26 15:20:19 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.swt.ui;
+
+import javax.microedition.lcdui.TextBox;
+
+import org.microemu.device.impl.ui.DisplayableImplUI;
+import org.microemu.device.ui.TextBoxUI;
+
+public class SwtTextBoxUI extends DisplayableImplUI implements TextBoxUI {
+
+ public SwtTextBoxUI(TextBox textBox) {
+ }
+
+ public int getCaretPosition() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getString() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setString(String text) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase-swt/src/main/java/org/microemu/device/swt/ui/SwtTextBoxUI.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase/pom.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/pom.xml?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/pom.xml (added)
+++ harmony/enhanced/microemulator/microemu-javase/pom.xml Mon May 26 15:20:19 2008
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0">
+ <!-- @version $Revision: 1626 $ ($Author: vlads $) $Date: 2008-03-04 21:47:36 -0500 (Tue, 04 Mar 2008) $ -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.microemu</groupId>
+ <artifactId>microemu</artifactId>
+ <version>2.0.3-SNAPSHOT</version><!--me-version-->
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>microemu-javase</artifactId>
+ <name>microemu-javase</name>
+
+ <description>javase</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.microemu</groupId>
+ <artifactId>microemu-midp</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- moved to microemu-javase-swing and swt -->
+ <!--
+ <dependency>
+ <groupId>org.microemu</groupId>
+ <artifactId>microemu-injected</artifactId>
+ <version>${project.version}</version>
+ <classifier>inject</classifier>
+ </dependency>
+ -->
+
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
\ No newline at end of file
Propchange: harmony/enhanced/microemulator/microemu-javase/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/Injected.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/Injected.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/Injected.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/Injected.java Mon May 26 15:20:19 2008
@@ -0,0 +1,116 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.Serializable;
+
+import org.microemu.app.util.MIDletOutputStreamRedirector;
+import org.microemu.app.util.MIDletResourceLoader;
+import org.microemu.app.util.MIDletSystemProperties;
+import org.microemu.log.Logger;
+
+/**
+ * @author vlads
+ *
+ * This code is added to MIDlet application to solve problems with security policy while running in Applet and Webstart.
+ * Also solves resource resource loading paterns commonly used in MIDlet and not aceptable in Java SE application
+ * The calls to this code is injected by ClassLoader or "Save for Web...".
+ *
+ * This class is used instead injected one when application is running in Applet with MicroEmulator.
+ *
+ * Serializable is just internal flag to verify tha proper class is loaded by application.
+ */
+public final class Injected implements Serializable {
+
+ private static final long serialVersionUID = -1L;
+
+ /**
+ * This allow redirection of stdout to MicroEmulator console
+ */
+ public final static PrintStream out = outPrintStream();
+
+ public final static PrintStream err = errPrintStream();
+
+ static {
+ Logger.addLogOrigin(Injected.class);
+ }
+
+ /**
+ * We don't need to instantiate the class, all access is static
+ */
+ private Injected() {
+
+ }
+
+ private static PrintStream outPrintStream() {
+ //return System.out;
+ return MIDletOutputStreamRedirector.out;
+ }
+
+ private static PrintStream errPrintStream() {
+ //return System.err;
+ return MIDletOutputStreamRedirector.err;
+ }
+
+ /**
+ * Redirect throwable.printStackTrace() to MicroEmulator console
+ */
+ public static void printStackTrace(Throwable t) {
+ Logger.error("MIDlet caught", t);
+ }
+
+ /**
+ * This code Ingected By MicroEmulator to enable access to System properties while running in Applet
+ *
+ * @param key the name of the system property.
+ * @return the string value of the system property,
+ * or <code>null</code> if there is no property with that key.
+ */
+ public static String getProperty(String key) {
+ return MIDletSystemProperties.getProperty(key);
+ }
+
+ /**
+ *
+ * Returns an input stream for reading the specified resource.
+ *
+ * <p> The search order is described in the documentation for {@link
+ * #getResource(String)}. </p>
+ *
+ * @param origClass
+ * @param name The resource name
+ *
+ * @return An input stream for reading the resource, or <tt>null</tt>
+ * if the resource could not be found
+ */
+ public static InputStream getResourceAsStream(Class origClass, String name) {
+ return MIDletResourceLoader.getResourceAsStream(origClass, name);
+ }
+
+ /**
+ * TODO fix ChangeCallsMethodVisitor
+ */
+ public static Throwable handleCatchThrowable(Throwable t) {
+ Logger.error("MIDlet caught", t);
+ return t;
+ }
+}
Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/Injected.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Common.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Common.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Common.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Common.java Mon May 26 15:20:19 2008
@@ -0,0 +1,954 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.zip.ZipException;
+
+import javax.microedition.midlet.MIDlet;
+import javax.microedition.midlet.MIDletStateChangeException;
+
+import org.microemu.EmulatorContext;
+import org.microemu.Injected;
+import org.microemu.MIDletAccess;
+import org.microemu.MIDletBridge;
+import org.microemu.MIDletContext;
+import org.microemu.MIDletEntry;
+import org.microemu.MicroEmulator;
+import org.microemu.RecordStoreManager;
+import org.microemu.app.classloader.ExtensionsClassLoader;
+import org.microemu.app.classloader.MIDletClassLoader;
+import org.microemu.app.classloader.MIDletClassLoaderConfig;
+import org.microemu.app.launcher.Launcher;
+import org.microemu.app.ui.Message;
+import org.microemu.app.ui.ResponseInterfaceListener;
+import org.microemu.app.ui.StatusBarListener;
+import org.microemu.app.util.DeviceEntry;
+import org.microemu.app.util.FileRecordStoreManager;
+import org.microemu.app.util.IOUtils;
+import org.microemu.app.util.MIDletResourceLoader;
+import org.microemu.app.util.MIDletSystemProperties;
+import org.microemu.app.util.MIDletThread;
+import org.microemu.app.util.MIDletTimer;
+import org.microemu.app.util.MidletURLReference;
+import org.microemu.device.Device;
+import org.microemu.device.DeviceFactory;
+import org.microemu.device.impl.DeviceImpl;
+import org.microemu.log.Logger;
+import org.microemu.microedition.ImplFactory;
+import org.microemu.microedition.ImplementationInitialization;
+import org.microemu.microedition.io.ConnectorImpl;
+import org.microemu.util.Base64Coder;
+import org.microemu.util.JadMidletEntry;
+import org.microemu.util.JadProperties;
+import org.microemu.util.MemoryRecordStoreManager;
+
+public class Common implements MicroEmulator, CommonInterface {
+
+ protected EmulatorContext emulatorContext;
+
+ protected JadProperties jad = new JadProperties();
+
+ private static Common instance;
+
+ private static Launcher launcher;
+
+ private static StatusBarListener statusBarListener = null;
+
+ private JadProperties manifest = new JadProperties();
+
+ private RecordStoreManager recordStoreManager;
+
+ private ResponseInterfaceListener responseInterfaceListener = null;
+
+ private ExtensionsClassLoader extensionsClassLoader;
+
+ private Vector extensions = new Vector();
+
+ private MIDletClassLoaderConfig mIDletClassLoaderConfig;
+
+ private boolean useSystemClassLoader = false;
+
+ private boolean autoTests = false;
+
+ private String propertiesJad = null;
+
+ private String midletClassOrJad = null;
+
+ private String jadURL = null;
+
+ private Object destroyNotify = new Object();
+
+ public Common(EmulatorContext context) {
+ instance = this;
+ this.emulatorContext = context;
+
+ try {
+ launcher = new Launcher(this);
+ launcher.setCurrentMIDlet(launcher);
+ } finally {
+ MIDletBridge.setThreadMIDletContext(null);
+ }
+
+ /*
+ * Initialize secutity context for implemenations, May be there are
+ * better place for this call
+ */
+ ImplFactory.instance();
+ MIDletSystemProperties.initContext();
+ // TODO integrate with ImplementationInitialization
+ ImplFactory.registerGCF(ImplFactory.DEFAULT, new ConnectorImpl());
+
+ MIDletBridge.setMicroEmulator(this);
+ }
+
+ public RecordStoreManager getRecordStoreManager() {
+ return recordStoreManager;
+ }
+
+ public void setRecordStoreManager(RecordStoreManager manager) {
+ this.recordStoreManager = manager;
+ }
+
+ public String getAppProperty(String key) {
+ if (key.equals("microedition.platform")) {
+ return "MicroEmulator";
+ } else if (key.equals("microedition.profiles")) {
+ return "MIDP-2.0";
+ } else if (key.equals("microedition.configuration")) {
+ return "CLDC-1.0";
+ } else if (key.equals("microedition.locale")) {
+ return Locale.getDefault().getLanguage();
+ } else if (key.equals("microedition.encoding")) {
+ return System.getProperty("file.encoding");
+ }
+
+ String result = jad.getProperty(key);
+ if (result == null) {
+ result = manifest.getProperty(key);
+ }
+
+ return result;
+ }
+
+ public InputStream getResourceAsStream(String name) {
+ return emulatorContext.getResourceAsStream(name);
+ }
+
+ public void notifyDestroyed(MIDletContext midletContext) {
+ Logger.debug("notifyDestroyed");
+ notifyImplementationMIDletDestroyed();
+ startLauncher(midletContext);
+ }
+
+ public void destroyMIDletContext(MIDletContext midletContext) {
+ if ((midletContext != null) && (MIDletBridge.getMIDletContext() == midletContext)
+ && !midletContext.isLauncher()) {
+ Logger.debug("destroyMIDletContext");
+ }
+ MIDletThread.contextDestroyed(midletContext);
+ synchronized (destroyNotify) {
+ destroyNotify.notifyAll();
+ }
+ }
+
+ public Launcher getLauncher() {
+ return launcher;
+ }
+
+ public static void dispose() {
+ try {
+ MIDletAccess midletAccess = MIDletBridge.getMIDletAccess();
+ if (midletAccess != null) {
+ midletAccess.destroyApp(true);
+ }
+ } catch (MIDletStateChangeException ex) {
+ Logger.error(ex);
+ }
+ // TODO to be removed when event dispatcher will run input method task
+ DeviceFactory.getDevice().getInputMethod().dispose();
+ }
+
+ public static boolean isJadExtension(String nameString) {
+ if (nameString == null) {
+ return false;
+ }
+ int end = nameString.lastIndexOf('.');
+ if (end == -1) {
+ return false;
+ }
+ return nameString.substring(end + 1, nameString.length()).toLowerCase(Locale.ENGLISH).equals("jad");
+ }
+
+ /**
+ * TODO add proper Error handling and display in this function.
+ */
+ public static void openJadUrlSafe(String urlString) {
+ try {
+ getInstance().openJadUrl(urlString);
+ } catch (IOException e) {
+ Message.error("Unable to open jad " + urlString, e);
+ }
+ }
+
+ protected void openJadUrl(String urlString) throws IOException {
+ midletClassOrJad = urlString;
+ if (!autoTests) {
+ openJadUrl(urlString, createMIDletClassLoader());
+ } else {
+ runAutoTests(urlString, false);
+ }
+ }
+
+ private void runAutoTests(final String urlString, final boolean exitAtTheEnd) {
+ final Common common = getInstance();
+ Thread t = new Thread("AutoTestsThread") {
+ public void run() {
+ boolean firstJad = true;
+ do {
+ common.jad.clear();
+ Logger.debug("AutoTests open jad", urlString);
+ try {
+ common.jad = loadJadProperties(urlString);
+ } catch (IOException e) {
+ if (firstJad) {
+ Logger.debug(e);
+ } else {
+ Logger.debug("AutoTests no more tests");
+ }
+ break;
+ }
+ firstJad = false;
+
+ JadMidletEntry jadMidletEntry;
+ Iterator it = common.jad.getMidletEntries().iterator();
+ if (!it.hasNext()) {
+ Message.error("MIDlet Suite has no entries");
+ break;
+ }
+ jadMidletEntry = (JadMidletEntry) it.next();
+ String midletClassName = jadMidletEntry.getClassName();
+
+ boolean firstJar = true;
+ do {
+ MIDletClassLoader midletClassLoader = createMIDletClassLoader();
+ String tmpURL = saveJar2TmpFile(urlString, firstJar);
+ if (tmpURL == null) {
+ Logger.debug("AutoTests no new jar");
+ break;
+ }
+ firstJar = false;
+ Class midletClass;
+ try {
+ loadJar(urlString, tmpURL, midletClassLoader);
+ midletClass = midletClassLoader.loadClass(midletClassName);
+ } catch (ClassNotFoundException e) {
+ Logger.debug(e);
+ break;
+ }
+ Logger.debug("AutoTests start class", midletClassName);
+ MIDletContext context = startMidlet(midletClass, MIDletBridge.getMIDletAccess());
+ // TODO Proper test If this is still active conetex.
+ if (MIDletBridge.getMIDletContext() == context) {
+ synchronized (destroyNotify) {
+ try {
+ destroyNotify.wait();
+ } catch (InterruptedException e) {
+ return;
+ }
+ }
+ }
+ while (MIDletThread.hasRunningThreads(context)) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ Logger.debug("AutoTests ends");
+ } while (true);
+
+ } while (true);
+
+ if (exitAtTheEnd) {
+ System.exit(0);
+ }
+ }
+ };
+
+ t.start();
+ }
+
+ protected String saveJar2TmpFile(String jarUrl, boolean reportError) {
+ InputStream is = null;
+ try {
+ URL url = new URL(jad.getJarURL());
+ URLConnection conn = url.openConnection();
+ is = conn.getInputStream();
+ File tmp = File.createTempFile("me2-", ".jar");
+ tmp.deleteOnExit();
+ IOUtils.copyToFile(is, tmp);
+ return IOUtils.getCanonicalFileClassLoaderURL(tmp);
+ } catch (IOException e) {
+ if (reportError) {
+ Message.error("Unable to open jar " + jarUrl, e);
+ }
+ return null;
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ private void openJadUrl(String urlString, MIDletClassLoader midletClassLoader) throws IOException {
+ try {
+ Logger.debug("openJad", urlString);
+ setStatusBar("Loading...");
+ jad.clear();
+ jad = loadJadProperties(urlString);
+
+ loadJar(urlString, jad.getJarURL(), midletClassLoader);
+
+ Config.getUrlsMRU().push(new MidletURLReference(jad.getSuiteName(), urlString));
+ } catch (MalformedURLException ex) {
+ throw ex;
+ } catch (ClassNotFoundException ex) {
+ Logger.error(ex);
+ throw new IOException(ex.getMessage());
+ } catch (FileNotFoundException ex) {
+ Message.error("File Not found", urlString, ex);
+ } catch (NullPointerException ex) {
+ Logger.error("Cannot open jad", urlString, ex);
+ } catch (IllegalArgumentException ex) {
+ Logger.error("Cannot open jad", urlString, ex);
+ }
+ }
+
+ private MIDletContext startMidlet(Class midletClass, MIDletAccess previousMidletAccess) {
+ try {
+ if (previousMidletAccess != null) {
+ previousMidletAccess.destroyApp(true);
+ }
+ } catch (Throwable e) {
+ Message.error("Unable to destroy MIDlet, " + Message.getCauseMessage(e), e);
+ }
+
+ MIDletContext context = new MIDletContext();
+ MIDletBridge.setThreadMIDletContext(context);
+ try {
+ MIDlet m;
+
+ final String errorTitle = "Error starting MIDlet";
+
+ try {
+ Object object = midletClass.newInstance();
+ if (!(object instanceof MIDlet)) {
+ Message.error(errorTitle, "Class " + midletClass.getName() + " should extend MIDlet");
+ return null;
+ }
+ m = (MIDlet) object;
+ } catch (Throwable e) {
+ Message.error(errorTitle, "Unable to create MIDlet, " + Message.getCauseMessage(e), e);
+ MIDletBridge.destroyMIDletContext(context);
+ return null;
+ }
+
+ try {
+ if (context.getMIDlet() != m) {
+ throw new Error("MIDlet Context corrupted");
+ }
+ context.getMIDletAccess().startApp();
+
+ launcher.setCurrentMIDlet(m);
+ notifyImplementationMIDletStart();
+ return context;
+ } catch (Throwable e) {
+ Message.error(errorTitle, "Unable to start MIDlet, " + Message.getCauseMessage(e), e);
+ MIDletBridge.destroyMIDletContext(context);
+ return null;
+ }
+
+ } finally {
+ MIDletBridge.setThreadMIDletContext(null);
+ }
+
+ }
+
+ protected void startLauncher(MIDletContext midletContext) {
+ if ((midletContext != null) && (midletContext.isLauncher())) {
+ return;
+ }
+ if (midletContext != null) {
+ try {
+ MIDletAccess previousMidletAccess = midletContext.getMIDletAccess();
+ if (previousMidletAccess != null) {
+ previousMidletAccess.destroyApp(true);
+ }
+ } catch (Throwable e) {
+ Logger.error("destroyApp error", e);
+ }
+ }
+
+ try {
+ launcher = new Launcher(this);
+ MIDletBridge.getMIDletAccess(launcher).startApp();
+ launcher.setCurrentMIDlet(launcher);
+ } catch (Throwable e) {
+ Message.error("Unable to start launcher MIDlet, " + Message.getCauseMessage(e), e);
+ handleStartMidletException(e);
+ } finally {
+ MIDletBridge.setThreadMIDletContext(null);
+ }
+ }
+
+ public void setStatusBarListener(StatusBarListener listener) {
+ statusBarListener = listener;
+ }
+
+ public boolean platformRequest(String URL) {
+ return false;
+ }
+
+ public void setResponseInterfaceListener(ResponseInterfaceListener listener) {
+ responseInterfaceListener = listener;
+ }
+
+ protected void handleStartMidletException(Throwable e) {
+
+ }
+
+ /**
+ * Show message describing problem with jar if any
+ */
+ protected boolean describeJarProblem(URL jarUrl, MIDletClassLoader midletClassLoader) {
+ InputStream is = null;
+ JarInputStream jis = null;
+ try {
+ final String message = "Unable to open jar " + jarUrl;
+ URLConnection conn;
+ try {
+ conn = jarUrl.openConnection();
+ } catch (IOException e) {
+ Message.error(message, e);
+ return true;
+ }
+ try {
+ is = conn.getInputStream();
+ } catch (FileNotFoundException e) {
+ Message.error("The system cannot find the jar file " + jarUrl, e);
+ return true;
+ } catch (IOException e) {
+ Message.error(message, e);
+ return true;
+ }
+ try {
+ jis = new JarInputStream(is);
+ } catch (IOException e) {
+ Message.error(message, e);
+ return true;
+ }
+ try {
+ JarEntry entry = jis.getNextJarEntry();
+ if (entry == null) {
+ Message.error("Empty jar " + jarUrl);
+ return true;
+ }
+ // Read till the end
+ while (jis.getNextJarEntry() != null)
+ ;
+ } catch (ZipException e) {
+ Message.error("Problem reading jar " + jarUrl, e);
+ return true;
+ } catch (IOException e) {
+ Message.error("Problem reading jar " + jarUrl, e);
+ return true;
+ }
+ // There seems to be no poblem with jar
+ return false;
+ } finally {
+ IOUtils.closeQuietly(jis);
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ protected void loadJar(String jadUrl, String jarUrl, MIDletClassLoader midletClassLoader)
+ throws ClassNotFoundException {
+ if (jarUrl == null) {
+ throw new ClassNotFoundException("Cannot find MIDlet-Jar-URL property in jad");
+ }
+ Logger.debug("openJar", jarUrl);
+
+ // Close Current MIDlet before oppening new one.
+ dispose();
+ // MIDletBridge.destroyMIDletContext(MIDletBridge.getMIDletContext());
+ MIDletBridge.clear();
+
+ setResponseInterface(false);
+ try {
+ URL url = null;
+ try {
+ url = new URL(jarUrl);
+ } catch (MalformedURLException ex) {
+ try {
+ url = new URL(jadUrl.substring(0, jadUrl.lastIndexOf('/') + 1) + jarUrl);
+ // TODO check if IOUtils.getCanonicalFileURL is needed
+ jad.setCorrectedJarURL(url.toExternalForm());
+ Logger.debug("openJar url", url);
+ } catch (MalformedURLException ex1) {
+ Logger.error("Unable to find jar url", ex1);
+ setResponseInterface(true);
+ }
+ }
+
+ midletClassLoader.addURL(url);
+
+ Launcher.removeMIDletEntries();
+
+ manifest.clear();
+ InputStream is = null;
+ try {
+ is = midletClassLoader.getResourceAsStream("META-INF/MANIFEST.MF");
+ if (is == null) {
+ if (!describeJarProblem(url, midletClassLoader)) {
+ Message.error("Unable to find MANIFEST in MIDlet jar");
+ }
+ return;
+ }
+ manifest.load(is);
+ } catch (IOException e) {
+ Message.error("Unable to read MANIFEST", e);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+
+ Launcher.setSuiteName(jad.getSuiteName());
+
+ for (Enumeration e = jad.getMidletEntries().elements(); e.hasMoreElements();) {
+ JadMidletEntry jadEntry = (JadMidletEntry) e.nextElement();
+ Class midletClass = midletClassLoader.loadClass(jadEntry.getClassName());
+ Launcher.addMIDletEntry(new MIDletEntry(jadEntry.getName(), midletClass));
+ }
+ startLauncher(MIDletBridge.getMIDletContext());
+ setStatusBar("");
+ } finally {
+ setResponseInterface(true);
+ }
+ }
+
+ public Device getDevice() {
+ return DeviceFactory.getDevice();
+ }
+
+ public void setDevice(Device device) {
+ MIDletSystemProperties.setDevice(device);
+ DeviceFactory.setDevice(device);
+ }
+
+ private static Common getInstance() {
+ return instance;
+ }
+
+ public static void setStatusBar(String text) {
+ if (statusBarListener != null) {
+ statusBarListener.statusBarChanged(text);
+ }
+ }
+
+ private void setResponseInterface(boolean state) {
+ if (responseInterfaceListener != null) {
+ responseInterfaceListener.stateChanged(state);
+ }
+ }
+
+ private void registerImplementation(String implClassName, Map properties, boolean notFoundError) {
+ final String errorText = "Implementation initialization";
+ try {
+ Class implClass = getExtensionsClassLoader().loadClass(implClassName);
+ if (ImplementationInitialization.class.isAssignableFrom(implClass)) {
+ Object inst = implClass.newInstance();
+ Map parameters = new HashMap();
+ parameters.put(ImplementationInitialization.PARAM_EMULATOR_ID, Config.getEmulatorID());
+ if (properties != null) {
+ parameters.putAll(properties);
+ } else {
+ Map extensions = Config.getExtensions();
+ Map prop = (Map) extensions.get(implClassName);
+ if (prop != null) {
+ parameters.putAll(prop);
+ }
+ }
+ ((ImplementationInitialization) inst).registerImplementation(parameters);
+ Logger.debug("implementation registered", implClassName);
+ extensions.add(inst);
+ } else {
+ Logger.debug("initialize implementation", implClassName);
+ boolean isStatic = true;
+ try {
+ // Create and object or call static initializer instance();
+ Constructor c = implClass.getConstructor(null);
+ if (Modifier.isPublic(c.getModifiers())) {
+ isStatic = false;
+ implClass.newInstance();
+ }
+ } catch (NoSuchMethodException e) {
+ }
+
+ if (isStatic) {
+ try {
+ Method getinst = implClass.getMethod("instance", null);
+ if (Modifier.isStatic(getinst.getModifiers())) {
+ getinst.invoke(implClass, null);
+ } else {
+ Logger.debug("No known way to initialize implementation class");
+ }
+ } catch (NoSuchMethodException e) {
+ Logger.debug("No known way to initialize implementation class");
+ } catch (InvocationTargetException e) {
+ Logger.debug("Unable to initialize Implementation", e.getCause());
+ }
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ if (notFoundError) {
+ Logger.error(errorText, e);
+ } else {
+ Logger.warn(errorText + " " + e);
+ }
+ } catch (InstantiationException e) {
+ Logger.error(errorText, e);
+ } catch (IllegalAccessException e) {
+ Logger.error(errorText, e);
+ }
+ }
+
+ public void loadImplementationsFromConfig() {
+ Map extensions = Config.getExtensions();
+ for (Iterator iterator = extensions.entrySet().iterator(); iterator.hasNext();) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ registerImplementation((String) entry.getKey(), (Map) entry.getValue(), false);
+ }
+ }
+
+ public void notifyImplementationMIDletStart() {
+ for (Iterator iterator = extensions.iterator(); iterator.hasNext();) {
+ ImplementationInitialization impl = (ImplementationInitialization) iterator.next();
+ impl.notifyMIDletStart();
+ }
+ }
+
+ public void notifyImplementationMIDletDestroyed() {
+ for (Iterator iterator = extensions.iterator(); iterator.hasNext();) {
+ ImplementationInitialization impl = (ImplementationInitialization) iterator.next();
+ impl.notifyMIDletDestroyed();
+ }
+ }
+
+ public void initParams(List params, DeviceEntry defaultDevice, Class defaultDeviceClass) {
+ MIDletClassLoaderConfig clConfig = new MIDletClassLoaderConfig();
+ Class deviceClass = null;
+ String deviceDescriptorLocation = null;
+ RecordStoreManager paramRecordStoreManager = null;
+
+ Iterator argsIterator = params.iterator();
+
+ try {
+ while (argsIterator.hasNext()) {
+ String arg = (String) argsIterator.next();
+ argsIterator.remove();
+
+ if ((arg.equals("--help")) || (arg.equals("-help"))) {
+ System.out.println(usage());
+ System.exit(0);
+ } else if (arg.equals("--id")) {
+ Config.setEmulatorID((String) argsIterator.next());
+ argsIterator.remove();
+ } else if ((arg.equals("--appclasspath")) || (arg.equals("-appclasspath")) || (arg.equals("-appcp"))) {
+ if (clConfig == null) {
+ throw new ConfigurationException("Wrong command line argument order");
+ }
+ clConfig.addAppClassPath((String) argsIterator.next());
+ argsIterator.remove();
+ } else if (arg.equals("--appclass")) {
+ if (clConfig == null) {
+ throw new ConfigurationException("Wrong command line argument order");
+ }
+ clConfig.addAppClass((String) argsIterator.next());
+ argsIterator.remove();
+ } else if (arg.startsWith("-Xautotest:")) {
+ autoTests = true;
+ jadURL = arg.substring("-Xautotest:".length());
+ } else if (arg.equals("-Xautotest")) {
+ autoTests = true;
+ } else if (arg.equals("--propertiesjad")) {
+ File file = new File((String) argsIterator.next());
+ argsIterator.remove();
+ propertiesJad = file.exists() ? IOUtils.getCanonicalFileURL(file) : arg;
+ } else if (arg.equals("--appclassloader")) {
+ if (clConfig == null) {
+ Message.error("Error", "Wrong command line argument order");
+ break;
+ }
+ clConfig.setDelegationType((String) argsIterator.next());
+ argsIterator.remove();
+ } else if (arg.equals("--usesystemclassloader")) {
+ useSystemClassLoader = true;
+ clConfig.setDelegationType("system");
+ } else if (arg.equals("-d") || arg.equals("--device")) {
+ if (argsIterator.hasNext()) {
+ String tmpDevice = (String) argsIterator.next();
+ argsIterator.remove();
+ if (!tmpDevice.toLowerCase().endsWith(".xml")) {
+ try {
+ deviceClass = Class.forName(tmpDevice);
+ } catch (ClassNotFoundException ex) {
+ }
+ }
+ if (deviceClass == null) {
+ deviceDescriptorLocation = tmpDevice;
+ }
+ }
+ } else if (arg.equals("--rms")) {
+ if (argsIterator.hasNext()) {
+ String tmpRms = (String) argsIterator.next();
+ argsIterator.remove();
+ if (tmpRms.equals("file")) {
+ paramRecordStoreManager = new FileRecordStoreManager();
+ } else if (tmpRms.equals("memory")) {
+ paramRecordStoreManager = new MemoryRecordStoreManager();
+ }
+ }
+ } else if ((arg.equals("--classpath")) || (arg.equals("-classpath")) || (arg.equals("-cp"))) {
+ getExtensionsClassLoader().addClasspath((String) argsIterator.next());
+ argsIterator.remove();
+ } else if (arg.equals("--impl")) {
+ registerImplementation((String) argsIterator.next(), null, true);
+ argsIterator.remove();
+ } else {
+ midletClassOrJad = arg;
+ }
+ }
+ } catch (ConfigurationException e) {
+ Message.error("Error", e.getMessage(), e);
+ return;
+ }
+
+ mIDletClassLoaderConfig = clConfig;
+
+ // TODO registerImplementations by reading jar files in classpath.
+
+ ClassLoader classLoader = getExtensionsClassLoader();
+ if (deviceDescriptorLocation != null) {
+ try {
+ setDevice(DeviceImpl.create(emulatorContext, classLoader, deviceDescriptorLocation, defaultDeviceClass));
+ } catch (IOException ex) {
+ Logger.error(ex);
+ }
+ }
+ if (DeviceFactory.getDevice() == null) {
+ try {
+ if (deviceClass == null) {
+ if (defaultDevice.getFileName() != null) {
+ URL[] urls = new URL[1];
+ urls[0] = new File(Config.getConfigPath(), defaultDevice.getFileName()).toURI().toURL();
+ classLoader = createExtensionsClassLoader(urls);
+ }
+ setDevice(DeviceImpl.create(emulatorContext, classLoader, defaultDevice.getDescriptorLocation(),
+ defaultDeviceClass));
+ } else {
+ DeviceImpl device = (DeviceImpl) deviceClass.newInstance();
+ device.init(emulatorContext);
+ setDevice(device);
+ }
+ } catch (InstantiationException ex) {
+ Logger.error(ex);
+ } catch (IllegalAccessException ex) {
+ Logger.error(ex);
+ } catch (IOException ex) {
+ Logger.error(ex);
+ }
+ }
+
+ if (getRecordStoreManager() == null) {
+ if (paramRecordStoreManager == null) {
+ String className = Config.getRecordStoreManagerClassName();
+ if (className != null) {
+ try {
+ Class clazz = Class.forName(className);
+ setRecordStoreManager((RecordStoreManager) clazz.newInstance());
+ } catch (ClassNotFoundException ex) {
+ Logger.error(ex);
+ } catch (InstantiationException ex) {
+ Logger.error(ex);
+ } catch (IllegalAccessException ex) {
+ Logger.error(ex);
+ }
+ }
+ if (getRecordStoreManager() == null) {
+ setRecordStoreManager(new FileRecordStoreManager());
+ }
+ } else {
+ setRecordStoreManager(paramRecordStoreManager);
+ }
+ }
+ }
+
+ private static ExtensionsClassLoader getExtensionsClassLoader() {
+ if (instance.extensionsClassLoader == null) {
+ instance.extensionsClassLoader = new ExtensionsClassLoader(new URL[] {}, instance.getClass()
+ .getClassLoader());
+ }
+ return instance.extensionsClassLoader;
+ }
+
+ private MIDletClassLoader createMIDletClassLoader() {
+ MIDletClassLoader mcl = new MIDletClassLoader(getExtensionsClassLoader());
+ if (!Serializable.class.isAssignableFrom(Injected.class)) {
+ Logger
+ .error("classpath configuration error, Wrong Injected class detected. microemu-injected module should be after microemu-javase in eclipse");
+ }
+ if (mIDletClassLoaderConfig != null) {
+ try {
+ mcl.configure(mIDletClassLoaderConfig);
+ } catch (MalformedURLException e) {
+ Message.error("Error", "Unable to find MIDlet classes, " + Message.getCauseMessage(e), e);
+ }
+ }
+ mcl.disableClassPreporcessing(Injected.class);
+ mcl.disableClassPreporcessing(MIDletThread.class);
+ mcl.disableClassPreporcessing(MIDletTimer.class);
+ MIDletResourceLoader.classLoader = mcl;
+ return mcl;
+ }
+
+ public static ClassLoader createExtensionsClassLoader(final URL[] urls) {
+ return new ExtensionsClassLoader(urls, getExtensionsClassLoader());
+ }
+
+ private static JadProperties loadJadProperties(String urlString) throws IOException {
+ JadProperties properties = new JadProperties();
+
+ URL url = new URL(urlString);
+ if (url.getUserInfo() == null) {
+ properties.load(url.openStream());
+ } else {
+ URLConnection cn = url.openConnection();
+ String userInfo = new String(Base64Coder.encode(url.getUserInfo().getBytes("UTF-8")));
+ cn.setRequestProperty("Authorization", "Basic " + userInfo);
+ properties.load(cn.getInputStream());
+ }
+
+ return properties;
+ }
+
+ public void initMIDlet(boolean startMidlet) {
+ Class midletClass = null;
+
+ if (midletClassOrJad != null && midletClassOrJad.endsWith(".jad")) {
+ try {
+ File file = new File(midletClassOrJad);
+ String url = file.exists() ? IOUtils.getCanonicalFileURL(file) : midletClassOrJad;
+ openJadUrl(url);
+ } catch (IOException exception) {
+ Logger.error("Cannot load " + midletClassOrJad + " URL", exception);
+ }
+ } else if (midletClassOrJad != null) {
+ useSystemClassLoader = mIDletClassLoaderConfig.isClassLoaderDisabled();
+ if (!useSystemClassLoader) {
+ MIDletClassLoader classLoader = createMIDletClassLoader();
+ try {
+ classLoader.addClassURL(midletClassOrJad);
+ midletClass = classLoader.loadClass(midletClassOrJad);
+ } catch (MalformedURLException e) {
+ Message.error("Error", "Unable to find MIDlet class, " + Message.getCauseMessage(e), e);
+ return;
+ } catch (ClassNotFoundException e) {
+ Message.error("Error", "Unable to find MIDlet class, " + Message.getCauseMessage(e), e);
+ return;
+ }
+ } else {
+ try {
+ midletClass = instance.getClass().getClassLoader().loadClass(midletClassOrJad);
+ } catch (ClassNotFoundException e) {
+ Message.error("Error", "Unable to find MIDlet class, " + Message.getCauseMessage(e), e);
+ return;
+ }
+ }
+ }
+
+ if (autoTests) {
+ if (jadURL != null) {
+ runAutoTests(jadURL, true);
+ }
+ } else {
+
+ if (midletClass != null && propertiesJad != null) {
+ try {
+ jad = loadJadProperties(propertiesJad);
+ } catch (IOException e) {
+ Logger.error("Cannot load " + propertiesJad + " URL", e);
+ }
+ }
+
+ boolean started = false;
+
+ if (midletClass == null) {
+ MIDletEntry entry = launcher.getSelectedMidletEntry();
+ if (startMidlet && entry != null) {
+ started = (null != startMidlet(entry.getMIDletClass(), MIDletBridge.getMIDletAccess()));
+ }
+ } else {
+ started = (null != startMidlet(midletClass, MIDletBridge.getMIDletAccess()));
+ }
+ if (!started) {
+ startLauncher(MIDletBridge.getMIDletContext());
+ }
+ }
+
+ }
+
+ public static String usage() {
+ return "[(-d | --device) ({device descriptor} | {device class name}) ] \n" + "[--rms (file | memory)] \n"
+ + "[--id EmulatorID ] \n" + "[--impl {JSR implementation class name}]\n"
+ + "[(--classpath|-cp) <JSR CLASSPATH>]\n" + "[(--appclasspath|--appcp) <MIDlet CLASSPATH>]\n"
+ + "[--appclass <library class name>]\n" + "[--appclassloader strict|delegating|system] \n"
+ + "[-Xautotest:<JAD file url>\n"
+ + "(({MIDlet class name} [--propertiesjad {jad file location}]) | {jad file location})";
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Common.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Config.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Config.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Config.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Config.java Mon May 26 15:20:19 2008
@@ -0,0 +1,547 @@
+/*
+ * 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;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+import nanoxml.XMLParseException;
+
+import org.microemu.EmulatorContext;
+import org.microemu.app.util.DeviceEntry;
+import org.microemu.app.util.IOUtils;
+import org.microemu.app.util.MIDletSystemProperties;
+import org.microemu.app.util.MRUList;
+import org.microemu.app.util.MidletURLReference;
+import org.microemu.device.impl.DeviceImpl;
+import org.microemu.device.impl.Rectangle;
+import org.microemu.log.Logger;
+import org.microemu.microedition.ImplementationInitialization;
+
+public class Config {
+
+ private static File meHome;
+
+ /**
+ * emulatorID used for multiple instance of MicroEmulator, now redefine home
+ */
+ private static String emulatorID;
+
+ private static XMLElement configXml;
+
+ private static DeviceEntry defaultDevice;
+
+ private static EmulatorContext emulatorContext;
+
+ private static MRUList urlsMRU = new MRUList(MidletURLReference.class, "midlet");
+
+ private static File initMEHomePath() {
+ try {
+ File meHome = new File(System.getProperty("user.home") + "/.microemulator/");
+ if (emulatorID != null) {
+ return new File(meHome, emulatorID);
+ } else {
+ return meHome;
+ }
+ } catch (SecurityException e) {
+ Logger.error("Cannot access user.home", e);
+ return null;
+ }
+ }
+
+ public static void loadConfig(DeviceEntry defaultDevice, EmulatorContext emulatorContext) {
+ Config.defaultDevice = defaultDevice;
+ Config.emulatorContext = emulatorContext;
+
+ File configFile = new File(getConfigPath(), "config2.xml");
+ try {
+ if (configFile.exists()) {
+ loadConfigFile("config2.xml");
+ } else {
+ configFile = new File(getConfigPath(), "config.xml");
+ if (configFile.exists()) {
+ // migrate from config.xml
+ loadConfigFile("config.xml");
+
+ for (Enumeration e = getDeviceEntries().elements(); e.hasMoreElements();) {
+ DeviceEntry entry = (DeviceEntry) e.nextElement();
+ if (!entry.canRemove()) {
+ continue;
+ }
+
+ removeDeviceEntry(entry);
+ File src = new File(getConfigPath(), entry.getFileName());
+ File dst = File.createTempFile("dev", ".jar", getConfigPath());
+ IOUtils.copyFile(src, dst);
+ entry.setFileName(dst.getName());
+ addDeviceEntry(entry);
+ }
+ } else {
+ createDefaultConfigXml();
+ }
+ saveConfig();
+ }
+ } catch (IOException ex) {
+ Logger.error(ex);
+ createDefaultConfigXml();
+ } finally {
+ // Happens in webstart untrusted environment
+ if (configXml == null) {
+ createDefaultConfigXml();
+ }
+ }
+ urlsMRU.read(configXml.getChildOrNew("files").getChildOrNew("recent"));
+ initSystemProperties();
+ }
+
+ private static void loadConfigFile(String configFileName) throws IOException {
+ File configFile = new File(getConfigPath(), configFileName);
+ InputStream is = null;
+ String xml = "";
+ try {
+ InputStream dis = new BufferedInputStream(is = new FileInputStream(configFile));
+ while (dis.available() > 0) {
+ byte[] b = new byte[dis.available()];
+ dis.read(b);
+ xml += new String(b);
+ }
+ configXml = new XMLElement();
+ configXml.parseString(xml);
+ } catch (XMLParseException e) {
+ Logger.error(e);
+ createDefaultConfigXml();
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ private static void createDefaultConfigXml() {
+ configXml = new XMLElement();
+ configXml.setName("config");
+ }
+
+ public static void saveConfig() {
+
+ urlsMRU.save(configXml.getChildOrNew("files").getChildOrNew("recent"));
+
+ File configFile = new File(getConfigPath(), "config2.xml");
+
+ getConfigPath().mkdirs();
+ FileWriter fw = null;
+ try {
+ fw = new FileWriter(configFile);
+ configXml.write(fw);
+ fw.close();
+ } catch (IOException ex) {
+ Logger.error(ex);
+ } finally {
+ IOUtils.closeQuietly(fw);
+ }
+ }
+
+ static Map getExtensions() {
+ Map extensions = new HashMap();
+ XMLElement extensionsXml = configXml.getChild("extensions");
+ if (extensionsXml == null) {
+ return extensions;
+ }
+ for (Enumeration en = extensionsXml.enumerateChildren(); en.hasMoreElements();) {
+ XMLElement extension = (XMLElement) en.nextElement();
+ if (!extension.getName().equals("extension")) {
+ continue;
+ }
+ String className = (String) extension.getChildString("className", null);
+ if (className == null) {
+ continue;
+ }
+
+ Map parameters = new HashMap();
+ parameters.put(ImplementationInitialization.PARAM_EMULATOR_ID, Config.getEmulatorID());
+
+ for (Enumeration een = extension.enumerateChildren(); een.hasMoreElements();) {
+ XMLElement propXml = (XMLElement) een.nextElement();
+ if (propXml.getName().equals("properties")) {
+ for (Enumeration e_prop = propXml.enumerateChildren(); e_prop.hasMoreElements();) {
+ XMLElement tmp_prop = (XMLElement) e_prop.nextElement();
+ if (tmp_prop.getName().equals("property")) {
+ parameters.put(tmp_prop.getStringAttribute("name"), tmp_prop.getStringAttribute("value"));
+ }
+ }
+ }
+ }
+
+ extensions.put(className, parameters);
+ }
+ return extensions;
+ }
+
+ private static void initSystemProperties() {
+ Map systemProperties = null;
+
+ for (Enumeration e = configXml.enumerateChildren(); e.hasMoreElements();) {
+ XMLElement tmp = (XMLElement) e.nextElement();
+ if (tmp.getName().equals("system-properties")) {
+ // Permits null values.
+ systemProperties = new HashMap();
+ for (Enumeration e_prop = tmp.enumerateChildren(); e_prop.hasMoreElements();) {
+ XMLElement tmp_prop = (XMLElement) e_prop.nextElement();
+ if (tmp_prop.getName().equals("system-property")) {
+ systemProperties.put(tmp_prop.getStringAttribute("name"), tmp_prop.getStringAttribute("value"));
+ }
+ }
+ }
+ }
+
+ // No <system-properties> in config2.xml
+ if (systemProperties == null) {
+ systemProperties = new Properties();
+ systemProperties.put("microedition.configuration", "CLDC-1.0");
+ systemProperties.put("microedition.profiles", "MIDP-2.0");
+ // Ask avetana to ignore MIDP profiles and load JSR-82
+ // implementation dll or so
+ systemProperties.put("avetana.forceNativeLibrary", Boolean.TRUE.toString());
+
+ XMLElement propertiesXml = configXml.getChildOrNew("system-properties");
+
+ for (Iterator i = systemProperties.entrySet().iterator(); i.hasNext();) {
+ Map.Entry e = (Map.Entry) i.next();
+ XMLElement xmlProperty = propertiesXml.addChild("system-property");
+ xmlProperty.setAttribute("value", (String) e.getValue());
+ xmlProperty.setAttribute("name", (String) e.getKey());
+ }
+
+ saveConfig();
+ }
+
+ MIDletSystemProperties.setProperties(systemProperties);
+ }
+
+ public static File getConfigPath() {
+ if (meHome == null) {
+ meHome = initMEHomePath();
+ }
+ return meHome;
+ }
+
+ public static Vector getDeviceEntries() {
+ Vector result = new Vector();
+
+ if (defaultDevice == null) {
+ defaultDevice = new DeviceEntry("Default device", null, DeviceImpl.DEFAULT_LOCATION, true, false);
+ }
+ defaultDevice.setDefaultDevice(true);
+ result.add(defaultDevice);
+
+ XMLElement devicesXml = configXml.getChild("devices");
+ if (devicesXml == null) {
+ return result;
+ }
+
+ for (Enumeration e_device = devicesXml.enumerateChildren(); e_device.hasMoreElements();) {
+ XMLElement tmp_device = (XMLElement) e_device.nextElement();
+ if (tmp_device.getName().equals("device")) {
+ boolean devDefault = false;
+ if (tmp_device.getStringAttribute("default") != null
+ && tmp_device.getStringAttribute("default").equals("true")) {
+ devDefault = true;
+ defaultDevice.setDefaultDevice(false);
+ }
+ String devName = tmp_device.getChildString("name", null);
+ String devFile = tmp_device.getChildString("filename", null);
+ String devClass = tmp_device.getChildString("class", null);
+ String devDescriptor = tmp_device.getChildString("descriptor", null);
+ ;
+ if (devDescriptor == null) {
+ result.add(new DeviceEntry(devName, devFile, devDefault, devClass, emulatorContext));
+ } else {
+ result.add(new DeviceEntry(devName, devFile, devDescriptor, devDefault));
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public static void addDeviceEntry(DeviceEntry entry) {
+ for (Enumeration en = getDeviceEntries().elements(); en.hasMoreElements();) {
+ DeviceEntry test = (DeviceEntry) en.nextElement();
+ if (test.getDescriptorLocation().equals(entry.getDescriptorLocation())) {
+ return;
+ }
+ }
+
+ XMLElement devicesXml = configXml.getChildOrNew("devices");
+
+ XMLElement deviceXml = devicesXml.addChild("device");
+ if (entry.isDefaultDevice()) {
+ deviceXml.setAttribute("default", "true");
+ }
+ deviceXml.addChild("name", entry.getName());
+ deviceXml.addChild("filename", entry.getFileName());
+ deviceXml.addChild("descriptor", entry.getDescriptorLocation());
+
+ saveConfig();
+ }
+
+ public static void removeDeviceEntry(DeviceEntry entry) {
+ XMLElement devicesXml = configXml.getChild("devices");
+ if (devicesXml == null) {
+ return;
+ }
+
+ for (Enumeration e_device = devicesXml.enumerateChildren(); e_device.hasMoreElements();) {
+ XMLElement tmp_device = (XMLElement) e_device.nextElement();
+ if (tmp_device.getName().equals("device")) {
+ String testDescriptor = tmp_device.getChildString("descriptor", null);
+ // this is needed by migration config.xml -> config2.xml
+ if (testDescriptor == null) {
+ devicesXml.removeChild(tmp_device);
+
+ saveConfig();
+ continue;
+ }
+ if (testDescriptor.equals(entry.getDescriptorLocation())) {
+ devicesXml.removeChild(tmp_device);
+
+ saveConfig();
+ break;
+ }
+ }
+ }
+ }
+
+ public static void changeDeviceEntry(DeviceEntry entry) {
+ XMLElement devicesXml = configXml.getChild("devices");
+ if (devicesXml == null) {
+ return;
+ }
+
+ for (Enumeration e_device = devicesXml.enumerateChildren(); e_device.hasMoreElements();) {
+ XMLElement tmp_device = (XMLElement) e_device.nextElement();
+ if (tmp_device.getName().equals("device")) {
+ String testDescriptor = tmp_device.getChildString("descriptor", null);
+ if (testDescriptor.equals(entry.getDescriptorLocation())) {
+ if (entry.isDefaultDevice()) {
+ tmp_device.setAttribute("default", "true");
+ } else {
+ tmp_device.removeAttribute("default");
+ }
+
+ saveConfig();
+ break;
+ }
+ }
+ }
+ }
+
+ public static Rectangle getDeviceEntryDisplaySize(DeviceEntry entry) {
+ XMLElement devicesXml = configXml.getChild("devices");
+
+ for (Enumeration e_device = devicesXml.enumerateChildren(); e_device.hasMoreElements();) {
+ XMLElement tmp_device = (XMLElement) e_device.nextElement();
+ if (tmp_device.getName().equals("device")) {
+ String testDescriptor = tmp_device.getChildString("descriptor", null);
+ if (testDescriptor.equals(entry.getDescriptorLocation())) {
+ XMLElement rectangleXml = tmp_device.getChild("rectangle");
+ if (rectangleXml != null) {
+ Rectangle result = new Rectangle();
+ result.x = rectangleXml.getChildInteger("x", -1);
+ result.y = rectangleXml.getChildInteger("y", -1);
+ result.width = rectangleXml.getChildInteger("width", -1);
+ result.height = rectangleXml.getChildInteger("height", -1);
+
+ return result;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public static void setDeviceEntryDisplaySize(DeviceEntry entry, Rectangle rect) {
+ if (entry == null) {
+ return;
+ }
+ XMLElement devicesXml = configXml.getChild("devices");
+ if (devicesXml == null) {
+ return;
+ }
+
+ for (Enumeration e_device = devicesXml.enumerateChildren(); e_device.hasMoreElements();) {
+ XMLElement tmp_device = (XMLElement) e_device.nextElement();
+ if (tmp_device.getName().equals("device")) {
+ String testDescriptor = tmp_device.getChildString("descriptor", null);
+ if (testDescriptor.equals(entry.getDescriptorLocation())) {
+ XMLElement mainXml = tmp_device.getChildOrNew("rectangle");
+ XMLElement xml = mainXml.getChildOrNew("x");
+ xml.setContent(String.valueOf(rect.x));
+ xml = mainXml.getChildOrNew("y");
+ xml.setContent(String.valueOf(rect.y));
+ xml = mainXml.getChildOrNew("width");
+ xml.setContent(String.valueOf(rect.width));
+ xml = mainXml.getChildOrNew("height");
+ xml.setContent(String.valueOf(rect.height));
+
+ saveConfig();
+ break;
+ }
+ }
+ }
+ }
+
+ public static String getRecordStoreManagerClassName() {
+ XMLElement recordStoreManagerXml = configXml.getChild("recordStoreManager");
+ if (recordStoreManagerXml == null) {
+ return null;
+ }
+
+ return recordStoreManagerXml.getStringAttribute("class");
+ }
+
+ public static void setRecordStoreManagerClassName(String className) {
+ XMLElement recordStoreManagerXml = configXml.getChildOrNew("recordStoreManager");
+ recordStoreManagerXml.setAttribute("class", className);
+
+ saveConfig();
+ }
+
+ public static boolean isLogConsoleLocationEnabled() {
+ XMLElement logConsoleXml = configXml.getChild("logConsole");
+ if (logConsoleXml == null) {
+ return true;
+ }
+
+ return logConsoleXml.getBooleanAttribute("locationEnabled", true);
+ }
+
+ public static void setLogConsoleLocationEnabled(boolean state) {
+ XMLElement logConsoleXml = configXml.getChildOrNew("logConsole");
+ if (state) {
+ logConsoleXml.setAttribute("locationEnabled", "true");
+ } else {
+ logConsoleXml.setAttribute("locationEnabled", "false");
+ }
+
+ saveConfig();
+ }
+
+ public static boolean isWindowOnStart(String name) {
+ XMLElement windowsXml = configXml.getChild("windows");
+ if (windowsXml == null) {
+ return false;
+ }
+
+ XMLElement mainXml = windowsXml.getChild(name);
+ if (mainXml == null) {
+ return false;
+ }
+
+ String attr = mainXml.getStringAttribute("onstart", "false");
+ if (attr.trim().toLowerCase().equals("true")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static Rectangle getWindow(String name, Rectangle defaultWindow) {
+ XMLElement windowsXml = configXml.getChild("windows");
+ if (windowsXml == null) {
+ return defaultWindow;
+ }
+
+ XMLElement mainXml = windowsXml.getChild(name);
+ if (mainXml == null) {
+ return defaultWindow;
+ }
+
+ Rectangle window = new Rectangle();
+ window.x = mainXml.getChildInteger("x", defaultWindow.x);
+ window.y = mainXml.getChildInteger("y", defaultWindow.y);
+ window.width = mainXml.getChildInteger("width", defaultWindow.width);
+ window.height = mainXml.getChildInteger("height", defaultWindow.height);
+
+ return window;
+ }
+
+ public static void setWindow(String name, Rectangle window, boolean onStart) {
+ XMLElement windowsXml = configXml.getChildOrNew("windows");
+ XMLElement mainXml = windowsXml.getChildOrNew(name);
+ if (onStart) {
+ mainXml.setAttribute("onstart", "true");
+ } else {
+ mainXml.removeAttribute("onstart");
+ }
+ XMLElement xml = mainXml.getChildOrNew("x");
+ xml.setContent(String.valueOf(window.x));
+ xml = mainXml.getChildOrNew("y");
+ xml.setContent(String.valueOf(window.y));
+ xml = mainXml.getChildOrNew("width");
+ xml.setContent(String.valueOf(window.width));
+ xml = mainXml.getChildOrNew("height");
+ xml.setContent(String.valueOf(window.height));
+
+ saveConfig();
+ }
+
+ public static String getRecentDirectory(String key) {
+ String defaultResult = ".";
+
+ XMLElement filesXml = configXml.getChild("files");
+ if (filesXml == null) {
+ return defaultResult;
+ }
+
+ return filesXml.getChildString(key, defaultResult);
+ }
+
+ public static void setRecentDirectory(String key, String recentJadDirectory) {
+ XMLElement filesXml = configXml.getChildOrNew("files");
+ XMLElement recentJadDirectoryXml = filesXml.getChildOrNew(key);
+ recentJadDirectoryXml.setContent(recentJadDirectory);
+
+ saveConfig();
+ }
+
+ public static MRUList getUrlsMRU() {
+ return urlsMRU;
+ }
+
+ public static String getEmulatorID() {
+ return emulatorID;
+ }
+
+ public static void setEmulatorID(String emulatorID) {
+ Config.emulatorID = emulatorID;
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/Config.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/ConfigurationException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/ConfigurationException.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/ConfigurationException.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/ConfigurationException.java Mon May 26 15:20:19 2008
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+public class ConfigurationException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public ConfigurationException(String message) {
+ super(message);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/ConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/classloader/ChangeCallsClassVisitor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/classloader/ChangeCallsClassVisitor.java?rev=660326&view=auto
==============================================================================
--- harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/classloader/ChangeCallsClassVisitor.java (added)
+++ harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/classloader/ChangeCallsClassVisitor.java Mon May 26 15:20:19 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.classloader;
+
+import org.microemu.app.util.MIDletThread;
+import org.objectweb.asm.ClassAdapter;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.MethodVisitor;
+
+/**
+ * @author vlads
+ *
+ */
+public class ChangeCallsClassVisitor extends ClassAdapter {
+
+ InstrumentationConfig config;
+
+ public ChangeCallsClassVisitor(ClassVisitor cv, InstrumentationConfig config) {
+ super(cv);
+ this.config = config;
+ }
+
+ public void visit(final int version, final int access, final String name, final String signature, String superName, final String[] interfaces) {
+ if ((config.isEnhanceThreadCreation()) && (superName.equals("java/lang/Thread"))) {
+ superName = ChangeCallsMethodVisitor.codeName(MIDletThread.class);
+ }
+ super.visit(version, access, name, signature, superName, interfaces);
+ }
+
+ public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
+ return new ChangeCallsMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), config);
+ }
+
+}
Propchange: harmony/enhanced/microemulator/microemu-javase/src/main/java/org/microemu/app/classloader/ChangeCallsClassVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native