|
From: <fd...@us...> - 2008-09-30 22:10:17
|
Revision: 4594
http://jnode.svn.sourceforge.net/jnode/?rev=4594&view=rev
Author: fduminy
Date: 2008-09-30 22:09:24 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
- further implementation of BDF fonts & peers related methods
- started implementation of missing methods in ttf fonts & peers
Modified Paths:
--------------
trunk/core/src/classpath/gnu/gnu/java/awt/ClasspathToolkit.java
trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java
trunk/gui/src/awt/org/jnode/awt/font/FontManager.java
trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/JNodeFontPeer.java
trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontPeer.java
trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/def/DefaultFontManager.java
trunk/gui/src/awt/org/jnode/awt/font/spi/AbstractFontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFFontDataFile.java
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFMemoryInput.java
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java
Added Paths:
-----------
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFFontPeer.java
Removed Paths:
-------------
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFURLInput.java
Modified: trunk/core/src/classpath/gnu/gnu/java/awt/ClasspathToolkit.java
===================================================================
--- trunk/core/src/classpath/gnu/gnu/java/awt/ClasspathToolkit.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/core/src/classpath/gnu/gnu/java/awt/ClasspathToolkit.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -38,36 +38,23 @@
package gnu.java.awt;
-import gnu.java.awt.EmbeddedWindow;
import gnu.java.awt.peer.ClasspathFontPeer;
import gnu.java.awt.peer.EmbeddedWindowPeer;
import gnu.java.security.action.SetAccessibleAction;
import java.awt.AWTException;
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.DisplayMode;
import java.awt.Font;
-import java.awt.FontMetrics;
+import java.awt.FontFormatException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Point;
import java.awt.Toolkit;
-import java.awt.font.FontRenderContext;
-import java.awt.image.ColorModel;
-import java.awt.image.ImageProducer;
import java.awt.peer.RobotPeer;
-import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.text.AttributedString;
-import java.util.HashMap;
-import java.util.Map;
import java.security.AccessController;
+import java.util.Map;
import javax.imageio.spi.IIORegistry;
@@ -187,7 +174,8 @@
* @throws IOException if a problem occurs while reading in the
* contents of <code>stream</code>.
*/
- public abstract Font createFont(int format, InputStream stream);
+ // jnode : added "throws FontFormatException, IOException" since Classpath's javadoc mention it
+ public abstract Font createFont(int format, InputStream stream) throws FontFormatException, IOException;
/**
* Creates a RobotPeer on a given GraphicsDevice.
Modified: trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/JNodeToolkit.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -37,6 +37,7 @@
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
@@ -80,7 +81,6 @@
import org.apache.log4j.Logger;
import org.jnode.awt.font.FontManager;
-import org.jnode.awt.font.JNodeFontPeer;
import org.jnode.awt.image.BufferedImageSurface;
import org.jnode.awt.image.JNodeImage;
import org.jnode.driver.DeviceException;
@@ -265,7 +265,7 @@
/**
* @see gnu.java.awt.ClasspathToolkit#createFont(int, java.io.InputStream)
*/
- public Font createFont(int format, InputStream stream) {
+ public Font createFont(int format, InputStream stream) throws FontFormatException, IOException {
return getFontManager().createFont(format, stream);
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/FontManager.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/FontManager.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/font/FontManager.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -25,9 +25,11 @@
import java.awt.Color;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
@@ -82,18 +84,11 @@
Color color);
/**
+ * @throws IOException
+ * @throws FontFormatException
*
*/
- public Font createFont(int format, InputStream stream);
+ public Font createFont(int format, InputStream stream) throws FontFormatException, IOException;
public ClasspathFontPeer createFontPeer(String name, Map attrs);
-
- /**
- * Translates the font into a font that is provided by a provider.
- *
- * @param font
- * @param providerName
- * @return
- */
- public Font getClosestProvidedFont(Font font, String providerName);
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -22,7 +22,10 @@
package org.jnode.awt.font;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.FontMetrics;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Map;
import java.util.Set;
@@ -32,7 +35,7 @@
* @author Ewout Prangsma (ep...@us...)
* @author Fabien DUMINY (fd...@jn...)
*/
-public interface FontProvider {
+public interface FontProvider<F extends Font> {
/**
* Give the name of the font (used for setting the first provider to use
* among all available ones)
@@ -65,7 +68,7 @@
*
* @return All fonts this provider can provide
*/
- public Set<Font> getAllFonts();
+ public Set<F> getAllFonts();
/**
* Gets a text renderer for the given font.
@@ -84,6 +87,14 @@
public FontMetrics getFontMetrics(Font font);
/**
+ * Translates the font into a font that is provided by this provider.
+ *
+ * @param font
+ * @return
+ */
+ public F getCompatibleFont(Font font);
+
+ /**
* Creates a font peer from the given name or return null if not supported/provided.
* As said in {@link JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
* "We don't know what kind of "name" the user requested (logical, face, family)".
@@ -92,5 +103,12 @@
* @param attrs
* @return
*/
- public JNodeFontPeer createFontPeer(String name, Map attrs);
+ public JNodeFontPeer<? extends FontProvider<F>, F> createFontPeer(String name, Map attrs);
+
+ /**
+ * Read and create a Font from the given InputStream
+ * @param stream
+ * @return
+ */
+ public F createFont(InputStream stream) throws FontFormatException, IOException;
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/JNodeFontPeer.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/JNodeFontPeer.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/font/JNodeFontPeer.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -39,14 +39,17 @@
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
*/
-public abstract class JNodeFontPeer extends ClasspathFontPeer implements FontPeer {
-
+public abstract class JNodeFontPeer<FP extends FontProvider<F>, F extends Font>
+ extends ClasspathFontPeer implements FontPeer {
+ protected final FP provider;
+
/**
* @param name
* @param attrs
*/
- public JNodeFontPeer(String name, Map attrs) {
+ public JNodeFontPeer(FP provider, String name, Map attrs) {
super(name, attrs);
+ this.provider = provider;
}
/**
@@ -145,4 +148,18 @@
*/
public abstract GlyphVector layoutGlyphVector(Font font, FontRenderContext frc,
char[] chars, int start, int limit, int flags);
+
+ /**
+ * Convert the given font to a Font whose type is F.
+ * The font given as input might not be an instance of F
+ * since {@link Font} class is public, not abstract and has a public constructor.
+ * If that's the case, then we are trying to find the closest font that
+ * this peer's provider provides.
+ *
+ * @param font any instance of {@link Font} (might not be an instance of F)
+ * @return
+ */
+ protected final F getCompatibleFont(Font font) {
+ return provider.getCompatibleFont(font);
+ }
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontPeer.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontPeer.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontPeer.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -10,20 +10,15 @@
import java.util.Locale;
import java.util.Map;
-import javax.naming.NamingException;
-
import org.apache.log4j.Logger;
-import org.jnode.awt.font.FontManager;
import org.jnode.awt.font.JNodeFontPeer;
import org.jnode.font.bdf.BDFFontContainer;
import org.jnode.font.bdf.BDFGlyph;
import org.jnode.font.bdf.BDFMetrics;
-import org.jnode.font.bdf.BDFParser;
-import org.jnode.naming.InitialNaming;
-import org.jnode.vm.Unsafe;
import sun.font.CoreMetrics;
import sun.font.FontLineMetrics;
+import sun.font.StandardGlyphVector;
/**
* Specific implementation of {@link JNodeFontPeer} for BDF fonts
@@ -31,11 +26,16 @@
* @author fabien
*
*/
-public class BDFFontPeer extends JNodeFontPeer {
+public class BDFFontPeer extends JNodeFontPeer<BDFFontProvider, BDFFont> {
private static final Logger log = Logger.getLogger(BDFFontPeer.class);
- public BDFFontPeer(String name, Map attrs) {
- super(name, attrs);
+ /**
+ * this the char used to replace missing glyphs in BDFFont
+ */
+ private static final char MISSING_GLYPH_CODE = '\u0020';
+
+ public BDFFontPeer(BDFFontProvider provider, String name, Map attrs) {
+ super(provider, name, attrs);
}
/**
@@ -43,13 +43,13 @@
*/
@Override
public boolean canDisplay(Font font, char c) {
- BDFFont bdfFont = toBDFFont(font);
+ BDFFont bdfFont = getCompatibleFont(font);
//TODO this is a temporary workaround : we should add a method to BDFFont
- BDFGlyph spaceGlyph = bdfFont.getContainer().getGlyph('\u0020');
+ BDFGlyph spaceGlyph = bdfFont.getContainer().getGlyph(MISSING_GLYPH_CODE);
BDFGlyph characterGlyph = bdfFont.getContainer().getGlyph(c);
- return (c == '\u0020') || ((c != '\u0020') && (characterGlyph != spaceGlyph));
+ return (c == MISSING_GLYPH_CODE) || ((c != MISSING_GLYPH_CODE) && (characterGlyph != spaceGlyph));
}
/**
@@ -78,10 +78,7 @@
@Override
public GlyphVector createGlyphVector(Font font, FontRenderContext frc,
CharacterIterator ci) {
- // TODO implement me
- System.out.println("JNodeFontPeer.createGlyphVector(" +
- "Font,FontRenderContext,CharacterIterator) not implemented");
- return null;
+ return new StandardGlyphVector(font, ci, frc);
}
/**
@@ -91,10 +88,7 @@
@Override
public GlyphVector createGlyphVector(Font font, FontRenderContext ctx,
int[] glyphCodes) {
- // TODO implement me
- System.out.println("JNodeFontPeer.createGlyphVector(" +
- "Font,FontRenderContext,int[]) not implemented");
- return null;
+ return new StandardGlyphVector(font, glyphCodes, ctx);
}
/**
@@ -103,8 +97,12 @@
*/
@Override
public byte getBaselineFor(Font font, char c) {
- System.out.println("JNodeFontPeer.getBaselineFor not implemented"); // TODO implement me
- return 0;
+ System.out.println("JNodeFontPeer.getBaselineFor not implemented");
+
+ // TODO find proper value from the BDFFontContainer
+ // it should be one of Font.CENTER_BASELINE, Font.HANGING_BASELINE,
+ // Font.ROMAN_BASELINE
+ return Font.ROMAN_BASELINE;
}
/**
@@ -112,7 +110,7 @@
*/
@Override
public FontMetrics getFontMetrics(Font font) {
- return toBDFFont(font).getFontMetrics();
+ return getCompatibleFont(font).getFontMetrics();
}
/**
@@ -120,7 +118,7 @@
*/
@Override
public String getGlyphName(Font font, int glyphIndex) {
- return toBDFFont(font).getContainer().getGlyphs()[glyphIndex].getName();
+ return getCompatibleFont(font).getContainer().getGlyphs()[glyphIndex].getName();
}
/**
@@ -131,7 +129,7 @@
@Override
public LineMetrics getLineMetrics(Font font, CharacterIterator ci,
int begin, int limit, FontRenderContext rc) {
- BDFFont bdfFont = toBDFFont(font);
+ BDFFont bdfFont = getCompatibleFont(font);
BDFMetrics fm = bdfFont.getContainer().getFontMetrics();
float ascent = fm.getAscent();
@@ -163,8 +161,12 @@
*/
@Override
public Rectangle2D getMaxCharBounds(Font font, FontRenderContext rc) {
- System.out.println("JNodeFontPeer.getMaxCharBounds not implemented"); // TODO implement me
- return null;
+ BDFFont bdfFont = getCompatibleFont(font);
+
+ final Rectangle2D bounds = provider.getMaxCharBounds(bdfFont.getContainer());
+ transform(bounds, rc);
+
+ return bounds;
}
/**
@@ -173,7 +175,7 @@
@Override
public int getMissingGlyphCode(Font font) {
//TODO this is a temporary workaround : we should add a method to BDFFont
- return '\u0020'; // this the char used to replace missing glyphs in BDFFont
+ return MISSING_GLYPH_CODE; // this the char used to replace missing glyphs in BDFFont
}
/**
@@ -181,7 +183,7 @@
*/
@Override
public int getNumGlyphs(Font font) {
- return toBDFFont(font).getContainer().getGlyphs().length;
+ return getCompatibleFont(font).getContainer().getGlyphs().length;
}
/**
@@ -189,7 +191,7 @@
*/
@Override
public String getPostScriptName(Font font) {
- return toBDFFont(font).getContainer().getName();
+ return getCompatibleFont(font).getContainer().getName();
}
/**
@@ -200,7 +202,7 @@
@Override
public Rectangle2D getStringBounds(Font font, CharacterIterator ci,
int begin, int limit, FontRenderContext frc) {
- BDFFont bdfFont = toBDFFont(font);
+ BDFFont bdfFont = getCompatibleFont(font);
BDFFontContainer container = bdfFont.getContainer();
double width = 0;
@@ -213,44 +215,21 @@
}
}
final Rectangle2D bounds = new Rectangle2D.Double(0, 0, width, height);
-
- if (frc.getTransform() != null) {
- double[] srcPoints =
- new double[] {bounds.getMinX(), bounds.getMinY(),
- bounds.getMinX(), bounds.getMaxY(),
- bounds.getMaxX(), bounds.getMaxY(),
- bounds.getMaxX(), bounds.getMinY()};
- double[] dstPoints = new double[srcPoints.length];
- frc.getTransform().transform(srcPoints, 0, dstPoints, 0, srcPoints.length / 2);
-
- // compute the bounding box of the result
- double minX = dstPoints[0];
- double minY = dstPoints[1];
- double maxX = minX;
- double maxY = minY;
- for (int i = 2; i < dstPoints.length; i += 2) {
- double x = dstPoints[i];
- minX = Math.min(minX, x);
- maxX = Math.max(maxX, x);
- double y = dstPoints[i + 1];
- minY = Math.min(minY, y);
- maxY = Math.max(maxY, y);
- }
- bounds.setRect(minX, minY, maxX - minX + 1, maxY - minY + 1);
- }
-
+ transform(bounds, frc);
return bounds;
}
/**
+ *
* @see gnu.java.awt.peer.ClasspathFontPeer#getSubFamilyName(java.awt.Font,
* java.util.Locale)
*/
@Override
public String getSubFamilyName(Font font, Locale locale) {
- System.out.println("JNodeFontPeer.getSubFamilyName not implemented"); // TODO implement me
- return null;
+ System.out.println("JNodeFontPeer.getSubFamilyName not implemented");
+ // TODO not implemented ... remove that while moving to openjdk
+ return "";
}
/**
@@ -258,8 +237,9 @@
*/
@Override
public boolean hasUniformLineMetrics(Font font) {
- System.out.println("JNodeFontPeer.hasUniformLineMetrics not implemented"); // TODO implement me
- return false;
+ // We don't have "subfonts" (terms used in GNU Classpath javadoc)
+ // => returns true
+ return true;
}
/**
@@ -269,36 +249,36 @@
@Override
public GlyphVector layoutGlyphVector(Font font, FontRenderContext frc,
char[] chars, int start, int limit, int flags) {
- System.out.println("JNodeFontPeer.layoutGlyphVector not implemented"); // TODO implement me
- return null;
+ //TODO work only for latin fonts but not for hindi, arabic ... fonts
+ // see GNU Classpath javadoc
+ return new StandardGlyphVector(font, chars, start, limit, frc);
}
- /**
- * Convert the given font to a BDFFont.
- * The font given as input might not be an instance of BDFFont
- * since {@link Font} class is public, not abstract and has a public constructor.
- * If that's the case, then we are trying to find the closest font that we provide.
- *
- * @param font any instance of {@link Font} (might not be an instance of BDFFont)
- * @return
- */
- private BDFFont toBDFFont(Font font) {
- if (!(font instanceof BDFFont)) {
- // ask the FontManager for a compatible Font that we provide
- try {
- FontManager mgr = InitialNaming.lookup(FontManager.NAME);
- font = mgr.getClosestProvidedFont(font, BDFFontProvider.NAME);
- } catch (NamingException ex) {
- // it should never happen since font peers are created
- // by the FontManager
- log.error(ex);
+ private void transform(Rectangle2D bounds, FontRenderContext frc) {
+ if (frc.getTransform() != null) {
+ double[] srcPoints =
+ new double[] {bounds.getMinX(), bounds.getMinY(),
+ bounds.getMinX(), bounds.getMaxY(),
+ bounds.getMaxX(), bounds.getMaxY(),
+ bounds.getMaxX(), bounds.getMinY()};
+ double[] dstPoints = new double[srcPoints.length];
+ frc.getTransform().transform(srcPoints, 0, dstPoints, 0, srcPoints.length / 2);
+
+ // compute the bounding box of the result
+ double minX = dstPoints[0];
+ double minY = dstPoints[1];
+ double maxX = minX;
+ double maxY = minY;
+ for (int i = 2; i < dstPoints.length; i += 2) {
+ double x = dstPoints[i];
+ minX = Math.min(minX, x);
+ maxX = Math.max(maxX, x);
+
+ double y = dstPoints[i + 1];
+ minY = Math.min(minY, y);
+ maxY = Math.max(maxY, y);
}
- }
-
- if (!(font instanceof BDFFont)) {
- throw new RuntimeException("unable to convert font " + font + " to a BDFFont");
- }
-
- return (BDFFont) font;
+ bounds.setRect(minX, minY, maxX - minX + 1, maxY - minY + 1);
+ }
}
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -22,12 +22,16 @@
package org.jnode.awt.font.bdf;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.FontMetrics;
+import java.awt.geom.Rectangle2D;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -38,6 +42,7 @@
import org.jnode.awt.font.renderer.RenderCache;
import org.jnode.awt.font.spi.AbstractFontProvider;
import org.jnode.font.bdf.BDFFontContainer;
+import org.jnode.font.bdf.BDFGlyph;
import org.jnode.vm.Unsafe;
/**
@@ -45,9 +50,7 @@
*
* @author Fabien DUMINY (fd...@jn...)
*/
-public class BDFFontProvider extends AbstractFontProvider<BDFFont> {
- static final String NAME = "bdf";
-
+public class BDFFontProvider extends AbstractFontProvider<BDFFont, BDFFontContainer> {
/**
* My logger
*/
@@ -60,21 +63,23 @@
"Vera-10.bdf", "Vera-12.bdf", "Vera-14.bdf", "VeraMono-12-8.bdf", "6x12_FixedMedium-12.bdf"
};
- private List<BDFFontContainer> containers;
+ private List<BDFFontContainer> containers;
+ private Map<BDFFontContainer, Size> maxCharBounds = new HashMap<BDFFontContainer, Size>();
+
public BDFFontProvider() {
- super(NAME);
+ super(BDFFont.class, "bdf");
}
protected TextRenderer createTextRenderer(RenderCache renderCache, Font font) {
- final BDFFont bdfFont = getBDFFont(font);
+ final BDFFont bdfFont = getCompatibleFont(font);
final TextRenderer renderer = new BDFTextRenderer(bdfFont.getContainer());
return renderer;
}
protected FontMetrics createFontMetrics(Font font) throws IOException {
- final BDFFont bdfFont = getBDFFont(font);
+ final BDFFont bdfFont = getCompatibleFont(font);
return bdfFont.getFontMetrics();
}
@@ -91,37 +96,62 @@
public BDFFontPeer createFontPeer(String name, Map attrs) {
BDFFontPeer peer = null;
+ List<BDFFontContainer> datas = getUserFontDatas();
+ for (BDFFontContainer container : datas) {
+ if (match(container, name, attrs)) {
+ peer = new BDFFontPeer(this, name, attrs);
+ datas.remove(container);
+ break;
+ }
+ }
+
for (BDFFontContainer container : getContainers()) {
- // it's a temporary workaround taking first font found
- //FIXME : find the proper way for matching the font name
- //if (container.getFamily().equals(name) || container.getName().equals(name)) {
- peer = new BDFFontPeer(name, attrs);
- break;
- //}
+ if (match(container, name, attrs)) {
+ peer = new BDFFontPeer(this, name, attrs);
+ break;
+ }
}
//Unsafe.debug("BDFFontProvider: name=" + name + "fontPeer=" + peer);
return peer;
}
-
+
+ /**
+ * Read an create a Font from the given InputStream
+ * @param stream
+ * @return
+ */
@Override
- protected BDFFont loadFont(URL url) throws IOException {
- Reader reader = new InputStreamReader(url.openStream());
+ public BDFFont createFont(InputStream stream) throws FontFormatException, IOException {
try {
+ Reader reader = new InputStreamReader(stream);
BDFFontContainer container = BDFFontContainer.createFont(reader);
+ addUserFontData(container);
return new BDFFont(container);
+ } catch (IOException e) {
+ throw e;
} catch (Exception e) {
- IOException ioe = new IOException("can't load BDFFont from " + url);
- ioe.initCause(e);
- throw ioe;
+ FontFormatException ffe = new FontFormatException("bad bdf format");
+ ffe.initCause(e);
+ throw ffe;
}
}
+
+ /**
+ * Load all default fonts.
+ */
+ @Override
+ protected final void loadFontsImpl() {
+ for (BDFFontContainer container : getContainers()) {
+ addFont(new BDFFont(container));
+ }
+ }
private List<BDFFontContainer> getContainers() {
if (containers == null) {
containers = new ArrayList<BDFFontContainer>();
- for (String fontResource : getSystemFonts()) {
+ for (String fontResource : SYSTEM_FONTS) {
try {
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL url = cl.getResource(fontResource);
@@ -142,23 +172,33 @@
return containers;
}
- protected String[] getSystemFonts() {
- return SYSTEM_FONTS;
- }
-
- private BDFFont getBDFFont(Font font) {
- final BDFFont bdfFont;
-
- if (font instanceof BDFFont) {
- bdfFont = (BDFFont) font;
- } else {
- bdfFont = getCompatibleFont(font);
+ Rectangle2D getMaxCharBounds(BDFFontContainer container) {
+ Size size = maxCharBounds.get(container);
+
+ if (size == null) {
+ size = new Size();
+ for (BDFGlyph g : container.getGlyphs()) {
+ if (g != null) {
+ size.maxCharWidth += g.getDWidth().width;
+ size.maxCharHeight = Math.max(g.getDWidth().height, size.maxCharHeight);
+ }
+ }
+ maxCharBounds.put(container, size);
}
- if (bdfFont == null) {
- log.warn("Font not instanceof BDFFont: " + font.getClass().getName());
- }
-
- return bdfFont;
+ return new Rectangle2D.Double(0, 0, size.maxCharWidth, size.maxCharHeight);
}
+
+ private boolean match(BDFFontContainer container, String name, Map attrs) {
+ // it's a temporary workaround taking first font found
+ //FIXME : find the proper way for matching the font name
+ //if (container.getFamily().equals(name) || container.getName().equals(name)) {
+ return true;
+ }
+
+ private static class Size
+ {
+ int maxCharWidth = 0;
+ int maxCharHeight = 0;
+ }
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/def/DefaultFontManager.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/def/DefaultFontManager.java 2008-09-30 21:58:37 UTC (rev 4593)
+++ trunk/gui/src/awt/org/jnode/awt/font/def/DefaultFontManager.java 2008-09-30 22:09:24 UTC (rev 4594)
@@ -25,9 +25,11 @@
import java.awt.Color;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
+import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
import java.util.ArrayList;
@@ -35,7 +37,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.naming.NamingException;
@@ -64,7 +65,7 @@
* Note : For now, we have only 2 providers (bdf, ttf) and we will probably
* never have more than 5 ones. So, a {@link List} is enough for our usage.
*/
- private final List<FontProvider> providers = new ArrayList<FontProvider>(2);
+ private final List<FontProvider<?>> providers = new ArrayList<FontProvider<?>>(2);
public final Map<Integer, String> fontTypeToProviderName = (Map<Integer, String>)
Collections.singletonMap(Font.TRUETYPE_FONT, "ttf");
@@ -121,7 +122,7 @@
*/
public synchronized Font[] getAllFonts() {
final HashSet<Font> all = new HashSet<Font>();
- for (FontProvider prv : providers) {
+ for (FontProvider<?> prv : providers) {
all.addAll(prv.getAllFonts());
}
return (Font[]) all.toArray(new Font[all.size()]);
@@ -189,23 +190,23 @@
}
}
- public Font createFont(int format, InputStream stream) {
+ public Font createFont(int format, InputStream stream) throws FontFormatException, IOException {
String name = fontTypeToProviderName.get(format);
if (name == null) throw new IllegalArgumentException("unknown format " + name);
- for (FontProvider prv : getProviders()) {
+ for (FontProvider<?> prv : getProviders()) {
if (prv.getName().equals(name)) {
- return null; //TODO
+ return prv.createFont(stream);
}
}
- throw new IllegalArgumentException("can't create font with format " + name);
+ ...
[truncated message content] |
|
From: <cr...@us...> - 2008-10-02 13:46:37
|
Revision: 4596
http://jnode.svn.sourceforge.net/jnode/?rev=4596&view=rev
Author: crawley
Date: 2008-10-02 13:42:14 +0000 (Thu, 02 Oct 2008)
Log Message:
-----------
Moved classes in org.jnode.vm.isolate.link to org.jnode.vm.isolate.
This will allow us to tighten access on various internal classes / methods
Modified Paths:
--------------
trunk/core/descriptors/org.jnode.vm.core.xml
trunk/core/src/classpath/ext/javax/isolate/Link.java
trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandLauncher.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
Added Paths:
-----------
trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java
trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java
trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java
trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/VmLink.java
Removed Paths:
-------------
trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/LinkImpl.java
trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageFactory.java
trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java
trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java
Modified: trunk/core/descriptors/org.jnode.vm.core.xml
===================================================================
--- trunk/core/descriptors/org.jnode.vm.core.xml 2008-10-02 13:24:26 UTC (rev 4595)
+++ trunk/core/descriptors/org.jnode.vm.core.xml 2008-10-02 13:42:14 UTC (rev 4596)
@@ -25,7 +25,6 @@
<export name="org.jnode.vm.classmgr.*"/>
<export name="org.jnode.vm.compiler.*"/>
<export name="org.jnode.vm.isolate.*"/>
- <export name="org.jnode.vm.isolate.link.*"/>
<export name="org.jnode.vm.memmgr.*"/>
<export name="org.jnode.vm.performance.*"/>
<export name="org.jnode.vm.scheduler.*"/>
Modified: trunk/core/src/classpath/ext/javax/isolate/Link.java
===================================================================
--- trunk/core/src/classpath/ext/javax/isolate/Link.java 2008-10-02 13:24:26 UTC (rev 4595)
+++ trunk/core/src/classpath/ext/javax/isolate/Link.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -24,7 +24,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
-import org.jnode.vm.isolate.link.VmLink;
+import org.jnode.vm.isolate.VmLink;
/**
* @author Ewout Prangsma (ep...@us...)
Modified: trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java
===================================================================
--- trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
+++ trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -24,7 +24,7 @@
import java.net.ServerSocket;
import java.net.Socket;
-import org.jnode.vm.isolate.link.LinkMessageFactory;
+import org.jnode.vm.isolate.LinkMessageFactory;
/**
* @author Ewout Prangsma (ep...@us...)
Added: trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,60 @@
+/*
+ * $Id: DataLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+
+final class DataLinkMessage extends LinkMessageImpl {
+
+ private final byte[] bytes;
+
+ private final int offset;
+
+ private final int length;
+
+ public DataLinkMessage(byte[] bytes, int offset, int length) {
+ this.bytes = bytes;
+ this.offset = offset;
+ this.length = length;
+ }
+
+ /**
+ * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
+ */
+ @Override
+ LinkMessageImpl cloneMessage() {
+ final byte[] data = new byte[length];
+ System.arraycopy(bytes, offset, data, 0, length);
+ return new DataLinkMessage(data, 0, length);
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#containsData()
+ */
+ @Override
+ public boolean containsData() {
+ return true;
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extract()
+ */
+ @Override
+ public Object extract() {
+ return extractData();
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extractData()
+ */
+ @Override
+ public byte[] extractData() {
+ if ((offset == 0) && (length == bytes.length)) {
+ return bytes;
+ } else {
+ byte[] data = new byte[length];
+ System.arraycopy(bytes, offset, data, 0, length);
+ return data;
+ }
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,54 @@
+/*
+ * $Id: IsolateLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+import javax.isolate.Isolate;
+
+
+
+final class IsolateLinkMessage extends LinkMessageImpl {
+
+ private final VmIsolate value;
+
+ /**
+ * Message constructor
+ *
+ * @param value
+ */
+ IsolateLinkMessage(VmIsolate isolate) {
+ this.value = isolate;
+ }
+
+ /**
+ * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
+ */
+ @Override
+ LinkMessageImpl cloneMessage() {
+ return new IsolateLinkMessage(value);
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extract()
+ */
+ @Override
+ public Object extract() {
+ return extractIsolate();
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#containsIsolate()
+ */
+ @Override
+ public boolean containsIsolate() {
+ return true;
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extractIsolate()
+ */
+ @Override
+ public Isolate extractIsolate() {
+ return value.getIsolate();
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,98 @@
+/*
+ * $Id: DataLinkImpl.java 4552 2008-09-11 11:38:42Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import javax.isolate.ClosedLinkException;
+import javax.isolate.Isolate;
+import javax.isolate.Link;
+import javax.isolate.LinkMessage;
+
+final class LinkImpl extends Link {
+
+ private final VmLink vmLink;
+
+ /**
+ * Constructor
+ *
+ * @param vmLink
+ */
+ LinkImpl(VmLink vmLink) {
+ this.vmLink = vmLink;
+ }
+
+ final VmLink getImpl() {
+ return vmLink;
+ }
+
+ /**
+ * @see javax.isolate.Link#close()
+ */
+ @Override
+ public void close() {
+ vmLink.close();
+ }
+
+ /**
+ * @see javax.isolate.Link#Equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof LinkImpl) {
+ return (((LinkImpl) other).vmLink == this.vmLink);
+ }
+ return false;
+ }
+
+ /**
+ * @see javax.isolate.Link#getReceiver()
+ */
+ @Override
+ public Isolate getReceiver() {
+ return vmLink.getReceiver().getIsolate();
+ }
+
+ /**
+ * @see javax.isolate.Link#getSender()
+ */
+ @Override
+ public Isolate getSender() {
+ return vmLink.getSender().getIsolate();
+ }
+
+ /**
+ * @see javax.isolate.Link#isOpen()
+ */
+ @Override
+ public boolean isOpen() {
+ return vmLink.isOpen();
+ }
+
+ /**
+ * @see javax.isolate.Link#receive()
+ */
+ @Override
+ public LinkMessage receive()
+ throws ClosedLinkException, IllegalStateException, InterruptedIOException, IOException {
+ return vmLink.receive();
+ }
+
+ /**
+ * @see javax.isolate.Link#send(javax.isolate.LinkMessage)
+ */
+ @Override
+ public void send(LinkMessage message) throws ClosedLinkException, InterruptedIOException, IOException {
+ vmLink.send(message);
+ }
+
+ /**
+ * @see javax.isolate.Link#toString()
+ */
+ @Override
+ public String toString() {
+ return vmLink.toString();
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,53 @@
+/*
+ * $Id: LinkLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+import javax.isolate.Link;
+
+
+final class LinkLinkMessage extends LinkMessageImpl {
+
+ private final VmLink value;
+
+ /**
+ * Message constructor
+ *
+ * @param value
+ */
+ LinkLinkMessage(VmLink link) {
+ this.value = link;
+ }
+
+ /**
+ * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
+ */
+ @Override
+ LinkMessageImpl cloneMessage() {
+ return new LinkLinkMessage(value);
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extract()
+ */
+ @Override
+ public Object extract() {
+ return extractLink();
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#containsLink()
+ */
+ @Override
+ public boolean containsLink() {
+ return true;
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extractLink()
+ */
+ @Override
+ public Link extractLink() {
+ return value.asLink();
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,83 @@
+/*
+ * $Id: LinkMessageFactory.java 4592 2008-09-30 12:00:11Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import javax.isolate.Link;
+import javax.isolate.LinkMessage;
+
+
+public final class LinkMessageFactory {
+
+ /**
+ * Create a LinkMessage containing the given link messages.
+ *
+ * @param messages
+ * @return
+ */
+ public static LinkMessage newCompositeMessage(LinkMessage... messages) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Create a LinkMessage containing the given data.
+ *
+ * @param bytes
+ * @return
+ */
+ public static LinkMessage newDataMessage(byte[] bytes,
+ int offset,
+ int length) {
+ return new DataLinkMessage(bytes, offset, length);
+ }
+
+ /**
+ * Create a LinkMessage containing the given isolate.
+ *
+ * @param isolate
+ * @return
+ */
+ public static LinkMessage newIsolateMessage(VmIsolate isolate) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Create a LinkMessage containing the given link.
+ *
+ * @return
+ */
+ public static LinkMessage newLinkMessage(Link link) {
+ return new LinkLinkMessage(((LinkImpl) link).getImpl());
+ }
+
+ /**
+ * Create a LinkMessage containing the given server socket.
+ *
+ * @return
+ */
+ public static LinkMessage newServerSocketMessage(ServerSocket socket) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Create a LinkMessage containing the given socket.
+ *
+ * @return
+ */
+ public static LinkMessage newSocketMessage(Socket socket) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Create a LinkMessage containing the given string.
+ *
+ * @param string
+ * @return
+ */
+ public static LinkMessage newStringMessage(String string) {
+ return new StringLinkMessage(string);
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,44 @@
+/*
+ * $Id: LinkMessageImpl.java 4595 2008-10-02 13:24:26Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+import javax.isolate.LinkMessage;
+
+/**
+ * Base class for all types of LinkMessage implementation classes.
+ *
+ * @author Ewout Prangsma (ep...@us...)
+ */
+abstract class LinkMessageImpl extends LinkMessage {
+
+ private boolean received = false;
+
+ /**
+ * Close this message in the current isolate.
+ *
+ * @return
+ */
+ abstract LinkMessageImpl cloneMessage();
+
+ /**
+ * Block the current thread, until this message has its received flag set.
+ */
+ final void waitUntilReceived() throws InterruptedException {
+ if (!received) {
+ synchronized (this) {
+ while (!received) {
+ wait();
+ }
+ }
+ }
+ }
+
+ /**
+ * Mark this message as received and notify all waiting threads.
+ */
+ final synchronized void notifyReceived() {
+ this.received = true;
+ notifyAll();
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,50 @@
+/*
+ * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.jnode.vm.isolate;
+
+/**
+ * This message type passes an object by reference. This is probably a bad idea
+ * because it 'breaks' the isolation of isolates. Use sparingly if at all.
+ *
+ * @author cr...@jn...
+ */
+public class ObjectLinkMessage extends LinkMessageImpl {
+
+ private final Object obj;
+
+ private ObjectLinkMessage(Object cr) {
+ this.obj = cr;
+ }
+
+ public static ObjectLinkMessage newMessage (Object obj) {
+ return new ObjectLinkMessage(obj);
+ }
+
+ @Override
+ public Object extract() {
+ return obj;
+ }
+
+ @Override
+ LinkMessageImpl cloneMessage() {
+ return new ObjectLinkMessage(obj);
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,90 @@
+/*
+ * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.jnode.vm.isolate;
+
+import javax.isolate.IsolateStatus;
+
+/**
+ * This class is use to transport status isolate information
+ * @author cr...@jn...
+ */
+public final class StatusLinkMessage extends LinkMessageImpl {
+
+ private final String state;
+ private final String exitReason;
+ private final int exitCode;
+
+ /**
+ * Internal message constructor used by cloneMessage
+ *
+ * @param value
+ */
+ private StatusLinkMessage(String state, String exitReason, int exitCode) {
+ this.state = state;
+ this.exitReason = exitReason;
+ this.exitCode = exitCode;
+ }
+
+ /**
+ * Message constructor used VmIsolate
+ *
+ * @param value
+ */
+ public StatusLinkMessage(IsolateStatus.State state, IsolateStatus.ExitReason exitReason,
+ int exitCode) {
+ this(state.toString(), exitReason.toString(), exitCode);
+ }
+
+ /**
+ * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
+ */
+ @Override
+ LinkMessageImpl cloneMessage() {
+ return new StatusLinkMessage(state, exitReason, exitCode);
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extract()
+ */
+ @Override
+ public Object extract() {
+ return extractStatus();
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#containsString()
+ */
+ @Override
+ public boolean containsStatus() {
+ return true;
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extractString()
+ */
+ @Override
+ public IsolateStatus extractStatus() {
+ return new IsolateStatus(
+ IsolateStatus.State.valueOf(state),
+ IsolateStatus.ExitReason.valueOf(exitReason),
+ exitCode);
+ }
+}
Added: trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,51 @@
+/*
+ * $Id: StringLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+
+final class StringLinkMessage extends LinkMessageImpl {
+
+ private final String value;
+
+ /**
+ * Message constructor
+ *
+ * @param value
+ */
+ StringLinkMessage(String value) {
+ this.value = value;
+ }
+
+ /**
+ * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
+ */
+ @Override
+ LinkMessageImpl cloneMessage() {
+ return new StringLinkMessage(new String(value));
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extract()
+ */
+ @Override
+ public Object extract() {
+ return extractString();
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#containsString()
+ */
+ @Override
+ public boolean containsString() {
+ return true;
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extractString()
+ */
+ @Override
+ public String extractString() {
+ return value;
+ }
+}
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-02 13:24:26 UTC (rev 4595)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -56,8 +56,6 @@
import org.jnode.vm.annotation.SharedStatics;
import org.jnode.vm.classmgr.VmIsolatedStatics;
import org.jnode.vm.classmgr.VmType;
-import org.jnode.vm.isolate.link.StatusLinkMessage;
-import org.jnode.vm.isolate.link.VmLink;
/**
* VM specific implementation of the Isolate class.
Added: trunk/core/src/core/org/jnode/vm/isolate/VmLink.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmLink.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmLink.java 2008-10-02 13:42:14 UTC (rev 4596)
@@ -0,0 +1,286 @@
+/*
+ * $Id: VmDataLink.java 4552 2008-09-11 11:38:42Z crawley $
+ */
+package org.jnode.vm.isolate;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.util.LinkedList;
+import java.util.Queue;
+
+import javax.isolate.ClosedLinkException;
+import javax.isolate.Link;
+import javax.isolate.LinkMessage;
+
+
+/**
+ * Shared implementation of javax.isolate.Link
+ *
+ * @author Ewout Prangsma (ep...@us...)
+ */
+public final class VmLink {
+
+ private final VmIsolateLocal<LinkImpl> linkHolder = new VmIsolateLocal<LinkImpl>();
+
+ private final Queue<LinkMessageImpl> messages = new LinkedList<LinkMessageImpl>();
+
+ private boolean closed = false;
+
+ private VmIsolate sender;
+
+ private VmIsolate receiver;
+
+ /**
+ * Create a new data link between the given isolates.
+ *
+ * @param sender
+ * @param receiver
+ * @return
+ */
+ public static Link newLink(VmIsolate sender, VmIsolate receiver) {
+ if (sender == receiver) {
+ throw new IllegalArgumentException("sender == receiver");
+ }
+ VmLink vmLink = new VmLink(sender, receiver);
+ return vmLink.asLink();
+ }
+
+ public static VmLink fromLink(Link link) {
+ return ((LinkImpl) link).getImpl();
+ }
+
+ /**
+ * @param sender
+ * @param receiver
+ */
+ VmLink(VmIsolate sender, VmIsolate receiver) {
+ this.sender = sender;
+ this.receiver = receiver;
+ }
+
+ /**
+ * Gets this shared link as Link instance.
+ *
+ * @return
+ */
+ public final Link asLink() {
+ final LinkImpl link = linkHolder.get();
+ if (link == null) {
+ linkHolder.set(new LinkImpl(this));
+ return linkHolder.get();
+ } else {
+ return link;
+ }
+ }
+
+ /**
+ * Close this link.
+ */
+ final void close() {
+ if (!this.closed) {
+ final VmIsolate current = VmIsolate.currentIsolate();
+ if ((current != receiver) && (current != sender)) {
+ throw new IllegalStateException(
+ "Only sender or receiver can close this link");
+ }
+ this.closed = true;
+ synchronized (this) {
+ notifyAll();
+ }
+ }
+ }
+
+ /**
+ * Is this link currently open.
+ *
+ * @return
+ */
+ final boolean isOpen() {
+ return !closed;
+ }
+
+ /**
+ * @return the receiver
+ */
+ final VmIsolate getReceiver() {
+ return receiver;
+ }
+
+ /**
+ * @return the sender
+ */
+ final VmIsolate getSender() {
+ return sender;
+ }
+
+ /**
+ * Receives a copy of a message sent on this Link.
+ * <p/>
+ * The current thread will block in this method until a sender is available.
+ * When the sender and receiver rendezvous, the message will then be
+ * transferred. If multiple threads invoke this method on the same object,
+ * only one thread will receive any message at rendezvous and the other
+ * threads will contend for subsequent access to the rendezvous point. A
+ * normal return indicates that the message was received successfully. If an
+ * exception occured on the sender side, no rendezvous will occur, and no
+ * object will be transferred; the receiver will wait for the next
+ * successful send. If an exception occurs on the receive, the sender will
+ * see a successful transfer.
+ * <p/>
+ * This method never returns null.
+ * <p/>
+ * If the sending isolate becomes terminated after this method is invoked
+ * but before it returns, the link will be closed, a ClosedLinkException
+ * will be thrown, any subsequent attempts to use receive() will result in a
+ * ClosedLinkException, and any Isolate objects corresponding to the receive
+ * side of the link will reflect a terminated state.
+ * <p/>
+ * If invoked on a closed Link, this method will throw a
+ * ClosedLinkException.
+ * <p/>
+ * If close() is invoked on the link while a thread is blocked in receive(),
+ * receive() will throw a ClosedLinkException. No message will have been
+ * transferred in that case.
+ * <p/>
+ * If Thread.interrupt() is invoked on a thread that has not yet completed
+ * an invocation of this method, the results are undefined. An
+ * InterruptedIOException may or may not be thrown; if not, control will
+ * return from the method with a valid LinkMessage object. However, even if
+ * InterruptedIOException is thrown, rendezvous and data transfer from the
+ * sending isolate may have occurred. In particular, undetected message loss
+ * between sender and receiver may occur.
+ * <p/>
+ * If a failure occurs due to the object being transferred between isolates
+ * an IOException may be thrown in the receiver. For example, if a message
+ * containing a large buffer is sent and the receiver has insufficient heap
+ * memory for the buffer or if construction of a link in the receiver
+ * isolate fails, an IOException will be thrown. The sender will see a
+ * successful transfer in these cases.
+ * <p/>
+ * If the current isolate is not a receiver on this Link an
+ * IllegalStateException will be thrown. The receiver will not rendezvous
+ * with a sender in this case.
+ *
+ * @return
+ */
+ final LinkMessage receive() throws ClosedLinkException,
+ IllegalStateException, InterruptedIOException, IOException {
+ if (VmIsolate.currentIsolate() != receiver) {
+ // Current isolate is not the receiver
+ throw new IllegalStateException();
+ }
+ if (this.closed) {
+ throw new ClosedLinkException();
+ }
+ final LinkMessageImpl message;
+ synchronized (this) {
+ while (messages.isEmpty()) {
+ if (this.closed) {
+ throw new ClosedLinkException();
+ }
+ try {
+ wait();
+ } catch (InterruptedException ex) {
+ throw new InterruptedIOException();
+ }
+ }
+ message = messages.poll();
+ }
+ message.notifyReceived();
+ return message.cloneMessage();
+ }
+
+ /**
+ * Sends the given message on this Link.
+ * <p/>
+ * The current thread will block in this method until a receiver is
+ * available. When the sender and receiver rendezvous, the message will then
+ * be transferred. A normal return indicates that the message was
+ * transferred. If an exception occurs on the sender side, no rendezvous
+ * will occur and no object will be transferred. But if an exception occurs
+ * on the receive(), the sender will see a successful transfer.
+ * <p/>
+ * If the receiving isolate becomes terminated after this method is invoked
+ * but before it returns, the link will be closed, a ClosedLinkException
+ * will be thrown, any subsequent attempts to use send() will result in a
+ * ClosedLinkException, and any Isolate objects corresponding to the receive
+ * side of the link will reflect a terminated state.
+ * <p/>
+ * If invoked on a closed link, this method will throw a
+ * ClosedLinkException.
+ * <p/>
+ * If close() is invoked on this Link while a thread is blocked in send(),
+ * send() will throw a ClosedLinkException. No message will have been
+ * transferred in that case.
+ * <p/>
+ * If Thread.interrupt() is invoked on a thread that has not yet completed
+ * an invocation of this method, the results are undefined. An
+ * InterruptedIOException may or may not be thrown; however, even if not,
+ * control will return from the method. Rendezvous and data transfer to the
+ * receiving isolate may or may not have occurred. In particular, undetected
+ * message loss betwe...
[truncated message content] |
|
From: <cr...@us...> - 2008-10-03 11:06:49
|
Revision: 4598
http://jnode.svn.sourceforge.net/jnode/?rev=4598&view=rev
Author: crawley
Date: 2008-10-03 11:06:43 +0000 (Fri, 03 Oct 2008)
Log Message:
-----------
Applied patch to use 0xffff as the unmapped character code in keypoard events.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
trunk/core/src/driver/org/jnode/driver/input/Key.java
trunk/core/src/driver/org/jnode/driver/input/KeyboardEvent.java
trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java
trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java
trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-02 13:45:02 UTC (rev 4597)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-03 11:06:43 UTC (rev 4598)
@@ -5,6 +5,7 @@
import java.io.Reader;
import java.io.Writer;
+import org.apache.log4j.Logger;
import org.jnode.driver.console.InputCompleter;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.input.KeyboardEvent;
@@ -52,7 +53,7 @@
private int pos;
private int lim;
- private static final char NO_CHAR = 0;
+ private static final char NO_CHAR = KeyEvent.CHAR_UNDEFINED;
private final Line currentLine;
private final TextConsole console;
@@ -128,11 +129,11 @@
KeyboardEvent event = keyboardHandler.getEvent();
if (!event.isConsumed()) {
char ch = event.getKeyChar();
+ int kc = event.getKeyCode();
if (ch != NO_CHAR) {
event.consume();
return !processChar(ch);
} else {
- int kc = event.getKeyCode();
int mods = event.getModifiers();
if (processVirtualKeystroke(kc, mods)) {
event.consume();
Modified: trunk/core/src/driver/org/jnode/driver/input/Key.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/Key.java 2008-10-02 13:45:02 UTC (rev 4597)
+++ trunk/core/src/driver/org/jnode/driver/input/Key.java 2008-10-03 11:06:43 UTC (rev 4598)
@@ -92,10 +92,6 @@
this.lowerVirtuelKey = virtuelKey;
this.upperVirtuelKey = virtuelKey;
this.altGrVirtuelKey = virtuelKey;
-
- lowerChar = 0;
- upperChar = 0;
- altGrChar = 0;
}
public char getLowerChar() {
Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardEvent.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardEvent.java 2008-10-02 13:45:02 UTC (rev 4597)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardEvent.java 2008-10-03 11:06:43 UTC (rev 4598)
@@ -30,7 +30,7 @@
*/
public class KeyboardEvent extends SystemEvent {
/** This value is returned by getKeyChar() when a KeyboardEvent has no char */
- public static final int NO_CHAR = 0;
+ public static final int NO_CHAR = KeyEvent.CHAR_UNDEFINED;
private int modifiers;
private int keyCode;
Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-02 13:45:02 UTC (rev 4597)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-03 11:06:43 UTC (rev 4598)
@@ -41,7 +41,11 @@
protected int lastDeadVK = -1;
protected final Keys keys;
+
+ // FIXME this is an evil hack to mitigate the performance issues that
+ // result from the interpretExtendedScanCode's inappropriate use of exceptions.
private final UnsupportedKeyException unsupportedKeyException = new UnsupportedKeyException();
+ private final DeadKeyException deadKeyException = new DeadKeyException();
private boolean extendedMode;
private int capsLock = 0;
@@ -143,6 +147,7 @@
mask = InputEvent.SHIFT_DOWN_MASK;
break;
case KeyEvent.VK_CAPS_LOCK:
+ // FIXME ... can someone explain why 'capslock' isn't a boolean??
if (capsLock == 0 || capsLock == 3)
mask = InputEvent.SHIFT_DOWN_MASK;
else
@@ -274,13 +279,18 @@
case KeyEvent.VK_DOWN:
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_PRINTSCREEN:
- case KeyEvent.VK_ALT_GRAPH:
case KeyEvent.VK_PROPS:
- case KeyEvent.VK_CONTROL: // both normal and extend should return 0
if (extended)
- return 0;
+ return KeyEvent.CHAR_UNDEFINED;
break;
+ case KeyEvent.VK_SHIFT:
+ case KeyEvent.VK_CONTROL:
+ case KeyEvent.VK_ALT:
+ case KeyEvent.VK_ALT_GRAPH:
+ case KeyEvent.VK_CAPS_LOCK:
+ return KeyEvent.CHAR_UNDEFINED;
+
case KeyEvent.VK_ENTER:
if (extended)
return enter;
@@ -292,7 +302,7 @@
}
if (deadKey) {
- throw new DeadKeyException();
+ throw deadKeyException;
} else if (lastDeadVK != -1) {
try {
Key key = keys.getKey(scancode);
@@ -303,11 +313,11 @@
if (deadChars.length > 1) {
return deadChars[1];
} else
- throw new UnsupportedKeyException();
+ throw unsupportedKeyException;
} else if (deadChars.length > 0)
return deadChars[0];
else
- return 0;
+ return KeyEvent.CHAR_UNDEFINED;
} finally {
if (!released) {
lastDeadVK = -1;
Modified: trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2008-10-02 13:45:02 UTC (rev 4597)
+++ trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2008-10-03 11:06:43 UTC (rev 4598)
@@ -296,7 +296,7 @@
if (ro) break;
char c = e.getKeyChar();
- if (c == 0 && k != KeyEvent.VK_DELETE) return;
+ if (c == KeyEvent.CHAR_UNDEFINED && k != KeyEvent.VK_DELETE) return;
if (cy == ls.size()) ls.add(new StringBuilder());
StringBuilder l = ls.get(oy());
switch (k) {
Modified: trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java 2008-10-02 13:45:02 UTC (rev 4597)
+++ trunk/gui/src/driver/org/jnode/driver/textscreen/swing/SwingPcTextScreen.java 2008-10-03 11:06:43 UTC (rev 4598)
@@ -157,20 +157,16 @@
keyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
- char c = e.getKeyChar();
- if (c == KeyEvent.CHAR_UNDEFINED) c = 0;
KeyboardEvent k = new KeyboardEvent(KeyEvent.KEY_PRESSED,
- e.getWhen(), e.getModifiersEx(), e.getKeyCode(), c);
+ e.getWhen(), e.getModifiersEx(), e.getKeyCode(), e.getKeyChar());
keyboardDriver.dispatchEvent(k);
}
@Override
public void keyReleased(KeyEvent e) {
- char c = e.getKeyChar();
- if (c == KeyEvent.CHAR_UNDEFINED) c = 0;
KeyboardEvent k = new KeyboardEvent(KeyEvent.KEY_RELEASED,
- e.getWhen(), e.getModifiersEx(), e.getKeyCode(), c);
+ e.getWhen(), e.getModifiersEx(), e.getKeyCode(), e.getKeyChar());
keyboardDriver.dispatchEvent(k);
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-10-03 12:59:19
|
Revision: 4599
http://jnode.svn.sourceforge.net/jnode/?rev=4599&view=rev
Author: crawley
Date: 2008-10-03 12:59:09 +0000 (Fri, 03 Oct 2008)
Log Message:
-----------
Tidying up the KeyboardInterpreterFactory API a bit
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java
trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java 2008-10-03 11:06:43 UTC (rev 4598)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java 2008-10-03 12:59:09 UTC (rev 4599)
@@ -26,10 +26,14 @@
import org.apache.log4j.Logger;
/**
- * KeyboardInterpreterFactory.java
+ * The KeyboardInterpreterFactory class provides static methods for creating KeyboardInterpreter
+ * objects and forming keyboard layout identifiers.
+ * <p>
+ * This is an interim API. We intend to replace it with a JNode service that includes
+ * methods for managing the mapping of keyboard layout IDs to keyboard layout classes.
*
- * @author Created by Marc DENTY
- * @since 0.15
+ * @author Marc DENTY
+ * @author cr...@jn...
*/
public class KeyboardInterpreterFactory {
@@ -37,74 +41,107 @@
.getLogger(KeyboardInterpreterFactory.class);
/**
- * Method loadDefaultKeyboardInterpreter
+ * Load the default keyboard layout as specified in the 'org.jnode.driver.input.KeyboardLayout'
+ * resource bundle. If none is specified or the specified layout cannot be used, we use the
+ * 'US_en' layout as a fallback.
*
* @return a valid KeyboardInterpreter
- * @version 2/8/2004
*/
public static KeyboardInterpreter getDefaultKeyboardInterpreter() {
+ String country = null;
+ String region = null;
+ String variant = null;
try {
- ResourceBundle rb = null;
- String defaultCountry = null;
- String defaultRegion = null;
-
+ ResourceBundle rb = ResourceBundle.getBundle("org.jnode.driver.input.KeyboardLayout",
+ Locale.getDefault(), Thread.currentThread().getContextClassLoader());
+ country = getProperty(rb, "defaultCountry");
+ // FIXME the following property name should be 'defaultLanguage'
+ region = getProperty(rb, "defaultRegion");
+ variant = getProperty(rb, "defaultVariant");
+ } catch (Exception ex) {
+ log.error("Cannot find the 'org.jnode.driver.input.KeyboardLayout' resource bundle", ex);
+ }
+ if (country != null) {
try {
- rb = ResourceBundle.getBundle("org.jnode.driver.input.KeyboardLayout", Locale.getDefault(),
- Thread.currentThread().getContextClassLoader());
- defaultCountry = rb.getString("defaultCountry");
- if (defaultCountry.trim().length() == 0) {
- defaultCountry = null;
+ KeyboardInterpreter ki = createKeyboardInterpreter(country, region, variant);
+ if (ki != null) {
+ return ki;
}
} catch (Exception ex) {
- log.warn("Cannot load default keyboard layout, loading US layout instead", ex);
- return getKeyboardInterpreter("US", null, null);
+ log.error("Cannot load the default '" +
+ makeKeyboardInterpreterID(country, region, variant) +
+ "' keyboard interpreter", ex);
}
- try {
- defaultRegion = rb.getString("defaultRegion");
- if (defaultRegion.trim().length() == 0) {
- defaultRegion = null;
- }
- } catch (Exception e) {
- //todo empty?
- }
-
- KeyboardInterpreter ki = getKeyboardInterpreter(defaultCountry,
- defaultRegion, null);
- if (ki == null) {
- throw new NullPointerException("KeyboardInterpreter for "
- + defaultCountry + " not found");
- } else {
- return ki;
- }
- } catch (Exception e) {
- try {
- return getKeyboardInterpreter("US", null, null);
- } catch (Exception ex) {
- log.error("Cannot load US keyboard interpreter", ex);
- //FIXME : this should never happen
- return null;
- } catch (Error ex) {
- log.error("Cannot load US keyboard interpreter", ex);
- //FIXME : this should never happen
- return null;
- }
}
+ // Use the US_en keyboard layout as a fallback if there was no resource bundle, no
+ // usable default keyboard layout or the specified default layout had no interpreter.
+ log.error("Trying the 'US_en' keyboard interpreter as a fallback");
+ try {
+ return createKeyboardInterpreter("US", "en", null);
+ } catch (Throwable ex) {
+ log.error("Cannot load 'US_en' keyboard interpreter", ex);
+ }
+ // FIXME we should probably throw an exception ...
+ return null;
}
+
+ /**
+ * Get a String-valued property value from the resource bundle, dealing
+ * with empty and missing values.
+ *
+ * @param rb the resource bundle
+ * @param key the property name
+ * @return the property value or <code>null</null> if the value is missing or empty.
+ */
+ private static String getProperty(ResourceBundle rb, String key) {
+ try {
+ String res = rb.getString(key);
+ res = res.trim();
+ return (res.length() == 0) ? null : res;
+ } catch (RuntimeException e) { /* ClassCastException or MissingResourceException */
+ return null;
+ }
+ }
/**
- * Method getKeyboardInterpreter this method
+ * Create a new keyboard interpreter object. Note that keyboard interpreter
+ * objects are stateful and therefore cannot be shared by multiple keyboards.
*
- * @param country a String
- * @param language a String
- * @param variant
- * @return a KeyboardInterpreter
- * @version 2/8/2004
+ * @param country the country code; e.g. US, GB, FR, DE, etc.
+ * @param language the language code; e.g. en, fr, de etc or <code>null</code>
+ * @param variant a keyboard variant name or <code>null</code>.
+ * @return a KeyboardInterpreter or <code>null</code>
*/
- public static KeyboardInterpreter getKeyboardInterpreter(String country,
- String language, String variant)
- throws InstantiationException,
- IllegalAccessException {
+ public static KeyboardInterpreter createKeyboardInterpreter(
+ String country, String language, String variant) {
+ final String id = makeKeyboardInterpreterID(country, language, variant);
+ log.debug("Looking for interpreter for keyboard layout '" + id + "'");
+ final String classI10N = "org.jnode.driver.input.l10n.KeyboardInterpreter_" + id;
+ try {
+ final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return (KeyboardInterpreter) cl.loadClass(classI10N).newInstance();
+ } catch (ClassNotFoundException ex) {
+ log.error("No keyboard interpreter class found for layout id " + id +
+ ": expected class name '" + classI10N + "'.");
+ } catch (Exception ex) {
+ log.error("Error loading or instantiating keyboard interpreter class '" +
+ classI10N + "'.", ex);
+ }
+ return null;
+ }
+
+ /**
+ * Convert a country / language / variant keyboard triple into a keyboard
+ * layout identifier.
+ *
+ * @param country the country code; e.g. US, GB, FR, DE, etc.
+ * @param language the language code; e.g. en, fr, de etc or <code>null</code>.
+ * @param variant a keyboard variant name or <code>null</code>.
+ * @return the keyboard layout identifier.
+ */
+ public static String makeKeyboardInterpreterID(
+ String country, String language, String variant) {
final String id;
country = country.toUpperCase();
if (language != null) {
@@ -119,17 +156,6 @@
} else {
id = country;
}
-
- log.debug("Searching for " + id);
- final String classI10N = "org.jnode.driver.input.l10n.KeyboardInterpreter_" + id;
-
- try {
- final ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return (KeyboardInterpreter) cl.loadClass(classI10N).newInstance();
- } catch (ClassNotFoundException e) {
- log.error("Keyboard interpreter for " + id + " not found.");
- }
-
- return null;
+ return id;
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-10-03 11:06:43 UTC (rev 4598)
+++ trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-10-03 12:59:09 UTC (rev 4599)
@@ -90,7 +90,7 @@
for (Device kb : kbDevs) {
final KeyboardAPI api = kb.getAPI(KeyboardAPI.class);
final KeyboardInterpreter kbInt =
- KeyboardInterpreterFactory.getKeyboardInterpreter(
+ KeyboardInterpreterFactory.createKeyboardInterpreter(
country, language, variant);
if (kbInt != null) {
out.println("Setting layout for keyboard " + kb.getId() + " to " +
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-10-03 13:21:40
|
Revision: 4600
http://jnode.svn.sourceforge.net/jnode/?rev=4600&view=rev
Author: crawley
Date: 2008-10-03 13:21:19 +0000 (Fri, 03 Oct 2008)
Log Message:
-----------
Split KeyboardInterpreter into an interface and abstract base class to
enable other possible key mapping systems ... or an interpreter that
loads the scancode mapping from a file.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/input/KeyboardAPIAdapter.java
trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_CH_fr.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DE.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DK.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DV.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_ES.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_FR.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_GB_en.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_HU.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_IT.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_NO.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_RU.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_SE.java
trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_US_en.java
trunk/gui/src/awt/org/jnode/awt/KeyboardHandler.java
Added Paths:
-----------
trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardInterpreter.java
Added: trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardInterpreter.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardInterpreter.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardInterpreter.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -0,0 +1,342 @@
+/*
+ * $Id: KeyboardInterpreter.java 4598 2008-10-03 11:06:43Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.driver.input;
+
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+
+/**
+ * A KeyboardInterpreter translate scancodes into KeyboardEvent's.
+ *
+ * @author epr
+ * @author Martin Husted Hartvig
+ */
+public abstract class AbstractKeyboardInterpreter implements KeyboardInterpreter {
+
+ private int flags;
+
+ protected int lastDeadVK = -1;
+
+ protected final Keys keys;
+
+ // FIXME this is an evil hack to mitigate the performance issues that
+ // result from the interpretExtendedScanCode's inappropriate use of exceptions.
+ private final UnsupportedKeyException unsupportedKeyException = new UnsupportedKeyException();
+ private final DeadKeyException deadKeyException = new DeadKeyException();
+
+ private boolean extendedMode;
+ private int capsLock = 0;
+
+ private final char enter = '\n';
+ private final char divide = '/';
+
+ public AbstractKeyboardInterpreter() {
+ keys = new Keys();
+
+ initKeys(keys);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jnode.driver.input.KeyboardInterpreter#interpretScancode(int)
+ */
+ public final KeyboardEvent interpretScancode(int scancode) {
+ final boolean extendedMode = this.extendedMode;
+
+ if (scancode == XT_EXTENDED) {
+ this.extendedMode = true;
+ return null;
+ } else {
+ this.extendedMode = false;
+ }
+
+ final boolean released = ((scancode & XT_RELEASE) != 0);
+ final long time = System.currentTimeMillis();
+
+ scancode &= 0x7f;
+
+ int vk = deriveKeyCode(scancode, extendedMode);
+
+ // debug output to find new keycodes
+// System.out.println("[" + (extendedMode ? "E" : "N") + scancode + "," + vk + "] " /*+ KeyEvent.getKeyText(vk)*/);
+
+ if (!extendedMode) {
+ if ((flags & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
+ vk = keys.getKey(scancode).getAltGrVirtuelKey();
+ } else if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) {
+ vk = keys.getKey(scancode).getUpperVirtuelKey();
+ } else {
+ vk = keys.getKey(scancode).getLowerVirtuelKey();
+ }
+ }
+
+
+ adjustFlags(vk, released);
+
+ // debug output to find new keycodes
+// System.out.println("[" + (extendedMode ? "E" : "N") + scancode + "," + vk + "] " /*+ KeyEvent.getKeyText(vk)*/);
+
+ try {
+ final char ch;
+ ch = interpretExtendedScanCode(scancode, vk, released, extendedMode);
+ return new KeyboardEvent(released ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED, time, flags, vk, ch);
+ } catch (UnsupportedKeyException e) {
+ final char ch;
+
+ if ((flags & InputEvent.CTRL_DOWN_MASK) != 0) {
+ ch = keys.getKey(scancode).getControlChar();
+ } else if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) {
+ ch = keys.getKey(scancode).getUpperChar();
+
+ if (!extendedMode)
+ vk = keys.getKey(scancode).getUpperVirtuelKey();
+ } else if ((flags & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
+ ch = keys.getKey(scancode).getAltGrChar();
+
+ if (!extendedMode)
+ vk = keys.getKey(scancode).getAltGrVirtuelKey();
+ } else {
+ ch = keys.getKey(scancode).getLowerChar();
+ }
+ return new KeyboardEvent(released ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED, time, flags, vk, ch);
+ } catch (DeadKeyException e) {
+ return null;
+ }
+ }
+
+ private void adjustFlags(int vk, boolean released) {
+ final int mask;
+ switch (vk) {
+ case KeyEvent.VK_ALT:
+ mask = InputEvent.ALT_DOWN_MASK;
+ break;
+ case KeyEvent.VK_ALT_GRAPH:
+ mask = InputEvent.ALT_GRAPH_DOWN_MASK;
+ break;
+ case KeyEvent.VK_CONTROL:
+ mask = InputEvent.CTRL_DOWN_MASK;
+ break;
+ case KeyEvent.VK_SHIFT:
+ mask = InputEvent.SHIFT_DOWN_MASK;
+ break;
+ case KeyEvent.VK_CAPS_LOCK:
+ // FIXME ... can someone explain why 'capslock' isn't a boolean??
+ if (capsLock == 0 || capsLock == 3)
+ mask = InputEvent.SHIFT_DOWN_MASK;
+ else
+ mask = 0;
+
+ capsLock++;
+ capsLock %= 4;
+
+ break;
+ default:
+ mask = 0;
+ }
+
+ if (mask != 0) {
+ if (released) {
+ this.flags &= ~mask;
+ } else {
+ this.flags |= mask;
+ }
+ }
+ }
+
+ protected int deriveKeyCode(int scancode, boolean extended) {
+ int vk = 0;
+
+ if (extended) {
+ switch (scancode) {
+ case 82:
+ vk = KeyEvent.VK_INSERT;
+ break;
+ case 71:
+ vk = KeyEvent.VK_HOME;
+ break;
+ case 73:
+ vk = KeyEvent.VK_PAGE_UP;
+ break;
+ case 83:
+ vk = KeyEvent.VK_DELETE;
+ break;
+ case 79:
+ vk = KeyEvent.VK_END;
+ break;
+ case 81:
+ vk = KeyEvent.VK_PAGE_DOWN;
+ break;
+ case 72:
+ vk = KeyEvent.VK_UP;
+ break;
+ case 75:
+ vk = KeyEvent.VK_LEFT;
+ break;
+ case 80:
+ vk = KeyEvent.VK_DOWN;
+ break;
+ case 77:
+ vk = KeyEvent.VK_RIGHT;
+ break;
+ case 28:
+ vk = KeyEvent.VK_ENTER;
+ break;
+ case 55:
+ vk = KeyEvent.VK_PRINTSCREEN;
+ break;
+ case 56:
+ vk = KeyEvent.VK_ALT_GRAPH;
+ break;
+ case 29:
+ vk = KeyEvent.VK_CONTROL;
+ break;
+ case 93:
+ vk = KeyEvent.VK_PROPS;
+ break;
+ case 53:
+ vk = KeyEvent.VK_DIVIDE;
+ break;
+ default:
+ vk = 0;
+ }
+ }
+
+ return vk;
+ }
+
+
+ /**
+ * Method interpretExtendedScanCode this method sould be used to handle the dead keys and other special keys
+ *
+ * @param scancode an int
+ * @param vk an int
+ * @param released a boolean
+ * @return the char to use or throws an Exception
+ * @throws UnsupportedKeyException is thrown if the current key is not handled by this method
+ * @throws DeadKeyException is thrown if the current key is a dead key
+ * @since 0.15
+ */
+ protected char interpretExtendedScanCode(int scancode, int vk, boolean released, boolean extended)
+ throws UnsupportedKeyException, DeadKeyException {
+ boolean deadKey = false;
+
+ switch (vk) {
+ case KeyEvent.VK_DEAD_ABOVEDOT:
+ case KeyEvent.VK_DEAD_ABOVERING:
+ case KeyEvent.VK_DEAD_ACUTE:
+ case KeyEvent.VK_DEAD_BREVE:
+ case KeyEvent.VK_DEAD_CARON:
+ case KeyEvent.VK_DEAD_CEDILLA:
+ case KeyEvent.VK_DEAD_CIRCUMFLEX:
+ case KeyEvent.VK_DEAD_DIAERESIS:
+ case KeyEvent.VK_DEAD_DOUBLEACUTE:
+ case KeyEvent.VK_DEAD_GRAVE:
+ case KeyEvent.VK_DEAD_IOTA:
+ case KeyEvent.VK_DEAD_MACRON:
+ case KeyEvent.VK_DEAD_OGONEK:
+ case KeyEvent.VK_DEAD_SEMIVOICED_SOUND:
+ case KeyEvent.VK_DEAD_TILDE:
+ case KeyEvent.VK_DEAD_VOICED_SOUND:
+ lastDeadVK = vk;
+ deadKey = true;
+ break;
+
+ case KeyEvent.VK_INSERT:
+ case KeyEvent.VK_HOME:
+ case KeyEvent.VK_PAGE_UP:
+ case KeyEvent.VK_DELETE:
+ case KeyEvent.VK_END:
+ case KeyEvent.VK_PAGE_DOWN:
+ case KeyEvent.VK_UP:
+ case KeyEvent.VK_LEFT:
+ case KeyEvent.VK_DOWN:
+ case KeyEvent.VK_RIGHT:
+ case KeyEvent.VK_PRINTSCREEN:
+ case KeyEvent.VK_PROPS:
+ if (extended)
+ return KeyEvent.CHAR_UNDEFINED;
+ break;
+
+ case KeyEvent.VK_SHIFT:
+ case KeyEvent.VK_CONTROL:
+ case KeyEvent.VK_ALT:
+ case KeyEvent.VK_ALT_GRAPH:
+ case KeyEvent.VK_CAPS_LOCK:
+ return KeyEvent.CHAR_UNDEFINED;
+
+ case KeyEvent.VK_ENTER:
+ if (extended)
+ return enter;
+ break;
+ case KeyEvent.VK_DIVIDE:
+ if (extended)
+ return divide;
+ break;
+ }
+
+ if (deadKey) {
+ throw deadKeyException;
+ } else if (lastDeadVK != -1) {
+ try {
+ Key key = keys.getKey(scancode);
+
+ char[] deadChars = key.getDeadKeyChar(lastDeadVK);
+
+ if (flags == InputEvent.SHIFT_DOWN_MASK) {
+ if (deadChars.length > 1) {
+ return deadChars[1];
+ } else
+ throw unsupportedKeyException;
+ } else if (deadChars.length > 0)
+ return deadChars[0];
+ else
+ return KeyEvent.CHAR_UNDEFINED;
+ } finally {
+ if (!released) {
+ lastDeadVK = -1;
+ }
+ }
+ }
+
+ throw unsupportedKeyException;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jnode.driver.input.KeyboardInterpreter#interpretKeycode(int)
+ */
+ public KeyboardEvent interpretKeycode(int keycode) {
+ final int scancode = keys.getScanCode(keycode);
+ if (scancode < 0) return null;
+ return interpretScancode(scancode);
+ }
+
+ /**
+ * @return Returns the flags.
+ */
+ protected final int getFlags() {
+ return this.flags;
+ }
+
+
+ protected abstract void initKeys(Keys keys);
+}
+
+
Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardAPIAdapter.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardAPIAdapter.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardAPIAdapter.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -83,7 +83,7 @@
}
/**
- * @see org.jnode.driver.input.KeyboardAPI#setKbInterpreter(org.jnode.driver.input.KeyboardInterpreter)
+ * @see org.jnode.driver.input.KeyboardAPI#setKbInterpreter(org.jnode.driver.input.AbstractKeyboardInterpreter)
*/
public void setKbInterpreter(KeyboardInterpreter kbInterpreter) {
if (kbInterpreter == null) {
Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -18,336 +18,31 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
package org.jnode.driver.input;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-
/**
* A KeyboardInterpreter translate scancodes into KeyboardEvent's.
*
* @author epr
* @author Martin Husted Hartvig
*/
-public abstract class KeyboardInterpreter {
- // FIXME We are currently using the character zero (0x0000) to indicate that no
- // (Unicode) character corresponds to a keycode. This means that we cannot represent
- // the NUL control character. Instead we should really be using 0xffff which Unicode
- // defines to be a non-character.
+public interface KeyboardInterpreter {
- private int flags;
-
- protected int lastDeadVK = -1;
-
- protected final Keys keys;
-
- // FIXME this is an evil hack to mitigate the performance issues that
- // result from the interpretExtendedScanCode's inappropriate use of exceptions.
- private final UnsupportedKeyException unsupportedKeyException = new UnsupportedKeyException();
- private final DeadKeyException deadKeyException = new DeadKeyException();
-
- private boolean extendedMode;
- private int capsLock = 0;
-
- private final char enter = '\n';
- private final char divide = '/';
-
public static final int XT_RELEASE = 0x80;
public static final int XT_EXTENDED = 0xE0;
- public KeyboardInterpreter() {
- keys = new Keys();
-
- initKeys(keys);
- }
-
/**
* Interpret a given scancode into a keyevent.
*
* @param scancode
*/
- public final KeyboardEvent interpretScancode(int scancode) {
- final boolean extendedMode = this.extendedMode;
+ public abstract KeyboardEvent interpretScancode(int scancode);
- if (scancode == XT_EXTENDED) {
- this.extendedMode = true;
- return null;
- } else {
- this.extendedMode = false;
- }
-
- final boolean released = ((scancode & XT_RELEASE) != 0);
- final long time = System.currentTimeMillis();
-
- scancode &= 0x7f;
-
- int vk = deriveKeyCode(scancode, extendedMode);
-
- // debug output to find new keycodes
-// System.out.println("[" + (extendedMode ? "E" : "N") + scancode + "," + vk + "] " /*+ KeyEvent.getKeyText(vk)*/);
-
- if (!extendedMode) {
- if ((flags & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
- vk = keys.getKey(scancode).getAltGrVirtuelKey();
- } else if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) {
- vk = keys.getKey(scancode).getUpperVirtuelKey();
- } else {
- vk = keys.getKey(scancode).getLowerVirtuelKey();
- }
- }
-
-
- adjustFlags(vk, released);
-
- // debug output to find new keycodes
-// System.out.println("[" + (extendedMode ? "E" : "N") + scancode + "," + vk + "] " /*+ KeyEvent.getKeyText(vk)*/);
-
- try {
- final char ch;
- ch = interpretExtendedScanCode(scancode, vk, released, extendedMode);
- return new KeyboardEvent(released ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED, time, flags, vk, ch);
- } catch (UnsupportedKeyException e) {
- final char ch;
-
- if ((flags & InputEvent.CTRL_DOWN_MASK) != 0) {
- ch = keys.getKey(scancode).getControlChar();
- } else if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) {
- ch = keys.getKey(scancode).getUpperChar();
-
- if (!extendedMode)
- vk = keys.getKey(scancode).getUpperVirtuelKey();
- } else if ((flags & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
- ch = keys.getKey(scancode).getAltGrChar();
-
- if (!extendedMode)
- vk = keys.getKey(scancode).getAltGrVirtuelKey();
- } else {
- ch = keys.getKey(scancode).getLowerChar();
- }
- return new KeyboardEvent(released ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED, time, flags, vk, ch);
- } catch (DeadKeyException e) {
- return null;
- }
- }
-
- private void adjustFlags(int vk, boolean released) {
- final int mask;
- switch (vk) {
- case KeyEvent.VK_ALT:
- mask = InputEvent.ALT_DOWN_MASK;
- break;
- case KeyEvent.VK_ALT_GRAPH:
- mask = InputEvent.ALT_GRAPH_DOWN_MASK;
- break;
- case KeyEvent.VK_CONTROL:
- mask = InputEvent.CTRL_DOWN_MASK;
- break;
- case KeyEvent.VK_SHIFT:
- mask = InputEvent.SHIFT_DOWN_MASK;
- break;
- case KeyEvent.VK_CAPS_LOCK:
- // FIXME ... can someone explain why 'capslock' isn't a boolean??
- if (capsLock == 0 || capsLock == 3)
- mask = InputEvent.SHIFT_DOWN_MASK;
- else
- mask = 0;
-
- capsLock++;
- capsLock %= 4;
-
- break;
- default:
- mask = 0;
- }
-
- if (mask != 0) {
- if (released) {
- this.flags &= ~mask;
- } else {
- this.flags |= mask;
- }
- }
- }
-
- protected int deriveKeyCode(int scancode, boolean extended) {
- int vk = 0;
-
- if (extended) {
- switch (scancode) {
- case 82:
- vk = KeyEvent.VK_INSERT;
- break;
- case 71:
- vk = KeyEvent.VK_HOME;
- break;
- case 73:
- vk = KeyEvent.VK_PAGE_UP;
- break;
- case 83:
- vk = KeyEvent.VK_DELETE;
- break;
- case 79:
- vk = KeyEvent.VK_END;
- break;
- case 81:
- vk = KeyEvent.VK_PAGE_DOWN;
- break;
- case 72:
- vk = KeyEvent.VK_UP;
- break;
- case 75:
- vk = KeyEvent.VK_LEFT;
- break;
- case 80:
- vk = KeyEvent.VK_DOWN;
- break;
- case 77:
- vk = KeyEvent.VK_RIGHT;
- break;
- case 28:
- vk = KeyEvent.VK_ENTER;
- break;
- case 55:
- vk = KeyEvent.VK_PRINTSCREEN;
- break;
- case 56:
- vk = KeyEvent.VK_ALT_GRAPH;
- break;
- case 29:
- vk = KeyEvent.VK_CONTROL;
- break;
- case 93:
- vk = KeyEvent.VK_PROPS;
- break;
- case 53:
- vk = KeyEvent.VK_DIVIDE;
- break;
- default:
- vk = 0;
- }
- }
-
- return vk;
- }
-
-
/**
- * Method interpretExtendedScanCode this method sould be used to handle the dead keys and other special keys
- *
- * @param scancode an int
- * @param vk an int
- * @param released a boolean
- * @return the char to use or throws an Exception
- * @throws UnsupportedKeyException is thrown if the current key is not handled by this method
- * @throws DeadKeyException is thrown if the current key is a dead key
- * @since 0.15
- */
- protected char interpretExtendedScanCode(int scancode, int vk, boolean released, boolean extended)
- throws UnsupportedKeyException, DeadKeyException {
- boolean deadKey = false;
-
- switch (vk) {
- case KeyEvent.VK_DEAD_ABOVEDOT:
- case KeyEvent.VK_DEAD_ABOVERING:
- case KeyEvent.VK_DEAD_ACUTE:
- case KeyEvent.VK_DEAD_BREVE:
- case KeyEvent.VK_DEAD_CARON:
- case KeyEvent.VK_DEAD_CEDILLA:
- case KeyEvent.VK_DEAD_CIRCUMFLEX:
- case KeyEvent.VK_DEAD_DIAERESIS:
- case KeyEvent.VK_DEAD_DOUBLEACUTE:
- case KeyEvent.VK_DEAD_GRAVE:
- case KeyEvent.VK_DEAD_IOTA:
- case KeyEvent.VK_DEAD_MACRON:
- case KeyEvent.VK_DEAD_OGONEK:
- case KeyEvent.VK_DEAD_SEMIVOICED_SOUND:
- case KeyEvent.VK_DEAD_TILDE:
- case KeyEvent.VK_DEAD_VOICED_SOUND:
- lastDeadVK = vk;
- deadKey = true;
- break;
-
- case KeyEvent.VK_INSERT:
- case KeyEvent.VK_HOME:
- case KeyEvent.VK_PAGE_UP:
- case KeyEvent.VK_DELETE:
- case KeyEvent.VK_END:
- case KeyEvent.VK_PAGE_DOWN:
- case KeyEvent.VK_UP:
- case KeyEvent.VK_LEFT:
- case KeyEvent.VK_DOWN:
- case KeyEvent.VK_RIGHT:
- case KeyEvent.VK_PRINTSCREEN:
- case KeyEvent.VK_PROPS:
- if (extended)
- return KeyEvent.CHAR_UNDEFINED;
- break;
-
- case KeyEvent.VK_SHIFT:
- case KeyEvent.VK_CONTROL:
- case KeyEvent.VK_ALT:
- case KeyEvent.VK_ALT_GRAPH:
- case KeyEvent.VK_CAPS_LOCK:
- return KeyEvent.CHAR_UNDEFINED;
-
- case KeyEvent.VK_ENTER:
- if (extended)
- return enter;
- break;
- case KeyEvent.VK_DIVIDE:
- if (extended)
- return divide;
- break;
- }
-
- if (deadKey) {
- throw deadKeyException;
- } else if (lastDeadVK != -1) {
- try {
- Key key = keys.getKey(scancode);
-
- char[] deadChars = key.getDeadKeyChar(lastDeadVK);
-
- if (flags == InputEvent.SHIFT_DOWN_MASK) {
- if (deadChars.length > 1) {
- return deadChars[1];
- } else
- throw unsupportedKeyException;
- } else if (deadChars.length > 0)
- return deadChars[0];
- else
- return KeyEvent.CHAR_UNDEFINED;
- } finally {
- if (!released) {
- lastDeadVK = -1;
- }
- }
- }
-
- throw unsupportedKeyException;
- }
-
- /**
* @param keycode
* @return
* @throws UnsupportedKeyException
*/
- public KeyboardEvent interpretKeycode(int keycode) {
- final int scancode = keys.getScanCode(keycode);
- if (scancode < 0) return null;
- return interpretScancode(scancode);
- }
+ public abstract KeyboardEvent interpretKeycode(int keycode);
- /**
- * @return Returns the flags.
- */
- protected final int getFlags() {
- return this.flags;
- }
-
-
- protected abstract void initKeys(Keys keys);
-}
-
-
+}
\ No newline at end of file
Modified: trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_CH_fr.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_CH_fr.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_CH_fr.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -23,7 +23,7 @@
import java.awt.event.KeyEvent;
import org.jnode.driver.input.Key;
-import org.jnode.driver.input.KeyboardInterpreter;
+import org.jnode.driver.input.AbstractKeyboardInterpreter;
import org.jnode.driver.input.Keys;
/**
@@ -31,7 +31,7 @@
*
* @author Yves Galante
*/
-public class KeyboardInterpreter_CH_fr extends KeyboardInterpreter {
+public class KeyboardInterpreter_CH_fr extends AbstractKeyboardInterpreter {
public KeyboardInterpreter_CH_fr() {
Modified: trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DE.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DE.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DE.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -23,7 +23,7 @@
import java.awt.event.KeyEvent;
import org.jnode.driver.input.Key;
-import org.jnode.driver.input.KeyboardInterpreter;
+import org.jnode.driver.input.AbstractKeyboardInterpreter;
import org.jnode.driver.input.Keys;
/**
@@ -31,7 +31,7 @@
* @since 0.1.9
*/
-public class KeyboardInterpreter_DE extends KeyboardInterpreter {
+public class KeyboardInterpreter_DE extends AbstractKeyboardInterpreter {
protected void initKeys(Keys keys) {
Key key;
Modified: trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DK.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DK.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DK.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -23,7 +23,7 @@
import java.awt.event.KeyEvent;
import org.jnode.driver.input.Key;
-import org.jnode.driver.input.KeyboardInterpreter;
+import org.jnode.driver.input.AbstractKeyboardInterpreter;
import org.jnode.driver.input.Keys;
/**
@@ -31,7 +31,7 @@
* @since 0.1.6
*/
-public class KeyboardInterpreter_DK extends KeyboardInterpreter {
+public class KeyboardInterpreter_DK extends AbstractKeyboardInterpreter {
protected void initKeys(Keys keys) {
Key key;
Modified: trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DV.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DV.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_DV.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -23,7 +23,7 @@
import java.awt.event.KeyEvent;
import org.jnode.driver.input.Key;
-import org.jnode.driver.input.KeyboardInterpreter;
+import org.jnode.driver.input.AbstractKeyboardInterpreter;
import org.jnode.driver.input.Keys;
@@ -34,7 +34,7 @@
* @author Sam Reid
* @since 0.15
*/
-public class KeyboardInterpreter_DV extends KeyboardInterpreter {
+public class KeyboardInterpreter_DV extends AbstractKeyboardInterpreter {
protected void initKeys(Keys keys) {
keys.setKey(1, new Key(KeyEvent.VK_ESCAPE));
Modified: trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_ES.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_ES.java 2008-10-03 12:59:09 UTC (rev 4599)
+++ trunk/core/src/driver/org/jnode/driver/input/l10n/KeyboardInterpreter_ES.java 2008-10-03 13:21:19 UTC (rev 4600)
@@ -23,7 +23,7 @@
import java.awt.event.KeyEvent;
import org.jnode.driver.input.Key;
-import org.jnode.driver.input.KeyboardInterpreter;
+import org.jnode.driver.input.AbstractKeyboard...
[truncated message content] |
|
From: <cr...@us...> - 2008-10-04 06:31:36
|
Revision: 4601
http://jnode.svn.sourceforge.net/jnode/?rev=4601&view=rev
Author: crawley
Date: 2008-10-04 06:27:09 +0000 (Sat, 04 Oct 2008)
Log Message:
-----------
Converted the KeyboardInterpreterFactory into a manager object with
additional methods for registering new keyboard interpreters.
Modified Paths:
--------------
trunk/core/descriptors/org.jnode.driver.input.xml
trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java
trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java
trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java
trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java
Added Paths:
-----------
trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java
trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterException.java
trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java
trunk/core/src/driver/org/jnode/driver/input/MissingKeyboardInterpreterClassException.java
Removed Paths:
-------------
trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java
Modified: trunk/core/descriptors/org.jnode.driver.input.xml
===================================================================
--- trunk/core/descriptors/org.jnode.driver.input.xml 2008-10-03 13:21:19 UTC (rev 4600)
+++ trunk/core/descriptors/org.jnode.driver.input.xml 2008-10-04 06:27:09 UTC (rev 4601)
@@ -5,7 +5,8 @@
name="JNode input driver"
version="@VERSION@"
license-name="lgpl"
- provider-name="JNode.org">
+ provider-name="JNode.org"
+ class="org.jnode.driver.input.KeyboardInputPlugin">
<requires>
<import plugin="org.jnode.driver.character"/>
Modified: trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java 2008-10-03 13:21:19 UTC (rev 4600)
+++ trunk/core/src/driver/org/jnode/driver/input/AbstractKeyboardDriver.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -28,8 +28,12 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+
+import javax.naming.NameNotFoundException;
+
import org.jnode.driver.Device;
import org.jnode.driver.DriverException;
+import org.jnode.naming.InitialNaming;
import org.jnode.util.SystemInputStream;
/**
@@ -93,7 +97,14 @@
*/
protected synchronized void startDevice() throws DriverException {
this.channel = getChannel();
- this.kbInterpreter = createKeyboardInterpreter();
+ try {
+ KeyboardLayoutManager mgr = InitialNaming.lookup(KeyboardLayoutManager.NAME);
+ this.kbInterpreter = mgr.createDefaultKeyboardInterpreter();
+ } catch (NameNotFoundException ex) {
+ throw new DriverException("Cannot find the keyboard layout manager", ex);
+ } catch (KeyboardInterpreterException ex) {
+ throw new DriverException();
+ }
final Device dev = getDevice();
final String id = dev.getId();
@@ -123,15 +134,6 @@
protected abstract ByteChannel getChannel();
/**
- * Create an interpreter for this keyboard device
- *
- * @return The created interpreter
- */
- protected KeyboardInterpreter createKeyboardInterpreter() {
- return KeyboardInterpreterFactory.getDefaultKeyboardInterpreter();
- }
-
- /**
* Stop the keyboard device.
*/
protected synchronized void stopDevice() throws DriverException {
Added: trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInputPlugin.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -0,0 +1,34 @@
+package org.jnode.driver.input;
+
+import javax.naming.NamingException;
+
+import org.jnode.naming.InitialNaming;
+import org.jnode.plugin.Plugin;
+import org.jnode.plugin.PluginDescriptor;
+import org.jnode.plugin.PluginException;
+
+public class KeyboardInputPlugin extends Plugin {
+
+ private KeyboardLayoutManager mgr;
+
+ public KeyboardInputPlugin(PluginDescriptor descriptor) {
+ super(descriptor);
+ }
+
+ @Override
+ protected void startPlugin() throws PluginException {
+ try {
+ mgr = new KeyboardLayoutManager();
+ InitialNaming.bind(KeyboardLayoutManager.NAME, mgr);
+ // TODO Load the initial layout mappings from the plugin descriptor.
+ } catch (NamingException ex) {
+ throw new PluginException(ex);
+ }
+ }
+
+ @Override
+ protected void stopPlugin() throws PluginException {
+ // Nothing needs to be done
+ }
+
+}
Modified: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-03 13:21:19 UTC (rev 4600)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreter.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -21,12 +21,20 @@
package org.jnode.driver.input;
/**
- * A KeyboardInterpreter translate scancodes into KeyboardEvent's.
+ * A KeyboardInterpreter translates a sequence of scancodes to the corresponding
+ * KeyboardEvent's. An instance is stateful, remembering the state of the SHIFT,
+ * CTRL and other 'modifier' keys for example.
*
* @author epr
* @author Martin Husted Hartvig
+ * @author cr...@jn...
*/
public interface KeyboardInterpreter {
+
+ public interface Factory {
+ // Create a new interpreter instance.
+ public KeyboardInterpreter create() throws KeyboardInterpreterException;
+ }
public static final int XT_RELEASE = 0x80;
public static final int XT_EXTENDED = 0xE0;
@@ -36,13 +44,13 @@
*
* @param scancode
*/
- public abstract KeyboardEvent interpretScancode(int scancode);
+ public KeyboardEvent interpretScancode(int scancode);
/**
* @param keycode
* @return
* @throws UnsupportedKeyException
*/
- public abstract KeyboardEvent interpretKeycode(int keycode);
+ public KeyboardEvent interpretKeycode(int keycode);
}
\ No newline at end of file
Added: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterException.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterException.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterException.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -0,0 +1,13 @@
+package org.jnode.driver.input;
+
+public class KeyboardInterpreterException extends Exception {
+
+ public KeyboardInterpreterException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public KeyboardInterpreterException(String message) {
+ super(message);
+ }
+
+}
Deleted: trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java 2008-10-03 13:21:19 UTC (rev 4600)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardInterpreterFactory.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -1,161 +0,0 @@
-/*
- * $Id$
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.driver.input;
-
-import java.util.Locale;
-import java.util.ResourceBundle;
-import org.apache.log4j.Logger;
-
-/**
- * The KeyboardInterpreterFactory class provides static methods for creating KeyboardInterpreter
- * objects and forming keyboard layout identifiers.
- * <p>
- * This is an interim API. We intend to replace it with a JNode service that includes
- * methods for managing the mapping of keyboard layout IDs to keyboard layout classes.
- *
- * @author Marc DENTY
- * @author cr...@jn...
- */
-public class KeyboardInterpreterFactory {
-
- private static final Logger log = Logger
- .getLogger(KeyboardInterpreterFactory.class);
-
- /**
- * Load the default keyboard layout as specified in the 'org.jnode.driver.input.KeyboardLayout'
- * resource bundle. If none is specified or the specified layout cannot be used, we use the
- * 'US_en' layout as a fallback.
- *
- * @return a valid KeyboardInterpreter
- */
- public static KeyboardInterpreter getDefaultKeyboardInterpreter() {
- String country = null;
- String region = null;
- String variant = null;
- try {
- ResourceBundle rb = ResourceBundle.getBundle("org.jnode.driver.input.KeyboardLayout",
- Locale.getDefault(), Thread.currentThread().getContextClassLoader());
- country = getProperty(rb, "defaultCountry");
- // FIXME the following property name should be 'defaultLanguage'
- region = getProperty(rb, "defaultRegion");
- variant = getProperty(rb, "defaultVariant");
- } catch (Exception ex) {
- log.error("Cannot find the 'org.jnode.driver.input.KeyboardLayout' resource bundle", ex);
- }
- if (country != null) {
- try {
- KeyboardInterpreter ki = createKeyboardInterpreter(country, region, variant);
- if (ki != null) {
- return ki;
- }
- } catch (Exception ex) {
- log.error("Cannot load the default '" +
- makeKeyboardInterpreterID(country, region, variant) +
- "' keyboard interpreter", ex);
- }
- }
- // Use the US_en keyboard layout as a fallback if there was no resource bundle, no
- // usable default keyboard layout or the specified default layout had no interpreter.
- log.error("Trying the 'US_en' keyboard interpreter as a fallback");
- try {
- return createKeyboardInterpreter("US", "en", null);
- } catch (Throwable ex) {
- log.error("Cannot load 'US_en' keyboard interpreter", ex);
- }
- // FIXME we should probably throw an exception ...
- return null;
- }
-
- /**
- * Get a String-valued property value from the resource bundle, dealing
- * with empty and missing values.
- *
- * @param rb the resource bundle
- * @param key the property name
- * @return the property value or <code>null</null> if the value is missing or empty.
- */
- private static String getProperty(ResourceBundle rb, String key) {
- try {
- String res = rb.getString(key);
- res = res.trim();
- return (res.length() == 0) ? null : res;
- } catch (RuntimeException e) { /* ClassCastException or MissingResourceException */
- return null;
- }
- }
-
- /**
- * Create a new keyboard interpreter object. Note that keyboard interpreter
- * objects are stateful and therefore cannot be shared by multiple keyboards.
- *
- * @param country the country code; e.g. US, GB, FR, DE, etc.
- * @param language the language code; e.g. en, fr, de etc or <code>null</code>
- * @param variant a keyboard variant name or <code>null</code>.
- * @return a KeyboardInterpreter or <code>null</code>
- */
- public static KeyboardInterpreter createKeyboardInterpreter(
- String country, String language, String variant) {
- final String id = makeKeyboardInterpreterID(country, language, variant);
- log.debug("Looking for interpreter for keyboard layout '" + id + "'");
- final String classI10N = "org.jnode.driver.input.l10n.KeyboardInterpreter_" + id;
-
- try {
- final ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return (KeyboardInterpreter) cl.loadClass(classI10N).newInstance();
- } catch (ClassNotFoundException ex) {
- log.error("No keyboard interpreter class found for layout id " + id +
- ": expected class name '" + classI10N + "'.");
- } catch (Exception ex) {
- log.error("Error loading or instantiating keyboard interpreter class '" +
- classI10N + "'.", ex);
- }
- return null;
- }
-
- /**
- * Convert a country / language / variant keyboard triple into a keyboard
- * layout identifier.
- *
- * @param country the country code; e.g. US, GB, FR, DE, etc.
- * @param language the language code; e.g. en, fr, de etc or <code>null</code>.
- * @param variant a keyboard variant name or <code>null</code>.
- * @return the keyboard layout identifier.
- */
- public static String makeKeyboardInterpreterID(
- String country, String language, String variant) {
- final String id;
- country = country.toUpperCase();
- if (language != null) {
- language = language.toLowerCase();
- if (variant == null) {
- id = country + "_" + language;
- } else {
- id = country + "_" + language + "_" + variant;
- }
- } else if (variant != null) {
- id = country + "_" + variant;
- } else {
- id = country;
- }
- return id;
- }
-}
Added: trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/input/KeyboardLayoutManager.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -0,0 +1,232 @@
+package org.jnode.driver.input;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The KeyboardManager provides methods for creating KeyboardInterpreter objects, and managing
+ * the mapping from various kinds of identifiers to keyboard layout classes.
+ *
+ * @author Marc DENTY
+ * @author cr...@jn...
+ */
+public class KeyboardLayoutManager {
+
+ private final Logger log = Logger.getLogger(KeyboardLayoutManager.class);
+
+ /**
+ * The name used to bind this manager in the InitialNaming namespace.
+ */
+ public static Class<KeyboardLayoutManager> NAME = KeyboardLayoutManager.class;
+
+ private HashMap<String, KeyboardInterpreter.Factory> map =
+ new HashMap<String, KeyboardInterpreter.Factory>();
+
+ /**
+ * Load the default keyboard layout as specified in the 'org.jnode.driver.input.KeyboardLayout'
+ * resource bundle. If none is specified or the specified layout cannot be used, we use the
+ * 'US_en' layout as a fallback.
+ *
+ * @return a valid KeyboardInterpreter
+ * @throws KeyboardInterpreterException
+ */
+ public KeyboardInterpreter createDefaultKeyboardInterpreter() throws KeyboardInterpreterException {
+ String country = null;
+ String region = null;
+ String variant = null;
+ try {
+ ResourceBundle rb = ResourceBundle.getBundle("org.jnode.driver.input.KeyboardLayout",
+ Locale.getDefault(), Thread.currentThread().getContextClassLoader());
+ country = getProperty(rb, "defaultCountry");
+ // FIXME the following property name should be 'defaultLanguage'
+ region = getProperty(rb, "defaultRegion");
+ variant = getProperty(rb, "defaultVariant");
+ } catch (Exception ex) {
+ log.error("Cannot find the 'org.jnode.driver.input.KeyboardLayout' resource bundle", ex);
+ }
+ if (country != null) {
+ try {
+ KeyboardInterpreter ki = createKeyboardInterpreter(country, region, variant);
+ if (ki != null) {
+ return ki;
+ }
+ } catch (Exception ex) {
+ log.error("Cannot load the default '" +
+ makeKeyboardInterpreterID(country, region, variant) +
+ "' keyboard interpreter", ex);
+ }
+ }
+ // Use the US_en keyboard layout as a fallback if there was no resource bundle, no
+ // usable default keyboard layout or the specified default layout had no interpreter.
+ log.error("Trying the 'US_en' keyboard interpreter as a fallback");
+ try {
+ return createKeyboardInterpreter("US_en");
+ } catch (Throwable ex) {
+ log.error("Cannot load 'US_en' keyboard interpreter", ex);
+ throw new KeyboardInterpreterException("Cannot create a keyboard interpreter", ex);
+ }
+ }
+
+ /**
+ * Get a String-valued property value from the resource bundle, dealing
+ * with empty and missing values.
+ *
+ * @param rb the resource bundle
+ * @param key the property name
+ * @return the property value or <code>null</null> if the value is missing or empty.
+ */
+ private String getProperty(ResourceBundle rb, String key) {
+ try {
+ String res = rb.getString(key);
+ res = res.trim();
+ return (res.length() == 0) ? null : res;
+ } catch (RuntimeException e) { /* ClassCastException or MissingResourceException */
+ return null;
+ }
+ }
+
+ /**
+ * Create a new keyboard interpreter object. Note that keyboard interpreter
+ * objects are stateful and therefore cannot be shared by multiple keyboards.
+ *
+ * @param a keyboard layout name or identifier.
+ * @return a KeyboardInterpreter
+ * @throws KeyboardInterpreterException
+ */
+ public KeyboardInterpreter createKeyboardInterpreter(String id)
+ throws KeyboardInterpreterException {
+ log.debug("Looking for interpreter for keyboard layout '" + id + "'");
+ KeyboardInterpreter.Factory factory = null;
+ synchronized (this) {
+ factory = map.get(id);
+ }
+ if (factory != null) {
+ return factory.create();
+ } else {
+ // As a fall-back look for a hard-coded keyboard interpreter class in the
+ // org.jnode.driver.input.l10n plugin.
+ final String classI10N = "org.jnode.driver.input.l10n.KeyboardInterpreter_" + id;
+ try {
+ return new KIClassWrapper(classI10N).create();
+ } catch (MissingKeyboardInterpreterClassException ex) {
+ // We tried and failed the fall-back, so report original problem:
+ // that 'id' is not a registered keyboard interpreter.
+ throw new KeyboardInterpreterException(
+ "No keyboard interpreter registered with id '" + id + "'");
+ }
+ }
+ }
+
+ /**
+ * Create a new keyboard interpreter object. Note that keyboard interpreter
+ * objects are stateful and therefore cannot be shared by multiple keyboards.
+ *
+ * @param country the country code; e.g. US, GB, FR, DE, etc.
+ * @param language the language code; e.g. en, fr, de etc or <code>null</code>
+ * @param variant a keyboard variant name or <code>null</code>.
+ * @return a KeyboardInterpreter
+ * @throws KeyboardInterpreterException
+ */
+ public KeyboardInterpreter createKeyboardInterpreter(
+ String country, String language, String variant)
+ throws KeyboardInterpreterException {
+ return createKeyboardInterpreter(
+ makeKeyboardInterpreterID(country, language, variant));
+ }
+
+ /**
+ * Convert a country / language / variant keyboard triple into a keyboard
+ * layout identifier.
+ *
+ * @param country the country code; e.g. US, GB, FR, DE, etc.
+ * @param language the language code; e.g. en, fr, de etc or <code>null</code>.
+ * @param variant a keyboard variant name or <code>null</code>.
+ * @return the keyboard layout identifier.
+ */
+ public String makeKeyboardInterpreterID(
+ String country, String language, String variant) {
+ final String id;
+ country = country.toUpperCase();
+ if (language != null) {
+ language = language.toLowerCase();
+ if (variant == null) {
+ id = country + "_" + language;
+ } else {
+ id = country + "_" + language + "_" + variant;
+ }
+ } else if (variant != null) {
+ id = country + "_" + variant;
+ } else {
+ id = country;
+ }
+ return id;
+ }
+
+ /**
+ * Register a keyboard interpreter factory object.
+ *
+ * @param name the keyboard layout identifier.
+ * @param factory the factory to be registered.
+ */
+ public synchronized void registerKeyboardLayout(
+ String name, KeyboardInterpreter.Factory factory) {
+ map.put(name, factory);
+ }
+
+ /**
+ * Register a keyboard interpreter class. The class is
+ *
+ * @param name the keyboard layout identifier.
+ * @param factory the name of the class to be registered.
+ */
+ public void registerKeyboardLayout(String name, String className) {
+ registerKeyboardLayout(name, new KIClassWrapper(className));
+ }
+
+ /**
+ * This wrapper class allows us to treat a class name as a keyboard interpreter
+ * factory.
+ */
+ private static class KIClassWrapper implements KeyboardInterpreter.Factory {
+ private final String className;
+
+ /**
+ * Create a wrapper object for a class.
+ *
+ * @param className the FQN of a class that should implement the KeyboardInterpreter
+ * interface and provide a public no-args constructor.
+ */
+ public KIClassWrapper(String className) {
+ this.className = className;
+ }
+
+ /**
+ * Create an instance corresponding to the wrapped class name.
+ *
+ * @throws MissingKeyboardInterpreterClassException if the class was not found
+ * @throws KeyboardInterpreterException for some other error; e.g. if there is
+ * not a public no-args constructor, if an exception is thrown by the constructor
+ * or if the resulting object is not a KeyboardInterpreter.
+ */
+ @Override
+ public KeyboardInterpreter create() throws KeyboardInterpreterException {
+ try {
+ // FIXME ... think about whether using the current thread's class
+ // loader might present a security issue.
+ final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return (KeyboardInterpreter) cl.loadClass(className).newInstance();
+ } catch (ClassNotFoundException ex) {
+ throw new MissingKeyboardInterpreterClassException(
+ "Keyboard interpreter class not found: " + className);
+ } catch (Exception ex) {
+ // Could be an access, and instantiation or a typecast exception ...
+ throw new KeyboardInterpreterException(
+ "Error instantiating keyboard interpreter class:" +
+ className, ex);
+ }
+ }
+ }
+}
Added: trunk/core/src/driver/org/jnode/driver/input/MissingKeyboardInterpreterClassException.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/input/MissingKeyboardInterpreterClassException.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/input/MissingKeyboardInterpreterClassException.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -0,0 +1,13 @@
+package org.jnode.driver.input;
+
+public class MissingKeyboardInterpreterClassException extends KeyboardInterpreterException {
+
+ public MissingKeyboardInterpreterClassException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MissingKeyboardInterpreterClassException(String message) {
+ super(message);
+ }
+
+}
Modified: trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java 2008-10-03 13:21:19 UTC (rev 4600)
+++ trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -21,6 +21,8 @@
package org.jnode.driver.input.usb;
+import javax.naming.NameNotFoundException;
+
import org.apache.log4j.Logger;
import org.jnode.driver.Driver;
import org.jnode.driver.DriverException;
@@ -37,7 +39,9 @@
import org.jnode.driver.input.KeyboardAPI;
import org.jnode.driver.input.KeyboardAPIAdapter;
import org.jnode.driver.input.KeyboardInterpreter;
-import org.jnode.driver.input.KeyboardInterpreterFactory;
+import org.jnode.driver.input.KeyboardInterpreterException;
+import org.jnode.driver.input.KeyboardLayoutManager;
+import org.jnode.naming.InitialNaming;
import org.jnode.util.ByteQueue;
import org.jnode.util.ByteQueueProcessor;
import org.jnode.util.ByteQueueProcessorThread;
@@ -79,6 +83,7 @@
161, 115, 114, 113, 150, 158, 159, 128, 136, 177, 178, 176, 142, 152, 173, 140};
/**
+ * @throws NameNotFoundException
* @see org.jnode.driver.Driver#startDevice()
*/
protected void startDevice() throws DriverException {
@@ -110,8 +115,9 @@
final USBRequest req = intPipe.createRequest(intData);
intPipe.asyncSubmit(req);
- // Register the PointerAPI
- apiAdapter.setKbInterpreter(KeyboardInterpreterFactory.getDefaultKeyboardInterpreter());
+ // Configure the default keyboard layout and register the KeyboardAPI
+ KeyboardLayoutManager mgr = InitialNaming.lookup(KeyboardLayoutManager.NAME);
+ apiAdapter.setKbInterpreter(mgr.createDefaultKeyboardInterpreter());
dev.registerAPI(KeyboardAPI.class, apiAdapter);
// Start the key event thread
@@ -120,6 +126,10 @@
keyEventThread.start();
} catch (USBException ex) {
throw new DriverException(ex);
+ } catch (NameNotFoundException ex) {
+ throw new DriverException("Cannot find keyboard layout manager", ex);
+ } catch (KeyboardInterpreterException ex) {
+ throw new DriverException(ex);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-10-03 13:21:19 UTC (rev 4600)
+++ trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-10-04 06:27:09 UTC (rev 4601)
@@ -29,7 +29,9 @@
import org.jnode.driver.DeviceUtils;
import org.jnode.driver.input.KeyboardAPI;
import org.jnode.driver.input.KeyboardInterpreter;
-import org.jnode.driver.input.KeyboardInterpreterFactory;
+import org.jnode.driver.input.KeyboardInterpreterException;
+import org.jnode.driver.input.KeyboardLayoutManager;
+import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
@@ -66,6 +68,7 @@
*/
public void execute(CommandLine cmdLine, InputStream in, PrintStream out,
PrintStream err) throws Exception {
+ final KeyboardLayoutManager mgr = InitialNaming.lookup(KeyboardLayoutManager.NAME);
final Collection<Device> kbDevs =
DeviceUtils.getDevicesByAPI(KeyboardAPI.class);
@@ -89,16 +92,17 @@
for (Device kb : kbDevs) {
final KeyboardAPI api = kb.getAPI(KeyboardAPI.class);
- final KeyboardInterpreter kbInt =
- KeyboardInterpreterFactory.createKeyboardInterpreter(
+ try {
+ final KeyboardInterpreter kbInt = mgr.createKeyboardInterpreter(
country, language, variant);
- if (kbInt != null) {
out.println("Setting layout for keyboard " + kb.getId() + " to " +
kbInt.getClass().getName());
api.setKbInterpreter(kbInt);
- } else {
- out.println("No suitable keyboard layout found");
- break;
+ } catch (KeyboardInterpreterException ex) {
+ out.println("No suitable keyboard layout found: " + ex.getMessage());
+ // Re-throw the exception so that the shell can decide whether or not
+ // to print a stacktrace.
+ throw ex;
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-10-02 14:07:56
|
Revision: 4595
http://jnode.svn.sourceforge.net/jnode/?rev=4595&view=rev
Author: crawley
Date: 2008-10-02 13:24:26 +0000 (Thu, 02 Oct 2008)
Log Message:
-----------
Implemented more infrastructure for isolate Status messages.
Modified Paths:
--------------
trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java
trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
Added Paths:
-----------
trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java
Modified: trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java
===================================================================
--- trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -88,7 +88,7 @@
* @param type
* @param exitReason
*/
- IsolateStatus(State state, ExitReason exitReason, int exitCode) {
+ public IsolateStatus(State state, ExitReason exitReason, int exitCode) {
this.state = state;
this.exitReason = exitReason;
this.exitCode = exitCode;
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -35,7 +35,9 @@
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
+import javax.isolate.IsolateStatus;
import javax.isolate.Link;
+import javax.isolate.LinkMessage;
import javax.naming.NameNotFoundException;
import org.jnode.naming.InitialNaming;
@@ -54,6 +56,7 @@
import org.jnode.vm.annotation.SharedStatics;
import org.jnode.vm.classmgr.VmIsolatedStatics;
import org.jnode.vm.classmgr.VmType;
+import org.jnode.vm.isolate.link.StatusLinkMessage;
import org.jnode.vm.isolate.link.VmLink;
/**
@@ -783,6 +786,26 @@
}
private void sendStatus(VmLink link, State state) {
- // TODO implement.
+ IsolateStatus.State istate = null;
+ switch (state) {
+ case CREATED:
+ istate = IsolateStatus.State.UNKNOWN;
+ break;
+ case STARTING:
+ istate = IsolateStatus.State.STARTING;
+ break;
+ case STARTED:
+ istate = IsolateStatus.State.STARTED;
+ break;
+ case EXITED:
+ istate = IsolateStatus.State.EXITING;
+ break;
+ case TERMINATED:
+ istate = IsolateStatus.State.EXITED;
+ break;
+ }
+ LinkMessage message =
+ new StatusLinkMessage(istate, IsolateStatus.ExitReason.IMPLICIT_EXIT, 0);
+ link.sendStatus(message);
}
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -22,7 +22,7 @@
* @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
*/
@Override
- LinkMessageImpl CloneMessage() {
+ LinkMessageImpl cloneMessage() {
final byte[] data = new byte[length];
System.arraycopy(bytes, offset, data, 0, length);
return new DataLinkMessage(data, 0, length);
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -25,7 +25,7 @@
* @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
*/
@Override
- LinkMessageImpl CloneMessage() {
+ LinkMessageImpl cloneMessage() {
return new IsolateLinkMessage(value);
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -23,7 +23,7 @@
* @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
*/
@Override
- LinkMessageImpl CloneMessage() {
+ LinkMessageImpl cloneMessage() {
return new LinkLinkMessage(value);
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -19,7 +19,7 @@
*
* @return
*/
- abstract LinkMessageImpl CloneMessage();
+ abstract LinkMessageImpl cloneMessage();
/**
* Block the current thread, until this message has its received flag set.
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -1,13 +1,39 @@
+/*
+ * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
package org.jnode.vm.isolate.link;
+/**
+ * This message type passes an object by reference. This is probably a bad idea
+ * because it 'breaks' the isolation of isolates. Use sparingly if at all.
+ *
+ * @author cr...@jn...
+ */
public class ObjectLinkMessage extends LinkMessageImpl {
-
+
private final Object obj;
-
+
private ObjectLinkMessage(Object cr) {
this.obj = cr;
}
-
+
public static ObjectLinkMessage newMessage (Object obj) {
return new ObjectLinkMessage(obj);
}
@@ -18,7 +44,7 @@
}
@Override
- LinkMessageImpl CloneMessage() {
+ LinkMessageImpl cloneMessage() {
return new ObjectLinkMessage(obj);
}
}
Added: trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -0,0 +1,90 @@
+/*
+ * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.jnode.vm.isolate.link;
+
+import javax.isolate.IsolateStatus;
+
+/**
+ * This class is use to transport status isolate information
+ * @author cr...@jn...
+ */
+public final class StatusLinkMessage extends LinkMessageImpl {
+
+ private final String state;
+ private final String exitReason;
+ private final int exitCode;
+
+ /**
+ * Internal message constructor used by cloneMessage
+ *
+ * @param value
+ */
+ private StatusLinkMessage(String state, String exitReason, int exitCode) {
+ this.state = state;
+ this.exitReason = exitReason;
+ this.exitCode = exitCode;
+ }
+
+ /**
+ * Message constructor used VmIsolate
+ *
+ * @param value
+ */
+ public StatusLinkMessage(IsolateStatus.State state, IsolateStatus.ExitReason exitReason,
+ int exitCode) {
+ this(state.toString(), exitReason.toString(), exitCode);
+ }
+
+ /**
+ * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
+ */
+ @Override
+ LinkMessageImpl cloneMessage() {
+ return new StatusLinkMessage(state, exitReason, exitCode);
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extract()
+ */
+ @Override
+ public Object extract() {
+ return extractStatus();
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#containsString()
+ */
+ @Override
+ public boolean containsStatus() {
+ return true;
+ }
+
+ /**
+ * @see javax.isolate.LinkMessage#extractString()
+ */
+ @Override
+ public IsolateStatus extractStatus() {
+ return new IsolateStatus(
+ IsolateStatus.State.valueOf(state),
+ IsolateStatus.ExitReason.valueOf(exitReason),
+ exitCode);
+ }
+}
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -21,7 +21,7 @@
* @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
*/
@Override
- LinkMessageImpl CloneMessage() {
+ LinkMessageImpl cloneMessage() {
return new StringLinkMessage(new String(value));
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -189,7 +189,7 @@
message = messages.poll();
}
message.notifyReceived();
- return message.CloneMessage();
+ return message.cloneMessage();
}
/**
@@ -278,18 +278,11 @@
*
* @param message the status message to be sent.
*/
- public final void sendStatus(LinkMessage message) {
- if (VmIsolate.currentIsolate() != sender) {
- // Current isolate is not the sender for this message
- throw new UnsupportedOperationException();
+ public final synchronized void sendStatus(LinkMessage message) {
+ if (!this.closed) {
+ // Send message
+ messages.add((LinkMessageImpl) message);
+ notifyAll();
}
- final LinkMessageImpl messageImpl = (LinkMessageImpl) message;
- synchronized (this) {
- if (!this.closed) {
- // Send message
- messages.add(messageImpl);
- notifyAll();
- }
- }
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-09-30 22:09:24 UTC (rev 4594)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-10-02 13:24:26 UTC (rev 4595)
@@ -12,7 +12,9 @@
import java.util.Properties;
import javax.isolate.Isolate;
+import javax.isolate.IsolateStatus;
import javax.isolate.Link;
+import javax.isolate.LinkMessage;
import javax.isolate.StreamBindings;
import org.jnode.shell.CommandRunner;
@@ -107,9 +109,18 @@
public void start(ThreadExitListener listener) throws ShellInvocationException {
try {
Link cl = Link.newLink(Isolate.currentIsolate(), isolate);
+ Link sl = isolate.newStatusLink();
isolate.start(cl);
ObjectLinkMessage msg = ObjectLinkMessage.newMessage(this.cr);
cl.send(msg);
+ while (true) {
+ LinkMessage statusMsg = sl.receive();
+ IsolateStatus status = statusMsg.extractStatus();
+ if (status.getState().equals(IsolateStatus.State.EXITED)) {
+ System.err.println("Got the EXITED message");
+ break;
+ }
+ }
} catch (Exception ex) {
throw new ShellInvocationException("Cannot start isolate", ex);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2008-10-06 07:56:27
|
Revision: 4607
http://jnode.svn.sourceforge.net/jnode/?rev=4607&view=rev
Author: lsantha
Date: 2008-10-06 07:56:13 +0000 (Mon, 06 Oct 2008)
Log Message:
-----------
Progress with isolates.
Modified Paths:
--------------
trunk/core/src/classpath/ext/javax/isolate/Isolate.java
trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java
trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java
trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java
trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
trunk/core/src/test/org/jnode/test/core/IsolateTest.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
Added Paths:
-----------
trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java
trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java
Modified: trunk/core/src/classpath/ext/javax/isolate/Isolate.java
===================================================================
--- trunk/core/src/classpath/ext/javax/isolate/Isolate.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/classpath/ext/javax/isolate/Isolate.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -35,11 +35,11 @@
/** The actual isolate implementation */
private final VmIsolate impl;
+ //todo hide this constructor
/**
* Constructor for the root isolate.
*
- * @param mainClass
- * @param args
+ * @param impl the JNode speciffic isolate implementation
*/
public Isolate(VmIsolate impl) {
this.impl = impl;
@@ -51,10 +51,8 @@
* @param mainClass
* @param args
*/
- public Isolate(String mainClass, String[] args) {
- this(new StreamBindings(),
- (Properties) AccessController.doPrivileged(new GetPropertiesAction()),
- mainClass, args);
+ public Isolate(String mainClass, String... args) {
+ this(new StreamBindings(), AccessController.doPrivileged(new GetPropertiesAction()), mainClass, args);
}
/**
@@ -64,22 +62,20 @@
* @param args
* @param properties
*/
- public Isolate(Properties properties, String mainClass, String[] args) {
+ public Isolate(Properties properties, String mainClass, String... args) {
this(new StreamBindings(), properties, mainClass, args);
}
/**
* Initialize this instance.
- *
- * @param mainClass
- * @param mainArgs
+ *
* @param bindings
* @param properties
+ * @param mainClass
+ * @param args
*/
- public Isolate(StreamBindings bindings, Properties properties,
- String mainClass, String[] args) {
- this.impl = new VmIsolate(this, bindings.getBindings(), properties,
- mainClass, args);
+ public Isolate(StreamBindings bindings, Properties properties, String mainClass, String... args) {
+ this.impl = new VmIsolate(this, bindings.getBindings(), properties, mainClass, args);
}
/**
@@ -119,53 +115,61 @@
}
/**
- * Has this isolate reached the exited state.
+ * Gets a new Link associated with this Isolate from which the current
+ * isolate can receive status link messages.
*
* @return
+ * @throws ClosedLinkException
*/
- public boolean hasExited() {
- return impl.hasExited();
+ public Link newStatusLink() throws ClosedLinkException {
+ return impl.newStatusLink(currentIsolate().impl);
}
/**
- * Has this isolate reached the terminated state.
+ * Start this isolate.
*
- * @return
+ * @param links
+ * @throws IsolateStartupException
*/
- public boolean hasTerminated() {
- return impl.hasTerminated();
+ public void start(Link... links) throws IsolateStartupException {
+ impl.start(this, links);
}
/**
- * Has this isolate reached the started state.
+ * Returns an array of active Isolate objects.
+ * The array contains one entry for each isolate in the invoker's aggregate that has been started but has not yet
+ * terminated. New isolates may have been constructed or existing ones terminated by the time method returns.
+ *
+ * @return the active Isolate objects present at the time of the call
*
- * @return
+ * @throws SecurityException if a security manager is present and permission to query isolates is denied
*/
- public boolean hasStarted() {
- return impl.hasStarted();
+ public static Isolate[] getIsolates() {
+ //todo implement it
+ throw new UnsupportedOperationException();
}
/**
- * Gets a new Link associated with this Isolate from which the current
- * isolate can receive status link messages.
+ * Returns the name of the main class of this isolate.
*
- * @return
- * @throws ClosedLinkException
+ * @return the name of the main class of this isolate
*/
- public Link newStatusLink() throws ClosedLinkException {
- return impl.newStatusLink(currentIsolate().impl);
+ public String getMainClassName() {
+ return impl.getMainClassName();
}
/**
- * Start this isolate.
+ * Returns the current state of the isolate.
+ *
+ * @return the current state of an isolate
*
- * @param messages
- * @throws IsolateStartupException
+ * @throws IllegalStateException if called before the isolate is started
+ * @throws SecurityException if a security manager is present and permission to query isolates is denied
*/
- public void start(Link... links) throws IsolateStartupException {
- impl.start(this, links);
+ public IsolateStatus.State getState() {
+ return impl.getIsolateState();
}
-
+
/**
* Retrieves a copy of the Link array passed to start() by the current
* isolate's creator. Modification of this array will have no effect on
@@ -180,6 +184,7 @@
return VmIsolate.getLinks();
}
+ //todo hide this method
/**
* Gets the implementation instance.
*
@@ -188,4 +193,10 @@
final VmIsolate getImpl() {
return impl;
}
+
+ @Override
+ public String toString() {
+ //todo implement it
+ return super.toString(); //To change body of overridden methods use File | Settings | File Templates.
+ }
}
Modified: trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java
===================================================================
--- trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/classpath/ext/javax/isolate/IsolateStatus.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -84,11 +84,11 @@
/**
* Initialize this instance.
- * @param source
- * @param type
+ * @param state
* @param exitReason
+ * @param exitCode
*/
- public IsolateStatus(State state, ExitReason exitReason, int exitCode) {
+ protected IsolateStatus(State state, ExitReason exitReason, int exitCode) {
this.state = state;
this.exitReason = exitReason;
this.exitCode = exitCode;
Modified: trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -12,7 +12,7 @@
private final int length;
- public DataLinkMessage(byte[] bytes, int offset, int length) {
+ DataLinkMessage(byte[] bytes, int offset, int length) {
this.bytes = bytes;
this.offset = offset;
this.length = length;
Added: trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -0,0 +1,38 @@
+/*
+ * $
+ */
+package org.jnode.vm.isolate;
+
+import javax.isolate.IsolateStatus;
+
+/**
+ * @author Levente S\u00e1ntha
+ */
+public class IsolateStatusImpl extends IsolateStatus implements Cloneable {
+ public IsolateStatusImpl(State state, ExitReason exitReason, int exitCode) {
+ super(state, exitReason, exitCode);
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public IsolateStatusImpl copy() {
+ try {
+ return (IsolateStatusImpl) this.clone();
+ } catch (CloneNotSupportedException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ @Override
+ public String toString() {
+ State s = getState();
+ if(s.equals(State.EXITED)) {
+ return getState() + "(" + getExitReason() + "," + getExitCode();
+ } else {
+ return getState().toString();
+ }
+ }
+}
Modified: trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -28,9 +28,7 @@
* @param bytes
* @return
*/
- public static LinkMessage newDataMessage(byte[] bytes,
- int offset,
- int length) {
+ public static LinkMessage newDataMessage(byte[] bytes, int offset, int length) {
return new DataLinkMessage(bytes, offset, length);
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -15,7 +15,7 @@
private boolean received = false;
/**
- * Close this message in the current isolate.
+ * Clone this message in the current isolate.
*
* @return
*/
Modified: trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -9,13 +9,13 @@
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful, but
+ * This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jnode.vm.isolate;
@@ -23,68 +23,35 @@
import javax.isolate.IsolateStatus;
/**
- * This class is use to transport status isolate information
- * @author cr...@jn...
+ * @author Levente S\u00e1ntha
*/
-public final class StatusLinkMessage extends LinkMessageImpl {
+final class StatusLinkMessage extends LinkMessageImpl {
+ private final IsolateStatusImpl status;
- private final String state;
- private final String exitReason;
- private final int exitCode;
-
- /**
- * Internal message constructor used by cloneMessage
- *
- * @param value
- */
- private StatusLinkMessage(String state, String exitReason, int exitCode) {
- this.state = state;
- this.exitReason = exitReason;
- this.exitCode = exitCode;
+ StatusLinkMessage(IsolateStatus status) {
+ this.status = (IsolateStatusImpl) status;
}
/**
- * Message constructor used VmIsolate
+ * Clone this message in the current isolate.
*
- * @param value
+ * @return
*/
- public StatusLinkMessage(IsolateStatus.State state, IsolateStatus.ExitReason exitReason,
- int exitCode) {
- this(state.toString(), exitReason.toString(), exitCode);
+ LinkMessageImpl cloneMessage() {
+ return new StatusLinkMessage(status.copy());
}
- /**
- * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage()
- */
@Override
- LinkMessageImpl cloneMessage() {
- return new StatusLinkMessage(state, exitReason, exitCode);
+ public boolean containsStatus() {
+ return true;
}
- /**
- * @see javax.isolate.LinkMessage#extract()
- */
- @Override
public Object extract() {
- return extractStatus();
+ return status;
}
- /**
- * @see javax.isolate.LinkMessage#containsString()
- */
@Override
- public boolean containsStatus() {
- return true;
- }
-
- /**
- * @see javax.isolate.LinkMessage#extractString()
- */
- @Override
public IsolateStatus extractStatus() {
- return new IsolateStatus(
- IsolateStatus.State.valueOf(state),
- IsolateStatus.ExitReason.valueOf(exitReason),
- exitCode);
+ return status;
}
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -37,7 +37,6 @@
import javax.isolate.IsolateStartupException;
import javax.isolate.IsolateStatus;
import javax.isolate.Link;
-import javax.isolate.LinkMessage;
import javax.naming.NameNotFoundException;
import org.jnode.naming.InitialNaming;
@@ -95,6 +94,10 @@
*/
private State state = State.CREATED;
+ private IsolateStatus.State isolateState;
+ private IsolateStatus.ExitReason exitReason;
+ private int exitCode;
+
/**
* The root of the threadgroups for this isolate.
*/
@@ -159,7 +162,33 @@
*/
@SharedStatics
private enum State {
- CREATED, STARTING, STARTED, EXITED, TERMINATED
+ CREATED(IsolateStatus.State.UNKNOWN),
+
+ STARTING(IsolateStatus.State.STARTING),
+
+ STARTED(IsolateStatus.State.STARTED),
+
+ EXITING(IsolateStatus.State.EXITING),
+
+ EXITED(IsolateStatus.State.EXITED),
+
+ TERMINATING(IsolateStatus.State.EXITING),
+
+ TERMINATED(IsolateStatus.State.EXITED),
+
+ NEVERSTARTED(IsolateStatus.State.UNKNOWN),
+
+ UNKNOWN(IsolateStatus.State.UNKNOWN);
+
+ private final IsolateStatus.State isolateState;
+
+ private State(IsolateStatus.State isolateState) {
+ this.isolateState = isolateState;
+ }
+
+ IsolateStatus.State getIsolateState() {
+ return isolateState;
+ }
}
public static boolean walkIsolates(ObjectVisitor visitor) {
@@ -352,12 +381,22 @@
//todo handle demon threads
if (threadGroup.activeCount() > 0 || threadGroup.activeGroupCount() > 0)
return;
-
+
+ changeState(State.EXITING);
try {
threadGroup.destroy();
} catch (Throwable t) {
t.printStackTrace();
}
+
+ this.exitCode = status;
+ if(currentIsolate() == this) {
+ //todo implement: IMPLICIT_EXIT, UNCAUGHT_EXCEPTION
+ this.exitReason = IsolateStatus.ExitReason.SELF_EXIT;
+ } else {
+ this.exitReason = IsolateStatus.ExitReason.OTHER_EXIT;
+ }
+
changeState(State.EXITED);
StaticData.isolates.remove(this);
}
@@ -370,8 +409,9 @@
@SuppressWarnings("deprecation")
public final void halt(Isolate isolate, int status) {
testIsolate(isolate);
+ changeState(State.EXITING);
switch (state) {
- case STARTED:
+ case EXITING:
threadGroup.stop();
break;
}
@@ -381,7 +421,13 @@
} catch (Throwable t) {
t.printStackTrace();
}
- changeState(State.TERMINATED);
+ this.exitCode = status;
+ if(currentIsolate() == this) {
+ this.exitReason = IsolateStatus.ExitReason.SELF_HALT;
+ } else {
+ this.exitReason = IsolateStatus.ExitReason.OTHER_HALT;
+ }
+ changeState(State.EXITED);
StaticData.isolates.remove(this);
}
@@ -451,8 +497,9 @@
/**
* Start this isolate.
*
- * @param messages
- * @throws IsolateStartupException
+ * @param isolate the isolate to start
+ * @param links an array of links passed to the isolate on startup
+ * @throws IsolateStartupException on startup failure
*/
@PrivilegedActionPragma
public synchronized final void start(Isolate isolate, Link[] links)
@@ -518,9 +565,6 @@
final IsolateThread mainThread = new IsolateThread(threadGroup, this,
piManager, stdout, stderr, stdin);
- // Update the state of this isolate.
- changeState(State.STARTED);
-
// Start the main thread.
mainThread.start();
}
@@ -538,7 +582,7 @@
task.run();
return;
}
-
+
synchronized(taskSync){
taskList.add(task);
taskSync.notifyAll();
@@ -633,6 +677,9 @@
}
});
+ // Update the state of this isolate.
+ changeState(State.STARTED);
+
// Run main method.
mainMethod.invoke(null, new Object[]{args});
} catch (Throwable ex) {
@@ -756,6 +803,10 @@
return isolateLocalMap;
}
+ public IsolateStatus.State getIsolateState() {
+ return isolateState;
+ }
+
/**
* Create and return a new status link for this isolate and the supplied
* receiver isolate.
@@ -766,44 +817,32 @@
Link link = VmLink.newLink(this, receiver);
VmLink vmLink = VmLink.fromLink(link);
statusLinks.add(vmLink);
- if (state == State.TERMINATED) {
+ if (isolateState != null && isolateState.equals(IsolateStatus.State.EXITED)) {
// The spec says that we should immediately send a link message
// if the isolate is already 'EXITED'.
- sendStatus(vmLink, state);
+ sendStatus(vmLink, isolateState);
}
return link;
}
-
- private synchronized void changeState(State newState) {
- if (state != newState) {
- this.state = newState;
+
+ private synchronized boolean changeState(State newState) {
+ this.state = newState;
+ IsolateStatus.State newIsolateState = newState.getIsolateState();
+ if (isolateState != newIsolateState) {
+ this.isolateState = newIsolateState;
for (VmLink link : statusLinks) {
- sendStatus(link, this.state);
+ sendStatus(link, this.isolateState);
}
}
+ return true;
}
- private void sendStatus(VmLink link, State state) {
- IsolateStatus.State istate = null;
- switch (state) {
- case CREATED:
- istate = IsolateStatus.State.UNKNOWN;
- break;
- case STARTING:
- istate = IsolateStatus.State.STARTING;
- break;
- case STARTED:
- istate = IsolateStatus.State.STARTED;
- break;
- case EXITED:
- istate = IsolateStatus.State.EXITING;
- break;
- case TERMINATED:
- istate = IsolateStatus.State.EXITED;
- break;
+ private void sendStatus(VmLink link, IsolateStatus.State state) {
+ if(state.equals(IsolateStatus.State.EXITED)) {
+ org.jnode.vm.Unsafe.debugStackTrace();
+ link.sendStatus(new StatusLinkMessage(new IsolateStatusImpl(state, exitReason, exitCode)));
+ } else {
+ link.sendStatus(new StatusLinkMessage(new IsolateStatusImpl(state, null, -1)));
}
- LinkMessage message =
- new StatusLinkMessage(istate, IsolateStatus.ExitReason.IMPLICIT_EXIT, 0);
- link.sendStatus(message);
}
}
Modified: trunk/core/src/test/org/jnode/test/core/IsolateTest.java
===================================================================
--- trunk/core/src/test/org/jnode/test/core/IsolateTest.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/core/src/test/org/jnode/test/core/IsolateTest.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -5,6 +5,10 @@
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
+import javax.isolate.Link;
+import javax.isolate.ClosedLinkException;
+import javax.isolate.LinkMessage;
+import javax.isolate.IsolateStatus;
public class IsolateTest {
Copied: trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java (from rev 4600, trunk/core/src/test/org/jnode/test/core/LinkTest.java)
===================================================================
--- trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java (rev 0)
+++ trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -0,0 +1,64 @@
+/*
+ * $Id$
+ */
+package org.jnode.test.core;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import javax.isolate.ClosedLinkException;
+import javax.isolate.Isolate;
+import javax.isolate.IsolateStartupException;
+import javax.isolate.Link;
+import javax.isolate.LinkMessage;
+import javax.isolate.IsolateStatus;
+
+public class StatusLinkTest {
+
+ public static void main(String[] args) throws IsolateStartupException, InterruptedIOException, IOException {
+ String clsName = ChildClass.class.getName();
+ Isolate child = new Isolate(clsName);
+ Link link = child.newStatusLink();
+ new Thread(new StatusMonitor(link)).start();
+ child.start();
+ }
+
+ public static class StatusMonitor implements Runnable {
+ private final Link link;
+
+ public StatusMonitor(Link link) {
+ this.link = link;
+ }
+
+ public void run() {
+ try {
+ while (true) {
+ LinkMessage msg = link.receive();
+ if(msg.containsStatus()) {
+ IsolateStatus is = msg.extractStatus();
+ if(is.getState().equals(IsolateStatus.State.EXITED)) {
+ System.out.println("Message: state=" + is.getState() + " code=" + is.getExitCode() +
+ " reason=" + is.getExitReason());
+ break;
+ } else {
+ System.out.println("Message: state=" + is.getState());
+ }
+ } else {
+ System.out.println("Unknown message: " + msg);
+ }
+ }
+ } catch (Exception x) {
+ x.printStackTrace();
+ }
+ }
+ }
+
+ public static class ChildClass {
+
+ public static void main(String[] args) throws InterruptedException {
+ System.out.println("Child: started");
+ System.out.println("Child: sleeping 3 seconds");
+ Thread.sleep(3000);
+ System.out.println("Child: exiting");
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-10-05 06:54:44 UTC (rev 4606)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-10-06 07:56:13 UTC (rev 4607)
@@ -8,6 +8,7 @@
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import java.io.InterruptedIOException;
import java.net.Socket;
import java.util.Properties;
@@ -102,7 +103,8 @@
@Override
public boolean isAlive() {
- return isolate.hasStarted() && !isolate.hasExited();
+ final IsolateStatus.State state = isolate.getState();
+ return IsolateStatus.State.STARTED.equals(state);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2008-10-06 09:26:34
|
Revision: 4608
http://jnode.svn.sourceforge.net/jnode/?rev=4608&view=rev
Author: lsantha
Date: 2008-10-06 09:00:26 +0000 (Mon, 06 Oct 2008)
Log Message:
-----------
Style fixes.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java
trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
trunk/core/src/core/org/jnode/vm/isolate/VmIsolateLocal.java
trunk/core/src/driver/org/jnode/driver/Device.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
trunk/core/src/test/org/jnode/test/core/IsolateTest.java
trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java
trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/spi/AbstractFontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java
trunk/gui/src/awt/org/jnode/awt/util/BasicGraphics.java
trunk/gui/src/awt/org/jnode/awt/util/SurfaceGraphics2D.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
Modified: trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/core/org/jnode/vm/isolate/IsolateStatusImpl.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -29,7 +29,7 @@
@Override
public String toString() {
State s = getState();
- if(s.equals(State.EXITED)) {
+ if (s.equals(State.EXITED)) {
return getState() + "(" + getExitReason() + "," + getExitCode();
} else {
return getState().toString();
Modified: trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -23,7 +23,7 @@
/**
* This message type passes an object by reference. This is probably a bad idea
* because it 'breaks' the isolation of isolates. Use sparingly if at all.
- *
+ *
* @author cr...@jn...
*/
public class ObjectLinkMessage extends LinkMessageImpl {
@@ -34,7 +34,7 @@
this.obj = cr;
}
- public static ObjectLinkMessage newMessage (Object obj) {
+ public static ObjectLinkMessage newMessage(Object obj) {
return new ObjectLinkMessage(obj);
}
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -29,16 +29,14 @@
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Properties;
-import java.util.List;
-import java.util.LinkedList;
-
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
import javax.isolate.IsolateStatus;
import javax.isolate.Link;
import javax.naming.NameNotFoundException;
-
import org.jnode.naming.InitialNaming;
import org.jnode.plugin.PluginManager;
import org.jnode.util.BootableHashMap;
@@ -177,7 +175,7 @@
TERMINATED(IsolateStatus.State.EXITED),
NEVERSTARTED(IsolateStatus.State.UNKNOWN),
-
+
UNKNOWN(IsolateStatus.State.UNKNOWN);
private final IsolateStatus.State isolateState;
@@ -241,7 +239,7 @@
}
static synchronized int nextId() {
- return nextId ++;
+ return nextId++;
}
}
@@ -390,7 +388,7 @@
}
this.exitCode = status;
- if(currentIsolate() == this) {
+ if (currentIsolate() == this) {
//todo implement: IMPLICIT_EXIT, UNCAUGHT_EXCEPTION
this.exitReason = IsolateStatus.ExitReason.SELF_EXIT;
} else {
@@ -422,7 +420,7 @@
t.printStackTrace();
}
this.exitCode = status;
- if(currentIsolate() == this) {
+ if (currentIsolate() == this) {
this.exitReason = IsolateStatus.ExitReason.SELF_HALT;
} else {
this.exitReason = IsolateStatus.ExitReason.OTHER_HALT;
@@ -498,11 +496,11 @@
* Start this isolate.
*
* @param isolate the isolate to start
- * @param links an array of links passed to the isolate on startup
+ * @param links an array of links passed to the isolate on startup
* @throws IsolateStartupException on startup failure
*/
@PrivilegedActionPragma
- public synchronized final void start(Isolate isolate, Link[] links)
+ public final void start(Isolate isolate, Link[] links)
throws IsolateStartupException {
testIsolate(isolate);
// The creator of this isolate must be the same as the current isolate
@@ -773,6 +771,7 @@
/**
* Returns the identifier of this isolate.
+ *
* @return the unique identifier
*/
public int getId() {
@@ -781,6 +780,7 @@
/**
* Returns the state of this isolate.
+ *
* @return the current state
*/
public State getState() {
@@ -789,6 +789,7 @@
/**
* Returns the VmIsolate instance which created this VmIsolate instance.
+ *
* @return
*/
public VmIsolate getCreator() {
@@ -797,6 +798,7 @@
/**
* Returns the map of isolate locals belonging to this isolate.
+ *
* @return the isolate local map
*/
BootableHashMap getIsolateLocalMap() {
@@ -810,6 +812,7 @@
/**
* Create and return a new status link for this isolate and the supplied
* receiver isolate.
+ *
* @param receiver the receiver for the link.
* @return the link.
*/
@@ -817,7 +820,7 @@
Link link = VmLink.newLink(this, receiver);
VmLink vmLink = VmLink.fromLink(link);
statusLinks.add(vmLink);
- if (isolateState != null && isolateState.equals(IsolateStatus.State.EXITED)) {
+ if (isolateState != null && isolateState.equals(IsolateStatus.State.EXITED)) {
// The spec says that we should immediately send a link message
// if the isolate is already 'EXITED'.
sendStatus(vmLink, isolateState);
@@ -838,7 +841,7 @@
}
private void sendStatus(VmLink link, IsolateStatus.State state) {
- if(state.equals(IsolateStatus.State.EXITED)) {
+ if (state.equals(IsolateStatus.State.EXITED)) {
org.jnode.vm.Unsafe.debugStackTrace();
link.sendStatus(new StatusLinkMessage(new IsolateStatusImpl(state, exitReason, exitCode)));
} else {
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolateLocal.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolateLocal.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolateLocal.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -3,7 +3,6 @@
*/
package org.jnode.vm.isolate;
-import org.jnode.util.BootableHashMap;
import org.jnode.vm.VmSystemObject;
/**
Modified: trunk/core/src/driver/org/jnode/driver/Device.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/Device.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/driver/org/jnode/driver/Device.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -245,8 +245,8 @@
*/
public final boolean implementsAPI(Class<? extends DeviceAPI> apiInterface) {
//lookup is classname based to handle multi isolate uscases
- for(Class clazz : apis.keySet()) {
- if(clazz.getName().equals(apiInterface.getName())) {
+ for (Class clazz : apis.keySet()) {
+ if (clazz.getName().equals(apiInterface.getName())) {
return true;
}
}
@@ -272,8 +272,8 @@
public final <T extends DeviceAPI> T getAPI(Class<T> apiInterface) throws ApiNotFoundException {
//lookup is classname based to handle multi isolate uscases
Class apiInterface2 = null;
- for(Class clazz : apis.keySet()) {
- if(clazz.getName().equals(apiInterface.getName())) {
+ for (Class clazz : apis.keySet()) {
+ if (clazz.getName().equals(apiInterface.getName())) {
apiInterface2 = clazz;
break;
}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -5,7 +5,6 @@
import java.io.Reader;
import java.io.Writer;
-import org.apache.log4j.Logger;
import org.jnode.driver.console.InputCompleter;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.input.KeyboardEvent;
Modified: trunk/core/src/test/org/jnode/test/core/IsolateTest.java
===================================================================
--- trunk/core/src/test/org/jnode/test/core/IsolateTest.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/test/org/jnode/test/core/IsolateTest.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -5,10 +5,6 @@
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
-import javax.isolate.Link;
-import javax.isolate.ClosedLinkException;
-import javax.isolate.LinkMessage;
-import javax.isolate.IsolateStatus;
public class IsolateTest {
Modified: trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java
===================================================================
--- trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -5,12 +5,11 @@
import java.io.IOException;
import java.io.InterruptedIOException;
-import javax.isolate.ClosedLinkException;
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
+import javax.isolate.IsolateStatus;
import javax.isolate.Link;
import javax.isolate.LinkMessage;
-import javax.isolate.IsolateStatus;
public class StatusLinkTest {
@@ -19,7 +18,7 @@
Isolate child = new Isolate(clsName);
Link link = child.newStatusLink();
new Thread(new StatusMonitor(link)).start();
- child.start();
+ child.start();
}
public static class StatusMonitor implements Runnable {
@@ -33,9 +32,9 @@
try {
while (true) {
LinkMessage msg = link.receive();
- if(msg.containsStatus()) {
+ if (msg.containsStatus()) {
IsolateStatus is = msg.extractStatus();
- if(is.getState().equals(IsolateStatus.State.EXITED)) {
+ if (is.getState().equals(IsolateStatus.State.EXITED)) {
System.out.println("Message: state=" + is.getState() + " code=" + is.getExitCode() +
" reason=" + is.getExitReason());
break;
@@ -43,7 +42,7 @@
System.out.println("Message: state=" + is.getState());
}
} else {
- System.out.println("Unknown message: " + msg);
+ System.out.println("Unknown message: " + msg);
}
}
} catch (Exception x) {
@@ -61,4 +60,4 @@
System.out.println("Child: exiting");
}
}
-}
\ No newline at end of file
+}
Modified: trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/gui/src/awt/org/jnode/awt/font/FontProvider.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -29,8 +29,6 @@
import java.util.Map;
import java.util.Set;
-import org.jnode.awt.JNodeToolkit;
-
/**
* @author Ewout Prangsma (ep...@us...)
* @author Fabien DUMINY (fd...@jn...)
@@ -96,7 +94,7 @@
/**
* Creates a font peer from the given name or return null if not supported/provided.
- * As said in {@link JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
+ * As said in {@link org.jnode.awt.JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
* "We don't know what kind of "name" the user requested (logical, face, family)".
*
* @param name
Modified: trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -34,20 +34,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import org.apache.log4j.Logger;
-import org.jnode.awt.JNodeToolkit;
-import org.jnode.awt.font.FontProvider;
import org.jnode.awt.font.TextRenderer;
import org.jnode.awt.font.renderer.RenderCache;
import org.jnode.awt.font.spi.AbstractFontProvider;
import org.jnode.font.bdf.BDFFontContainer;
import org.jnode.font.bdf.BDFGlyph;
-import org.jnode.vm.Unsafe;
/**
- * {@link FontProvider} for {@link BDFFont}s.
- *
+ * {@link org.jnode.awt.font.FontProvider} for {@link BDFFont}s.
+ *
* @author Fabien DUMINY (fd...@jn...)
*/
public class BDFFontProvider extends AbstractFontProvider<BDFFont, BDFFontContainer> {
@@ -64,11 +60,11 @@
};
private List<BDFFontContainer> containers;
-
- private Map<BDFFontContainer, Size> maxCharBounds = new HashMap<BDFFontContainer, Size>();
-
+
+ private Map<BDFFontContainer, Size> maxCharBounds = new HashMap<BDFFontContainer, Size>();
+
public BDFFontProvider() {
- super(BDFFont.class, "bdf");
+ super(BDFFont.class, "bdf");
}
protected TextRenderer createTextRenderer(RenderCache renderCache, Font font) {
@@ -82,12 +78,12 @@
final BDFFont bdfFont = getCompatibleFont(font);
return bdfFont.getFontMetrics();
}
-
+
/**
* Creates a font peer from the given name or return null if not supported/provided.
- * As said in {@link JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
+ * As said in {@link org.jnode.awt.JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
* "We don't know what kind of "name" the user requested (logical, face, family)".
- *
+ *
* @param name
* @param attrs
* @return
@@ -104,20 +100,21 @@
break;
}
}
-
+
for (BDFFontContainer container : getContainers()) {
if (match(container, name, attrs)) {
peer = new BDFFontPeer(this, name, attrs);
break;
}
}
-
+
//Unsafe.debug("BDFFontProvider: name=" + name + "fontPeer=" + peer);
return peer;
}
/**
* Read an create a Font from the given InputStream
+ *
* @param stream
* @return
*/
@@ -136,7 +133,7 @@
throw ffe;
}
}
-
+
/**
* Load all default fonts.
*/
@@ -146,7 +143,7 @@
addFont(new BDFFont(container));
}
}
-
+
private List<BDFFontContainer> getContainers() {
if (containers == null) {
containers = new ArrayList<BDFFontContainer>();
@@ -156,7 +153,7 @@
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL url = cl.getResource(fontResource);
if (url != null) {
- Reader reader = new InputStreamReader(url.openStream());
+ Reader reader = new InputStreamReader(url.openStream());
containers.add(BDFFontContainer.createFont(reader));
} else {
log.error("Cannot find font resource " + fontResource);
@@ -166,15 +163,15 @@
} catch (Throwable ex) {
log.error("Cannot find font " + fontResource, ex);
}
- }
+ }
}
-
+
return containers;
}
Rectangle2D getMaxCharBounds(BDFFontContainer container) {
Size size = maxCharBounds.get(container);
-
+
if (size == null) {
size = new Size();
for (BDFGlyph g : container.getGlyphs()) {
@@ -185,8 +182,8 @@
}
maxCharBounds.put(container, size);
}
-
- return new Rectangle2D.Double(0, 0, size.maxCharWidth, size.maxCharHeight);
+
+ return new Rectangle2D.Double(0, 0, size.maxCharWidth, size.maxCharHeight);
}
private boolean match(BDFFontContainer container, String name, Map attrs) {
@@ -195,9 +192,8 @@
//if (container.getFamily().equals(name) || container.getName().equals(name)) {
return true;
}
-
- private static class Size
- {
+
+ private static class Size {
int maxCharWidth = 0;
int maxCharHeight = 0;
}
Modified: trunk/gui/src/awt/org/jnode/awt/font/spi/AbstractFontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/spi/AbstractFontProvider.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/gui/src/awt/org/jnode/awt/font/spi/AbstractFontProvider.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -24,7 +24,6 @@
import java.awt.Font;
import java.awt.FontMetrics;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Modified: trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -27,18 +27,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.List;
import java.util.Map;
-
import org.apache.log4j.Logger;
-import org.jnode.awt.JNodeToolkit;
-import org.jnode.awt.font.JNodeFontPeer;
import org.jnode.awt.font.TextRenderer;
-import org.jnode.awt.font.bdf.BDFFont;
-import org.jnode.awt.font.bdf.BDFFontPeer;
import org.jnode.awt.font.renderer.RenderCache;
import org.jnode.awt.font.spi.AbstractFontProvider;
-import org.jnode.font.bdf.BDFFontContainer;
/**
* @author epr
@@ -77,12 +70,12 @@
return new TTFFontMetrics(font, getFontData(font));
}
-
+
/**
* Creates a font peer from the given name or return null if not supported/provided.
- * As said in {@link JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
+ * As said in {@link org.jnode.awt.JNodeToolkit#getClasspathFontPeer(String, java.util.Map)} javadoc :
* "We don't know what kind of "name" the user requested (logical, face, family)".
- *
+ *
* @param name
* @param attrs
* @return
@@ -109,12 +102,13 @@
// }
//
// return peer;
-
+
return new TTFFontPeer(this, name, attrs);
}
/**
* Read an create a Font from the given InputStream
+ *
* @param stream
* @return
*/
@@ -130,9 +124,9 @@
FontFormatException ffe = new FontFormatException("bad ttf format");
ffe.initCause(e);
throw ffe;
- }
+ }
}
-
+
/**
* Gets the font data for the given font
*
@@ -170,6 +164,6 @@
} catch (Throwable ex) {
log.error("Cannot find font " + fontResource, ex);
}
- }
+ }
}
}
Modified: trunk/gui/src/awt/org/jnode/awt/util/BasicGraphics.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/util/BasicGraphics.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/gui/src/awt/org/jnode/awt/util/BasicGraphics.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -62,7 +62,8 @@
clip = clip.intersection(r);
if (this.clip.width == 0 && this.clip.height == 0) {
- //TODO it's probably a regular (but rare) use case since a GUI (swing/awt) component can have width=0 and height=0
+ //TODO it's probably a regular (but rare) use case since a GUI (swing/awt)
+ // component can have width=0 and height=0
org.jnode.vm.Unsafe.debug(getClass().getSimpleName() + ": zero clip\n");
}
}
Modified: trunk/gui/src/awt/org/jnode/awt/util/SurfaceGraphics2D.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/util/SurfaceGraphics2D.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/gui/src/awt/org/jnode/awt/util/SurfaceGraphics2D.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -26,7 +26,6 @@
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
-import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.RoundRectangle2D;
@@ -41,7 +40,6 @@
import java.text.AttributedCharacterIterator;
import java.util.HashMap;
import java.util.Map;
-
import org.jnode.awt.JNodeToolkit;
import org.jnode.awt.font.FontManager;
import org.jnode.driver.video.Surface;
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-10-06 07:56:13 UTC (rev 4607)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-10-06 09:00:26 UTC (rev 4608)
@@ -8,16 +8,13 @@
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-import java.io.InterruptedIOException;
import java.net.Socket;
import java.util.Properties;
-
import javax.isolate.Isolate;
import javax.isolate.IsolateStatus;
import javax.isolate.Link;
import javax.isolate.LinkMessage;
import javax.isolate.StreamBindings;
-
import org.jnode.shell.CommandRunner;
import org.jnode.shell.CommandThread;
import org.jnode.shell.ShellInvocationException;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-10-10 13:01:43
|
Revision: 4618
http://jnode.svn.sourceforge.net/jnode/?rev=4618&view=rev
Author: crawley
Date: 2008-10-10 13:01:27 +0000 (Fri, 10 Oct 2008)
Log Message:
-----------
Implemented a new 'bindkeys' command. At the moment it just lists
the current KR key bindings.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java
trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/TextConsole.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java
trunk/shell/descriptors/org.jnode.shell.command.xml
Added Paths:
-----------
trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -4,7 +4,10 @@
import java.io.Reader;
import java.io.Writer;
+import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
+
+
/**
* This virtual console class operates on the console that has the current focus.
* The {@link #getOut()} and {@link #getErr()} return Writers that track changes
@@ -91,12 +94,12 @@
}
@Override
- public KeyEventBindings getKeyEventBindings() {
+ public ConsoleKeyEventBindings getKeyEventBindings() {
throw new UnsupportedOperationException();
}
@Override
- public void setKeyEventBindings(KeyEventBindings bindings) {
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
throw new UnsupportedOperationException();
}
Modified: trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -22,6 +22,7 @@
import java.awt.event.KeyEvent;
import java.util.HashMap;
+import java.util.Set;
import org.jnode.driver.input.KeyboardEvent;
@@ -31,30 +32,30 @@
*
* @author cr...@jn...
*/
-public class KeyEventBindings {
+public abstract class KeyEventBindings<T extends Enum<?>> {
- private final int defaultCharAction;
- private final int defaultVKAction;
- private CodeMap charMap;
- private CodeMap vkMap;
+ private final T defaultCharAction;
+ private final T defaultVKAction;
+ private CodeMap<T> charMap;
+ private CodeMap<T> vkMap;
/**
* Create empty bindings.
* @param defaultCharAction the default action for a character-valued event
* @param defaultVKAction the default action for a VK-valued event.
*/
- public KeyEventBindings(int defaultCharAction, int defaultVKAction) {
+ public KeyEventBindings(T defaultCharAction, T defaultVKAction) {
this.defaultCharAction = defaultCharAction;
this.defaultVKAction = defaultVKAction;
- this.charMap = new CodeMap(defaultCharAction);
- this.vkMap = new CodeMap(defaultVKAction);
+ this.charMap = new CodeMap<T>(defaultCharAction);
+ this.vkMap = new CodeMap<T>(defaultVKAction);
}
/**
* Create a copy of an existing KeyEventBindings object.
* @param bindings the bindings to be copied.
*/
- public KeyEventBindings(KeyEventBindings bindings) {
+ public KeyEventBindings(KeyEventBindings<T> bindings) {
this.defaultCharAction = bindings.defaultCharAction;
this.defaultVKAction = bindings.defaultVKAction;
this.charMap = new CodeMap(bindings.charMap);
@@ -75,7 +76,7 @@
* @param ch the character
* @return the corresponding action.
*/
- public int getKeyboardEventAction(KeyboardEvent event) {
+ public T getKeyboardEventAction(KeyboardEvent event) {
char ch = event.getKeyChar();
if (ch == KeyEvent.CHAR_UNDEFINED) {
return getVKAction(event.getKeyCode(), event.getModifiers());
@@ -90,7 +91,7 @@
* @param ch the character
* @return the corresponding action.
*/
- public int getCharAction(char ch) {
+ public T getCharAction(char ch) {
return charMap.get(ch);
}
@@ -101,7 +102,7 @@
* @param modifiers the modifier set
* @return the corresponding action.
*/
- public int getVKAction(int vk, int modifiers) {
+ public T getVKAction(int vk, int modifiers) {
checkVK(vk, modifiers);
return vkMap.get(vk | (modifiers << 16));
}
@@ -114,6 +115,10 @@
throw new IllegalArgumentException("modifiers range error");
}
}
+
+ public T getVKAction(VirtualKey vk) {
+ return vkMap.get(vk.value);
+ }
/**
* Set the action for a given character
@@ -121,7 +126,7 @@
* @param ch the character
* @param action the action
*/
- public void setCharAction(char ch, int action) {
+ public void setCharAction(char ch, T action) {
charMap.put(ch, action);
}
@@ -131,7 +136,7 @@
* @param vk the virtual key code
* @param action the action
*/
- public void setVKAction(int vk, int action) {
+ public void setVKAction(int vk, T action) {
checkVK(vk, 0);
vkMap.put(vk, action);
}
@@ -143,7 +148,7 @@
* @param modifiers the modifier set
* @param action the action
*/
- public void setVKAction(int vk, int modifiers, int action) {
+ public void setVKAction(int vk, int modifiers, T action) {
checkVK(vk, modifiers);
vkMap.put(vk | (modifiers << 16), action);
}
@@ -155,7 +160,7 @@
* @param chHi the last character in the range
* @param action the action
*/
- public void setCharAction(char chLo, char chHi, int action) {
+ public void setCharAction(char chLo, char chHi, T action) {
charMap.put(chLo, chHi, action);
}
@@ -167,7 +172,7 @@
* @param modifiers the modifier set
* @param action the action
*/
- public void setVKAction(int vkLo, int vkHi, int modifiers, int action) {
+ public void setVKAction(int vkLo, int vkHi, int modifiers, T action) {
checkVK(vkLo, modifiers);
checkVK(vkHi, modifiers);
if (modifiers == 0) {
@@ -181,27 +186,47 @@
}
}
}
+
+ public char[] getBoundChars() {
+ Set<Integer> charSet = charMap.getKeys();
+ char[] res = new char[charSet.size()];
+ int i = 0;
+ for (int ch : charSet) {
+ res[i++] = (char) ch;
+ }
+ return res;
+ }
+ public VirtualKey[] getBoundVKs() {
+ Set<Integer> vkSet = vkMap.getKeys();
+ VirtualKey[] res = new VirtualKey[vkSet.size()];
+ int i = 0;
+ for (int vk : vkSet) {
+ res[i++] = new VirtualKey(vk);
+ }
+ return res;
+ }
+
/**
* This class implements a sparse representation of an int to int
* mapping using a HashMap and a default value.
*/
- private static class CodeMap {
- private final HashMap<Integer, Integer> map;
- private final int defaultValue;
+ private static class CodeMap<T extends Enum<?>> {
+ private final HashMap<Integer, T> map;
+ private final T defaultValue;
- public CodeMap(int defaultValue) {
+ public CodeMap(T defaultValue) {
this.defaultValue = defaultValue;
- this.map = new HashMap<Integer, Integer>();
+ this.map = new HashMap<Integer, T>();
}
- public CodeMap(CodeMap codeMap) {
+ public CodeMap(CodeMap<T> codeMap) {
this.defaultValue = codeMap.defaultValue;
- this.map = new HashMap<Integer, Integer>(codeMap.map);
+ this.map = new HashMap<Integer, T>(codeMap.map);
}
- public int get(int key) {
- Integer value = this.map.get(key);
+ public T get(int key) {
+ T value = this.map.get(key);
if (value != null) {
return value;
} else {
@@ -209,7 +234,7 @@
}
}
- public void put(int key, int value) {
+ public void put(int key, T value) {
if (value == this.defaultValue) {
this.map.remove(key);
} else {
@@ -217,7 +242,7 @@
}
}
- public void put(int keyLo, int keyHi, int value) {
+ public void put(int keyLo, int keyHi, T value) {
if (keyLo > keyHi) {
throw new IllegalArgumentException("keyLo > keyHi");
}
@@ -231,5 +256,9 @@
}
}
}
+
+ public Set<Integer> getKeys() {
+ return map.keySet();
+ }
}
}
Modified: trunk/core/src/driver/org/jnode/driver/console/TextConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/TextConsole.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/TextConsole.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -24,7 +24,10 @@
import java.io.Reader;
import java.io.Writer;
+import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
+
+
/**
* @author Ewout Prangsma (ep...@us...)
* @author Levente S\u00e1ntha (ls...@us...)
@@ -210,13 +213,13 @@
*
* @return a copy of the current bindings.
*/
- public KeyEventBindings getKeyEventBindings();
+ public ConsoleKeyEventBindings getKeyEventBindings();
/**
* Set the console's key event bindings.
*
* @param bindings the new bindings.
*/
- public void setKeyEventBindings(KeyEventBindings bindings);
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings);
}
Added: trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -0,0 +1,64 @@
+/*
+ * $Id: TextConsole.java 4613 2008-10-08 13:56:25Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.jnode.driver.console;
+
+/**
+ * This class is used to represent a VK code / modifier pair in the context of
+ * the KeyEventBindings.
+ *
+ * @author cr...@jn...
+ */
+public class VirtualKey {
+
+ public final int value;
+
+ public VirtualKey(int value) {
+ this.value = value;
+ }
+
+ public int getVKCode() {
+ return value & 0xffff;
+ }
+
+ public int getModifiers() {
+ return value >>> 16;
+ }
+
+ @Override
+ public int hashCode() {
+ return value;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || this.getClass() != obj.getClass()) {
+ return false;
+ }
+ final VirtualKey other = (VirtualKey) obj;
+ if (value != other.value) {
+ return false;
+ }
+ return true;
+ }
+}
\ No newline at end of file
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -24,143 +24,52 @@
import org.jnode.driver.console.KeyEventBindings;
+
/**
* KeyEventBinding class for the Console system.
*
* @author cr...@jn...
*/
-public class ConsoleKeyEventBindings extends KeyEventBindings {
-
- /**
- * This KR code causes the event's character (or in some circumstances its
- * VK code) to be inserted into to the input buffer at the position of the
- * cursor. The cursor is then advanced to after the inserted character.
- */
- public static final byte KR_INSERT = 0;
+public class ConsoleKeyEventBindings extends KeyEventBindings<KeyboardReaderAction> {
/**
- * This KR code causes the event to be consumed with no other action.
- */
- public static final byte KR_CONSUME = 1;
-
- /**
- * This KR code causes the event to be ignored without consuming it.
- * (This KR code may go away.)
- */
- public static final byte KR_IGNORE = 2;
-
- /**
- * This KR code causes the input buffer to be terminated with
- * a '\n' and send to the input stream for reading.
- */
- public static final byte KR_ENTER = 3;
-
- /**
- * This KR code causes the input buffer to be cleared. All characters
- * are removed and the input cursor is set to the start of the buffer.
- */
- public static final byte KR_KILL_LINE = 4;
-
- /**
- * This KR code causes the input completion to be performed.
- */
- public static final byte KR_COMPLETE = 5;
-
- /**
- * This KR code causes the input line to be refreshed to the
- * console.
- */
- public static final byte KR_REDRAW = 6;
-
- /**
- * This KR code denotes a 'soft eof' marker.
- */
- public static final byte KR_SOFT_EOF = 7;
-
- /**
- * This KR code causes the input cursor to be moved one
- * character to the left. If the cursor is already at the start of the
- * input buffer, it is not moved. No characters are added or removed.
- */
- public static final byte KR_CURSOR_LEFT = 8;
-
- /**
- * This KR code causes the input cursor to be moved one
- * character to the right. If the cursor is already at the end of the
- * input buffer, it is not moved. No characters are added or removed.
- */
- public static final byte KR_CURSOR_RIGHT = 9;
-
- /**
- * This KR code causes the input cursor to be moved to the before the
- * first character in the input buffer. No characters are added or removed.
- */
- public static final byte KR_CURSOR_TO_START = 10;
-
- /**
- * This KR code causes the input buffer cursor to be moved to after the
- * last character in the input buffer. No characters are added or removed.
- */
- public static final byte KR_CURSOR_TO_END = 11;
-
- /**
- * This KR code causes one character to the left of the input cursor to be
- * deleted from the input buffer.
- */
- public static final byte KR_DELETE_BEFORE = 12;
-
- /**
- * This KR code causes one character to the right of the input cursor to be
- * deleted from the input buffer.
- */
- public static final byte KR_DELETE_AFTER = 13;
-
- /**
- * This KR code causes all characters to the right of the input cursor to be
- * deleted from the input buffer.
- */
- public static final byte KR_DELETE_TO_END = 14;
-
- /**
- * This KR code causes the previous history line to be selected.
- */
- public static final byte KR_HISTORY_UP = 15;
-
- /**
- * This KR code causes the next history line to be selected.
- */
- public static final byte KR_HISTORY_DOWN = 16;
-
- /**
* Create empty bindings. The default action for characters is to insert
* the character. The default action for virtual keys is to ignore the key.
*/
public ConsoleKeyEventBindings() {
- super(KR_INSERT, KR_IGNORE);
+ super(KeyboardReaderAction.KR_INSERT, KeyboardReaderAction.KR_IGNORE);
}
/**
- * Create KeyEventBindings initialized to the hard-wired defaults.
+ * Create a copy of an existing ConsoleKeyEventBindings object.
+ * @param bindings the bindings to be copied.
+ */
+ public ConsoleKeyEventBindings(ConsoleKeyEventBindings bindings) {
+ super(bindings);
+ }
+
+ /**
+ * Create a ConsoleKeyEventBindings object initialized to the hard-wired defaults.
* @return the default bindings.
*/
public static ConsoleKeyEventBindings createDefault() {
ConsoleKeyEventBindings res = new ConsoleKeyEventBindings();
- res.setVKAction(KeyEvent.VK_BACK_SPACE, KR_DELETE_BEFORE);
- res.setCharAction('\b', KR_DELETE_BEFORE);
- res.setVKAction(KeyEvent.VK_ENTER, KR_ENTER);
- res.setCharAction('\n', KR_ENTER);
- res.setVKAction(KeyEvent.VK_TAB, KR_COMPLETE);
- res.setCharAction('\t', KR_COMPLETE);
- res.setCharAction('\004', KR_SOFT_EOF);
- res.setCharAction('\014', KR_KILL_LINE);
- res.setVKAction(KeyEvent.VK_UP, KR_HISTORY_UP);
- res.setVKAction(KeyEvent.VK_DOWN, KR_HISTORY_DOWN);
- res.setVKAction(KeyEvent.VK_LEFT, KR_CURSOR_LEFT);
- res.setVKAction(KeyEvent.VK_RIGHT, KR_CURSOR_RIGHT);
- res.setVKAction(KeyEvent.VK_HOME, KR_CURSOR_TO_START);
- res.setVKAction(KeyEvent.VK_END, KR_CURSOR_TO_END);
- res.setCharAction('\177', KR_DELETE_AFTER);
- res.setVKAction(KeyEvent.VK_DELETE, KR_DELETE_AFTER);
+ res.setVKAction(KeyEvent.VK_BACK_SPACE, KeyboardReaderAction.KR_DELETE_BEFORE);
+ res.setCharAction('\b', KeyboardReaderAction.KR_DELETE_BEFORE);
+ res.setVKAction(KeyEvent.VK_ENTER, KeyboardReaderAction.KR_ENTER);
+ res.setCharAction('\n', KeyboardReaderAction.KR_ENTER);
+ res.setVKAction(KeyEvent.VK_TAB, KeyboardReaderAction.KR_COMPLETE);
+ res.setCharAction('\t', KeyboardReaderAction.KR_COMPLETE);
+ res.setCharAction('\004', KeyboardReaderAction.KR_SOFT_EOF);
+ res.setCharAction('\014', KeyboardReaderAction.KR_KILL_LINE);
+ res.setVKAction(KeyEvent.VK_UP, KeyboardReaderAction.KR_HISTORY_UP);
+ res.setVKAction(KeyEvent.VK_DOWN, KeyboardReaderAction.KR_HISTORY_DOWN);
+ res.setVKAction(KeyEvent.VK_LEFT, KeyboardReaderAction.KR_CURSOR_LEFT);
+ res.setVKAction(KeyEvent.VK_RIGHT, KeyboardReaderAction.KR_CURSOR_RIGHT);
+ res.setVKAction(KeyEvent.VK_HOME, KeyboardReaderAction.KR_CURSOR_TO_START);
+ res.setVKAction(KeyEvent.VK_END, KeyboardReaderAction.KR_CURSOR_TO_END);
+ res.setCharAction('\177', KeyboardReaderAction.KR_DELETE_AFTER);
+ res.setVKAction(KeyEvent.VK_DELETE, KeyboardReaderAction.KR_DELETE_AFTER);
return res;
}
}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -1,27 +1,11 @@
package org.jnode.driver.console.textscreen;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_COMPLETE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CONSUME;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_LEFT;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_RIGHT;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_TO_END;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_TO_START;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_DELETE_AFTER;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_DELETE_BEFORE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_ENTER;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_HISTORY_UP;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_IGNORE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_INSERT;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_KILL_LINE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_SOFT_EOF;
-
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import org.jnode.driver.console.InputCompleter;
-import org.jnode.driver.console.KeyEventBindings;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.input.KeyboardEvent;
import org.jnode.system.event.FocusEvent;
@@ -80,7 +64,7 @@
private InputCompleter completer;
private final Writer out;
- private KeyEventBindings bindings = ConsoleKeyEventBindings.createDefault();
+ private ConsoleKeyEventBindings bindings = ConsoleKeyEventBindings.createDefault();
private String currentPrompt;
@@ -135,8 +119,8 @@
*
* @return a copy of the current bindings.
*/
- public KeyEventBindings getKeyEventBindings() {
- return new KeyEventBindings(bindings);
+ public ConsoleKeyEventBindings getKeyEventBindings() {
+ return new ConsoleKeyEventBindings(bindings);
}
/**
@@ -144,8 +128,8 @@
*
* @param bindings the new bindings.
*/
- public void setKeyEventBindings(KeyEventBindings bindings) {
- this.bindings = new KeyEventBindings(bindings);
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
+ this.bindings = new ConsoleKeyEventBindings(bindings);
}
@Override
@@ -169,7 +153,7 @@
private boolean processEvent() throws IOException {
KeyboardEvent event = keyboardHandler.getEvent();
if (!event.isConsumed()) {
- int action = bindings.getKeyboardEventAction(event);
+ KeyboardReaderAction action = bindings.getKeyboardEventAction(event);
boolean breakChar = false;
boolean consume = true;
switch (action) {
Added: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -0,0 +1,113 @@
+package org.jnode.driver.console.textscreen;
+
+public enum KeyboardReaderAction {
+
+ /**
+ * This action causes the event's character (or in some circumstances its
+ * VK code) to be inserted into to the input buffer at the position of the
+ * cursor. The cursor is then advanced to after the inserted character.
+ */
+ KR_INSERT,
+
+ /**
+ * This action causes the event to be consumed with no other action.
+ */
+ KR_CONSUME,
+
+ /**
+ * This action causes the event to be ignored without consuming it.
+ * (This action may go away.)
+ */
+ KR_IGNORE,
+
+ /**
+ * This action causes the input buffer to be terminated with
+ * a '\n' and send to the input stream for reading.
+ */
+ KR_ENTER,
+
+ /**
+ * This action causes the input buffer to be cleared. All characters
+ * are removed and the input cursor is set to the start of the buffer.
+ */
+ KR_KILL_LINE,
+
+ /**
+ * This action causes the input completion to be performed.
+ */
+ KR_COMPLETE,
+
+ /**
+ * This action causes the input line to be refreshed to the
+ * console.
+ */
+ KR_REDRAW,
+
+ /**
+ * This action denotes a 'soft eof' marker.
+ */
+ KR_SOFT_EOF,
+
+ /**
+ * This action causes the input cursor to be moved one
+ * character to the left. If the cursor is already at the start of the
+ * input buffer, it is not moved. No characters are added or removed.
+ */
+ KR_CURSOR_LEFT,
+
+ /**
+ * This action causes the input cursor to be moved one
+ * character to the right. If the cursor is already at the end of the
+ * input buffer, it is not moved. No characters are added or removed.
+ */
+ KR_CURSOR_RIGHT,
+
+ /**
+ * This action causes the input cursor to be moved to the before the
+ * first character in the input buffer. No characters are added or removed.
+ */
+ KR_CURSOR_TO_START,
+
+ /**
+ * This action causes the input buffer cursor to be moved to after the
+ * last character in the input buffer. No characters are added or removed.
+ */
+ KR_CURSOR_TO_END,
+
+ /**
+ * This action causes one character to the left of the input cursor to be
+ * deleted from the input buffer.
+ */
+ KR_DELETE_BEFORE,
+
+ /**
+ * This action causes one character to the right of the input cursor to be
+ * deleted from the input buffer.
+ */
+ KR_DELETE_AFTER,
+
+ /**
+ * This action causes all characters to the right of the input cursor to be
+ * deleted from the input buffer.
+ */
+ KR_DELETE_TO_END,
+
+ /**
+ * This action causes the previous history line to be selected.
+ */
+ KR_HISTORY_UP,
+
+ /**
+ * This action causes the next history line to be selected.
+ */
+ KR_HISTORY_DOWN;
+
+
+ public static KeyboardReaderAction getDefaultCharAction() {
+ return KR_INSERT;
+ }
+
+ public static KeyboardReaderAction getDefaultVKAction() {
+ return KR_IGNORE;
+ }
+}
\ No newline at end of file
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.SortedSet;
+
import org.jnode.driver.console.CompletionInfo;
import org.jnode.driver.console.InputCompleter;
import org.jnode.driver.console.ScrollableTextConsole;
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -341,7 +341,7 @@
}
@Override
- public KeyEventBindings getKeyEventBindings() {
+ public ConsoleKeyEventBindings getKeyEventBindings() {
if (in instanceof KeyboardReader) {
return ((KeyboardReader) in).getKeyEventBindings();
} else {
@@ -350,7 +350,7 @@
}
@Override
- public void setKeyEventBindings(KeyEventBindings bindings) {
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
if (in instanceof KeyboardReader) {
((KeyboardReader) in).setKeyEventBindings(bindings);
} else {
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -22,7 +22,9 @@
package org.jnode.driver.console.textscreen;
import java.io.PrintStream;
+
import javax.naming.NamingException;
+
import org.jnode.driver.console.ConsoleException;
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.console.TextConsole;
Modified: trunk/shell/descriptors/org.jnode.shell.command.xml
===================================================================
--- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-10 13:01:27 UTC (rev 4618)
@@ -19,6 +19,7 @@
<extension point="org.jnode.shell.aliases">
<alias name="alias" class="org.jnode.shell.command.AliasCommand"/>
+ <alias name="bindkeys" class="org.jnode.shell.command.BindKeysCommand"/>
<alias name="class" class="org.jnode.shell.command.ClassCommand"/>
<alias name="classpath" class="org.jnode.shell.command.ClasspathCommand" internal="yes"/>
<alias name="compile" class="org.jnode.shell.command.CompileCommand"/>
@@ -54,6 +55,8 @@
<argument argLabel="className"/...
[truncated message content] |
|
From: <cr...@us...> - 2008-10-11 03:45:07
|
Revision: 4619
http://jnode.svn.sourceforge.net/jnode/?rev=4619&view=rev
Author: crawley
Date: 2008-10-11 03:44:57 +0000 (Sat, 11 Oct 2008)
Log Message:
-----------
Implemented some more 'bindkeys' functionality
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
trunk/shell/descriptors/org.jnode.shell.command.xml
trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-10 13:01:27 UTC (rev 4618)
+++ trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-11 03:44:57 UTC (rev 4619)
@@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Set;
+import org.jnode.driver.console.textscreen.KeyboardReaderAction;
import org.jnode.driver.input.KeyboardEvent;
/**
@@ -131,14 +132,13 @@
}
/**
- * Set the action for a given virtual key code and no modifiers
+ * Unset the action for a given character.
+ * This is equivalent to setting the action to the default action.
*
- * @param vk the virtual key code
- * @param action the action
+ * @param ch the character
*/
- public void setVKAction(int vk, T action) {
- checkVK(vk, 0);
- vkMap.put(vk, action);
+ public void unsetCharAction(char ch) {
+ charMap.put(ch, defaultCharAction);
}
/**
@@ -154,6 +154,37 @@
}
/**
+ * Unset the action for a given virtual key code and modifier set.
+ * This is equivalent to setting the action to the default action.
+ *
+ * @param vk the virtual key code
+ * @param modifiers the modifier set
+ */
+ public void unsetVKAction(int vk, int modifiers) {
+ setVKAction(vk, modifiers, defaultVKAction);
+ }
+
+ /**
+ * Set the action for a given VirtualKey
+ *
+ * @param vk the VirtualKey
+ * @param action the action
+ */
+ public void setVKAction(VirtualKey vk, T action) {
+ setVKAction(vk.getVKCode(), vk.getModifiers(), action);
+ }
+
+ /**
+ * Unset the action for a given VirtualKey.
+ * This is equivalent to setting the action to the default action.
+ *
+ * @param vk the VirtualKey
+ */
+ public void unsetVKAction(VirtualKey vk) {
+ setVKAction(vk, defaultVKAction);
+ }
+
+ /**
* Set the action for a given range of characters
*
* @param chLo the first character in the range
@@ -187,6 +218,10 @@
}
}
+ /**
+ * Get all characters that are currently bound to an action.
+ * @return the bound characters.
+ */
public char[] getBoundChars() {
Set<Integer> charSet = charMap.getKeys();
char[] res = new char[charSet.size()];
@@ -197,6 +232,10 @@
return res;
}
+ /**
+ * Get all virtual keys that are currently bound to an action.
+ * @return the bound virtual keys.
+ */
public VirtualKey[] getBoundVKs() {
Set<Integer> vkSet = vkMap.getKeys();
VirtualKey[] res = new VirtualKey[vkSet.size()];
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-10 13:01:27 UTC (rev 4618)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-11 03:44:57 UTC (rev 4619)
@@ -54,22 +54,22 @@
*/
public static ConsoleKeyEventBindings createDefault() {
ConsoleKeyEventBindings res = new ConsoleKeyEventBindings();
- res.setVKAction(KeyEvent.VK_BACK_SPACE, KeyboardReaderAction.KR_DELETE_BEFORE);
+ res.setVKAction(KeyEvent.VK_BACK_SPACE, 0, KeyboardReaderAction.KR_DELETE_BEFORE);
res.setCharAction('\b', KeyboardReaderAction.KR_DELETE_BEFORE);
- res.setVKAction(KeyEvent.VK_ENTER, KeyboardReaderAction.KR_ENTER);
+ res.setVKAction(KeyEvent.VK_ENTER, 0, KeyboardReaderAction.KR_ENTER);
res.setCharAction('\n', KeyboardReaderAction.KR_ENTER);
- res.setVKAction(KeyEvent.VK_TAB, KeyboardReaderAction.KR_COMPLETE);
+ res.setVKAction(KeyEvent.VK_TAB, 0, KeyboardReaderAction.KR_COMPLETE);
res.setCharAction('\t', KeyboardReaderAction.KR_COMPLETE);
res.setCharAction('\004', KeyboardReaderAction.KR_SOFT_EOF);
res.setCharAction('\014', KeyboardReaderAction.KR_KILL_LINE);
- res.setVKAction(KeyEvent.VK_UP, KeyboardReaderAction.KR_HISTORY_UP);
- res.setVKAction(KeyEvent.VK_DOWN, KeyboardReaderAction.KR_HISTORY_DOWN);
- res.setVKAction(KeyEvent.VK_LEFT, KeyboardReaderAction.KR_CURSOR_LEFT);
- res.setVKAction(KeyEvent.VK_RIGHT, KeyboardReaderAction.KR_CURSOR_RIGHT);
- res.setVKAction(KeyEvent.VK_HOME, KeyboardReaderAction.KR_CURSOR_TO_START);
- res.setVKAction(KeyEvent.VK_END, KeyboardReaderAction.KR_CURSOR_TO_END);
+ res.setVKAction(KeyEvent.VK_UP, 0, KeyboardReaderAction.KR_HISTORY_UP);
+ res.setVKAction(KeyEvent.VK_DOWN, 0, KeyboardReaderAction.KR_HISTORY_DOWN);
+ res.setVKAction(KeyEvent.VK_LEFT, 0, KeyboardReaderAction.KR_CURSOR_LEFT);
+ res.setVKAction(KeyEvent.VK_RIGHT, 0, KeyboardReaderAction.KR_CURSOR_RIGHT);
+ res.setVKAction(KeyEvent.VK_HOME, 0, KeyboardReaderAction.KR_CURSOR_TO_START);
+ res.setVKAction(KeyEvent.VK_END, 0, KeyboardReaderAction.KR_CURSOR_TO_END);
res.setCharAction('\177', KeyboardReaderAction.KR_DELETE_AFTER);
- res.setVKAction(KeyEvent.VK_DELETE, KeyboardReaderAction.KR_DELETE_AFTER);
+ res.setVKAction(KeyEvent.VK_DELETE, 0, KeyboardReaderAction.KR_DELETE_AFTER);
return res;
}
}
Modified: trunk/shell/descriptors/org.jnode.shell.command.xml
===================================================================
--- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-10 13:01:27 UTC (rev 4618)
+++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-11 03:44:57 UTC (rev 4619)
@@ -55,7 +55,13 @@
<argument argLabel="className"/>
</sequence>
</syntax>
- <syntax alias="bindkeys" description="Show the key bindings">
+ <syntax alias="bindkeys">
+ <empty description="Show the key bindings"/>
+ <option argLabel="reset" longName="reset" description="Reset the key bindings to the default settings"/>
+ <sequence description="Remove key bindings">
+ <option argLabel="remove" shortName="r" longName="remove"/>
+ <argument argLabel="action"/>
+ </sequence>
</syntax>
<syntax alias="class" description="Show details of a Java class">
<argument argLabel="className"/>
Modified: trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-10 13:01:27 UTC (rev 4618)
+++ trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-11 03:44:57 UTC (rev 4619)
@@ -20,8 +20,6 @@
*/
package org.jnode.shell.command;
-import static java.awt.event.KeyEvent.*;
-
import java.awt.event.KeyEvent;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -30,12 +28,17 @@
import java.util.Map;
import org.jnode.driver.console.Console;
+import org.jnode.driver.console.KeyEventBindings;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.console.VirtualKey;
import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
import org.jnode.driver.console.textscreen.KeyboardReaderAction;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.ShellUtils;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.EnumArgument;
+import org.jnode.shell.syntax.FlagArgument;
+import org.jnode.shell.syntax.StringArgument;
/**
* This command allows the user to examine and change JNode's key bindings.
@@ -43,11 +46,51 @@
* @author cr...@jn...
*/
public class BindKeysCommand extends AbstractCommand {
+
+ private static final String[] ASCII_NAMES = new String[] {
+ "NUL", "SOH", "STC", "ETX", "EOT", "ENQ", "ACK", "BEL",
+ "BS", "HT", "NL", "VT", "FF", "CR", "SO", "SI",
+ "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
+ "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
+ };
+
+ private static class ActionArgument extends EnumArgument<KeyboardReaderAction> {
+ public ActionArgument(String label, int flags, String description) {
+ super(label, flags, KeyboardReaderAction.class, description);
+ }
+
+ @Override
+ protected String argumentKind() {
+ return "keyboard reader action";
+ }
+ }
+
+ private final FlagArgument FLAG_RESET =
+ new FlagArgument("reset", Argument.OPTIONAL, "reset the bindings to the default values");
+
+ private final FlagArgument FLAG_ADD =
+ new FlagArgument("add", Argument.OPTIONAL, "add bindings");
+
+ private final FlagArgument FLAG_REMOVE =
+ new FlagArgument("remove", Argument.OPTIONAL, "remove bindings");
+
+ private final ActionArgument ARG_ACTION =
+ new ActionArgument("action", Argument.OPTIONAL, "an keyboard reader action");
+
+ private final StringArgument ARG_VK_NAME =
+ new StringArgument("vkName", Argument.OPTIONAL + Argument.MULTIPLE, "a virtual key specification");
+
+ private final StringArgument ARG_CHAR_NAME =
+ new StringArgument("charName", Argument.OPTIONAL + Argument.MULTIPLE, "a character");
+
private PrintWriter out;
private PrintWriter err;
+
public BindKeysCommand() {
super("display or change the keyboard bindings");
+ registerArguments(FLAG_RESET, FLAG_ADD, FLAG_REMOVE,
+ ARG_ACTION, ARG_VK_NAME, ARG_CHAR_NAME);
}
@Override
@@ -56,43 +99,106 @@
err = getError().getPrintWriter();
Console console = ShellUtils.getCurrentShell().getConsole();
if (!(console instanceof TextConsole)) {
- err.println("The current console is not a TextConsole");
+ err.println("The current console is not a TextConsole.");
}
TextConsole textConsole = (TextConsole) console;
- displayBindings(textConsole);
+ if (FLAG_RESET.isSet()) {
+ resetBindings(textConsole);
+ } else if (FLAG_ADD.isSet()) {
+ addBindings(textConsole);
+ } else if (FLAG_REMOVE.isSet()) {
+ removeBindings(textConsole);
+ } else {
+ displayBindings(textConsole);
+ }
}
- private void displayBindings(TextConsole console) {
+ /**
+ * Remove bindings for an action.
+ *
+ * @param console the console whose bindings are to be changed
+ */
+ private void removeBindings(TextConsole console) {
ConsoleKeyEventBindings bindings = console.getKeyEventBindings();
+ // This throws an unchecked exception if the action is not supplied. It signals
+ // a bug in the command syntax and should be allowed to propagate to the shell.
+ KeyboardReaderAction action = ARG_ACTION.getValue();
- // Build a map from actions to the characters that map to them.
- char[] boundChars = bindings.getBoundChars();
- Map<KeyboardReaderAction, List<Character>> charMap =
- new HashMap<KeyboardReaderAction, List<Character>>();
- for (char ch : boundChars) {
- KeyboardReaderAction action = bindings.getCharAction(ch);
- List<Character> list = charMap.get(action);
- if (list == null) {
- list = new ArrayList<Character>();
- charMap.put(action, list);
+ if (ARG_CHAR_NAME.isSet() || ARG_VK_NAME.isSet()) {
+ // If character or virtual key names were supplied, remove only those bindings.
+ if (ARG_CHAR_NAME.isSet()) {
+ for (String charName : ARG_CHAR_NAME.getValues()) {
+ char ch = getCharacter(charName);
+ if (ch != KeyEvent.CHAR_UNDEFINED) {
+ bindings.unsetCharAction(ch);
+ } else {
+ err.println("Cannot translate character name '" + charName + "'");
+ exit(1);
+ }
+ }
+ }
+ if (ARG_VK_NAME.isSet()) {
+ for (String vkName : ARG_VK_NAME.getValues()) {
+ VirtualKey vk = getVirtualKey(vkName);
+ if (vk != null) {
+ bindings.unsetVKAction(vk);
+ } else {
+ err.println("Cannot translate virtual key name '" + vkName + "'");
+ exit(1);
+ }
+ }
+ }
+ } else {
+ // Otherwise remove all bindings for the action.
+ int count = 0;
+ List<Character> chars = buildCharMap(bindings).get(action);
+ if (chars != null) {
+ for (char ch : chars) {
+ bindings.unsetCharAction(ch);
+ count++;
+ }
}
- list.add(ch);
- }
-
- // Build a map from actions to the virtual keys that map to them.
- VirtualKey[] boundKeys = bindings.getBoundVKs();
- Map<KeyboardReaderAction, List<VirtualKey>> vkMap =
- new HashMap<KeyboardReaderAction, List<VirtualKey>>();
- for (VirtualKey vk : boundKeys) {
- KeyboardReaderAction action = bindings.getVKAction(vk);
- List<VirtualKey> list = vkMap.get(action);
- if (list == null) {
- list = new ArrayList<VirtualKey>();
- vkMap.put(action, list);
+ List<VirtualKey> vks = buildVKMap(bindings).get(action);
+ if (vks != null) {
+ for (VirtualKey vk : vks) {
+ bindings.unsetVKAction(vk);
+ count++;
+ }
}
- list.add(vk);
+ if (count == 0) {
+ err.println("There are no bindings for action '" + action + "'");
+ exit(1);
+ }
}
+ console.setKeyEventBindings(bindings);
+ out.println("Updated the current console's key bindings for action '" + action + "'.");
+ }
+
+ private char getCharacter(String charName) {
+ // TODO Auto-generated method stub
+ return KeyEvent.CHAR_UNDEFINED;
+ }
+
+ private VirtualKey getVirtualKey(String vkName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private void addBindings(TextConsole console) {
+ ConsoleKeyEventBindings bindings = console.getKeyEventBindings();
+ }
+
+ private void resetBindings(TextConsole console) {
+ console.setKeyEventBindings(ConsoleKeyEventBindings.createDefault());
+ out.println("Reset the current console's key bindings.");
+ }
+
+ private void displayBindings(TextConsole console) {
+ ConsoleKeyEventBindings bindings = console.getKeyEventBindings();
+ Map<KeyboardReaderAction, List<Character>> charMap = buildCharMap(bindings);
+ Map<KeyboardReaderAction, List<VirtualKey>> vkMap = buildVKMap(bindings);
+
for (KeyboardReaderAction action : KeyboardReaderAction.values()) {
List<Character> chars = charMap.get(action);
List<VirtualKey> vks = vkMap.get(action);
@@ -133,6 +239,50 @@
}
}
+ /**
+ * Build a map from actions to the virtual keys that map to them.
+ * @param bindings
+ * @return the map
+ */
+ private Map<KeyboardReaderAction, List<VirtualKey>> buildVKMap(
+ KeyEventBindings<KeyboardReaderAction> bindings) {
+ VirtualKey[] boundKeys = bindings.getBoundVKs();
+ Map<KeyboardReaderAction, List<VirtualKey>> vkMap =
+ new HashMap<KeyboardReaderAction, List<VirtualKey>>();
+ for (VirtualKey vk : boundKeys) {
+ KeyboardReaderAction action = bindings.getVKAction(vk);
+ List<VirtualKey> list = vkMap.get(action);
+ if (list == null) {
+ list = new ArrayList<VirtualKey>();
+ vkMap.put(action, list);
+ }
+ list.add(vk);
+ }
+ return vkMap;
+ }
+
+ /**
+ * Build a map from actions to the characters that map to them.
+ * @param bindings
+ * @return the map.
+ */
+ private Map<KeyboardReaderAction, List<Character>> buildCharMap(
+ KeyEventBindings<KeyboardReaderAction> bindings) {
+ char[] boundChars = bindings.getBoundChars();
+ Map<KeyboardReaderAction, List<Character>> charMap =
+ new HashMap<KeyboardReaderAction, List<Character>>();
+ for (char ch : boundChars) {
+ KeyboardReaderAction action = bindings.getCharAction(ch);
+ List<Character> list = charMap.get(action);
+ if (list == null) {
+ list = new ArrayList<Character>();
+ charMap.put(action, list);
+ }
+ list.add(ch);
+ }
+ return charMap;
+ }
+
private String describe(KeyboardReaderAction action) {
return action.toString();
}
@@ -140,13 +290,6 @@
private KeyboardReaderAction getAction(String name) {
return KeyboardReaderAction.valueOf(name);
}
-
- private static final String[] ASCII_NAMES = new String[] {
- "NUL", "SOH", "STC", "ETX", "EOT", "ENQ", "ACK", "BEL",
- "BS", "HT", "NL", "VT", "FF", "CR", "SO", "SI",
- "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
- "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
- };
private String describe(char ch) {
StringBuilder sb = new StringBuilder();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-10-12 02:50:28
|
Revision: 4622
http://jnode.svn.sourceforge.net/jnode/?rev=4622&view=rev
Author: crawley
Date: 2008-10-12 02:50:20 +0000 (Sun, 12 Oct 2008)
Log Message:
-----------
Added support for adding and removing bindings. The bindkeys command can
now list and reset bindings and can add and remove both VK and character-based
bindings ... with a gotcha which I will describe on issue #2721.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
trunk/shell/descriptors/org.jnode.shell.command.xml
trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java 2008-10-11 15:10:13 UTC (rev 4621)
+++ trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java 2008-10-12 02:50:20 UTC (rev 4622)
@@ -34,6 +34,10 @@
this.value = value;
}
+ public VirtualKey(int vk, int modifiers) {
+ this.value = vk | (modifiers << 16);
+ }
+
public int getVKCode() {
return value & 0xffff;
}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-11 15:10:13 UTC (rev 4621)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-12 02:50:20 UTC (rev 4622)
@@ -55,12 +55,17 @@
public static ConsoleKeyEventBindings createDefault() {
ConsoleKeyEventBindings res = new ConsoleKeyEventBindings();
res.setVKAction(KeyEvent.VK_BACK_SPACE, 0, KeyboardReaderAction.KR_DELETE_BEFORE);
+ res.setVKAction(KeyEvent.VK_H, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_DELETE_BEFORE);
res.setCharAction('\b', KeyboardReaderAction.KR_DELETE_BEFORE);
res.setVKAction(KeyEvent.VK_ENTER, 0, KeyboardReaderAction.KR_ENTER);
+ res.setVKAction(KeyEvent.VK_J, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_ENTER);
res.setCharAction('\n', KeyboardReaderAction.KR_ENTER);
res.setVKAction(KeyEvent.VK_TAB, 0, KeyboardReaderAction.KR_COMPLETE);
+ res.setVKAction(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_COMPLETE);
res.setCharAction('\t', KeyboardReaderAction.KR_COMPLETE);
+ res.setVKAction(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_SOFT_EOF);
res.setCharAction('\004', KeyboardReaderAction.KR_SOFT_EOF);
+ res.setVKAction(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_KILL_LINE);
res.setCharAction('\014', KeyboardReaderAction.KR_KILL_LINE);
res.setVKAction(KeyEvent.VK_UP, 0, KeyboardReaderAction.KR_HISTORY_UP);
res.setVKAction(KeyEvent.VK_DOWN, 0, KeyboardReaderAction.KR_HISTORY_DOWN);
Modified: trunk/shell/descriptors/org.jnode.shell.command.xml
===================================================================
--- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-11 15:10:13 UTC (rev 4621)
+++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-12 02:50:20 UTC (rev 4622)
@@ -61,7 +61,23 @@
<sequence description="Remove key bindings">
<option argLabel="remove" shortName="r" longName="remove"/>
<argument argLabel="action"/>
+ <repeat minCount="0">
+ <alternatives>
+ <argument argLabel="vkSpec"/>
+ <argument argLabel="character"/>
+ </alternatives>
+ </repeat>
</sequence>
+ <sequence description="Add key bindings">
+ <option argLabel="add" shortName="a" longName="add"/>
+ <argument argLabel="action"/>
+ <repeat minCount="1">
+ <alternatives>
+ <argument argLabel="vkSpec"/>
+ <argument argLabel="character"/>
+ </alternatives>
+ </repeat>
+ </sequence>
</syntax>
<syntax alias="class" description="Show details of a Java class">
<argument argLabel="className"/>
Modified: trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-11 15:10:13 UTC (rev 4621)
+++ trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-12 02:50:20 UTC (rev 4622)
@@ -20,8 +20,11 @@
*/
package org.jnode.shell.command;
+import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,10 +38,11 @@
import org.jnode.driver.console.textscreen.KeyboardReaderAction;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.ShellUtils;
+import org.jnode.shell.CommandLine.Token;
import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.CommandSyntaxException;
import org.jnode.shell.syntax.EnumArgument;
import org.jnode.shell.syntax.FlagArgument;
-import org.jnode.shell.syntax.StringArgument;
/**
* This command allows the user to examine and change JNode's key bindings.
@@ -47,11 +51,55 @@
*/
public class BindKeysCommand extends AbstractCommand {
+ private static final Map<String, Integer> VK_NAME_MAP =
+ new HashMap<String, Integer>();
+ private static final Map<Integer, String> VK_MAP =
+ new HashMap<Integer, String>();
+ private static final Map<String, Integer> MODIFIER_NAME_MAP =
+ new HashMap<String, Integer>();
+ private static final Map<Integer, String> MODIFIER_MAP =
+ new HashMap<Integer, String>();
+
+ static {
+ // This is the best way I can think of to enumerate all of the VK_ codes
+ // defined by the KeyEvent class.
+ for (Field field : KeyEvent.class.getFields()) {
+ if (Modifier.isStatic(field.getModifiers()) &&
+ field.getName().startsWith("VK_")) {
+ try {
+ Integer vk = (Integer) field.get(null);
+ String name = constCase(KeyEvent.getKeyText(vk.intValue()));
+ VK_NAME_MAP.put(name, vk);
+ VK_MAP.put(vk, name);
+ } catch (IllegalAccessException ex) {
+ // This cannot happen. But if it does we'll just ignore
+ // the virtual key constant that caused it.
+ }
+ }
+ }
+ // Now do the same for the modifiers. Note that we map the names to the 'new'
+ // modifier mask values; see KeyEvent javadoc ...
+ initModifier("AWT.shift", "Shift", KeyEvent.SHIFT_DOWN_MASK);
+ initModifier("AWT.control", "Ctrl", KeyEvent.CTRL_DOWN_MASK);
+ initModifier("AWT.alt", "Alt", KeyEvent.ALT_DOWN_MASK);
+ initModifier("AWT.meta", "Meta", KeyEvent.META_DOWN_MASK);
+ initModifier("AWT.button1", "Button 1", KeyEvent.BUTTON1_DOWN_MASK);
+ initModifier("AWT.button2", "Button 2", KeyEvent.BUTTON2_DOWN_MASK);
+ initModifier("AWT.button3", "Button 3", KeyEvent.BUTTON3_DOWN_MASK);
+ initModifier("AWT.altGraph", "Alt Graph", KeyEvent.ALT_GRAPH_DOWN_MASK);
+ }
+
+ private static void initModifier(String propName, String dflt, int modifier) {
+ String name = constCase(Toolkit.getProperty(propName, dflt));
+ MODIFIER_NAME_MAP.put(name, modifier);
+ MODIFIER_MAP.put(modifier, name);
+ }
+
private static final String[] ASCII_NAMES = new String[] {
"NUL", "SOH", "STC", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS", "HT", "NL", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
- "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
+ "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US", "SP"
};
private static class ActionArgument extends EnumArgument<KeyboardReaderAction> {
@@ -64,9 +112,75 @@
return "keyboard reader action";
}
}
+
+ private static class VirtualKeyArgument extends Argument<VirtualKey> {
+ protected VirtualKeyArgument(String label, int flags, String description) {
+ super(label, flags, new VirtualKey[0], description);
+ }
+
+ @Override
+ protected String argumentKind() {
+ return "VK spec";
+ }
+
+ @Override
+ protected VirtualKey doAccept(Token value) throws CommandSyntaxException {
+ String str = value.token;
+ String[] parts = str.split("\\+");
+ int modifiers = 0;
+ for (int i = 0; i < parts.length - 1; i++) {
+ Integer m = MODIFIER_NAME_MAP.get(constCase(parts[i]));
+ if (m == null) {
+ throw new CommandSyntaxException(parts[i] + "' is an unknown modifier");
+ }
+ modifiers |= m;
+ }
+ Integer vk = VK_NAME_MAP.get(constCase(parts[parts.length - 1]));
+ if (vk == null) {
+ throw new CommandSyntaxException(parts[parts.length - 1] + "' is an unknown virtual key name");
+ }
+ return new VirtualKey(vk, modifiers);
+ }
+ }
+
+ private static class CharacterArgument extends Argument<Character> {
+
+ protected CharacterArgument(String label, int flags, String description) {
+ super(label, flags, new Character[0], description);
+ }
+
+ @Override
+ protected String argumentKind() {
+ return "character";
+ }
+
+ @Override
+ protected Character doAccept(Token value) throws CommandSyntaxException {
+ String str = value.token;
+ String upper = str.toUpperCase();
+ for (int i = 0; i < ASCII_NAMES.length; i++) {
+ if (ASCII_NAMES[i].equals(upper)) {
+ return (char) i;
+ }
+ }
+ if (upper.equals("DEL")) {
+ return '\177';
+ }
+ if (str.length() == 3 && str.charAt(0) == '\'' && str.charAt(2) == '\'') {
+ return str.charAt(1);
+ }
+ if (str.startsWith("0x") || str.startsWith("0X")) {
+ int ch = Integer.parseInt(str.substring(2), 16);
+ return (char) ch;
+ }
+ throw new CommandSyntaxException("invalid character");
+ }
+ }
+
private final FlagArgument FLAG_RESET =
- new FlagArgument("reset", Argument.OPTIONAL, "reset the bindings to the default values");
+ new FlagArgument("reset", Argument.OPTIONAL,
+ "reset the bindings to the default values");
private final FlagArgument FLAG_ADD =
new FlagArgument("add", Argument.OPTIONAL, "add bindings");
@@ -77,11 +191,13 @@
private final ActionArgument ARG_ACTION =
new ActionArgument("action", Argument.OPTIONAL, "an keyboard reader action");
- private final StringArgument ARG_VK_NAME =
- new StringArgument("vkName", Argument.OPTIONAL + Argument.MULTIPLE, "a virtual key specification");
+ private final VirtualKeyArgument ARG_VK_SPEC =
+ new VirtualKeyArgument("vkSpec", Argument.OPTIONAL + Argument.MULTIPLE,
+ "a virtual key specification");
- private final StringArgument ARG_CHAR_NAME =
- new StringArgument("charName", Argument.OPTIONAL + Argument.MULTIPLE, "a character");
+ private final CharacterArgument ARG_CHARACTER =
+ new CharacterArgument("character", Argument.OPTIONAL + Argument.MULTIPLE,
+ "a character");
private PrintWriter out;
private PrintWriter err;
@@ -90,9 +206,23 @@
public BindKeysCommand() {
super("display or change the keyboard bindings");
registerArguments(FLAG_RESET, FLAG_ADD, FLAG_REMOVE,
- ARG_ACTION, ARG_VK_NAME, ARG_CHAR_NAME);
+ ARG_ACTION, ARG_VK_SPEC, ARG_CHARACTER);
}
+ private static String constCase(String keyText) {
+ StringBuilder sb = new StringBuilder(keyText);
+ int len = keyText.length();
+ for (int i = 0; i < len; i++) {
+ char ch = sb.charAt(i);
+ if (ch == ' ') {
+ sb.setCharAt(i, '_');
+ } else {
+ sb.setCharAt(i, Character.toUpperCase(ch));
+ }
+ }
+ return sb.toString();
+ }
+
@Override
public void execute() throws Exception {
out = getOutput().getPrintWriter();
@@ -124,28 +254,16 @@
// a bug in the command syntax and should be allowed to propagate to the shell.
KeyboardReaderAction action = ARG_ACTION.getValue();
- if (ARG_CHAR_NAME.isSet() || ARG_VK_NAME.isSet()) {
- // If character or virtual key names were supplied, remove only those bindings.
- if (ARG_CHAR_NAME.isSet()) {
- for (String charName : ARG_CHAR_NAME.getValues()) {
- char ch = getCharacter(charName);
- if (ch != KeyEvent.CHAR_UNDEFINED) {
- bindings.unsetCharAction(ch);
- } else {
- err.println("Cannot translate character name '" + charName + "'");
- exit(1);
- }
+ if (ARG_VK_SPEC.isSet() || ARG_CHARACTER.isSet()) {
+ // If virtual key names were supplied, remove only those bindings.
+ if (ARG_VK_SPEC.isSet()) {
+ for (VirtualKey vk : ARG_VK_SPEC.getValues()) {
+ bindings.unsetVKAction(vk);
}
}
- if (ARG_VK_NAME.isSet()) {
- for (String vkName : ARG_VK_NAME.getValues()) {
- VirtualKey vk = getVirtualKey(vkName);
- if (vk != null) {
- bindings.unsetVKAction(vk);
- } else {
- err.println("Cannot translate virtual key name '" + vkName + "'");
- exit(1);
- }
+ if (ARG_CHARACTER.isSet()) {
+ for (char ch : ARG_CHARACTER.getValues()) {
+ bindings.unsetCharAction(ch);
}
}
} else {
@@ -174,18 +292,29 @@
out.println("Updated the current console's key bindings for action '" + action + "'.");
}
- private char getCharacter(String charName) {
- // TODO Auto-generated method stub
- return KeyEvent.CHAR_UNDEFINED;
- }
-
- private VirtualKey getVirtualKey(String vkName) {
- // TODO Auto-generated method stub
- return null;
- }
-
private void addBindings(TextConsole console) {
ConsoleKeyEventBindings bindings = console.getKeyEventBindings();
+ // This throws an unchecked exception if the action is not supplied. It signals
+ // a bug in the command syntax and should be allowed to propagate to the shell.
+ KeyboardReaderAction action = ARG_ACTION.getValue();
+
+ int count = 0;
+ if (ARG_VK_SPEC.isSet()) {
+ for (VirtualKey vk : ARG_VK_SPEC.getValues()) {
+ bindings.setVKAction(vk, action);
+ count++;
+ }
+ }
+ if (ARG_CHARACTER.isSet()) {
+ for (char ch : ARG_CHARACTER.getValues()) {
+ bindings.setCharAction(ch, action);
+ count++;
+ }
+ }
+ if (count > 0) {
+ console.setKeyEventBindings(bindings);
+ out.println("Updated the current console's key bindings for action '" + action + "'.");
+ }
}
private void resetBindings(TextConsole console) {
@@ -235,7 +364,6 @@
}
}
out.println(sb);
-
}
}
@@ -286,34 +414,54 @@
private String describe(KeyboardReaderAction action) {
return action.toString();
}
-
- private KeyboardReaderAction getAction(String name) {
- return KeyboardReaderAction.valueOf(name);
- }
private String describe(char ch) {
StringBuilder sb = new StringBuilder();
if (ch < 0x1f) {
- sb.append("CTRL-" + (char)(ch + 0x40));
- sb.append(" (").append(ASCII_NAMES[ch]).append(")");
+ sb.append(ASCII_NAMES[ch]);
} else if (ch == ' ') {
- sb.append("SPACE");
+ sb.append("SP");
} else if (ch == '\177') {
sb.append("DEL");
} else if (ch < '\177') {
- sb.append(ch);
+ sb.append('\'').append(ch).append('\'');
} else {
- sb.append(ch).append("(0x" + Integer.toHexString(ch)).append(')');
+ sb.append('\'').append(ch).append("' (0x" + Integer.toHexString(ch)).append(')');
}
return sb.toString();
}
private String describe(VirtualKey vk) {
- if (vk.getModifiers() != 0) {
- return (KeyEvent.getKeyModifiersText(vk.getModifiers()) + " " +
- KeyEvent.getKeyText(vk.getVKCode()));
- } else {
- return KeyEvent.getKeyText(vk.getVKCode());
+ int modifiers = vk.getModifiers();
+ StringBuilder sb = new StringBuilder();
+ // We don't use the KeyEvent.getKeyModifierText method because it
+ // expects the 'old' mask values and conflates some of the masks.
+ if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.SHIFT_DOWN_MASK)).append('+');
}
+ if ((modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.CTRL_DOWN_MASK)).append('+');
+ }
+ if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.ALT_DOWN_MASK)).append('+');
+ }
+ if ((modifiers & KeyEvent.META_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.META_DOWN_MASK)).append('+');
+ }
+ if ((modifiers & KeyEvent.BUTTON1_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.BUTTON1_DOWN_MASK)).append('+');
+ }
+ if ((modifiers & KeyEvent.BUTTON2_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.BUTTON2_DOWN_MASK)).append('+');
+ }
+ if ((modifiers & KeyEvent.BUTTON3_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.BUTTON3_DOWN_MASK)).append('+');
+ }
+ if ((modifiers & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) {
+ sb.append(MODIFIER_MAP.get(KeyEvent.ALT_GRAPH_DOWN_MASK)).append('+');
+ }
+ sb.append("VK_");
+ sb.append(VK_MAP.get(vk.getVKCode()));
+ return sb.toString();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2008-10-24 13:17:24
|
Revision: 4652
http://jnode.svn.sourceforge.net/jnode/?rev=4652&view=rev
Author: lsantha
Date: 2008-10-24 13:17:17 +0000 (Fri, 24 Oct 2008)
Log Message:
-----------
Fixed code style.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java
trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java
trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -24,7 +24,6 @@
import java.util.HashMap;
import java.util.Set;
-import org.jnode.driver.console.textscreen.KeyboardReaderAction;
import org.jnode.driver.input.KeyboardEvent;
/**
Modified: trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -65,4 +65,4 @@
}
return true;
}
-}
\ No newline at end of file
+}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -110,4 +110,4 @@
public static KeyboardReaderAction getDefaultVKAction() {
return KR_IGNORE;
}
-}
\ No newline at end of file
+}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -29,7 +29,6 @@
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.console.InputCompleter;
-import org.jnode.driver.console.KeyEventBindings;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.console.spi.AbstractConsole;
import org.jnode.driver.console.spi.ConsoleWriter;
Modified: trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -24,21 +24,16 @@
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.FontMetrics;
-import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.jnode.awt.JNodeToolkit;
-import org.jnode.awt.font.FontProvider;
-import org.jnode.awt.font.JNodeFontPeer;
import org.jnode.awt.font.TextRenderer;
import org.jnode.awt.font.renderer.RenderCache;
import org.jnode.awt.font.spi.AbstractFontProvider;
Modified: trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java
===================================================================
--- trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/gui/src/awt/org/jnode/awt/font/truetype/TTFontProvider.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -33,8 +33,6 @@
import org.jnode.awt.font.TextRenderer;
import org.jnode.awt.font.renderer.RenderCache;
import org.jnode.awt.font.spi.AbstractFontProvider;
-import org.jnode.awt.font.spi.AbstractFontProvider.Size;
-import org.jnode.awt.font.truetype.glyph.TTFGlyph;
/**
* @author epr
Modified: trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-24 13:12:13 UTC (rev 4651)
+++ trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-24 13:17:17 UTC (rev 4652)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
- package org.jnode.shell.command;
+package org.jnode.shell.command;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-04 11:12:29
|
Revision: 4667
http://jnode.svn.sourceforge.net/jnode/?rev=4667&view=rev
Author: crawley
Date: 2008-11-04 11:12:22 +0000 (Tue, 04 Nov 2008)
Log Message:
-----------
Checkstyle fixes
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java
trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java
Modified: trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java 2008-11-04 11:04:49 UTC (rev 4666)
+++ trunk/fs/src/fs/org/jnode/fs/command/Md5SumCommand.java 2008-11-04 11:12:22 UTC (rev 4667)
@@ -182,8 +182,7 @@
} else {
try {
out.println(toHexString(computeDigest(file)) + " " + file);
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
err.println(file + " was not md5summed: " + ex.getMessage());
}
}
@@ -198,8 +197,7 @@
try {
out.println(toHexString(computeDigest(null)));
return true;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
err.println("Input was not md5summed: " + ex.getMessage());
return false;
}
@@ -219,7 +217,7 @@
digestEngine.reset();
is = (file != null) ? new FileInputStream(file) : getInput().getInputStream();
int bytesRead;
- while ((bytesRead = is.read(buffer, 0, BUFFER_SIZE)) > 0 ) {
+ while ((bytesRead = is.read(buffer, 0, BUFFER_SIZE)) > 0) {
digestEngine.update(buffer, 0, bytesRead);
}
return digestEngine.digest();
Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java 2008-11-04 11:04:49 UTC (rev 4666)
+++ trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java 2008-11-04 11:12:22 UTC (rev 4667)
@@ -53,7 +53,7 @@
assertEquals(true, t.whitespaceAfterLast());
}
- public void testTokenizerSimple() throws ShellException{
+ public void testTokenizerSimple() throws ShellException {
SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer("a b c");
assertEquals(true, t.hasNext());
assertEquals(false, t.whitespaceAfterLast());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-05 13:26:07
|
Revision: 4670
http://jnode.svn.sourceforge.net/jnode/?rev=4670&view=rev
Author: crawley
Date: 2008-11-05 13:26:05 +0000 (Wed, 05 Nov 2008)
Log Message:
-----------
Fixes to allow ReaderInputStream to recover from encoder errors.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/util/ReaderInputStream.java
trunk/shell/src/test/org/jnode/test/shell/io/ReaderInputStreamTest.java
Modified: trunk/core/src/core/org/jnode/util/ReaderInputStream.java
===================================================================
--- trunk/core/src/core/org/jnode/util/ReaderInputStream.java 2008-11-04 21:26:57 UTC (rev 4669)
+++ trunk/core/src/core/org/jnode/util/ReaderInputStream.java 2008-11-05 13:26:05 UTC (rev 4670)
@@ -25,6 +25,7 @@
import java.io.Reader;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
@@ -42,6 +43,7 @@
private ByteBuffer bytes = ByteBuffer.allocate(2048);
private CharsetEncoder encoder;
+ private CoderResult cr;
public ReaderInputStream(Reader reader) {
this(reader, Charset.defaultCharset().name());
@@ -104,10 +106,12 @@
* @throws IOException
*/
private int fillBuffer(boolean wait) throws IOException {
+ // If there was a coder error left over from the last call, process
+ // it now.
+ resetAndThrowOnError();
bytes.clear();
// The loop is necessary because of the way that an encoder has to deal
// with UTF-16 surrogate pairs.
- CoderResult cr = null;
int count;
do {
if (chars.remaining() == 0 || cr == CoderResult.UNDERFLOW) {
@@ -126,25 +130,43 @@
if (reader.read(chars) == -1) {
chars.flip();
cr = encoder.encode(chars, bytes, true);
- if (cr.isError()) {
- cr.throwException();
+ count = bytes.position();
+ if (count == 0) {
+ // Only report errors now if we didn't manage to encode anything
+ resetAndThrowOnError();
}
- count = bytes.position();
bytes.flip();
return count > 0 ? count : -1;
}
chars.flip();
}
cr = encoder.encode(chars, bytes, false);
- if (cr.isError()) {
- cr.throwException();
+ count = bytes.position();
+ if (count == 0) {
+ // Only report errors now if we didn't manage to encode anything
+ resetAndThrowOnError();
}
- count = bytes.position();
} while (wait && count == 0);
bytes.flip();
return count;
}
+ private void resetAndThrowOnError() throws CharacterCodingException {
+ if (cr != null && cr.isError()) {
+ // Reset the encoder so that it will work next time we try to use it.
+ encoder.reset();
+ // Skip over the problem characters
+ for (int i = 0; i < cr.length(); i++) {
+ chars.get();
+ }
+ // Clear the coder result
+ CoderResult tmp = cr;
+ cr = null;
+ // ... and report the error using the appropriate exception.
+ tmp.throwException();
+ }
+ }
+
public Reader getReader() {
return reader;
}
Modified: trunk/shell/src/test/org/jnode/test/shell/io/ReaderInputStreamTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/io/ReaderInputStreamTest.java 2008-11-04 21:26:57 UTC (rev 4669)
+++ trunk/shell/src/test/org/jnode/test/shell/io/ReaderInputStreamTest.java 2008-11-05 13:26:05 UTC (rev 4670)
@@ -125,6 +125,7 @@
Reader r = new StringReader(LINE);
ReaderInputStream ris = new ReaderInputStream(r, "latin1");
byte[] buffer = new byte[257];
+ assertEquals(256, ris.read(buffer));
try {
ris.read(buffer);
fail("No exception raised");
@@ -133,6 +134,25 @@
}
}
+ public void testBadLatin1Recovery() throws Exception {
+ char[] chars = new char[11];
+ for (int i = 0; i < 11; i++) {
+ chars[i] = i == 5 ? '\u0101' : (char) ('A' + i);
+ }
+ final String LINE = new String(chars);
+ Reader r = new StringReader(LINE);
+ ReaderInputStream ris = new ReaderInputStream(r, "latin1");
+ byte[] buffer = new byte[5];
+ assertEquals(5, ris.read(buffer));
+ try {
+ ris.read();
+ fail("No exception raised");
+ } catch (UnmappableCharacterException ex) {
+ // expected
+ }
+ assertEquals(5, ris.read(buffer));
+ }
+
public void testUnicode() throws Exception {
char[] chars = new char[1024];
for (int i = 0; i < 1024; i++) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-08 11:16:16
|
Revision: 4678
http://jnode.svn.sourceforge.net/jnode/?rev=4678&view=rev
Author: crawley
Date: 2008-11-08 11:16:06 +0000 (Sat, 08 Nov 2008)
Log Message:
-----------
Mostly FIXME etc comments + a minor tweak to IsolateThreadImpl.stop ...
which doesn't seem to be getting called at the moment anyway.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java
trunk/shell/src/shell/org/jnode/shell/CommandThreadImpl.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-11-08 07:59:17 UTC (rev 4677)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-11-08 11:16:06 UTC (rev 4678)
@@ -422,10 +422,17 @@
}
private void stopAllThreads() {
+ // FIXME - this is probably unsafe because any of the threads being killed could
+ // be in the middle of updating a critical system data structure. I'm also
+ // unsure of the order in which we are killing the threads here. It might be
+ // better to kill the isolate's main thread first to give it the chance to
+ // do a graceful shutdown. (Stephen Crawley - 2008-11-08)
int ac = threadGroup.activeCount();
if (ac > 0) {
Thread[] ta = new Thread[ac];
int rc = threadGroup.enumerate(ta);
+ // FIXME - notwithstanding the above comments, is the 'current' thread the
+ // same one as the isolate's main thread? (Stephen Crawley - 2008-11-08)
Thread current = Thread.currentThread();
boolean found = false;
for (int i = 0; i < rc; i++) {
@@ -442,7 +449,7 @@
doExit();
}
} else {
- //todo analyze this case
+ // TODO - analyze this case
doExit();
}
}
@@ -456,7 +463,7 @@
//on this isolate may call this method
testIsolate(currentIsolate().isolate);
- //todo handle demon threads
+ // FIXME - handle demon threads
if (threadGroup.activeCount() > 0 || threadGroup.activeGroupCount() > 0)
return;
@@ -476,7 +483,7 @@
//on this isolate may call this method
testIsolate(currentIsolate().isolate);
- //todo handle demon threads
+ // FIXME - handle demon threads
if (threadGroup.activeCount() > 0 || threadGroup.activeGroupCount() > 0)
return;
@@ -773,7 +780,7 @@
});
//create the appcontext for this isolate
- //todo improve this
+ // TODO - improve this
Class.forName("sun.awt.SunToolkit").getMethod("createNewAppContext").invoke(null);
// Update the state of this isolate.
Modified: trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2008-11-08 07:59:17 UTC (rev 4677)
+++ trunk/shell/src/shell/org/jnode/shell/AsyncCommandInvoker.java 2008-11-08 11:16:06 UTC (rev 4678)
@@ -214,7 +214,6 @@
}
}
- @SuppressWarnings("deprecation")
private void doCtrlC() {
if (threadProcess != null && threadProcess.isAlive()
&& blockingThread != null && blockingThread.isAlive()) {
Modified: trunk/shell/src/shell/org/jnode/shell/CommandThreadImpl.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandThreadImpl.java 2008-11-08 07:59:17 UTC (rev 4677)
+++ trunk/shell/src/shell/org/jnode/shell/CommandThreadImpl.java 2008-11-08 11:16:06 UTC (rev 4678)
@@ -93,6 +93,9 @@
@SuppressWarnings("deprecation")
@Override
public void stop(ThreadDeath threadDeath) {
+ // FIXME - This is unsafe because the thread being killed could be in the
+ // middle of updating some critical system data structure. We should
+ // probably throw an exception.
super.stop(threadDeath);
}
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-11-08 07:59:17 UTC (rev 4677)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2008-11-08 11:16:06 UTC (rev 4678)
@@ -143,9 +143,7 @@
@Override
public void stop(ThreadDeath threadDeath) {
- // FIXME - not sure what status argument should be ... but this is moot
- // at the moment because VmIsolate.halt does nothing with it anyway.
- isolate.halt(0 /* FIXME */);
+ isolate.halt(-1);
}
public void waitFor() throws ShellInvocationException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-09 02:35:52
|
Revision: 4681
http://jnode.svn.sourceforge.net/jnode/?rev=4681&view=rev
Author: crawley
Date: 2008-11-09 02:35:50 +0000 (Sun, 09 Nov 2008)
Log Message:
-----------
Converting some commands to use the new 'execute' method
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java
trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java
trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java
trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java
trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java
trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java
Modified: trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -43,7 +43,7 @@
new DerbyCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws Exception {
File home_dir = ARG_HOME.getValue();
String command = FLAG_START.isSet() ? "start" : FLAG_STOP.isSet() ? "stop" : "?";
@@ -53,20 +53,14 @@
NetworkServerControlImpl server = new NetworkServerControlImpl();
- try {
- int server_command = server.parseArgs(new String[]{command});
+ int server_command = server.parseArgs(new String[]{command});
- if (server_command == NetworkServerControlImpl.COMMAND_START) {
- PrintWriter printWriter = new PrintWriter(out);
- server.setLogWriter(printWriter);
- server.start(printWriter);
- } else if (server_command == NetworkServerControlImpl.COMMAND_SHUTDOWN) {
- server.shutdown();
- }
-
- } catch (Exception e) {
- // FIXME ... don't do this!
- e.printStackTrace();
+ if (server_command == NetworkServerControlImpl.COMMAND_START) {
+ PrintWriter printWriter = getOutput().getPrintWriter();
+ server.setLogWriter(printWriter);
+ server.start(printWriter);
+ } else if (server_command == NetworkServerControlImpl.COMMAND_SHUTDOWN) {
+ server.shutdown();
}
// server.executeWork(server_command);
Modified: trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -44,13 +44,13 @@
new EditCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws Exception {
final File file = ARG_EDIT.isSet() ? ARG_EDIT.getValue() : null;
if (file == null)
Editor.editFile(null);
else if (file.isDirectory()) {
- err.println(file + " is a directory");
+ getError().getPrintWriter().println(file + " is a directory");
} else {
Editor.editFile(file);
}
Modified: trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -24,11 +24,11 @@
new LeedCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws Exception {
final File file = ARG_EDIT.getValue();
if (file.isDirectory()) {
- err.println(file + " is a directory");
+ getError().getPrintWriter().println(file + " is a directory");
} else {
TextEditor.main(new String[]{file.toString()});
}
Modified: trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -27,11 +27,11 @@
new LeedCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws Exception {
final File file = ARG_EDIT.getValue();
if (file.isDirectory()) {
- System.err.println(file + " is a directory");
+ getError().getPrintWriter().println(file + " is a directory");
} else {
TextEditor.main(new String[]{file.toString(), "ro"});
}
Modified: trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -37,7 +37,7 @@
public class NanoHTTPDCommand extends AbstractCommand {
@Override
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
File file = new File("/jnode/index.htm"); // ram disk is fat, so no long extension, I guess
if (!file.exists()) {
@@ -59,7 +59,7 @@
try {
Thread.sleep(250);
} catch (InterruptedException e) {
- e.printStackTrace(err);
+ e.printStackTrace(getError().getPrintWriter());
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -36,7 +36,7 @@
new JettyCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws Exception {
File webapp_dir = ARG_WEBAPP.getValue();
int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : 8080;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -29,10 +29,12 @@
new JPartitionCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
boolean install = ARG_INSTALL.isSet();
+ InputStream in = getInput().getInputStream();
+ PrintStream out = getOutput().getPrintStream();
+ PrintStream err = getError().getPrintStream();
ViewFactory viewFactory =
FLAG_CONSOLE.isSet() ? new ConsoleViewFactory(in, out, err)
: FLAG_SWING.isSet() ? new SwingViewFactory() : null;
Modified: trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -54,8 +54,7 @@
new RamDiskCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err)
+ public void execute()
throws NameNotFoundException, DriverException, DeviceAlreadyRegisteredException {
final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
if (FLAG_CREATE.isSet()) {
Modified: trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -56,7 +56,7 @@
protected abstract Formatter<T> getFormatter();
- public final void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public final void execute()
throws FileSystemException, NameNotFoundException, DeviceNotFoundException, DriverException {
Device dev = ARG_DEVICE.getValue();
Formatter<T> formatter = getFormatter();
Modified: trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -43,7 +43,7 @@
new BeepCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) {
+ public void execute() {
SpeakerUtils.beep();
}
}
Modified: trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java 2008-11-09 02:34:08 UTC (rev 4680)
+++ trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java 2008-11-09 02:35:50 UTC (rev 4681)
@@ -70,7 +70,7 @@
new PlayCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) {
+ public void execute() {
Note[] tune = ARG_TUNE.isSet() ? ARG_TUNE.getValue() : SpeakerUtils.SCALE;
SpeakerUtils.play(tune);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-09 04:22:07
|
Revision: 4685
http://jnode.svn.sourceforge.net/jnode/?rev=4685&view=rev
Author: crawley
Date: 2008-11-09 03:32:20 +0000 (Sun, 09 Nov 2008)
Log Message:
-----------
Checkstyle fixes
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java
trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java
trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java
trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java
trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java
trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java
trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java
Modified: trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -5,12 +5,10 @@
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.io.PrintWriter;
+
import org.apache.derby.impl.drda.NetworkServerControlImpl;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.FlagArgument;
Modified: trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -22,10 +22,8 @@
package org.jnode.apps.edit;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
Modified: trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -1,10 +1,8 @@
package org.jnode.apps.editor;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
Modified: trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -4,10 +4,8 @@
package org.jnode.apps.editor;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
Modified: trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -21,16 +21,15 @@
package org.jnode.apps.httpd;
-import fi.iki.elonen.NanoHTTPD;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Properties;
+
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
+import fi.iki.elonen.NanoHTTPD;
+
/**
* @author Martin Husted Hartvig (ha...@jn...)
*/
Modified: trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -4,10 +4,8 @@
package org.jnode.apps.jetty;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.PortNumberArgument;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -6,7 +6,6 @@
import org.jnode.apps.jpartition.consoleview.ConsoleViewFactory;
import org.jnode.apps.jpartition.swingview.SwingViewFactory;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
Modified: trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/fs/src/driver/org/jnode/driver/block/ramdisk/command/RamDiskCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -21,9 +21,8 @@
package org.jnode.driver.block.ramdisk.command;
-import java.io.InputStream;
-import java.io.PrintStream;
import javax.naming.NameNotFoundException;
+
import org.jnode.driver.DeviceAlreadyRegisteredException;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DriverException;
@@ -31,7 +30,6 @@
import org.jnode.driver.block.ramdisk.RamDiskDriver;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.shell.syntax.IntegerArgument;
Modified: trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -21,9 +21,6 @@
package org.jnode.fs.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import javax.naming.NameNotFoundException;
import org.jnode.driver.Device;
@@ -36,7 +33,6 @@
import org.jnode.fs.Formatter;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
Modified: trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/fs/src/fs/org/jnode/fs/command/DFCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -22,7 +22,6 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.StringWriter;
import java.util.Map;
import javax.naming.NameNotFoundException;
Modified: trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/gui/src/driver/org/jnode/driver/sound/command/BeepCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -21,12 +21,8 @@
package org.jnode.driver.sound.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.driver.sound.speaker.SpeakerUtils;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
/**
* This command plays a system beep.
Modified: trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java 2008-11-09 03:16:03 UTC (rev 4684)
+++ trunk/gui/src/driver/org/jnode/driver/sound/command/PlayCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
@@ -21,14 +21,11 @@
package org.jnode.driver.sound.command;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.util.HashMap;
import org.jnode.driver.sound.speaker.Note;
import org.jnode.driver.sound.speaker.SpeakerUtils;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.MappedArgument;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-09 08:08:30
|
Revision: 4686
http://jnode.svn.sourceforge.net/jnode/?rev=4686&view=rev
Author: crawley
Date: 2008-11-09 08:08:19 +0000 (Sun, 09 Nov 2008)
Log Message:
-----------
Changing commands to use 'execute()' and PrintWriters were appropriate
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java
trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java
trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java
trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java
trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java
trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java
trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java
trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java
trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrub.java
trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java
trunk/fs/src/fs/org/jnode/fs/jifs/command/CreateJIFSCommand.java
trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java
trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java
trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java
trunk/net/src/net/org/jnode/net/command/ArpCommand.java
trunk/net/src/net/org/jnode/net/command/BootpCommand.java
trunk/net/src/net/org/jnode/net/command/DhcpCommand.java
trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
trunk/net/src/net/org/jnode/net/command/NetstatCommand.java
trunk/net/src/net/org/jnode/net/command/PingCommand.java
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
trunk/net/src/net/org/jnode/net/command/RouteCommand.java
trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java
trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java
trunk/net/src/net/org/jnode/net/command/WgetCommand.java
trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java
Modified: trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/DirCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -23,15 +23,13 @@
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
@@ -58,12 +56,14 @@
new DirCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws IOException {
File[] paths = ARG_PATH.getValues();
if (paths.length == 0) {
paths = new File[] {new File(System.getProperty("user.dir"))};
}
+ PrintWriter out = getOutput().getPrintWriter(false);
+ PrintWriter err = getError().getPrintWriter();
for (File path : paths) {
if (!path.exists()) {
err.println("No such path: " + path);
@@ -81,7 +81,7 @@
}
}
- private void printList(File[] list, PrintStream out) {
+ private void printList(File[] list, PrintWriter out) {
if (list != null) {
Arrays.sort(list, new Comparator<File>() {
public int compare(File f1, File f2) {
Modified: trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,14 +22,11 @@
package org.jnode.fs.command;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
import org.jnode.driver.RemovableDeviceAPI;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
@@ -52,14 +49,14 @@
new EjectCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws ApiNotFoundException, IOException {
final Device dev = ARG_DEVICE.getValue();
final RemovableDeviceAPI api = dev.getAPI(RemovableDeviceAPI.class);
try {
api.eject();
} catch (IOException ex) {
- err.println("eject failed for " + dev.getId() + ": " + ex.getMessage());
+ getError().getPrintWriter().println("eject failed for " + dev.getId() + ": " + ex.getMessage());
exit(1);
}
}
Modified: trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -9,11 +9,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.net.URL;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.URLArgument;
@@ -39,9 +38,11 @@
new HexdumpCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws IOException {
+ public void execute() throws IOException {
+ boolean myInput = false;
InputStream is = null;
+ PrintWriter out = getOutput().getPrintWriter(false);
+ PrintWriter err = getError().getPrintWriter();
try {
// Set up the stream to be dumped.
File file = ARG_FILE.getValue();
@@ -61,7 +62,8 @@
exit(1);
}
} else {
- is = in;
+ is = getInput().getInputStream();
+ myInput = true;
}
// Now do the work
@@ -122,7 +124,7 @@
}
out.flush();
} finally {
- if (is != null && is != in) {
+ if (is != null && myInput) {
try {
is.close();
} catch (IOException ex) {
Modified: trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/MkdirCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,11 +22,9 @@
package org.jnode.fs.command;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
@@ -48,8 +46,9 @@
new MkdirCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) {
+ public void execute() {
File dir = ARG_DIR.getValue();
+ PrintWriter err = getError().getPrintWriter();
if (dir.exists()) {
err.println(dir.getPath() + " already exists.");
exit(1);
Modified: trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/MountCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,8 +22,7 @@
package org.jnode.fs.command;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import org.jnode.driver.Device;
@@ -32,7 +31,6 @@
import org.jnode.fs.service.FileSystemService;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
import org.jnode.shell.syntax.FileArgument;
@@ -60,11 +58,11 @@
new MountCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
// Find the filesystem service
final FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME);
-
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
if (!ARG_DEV.isSet()) {
// List all mounted file systems
Map<String, FileSystem<?>> filesystems = fss.getMountPoints();
Modified: trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/PwdCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,11 +22,8 @@
package org.jnode.fs.command;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
/**
* @author Martin Husted Hartvig (ha...@jn...)
@@ -40,8 +37,8 @@
new PwdCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) {
+ public void execute() {
File file = new File("");
- out.println(file.getAbsolutePath());
+ getOutput().getPrintWriter().println(file.getAbsolutePath());
}
}
Modified: trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/command/TouchCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,11 +22,9 @@
package org.jnode.fs.command;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
@@ -51,9 +49,10 @@
new TouchCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
File file = ARG_FILE.getValue();
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
if (!file.exists()) {
File parentFile = file.getParentFile();
if (parentFile != null && !parentFile.exists()) {
Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/ftpfs/command/FTPMountCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,18 +22,10 @@
package org.jnode.fs.ftpfs.command;
import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
-import javax.naming.NameNotFoundException;
-
import org.apache.log4j.Logger;
-import org.jnode.driver.DeviceAlreadyRegisteredException;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceUtils;
-import org.jnode.driver.DriverException;
-import org.jnode.fs.FileSystemException;
import org.jnode.fs.ftpfs.FTPFSDevice;
import org.jnode.fs.ftpfs.FTPFSDriver;
import org.jnode.fs.ftpfs.FTPFileSystem;
@@ -41,7 +33,6 @@
import org.jnode.fs.service.FileSystemService;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.HostNameArgument;
@@ -72,10 +63,7 @@
new FTPMountCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err)
- throws DriverException, NameNotFoundException, DeviceAlreadyRegisteredException,
- FileSystemException, IOException {
+ public void execute() throws Exception {
final File mountPoint = MOUNTPOINT_ARG.getValue();
final String host = HOST_ARG.getValue();
final String user = USERNAME_ARG.getValue();
@@ -94,6 +82,9 @@
fss.registerFileSystem(fs);
fss.mount(mountPoint.getAbsolutePath(), fs, null);
ok = true;
+ } catch (Exception ex) {
+ getError().getPrintStream().println("FTP mount failed: " + ex.getLocalizedMessage());
+ throw ex;
} finally {
if (!ok) {
try {
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrub.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrub.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrub.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -23,7 +23,7 @@
package org.jnode.fs.jfat.command;
import java.io.File;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import javax.naming.NameNotFoundException;
@@ -48,18 +48,18 @@
* @author Tango Devian
*/
public class JGrub {
- private final PrintStream out;
+ private final PrintWriter out;
private final MBRFormatter stage1;
private final Stage1_5 stage1_5;
private final Stage2 stage2;
private final Device device;
private final String mountPoint;
- public JGrub(PrintStream out, PrintStream err, Device device) throws GrubException {
- this(out, err, device, new MBRFormatter(), new Stage1_5(), new Stage2());
+ public JGrub(PrintWriter out, Device device) throws GrubException {
+ this(out, device, new MBRFormatter(), new Stage1_5(), new Stage2());
}
- protected JGrub(PrintStream out, PrintStream err, Device device, MBRFormatter stage1,
+ protected JGrub(PrintWriter out, Device device, MBRFormatter stage1,
Stage1_5 stage1_5, Stage2 stage2) throws GrubException {
this.out = out;
this.stage1 = stage1;
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,13 +22,9 @@
package org.jnode.fs.jfat.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.driver.Device;
import org.jnode.driver.block.BlockDeviceAPI;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
@@ -53,11 +49,11 @@
new JGrubInstallCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws GrubException {
Device device = ARG_DEVICE.getValue();
- JGrub jgrub = new JGrub(out, err, device);
+ JGrub jgrub = new JGrub(getOutput().getPrintWriter(), device);
jgrub.install();
}
}
Modified: trunk/fs/src/fs/org/jnode/fs/jifs/command/CreateJIFSCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jifs/command/CreateJIFSCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/jifs/command/CreateJIFSCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -21,9 +21,6 @@
package org.jnode.fs.jifs.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import javax.naming.NameNotFoundException;
import org.jnode.naming.InitialNaming;
@@ -31,7 +28,6 @@
import org.jnode.plugin.PluginException;
import org.jnode.plugin.PluginManager;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.EnumArgument;
@@ -66,8 +62,7 @@
registerArguments(ARG_ACTION);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws NameNotFoundException, PluginException {
+ public void execute() throws NameNotFoundException, PluginException {
final PluginManager mgr = InitialNaming.lookup(PluginManager.NAME);
final Plugin p =
mgr.getRegistry().getPluginDescriptor("org.jnode.fs.jifs.def").getPlugin();
Modified: trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSMountCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -23,8 +23,6 @@
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.net.InetAddress;
import javax.naming.NameNotFoundException;
@@ -42,7 +40,6 @@
import org.jnode.naming.InitialNaming;
import org.jnode.net.nfs.Protocol;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -90,8 +87,7 @@
new NFSMountCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws NameNotFoundException, DriverException, DeviceAlreadyRegisteredException,
+ public void execute() throws NameNotFoundException, DriverException, DeviceAlreadyRegisteredException,
FileSystemException, IOException {
final File mountPoint = MOUNTPOINT_ARG.getValue();
final InetAddress host = HOST_ARG.getAddress();
Modified: trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/fs/smbfs/command/SMBMountCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,8 +22,7 @@
package org.jnode.fs.smbfs.command;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceUtils;
import org.jnode.driver.DriverException;
@@ -34,7 +33,6 @@
import org.jnode.fs.smbfs.SMBFileSystemType;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.HostNameArgument;
@@ -65,8 +63,7 @@
new SMBMountCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
final File mountPoint = MOUNTPOINT_ARG.getValue();
final String host = HOST_ARG.getValue();
final String path = PATH_ARG.getValue();
Modified: trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -22,8 +22,7 @@
package org.jnode.partitions.command;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
@@ -42,7 +41,6 @@
import org.jnode.partitions.ibm.IBMPartitionTableType;
import org.jnode.partitions.ibm.IBMPartitionTypes;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -100,10 +98,10 @@
new FdiskCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
-
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
if (!ARG_DEVICE.isSet()) {
// Show all devices.
listAvailableDevices(dm, out);
@@ -143,7 +141,7 @@
return partNumber;
}
- private void modifyPartition(PartitionHelper helper, int id, PrintStream out) throws IOException {
+ private void modifyPartition(PartitionHelper helper, int id, PrintWriter out) throws IOException {
long start = ARG_START.getValue();
long size = ARG_SECTORS.isSet() ? ARG_SECTORS.getValue() : ARG_BYTES.getValue();
IBMPartitionTypes type = ARG_TYPE.getValue();
@@ -156,7 +154,7 @@
helper.modifyPartition(id, false, start, size, sizeUnit, type);
}
- private void printPartitionTable(Device dev, PrintStream out)
+ private void printPartitionTable(Device dev, PrintWriter out)
throws DeviceNotFoundException, ApiNotFoundException, IOException {
IDEDevice ideDev = null;
// FIXME ... this needs to be generalized to other disc device types.
@@ -208,7 +206,7 @@
}
}
- private void listAvailableDevices(DeviceManager dm, PrintStream out) {
+ private void listAvailableDevices(DeviceManager dm, PrintWriter out) {
final Collection<Device> allDevices = dm.getDevicesByAPI(BlockDeviceAPI.class);
for (Device dev : allDevices) {
out.println("Found device : " + dev.getId() + "[" + dev.getClass() + "]");
Modified: trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -1,7 +1,7 @@
package org.jnode.partitions.command;
import java.io.IOException;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import javax.naming.NameNotFoundException;
@@ -32,14 +32,14 @@
private final MasterBootRecord MBR;
private BootSector bs;
- private final PrintStream out;
+ private final PrintWriter out;
- public PartitionHelper(String deviceId, PrintStream out) throws DeviceNotFoundException, ApiNotFoundException,
+ public PartitionHelper(String deviceId, PrintWriter out) throws DeviceNotFoundException, ApiNotFoundException,
IOException, NameNotFoundException {
this((IDEDevice) DeviceUtils.getDeviceManager().getDevice(deviceId), out);
}
- public PartitionHelper(IDEDevice device, PrintStream out) throws DeviceNotFoundException, ApiNotFoundException,
+ public PartitionHelper(IDEDevice device, PrintWriter out) throws DeviceNotFoundException, ApiNotFoundException,
IOException {
this.current = device;
this.api = current.getAPI(BlockDeviceAPI.class);
Modified: trunk/net/src/net/org/jnode/net/command/ArpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ArpCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/net/src/net/org/jnode/net/command/ArpCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -21,8 +21,7 @@
package org.jnode.net.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.driver.net.NetworkException;
import org.jnode.net.NoSuchProtocolException;
@@ -31,7 +30,6 @@
import org.jnode.net.ethernet.EthernetConstants;
import org.jnode.net.util.NetUtils;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
@@ -55,9 +53,10 @@
new ArpCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws NoSuchProtocolException, NetworkException {
- ARPNetworkLayer arp = (ARPNetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_ARP);
+ public void execute() throws NoSuchProtocolException, NetworkException {
+ ARPNetworkLayer arp = (ARPNetworkLayer)
+ NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_ARP);
+ PrintWriter out = getOutput().getPrintWriter();
if (FLAG_CLEAR.isSet()) {
arp.getCache().clear();
out.println("Cleared the ARP cache");
Modified: trunk/net/src/net/org/jnode/net/command/BootpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/BootpCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/net/src/net/org/jnode/net/command/BootpCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -21,9 +21,6 @@
package org.jnode.net.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import javax.naming.NameNotFoundException;
import org.jnode.driver.Device;
@@ -32,7 +29,6 @@
import org.jnode.naming.InitialNaming;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
@@ -53,10 +49,9 @@
new BootpCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws NameNotFoundException, NetworkException {
+ public void execute() throws NameNotFoundException, NetworkException {
final Device dev = ARG_DEVICE.getValue();
- out.println("Trying to configure " + dev.getId() + "...");
+ getOutput().getPrintWriter().println("Trying to configure " + dev.getId() + "...");
final IPv4ConfigurationService cfg = InitialNaming.lookup(IPv4ConfigurationService.NAME);
cfg.configureDeviceBootp(dev, true);
}
Modified: trunk/net/src/net/org/jnode/net/command/DhcpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/DhcpCommand.java 2008-11-09 03:32:20 UTC (rev 4685)
+++ trunk/net/src/net/org/jnode/net/command/DhcpCommand.java 2008-11-09 08:08:19 UTC (rev 4686)
@@ -21,8 +21,7 @@
package org.jnode.net.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -39,7 +38,6 @@
import org.jnode.net.ethernet.EthernetConstants;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
@@ -61,8 +59,7 @@
new DhcpCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws DeviceNotFoundException, NameNotFoundException, ApiNotFoundException,
+ public void execute() throws DeviceNotFoundException, NameNotFoundException, ApiNotFoundException,
UnknownHostException, NetworkException {
final Device dev = ARG_DEVICE.getValue();
@@ -75,13 +72,14 @@
NetDeviceAPI api = loopback.getAPI(NetDeviceAPI.class);
ProtocolAddressInfo info = api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
if (info == null || !info.contains(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}))) {
+ PrintWriter err = getError().getPrintWriter();
err.println("The loopback network device is not bound to IP address 127.0.0.1");
err.println("Run 'ifconfig loopback 127.0.0.1 255.255.255.255' to fix this.");
exit(1);
}
// Now it should be safe to do the DHCP configuration.
- out.println("Configuring network device " + dev.getId() + "...");
+ getOutput().getPrintWriter().println("Configuring network device " + dev.getId() + "...");
final IPv4ConfigurationService cfg = InitialNaming.lookup(IPv4ConfigurationService.NAME);
cfg.configureDeviceDhcp(dev, true);
}
Modified: trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java...
[truncated message content] |
|
From: <cr...@us...> - 2008-11-09 13:23:38
|
Revision: 4692
http://jnode.svn.sourceforge.net/jnode/?rev=4692&view=rev
Author: crawley
Date: 2008-11-09 13:23:28 +0000 (Sun, 09 Nov 2008)
Log Message:
-----------
Converting commands to use execute() and PrintWriter + API ripple.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java
trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java
trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java
trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java
trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java
trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java
trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -21,7 +21,7 @@
package org.jnode.driver.console;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Set;
import org.jnode.driver.input.KeyboardListener;
@@ -151,5 +151,5 @@
*/
public Console createConsole(String name, int options);
- public void printConsoles(PrintStream ps);
+ public void printConsoles(PrintWriter pw);
}
Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -23,7 +23,7 @@
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -35,7 +35,9 @@
import java.util.Map;
import java.util.Set;
import java.util.Stack;
+
import javax.naming.NameNotFoundException;
+
import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
@@ -215,19 +217,19 @@
}
}
- public void printConsoles(PrintStream ps) {
+ public void printConsoles(PrintWriter pw) {
ArrayList<Integer> list = new ArrayList<Integer>();
list.addAll(stackMap.keySet());
Collections.sort(list);
for (Integer key : list) {
- ps.println("Screen of " + KeyEvent.getKeyText(key) + ":");
+ pw.println("Screen of " + KeyEvent.getKeyText(key) + ":");
Stack<Console> stack = stackMap.get(key);
int t_ind = stack.size();
for (int i = t_ind; i-- > 0;) {
Console console = stack.get(i);
String prefix = console == current ? " > " :
i == t_ind - 1 ? " * " : " ";
- ps.println(prefix + console.getConsoleName());
+ pw.println(prefix + console.getConsoleName());
}
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/shell/src/shell/org/jnode/shell/command/bsh/BshCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -28,7 +28,6 @@
import java.io.PrintStream;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -58,12 +57,13 @@
new BshCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
Interpreter bsh = null;
Object ret;
boolean interactive = false;
-
+ InputStream in = getInput().getInputStream();
+ OutputStream out = getOutput().getOutputStream();
+ OutputStream err = getError().getOutputStream();
if (FLAG_INTERACTIVE.isSet()) {
bsh = createInterpreter(in, out, err, true);
interactive = true;
@@ -77,7 +77,7 @@
ret = bsh.eval(code);
if (ret != null) {
- out.println(ret);
+ out.write((ret + "\n").getBytes());
}
}
@@ -90,9 +90,10 @@
ret = bsh.source(file);
if (ret != null) {
- out.println(ret);
+ out.write((ret + "\n").getBytes());
}
}
+ out.flush();
if (bsh == null) {
// If no arguments were given, default to interactive mode.
Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/shell/src/shell/org/jnode/shell/command/debug/DebugCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -6,11 +6,10 @@
import gnu.classpath.jdwp.JNodeSocketTransport;
import gnu.classpath.jdwp.Jdwp;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Reader;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.IntegerArgument;
@@ -35,8 +34,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT;
// FIXME - in the even of internal exceptions, JDWP writes to System.out.
@@ -56,6 +54,8 @@
});
t.start();
+ Reader in = getInput().getReader();
+ PrintWriter out = getOutput().getPrintWriter();
while (in.read() != 'q') {
out.println("Type 'q' to exit");
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/shell/src/shell/org/jnode/shell/command/debug/RemoteOutputCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -22,10 +22,9 @@
package org.jnode.shell.command.debug;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.io.Writer;
import java.net.ConnectException;
import java.net.InetAddress;
@@ -39,7 +38,6 @@
import org.jnode.debug.RemoteReceiver;
import org.jnode.debug.UDPOutputStream;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.ShellUtils;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
@@ -68,9 +66,8 @@
registerArguments(ARG_ADDRESS, ARG_PORT, FLAG_UDP);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ PrintWriter err = getError().getPrintWriter();
try {
final int port = ARG_PORT.isSet() ? ARG_PORT.getValue() : DEFAULT_PORT;
final InetAddress addr = ARG_ADDRESS.getAsInetAddress();
Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ClearConsoleCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -21,12 +21,8 @@
package org.jnode.shell.command.driver.console;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.driver.console.TextConsole;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.Shell;
import org.jnode.shell.ShellUtils;
@@ -51,8 +47,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
final Shell shell = ShellUtils.getCurrentShell();
TextConsole tc = (TextConsole) shell.getConsole();
tc.clear();
Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2008-11-09 12:24:49 UTC (rev 4691)
+++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
@@ -21,7 +21,7 @@
package org.jnode.shell.command.driver.console;
-import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -33,7 +33,6 @@
import org.jnode.driver.console.TextConsole;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.CommandShell;
import org.jnode.shell.ShellException;
import org.jnode.shell.ShellManager;
@@ -73,9 +72,8 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws NameNotFoundException, IsolateStartupException, ShellException {
-
+ public void execute() throws NameNotFoundException, IsolateStartupException, ShellException {
+ final PrintWriter out = getOutput().getPrintWriter();
final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();
@@ -120,7 +118,8 @@
try {
final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();
- TextConsole console = createConsoleWithShell(conMgr, System.out);
+ final PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
+ TextConsole console = createConsoleWithShell(conMgr, out);
System.setIn(new ReaderInputStream(console.getIn()));
System.setOut(new PrintStream(new WriterOutputStream(console.getOut()), true));
System.setErr(new PrintStream(new WriterOutputStream(console.getErr()), true));
@@ -132,7 +131,7 @@
}
}
- private static TextConsole createConsoleWithShell(final ConsoleManager conMgr, PrintStream out)
+ private static TextConsole createConsoleWithShell(final ConsoleManager conMgr, PrintWriter out)
throws ShellException {
final TextConsole console = (TextConsole) conMgr.createConsole(null,
ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-09 13:57:39
|
Revision: 4693
http://jnode.svn.sourceforge.net/jnode/?rev=4693&view=rev
Author: crawley
Date: 2008-11-09 13:57:29 +0000 (Sun, 09 Nov 2008)
Log Message:
-----------
Changing commands to use 'execute()' and PrintWriters + API ripple
Modified Paths:
--------------
trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java
trunk/core/src/core/org/jnode/vm/Vm.java
trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java
trunk/core/src/core/org/jnode/vm/classmgr/VmStaticsAllocator.java
trunk/core/src/core/org/jnode/vm/memmgr/VmHeapManager.java
trunk/core/src/core/org/jnode/vm/memmgr/def/DefaultHeapManager.java
trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java
trunk/core/src/core/org/jnode/vm/x86/VmX86Processor.java
trunk/core/src/mmtk-vm/org/jnode/vm/memmgr/mmtk/BaseMmtkHeapManager.java
trunk/gui/src/driver/org/jnode/driver/video/vesa/VESACommand.java
trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java
trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java
trunk/shell/src/shell/org/jnode/shell/command/driver/system/bus/SMBusCommand.java
trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java
trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java
trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java
trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java
trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java
trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java
trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java
trunk/shell/src/shell/org/jnode/shell/command/system/VmInfoCommand.java
trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java
Modified: trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java
===================================================================
--- trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -25,6 +25,7 @@
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.net.URL;
@@ -40,11 +41,12 @@
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
+
import org.apache.tools.ant.Project;
import org.jnode.assembler.Label;
import org.jnode.assembler.NativeStream;
+import org.jnode.assembler.UnresolvedObjectRefException;
import org.jnode.assembler.NativeStream.ObjectRef;
-import org.jnode.assembler.UnresolvedObjectRefException;
import org.jnode.assembler.x86.X86BinaryAssembler;
import org.jnode.plugin.PluginDescriptor;
import org.jnode.plugin.PluginException;
@@ -626,10 +628,11 @@
log("Boot heap size " + (bootHeapSize >>> 10) + "K bitmap size "
+ (bootHeapBitmapSize >>> 10) + "K");
log("Shared statics");
- clsMgr.getSharedStatics().dumpStatistics(System.out);
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
+ clsMgr.getSharedStatics().dumpStatistics(out);
log("Isolated statics");
- clsMgr.getIsolatedStatics().dumpStatistics(System.out);
- vm.dumpStatistics(System.out);
+ clsMgr.getIsolatedStatics().dumpStatistics(out);
+ vm.dumpStatistics(out);
logStatistics(os);
Modified: trunk/core/src/core/org/jnode/vm/Vm.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/Vm.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/Vm.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@@ -411,7 +411,7 @@
}
}
- public void dumpStatistics(PrintStream out) {
+ public void dumpStatistics(PrintWriter out) {
if (statistics != null) {
final Statistic[] stats = getStatistics();
for (int i = 0; i < stats.length; i++) {
Modified: trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.classmgr;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.nio.ByteOrder;
import org.jnode.assembler.Label;
@@ -365,7 +365,7 @@
return true;
}
- public final void dumpStatistics(PrintStream out) {
+ public final void dumpStatistics(PrintWriter out) {
allocator.dumpStatistics(out);
}
Modified: trunk/core/src/core/org/jnode/vm/classmgr/VmStaticsAllocator.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/classmgr/VmStaticsAllocator.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/classmgr/VmStaticsAllocator.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.classmgr;
-import java.io.PrintStream;
+import java.io.PrintWriter;
/**
* @author Ewout Prangsma (ep...@us...)
@@ -95,7 +95,7 @@
return types.length;
}
- public final void dumpStatistics(PrintStream out) {
+ public final void dumpStatistics(PrintWriter out) {
out.println(" #static int fields " + typeCounter[TYPE_INT]);
out.println(" #static long fields " + typeCounter[TYPE_LONG]);
out.println(" #methods " + typeCounter[TYPE_METHOD_CODE]);
Modified: trunk/core/src/core/org/jnode/vm/memmgr/VmHeapManager.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/memmgr/VmHeapManager.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/memmgr/VmHeapManager.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.memmgr;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.vm.Unsafe;
import org.jnode.vm.VmMagic;
@@ -333,7 +333,7 @@
/**
* Print the statics on this object on out.
*/
- public abstract void dumpStatistics(PrintStream out);
+ public abstract void dumpStatistics(PrintWriter out);
public abstract GCStatistics getStatistics();
Modified: trunk/core/src/core/org/jnode/vm/memmgr/def/DefaultHeapManager.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/memmgr/def/DefaultHeapManager.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/memmgr/def/DefaultHeapManager.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.memmgr.def;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.vm.MemoryBlockManager;
import org.jnode.vm.VmArchitecture;
@@ -408,7 +408,7 @@
/**
* Print the statics on this object on out.
*/
- public void dumpStatistics(PrintStream out) {
+ public void dumpStatistics(PrintWriter out) {
out.println("WriteBarrier: " + getWriteBarrier());
}
Modified: trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.scheduler;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.util.NumberUtils;
import org.jnode.vm.CpuID;
@@ -655,7 +655,7 @@
*
* @param out
*/
- public abstract void dumpStatistics(PrintStream out);
+ public abstract void dumpStatistics(PrintWriter out);
/**
* Gets the isolates statics table of the current thread.
Modified: trunk/core/src/core/org/jnode/vm/x86/VmX86Processor.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/x86/VmX86Processor.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/core/org/jnode/vm/x86/VmX86Processor.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.x86;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.system.BootLog;
import org.jnode.system.ResourceManager;
@@ -387,7 +387,7 @@
return perfCounters;
}
- public void dumpStatistics(PrintStream out) {
+ public void dumpStatistics(PrintWriter out) {
out.println("Type : " + (bootProcessor ? "BSP" : (logical ? "AP-logical" : "AP")));
out.println("CPUID : " + getCPUID());
out.println("fxSave/Res : " + fxSaveCounter + "/" + fxRestoreCounter
Modified: trunk/core/src/mmtk-vm/org/jnode/vm/memmgr/mmtk/BaseMmtkHeapManager.java
===================================================================
--- trunk/core/src/mmtk-vm/org/jnode/vm/memmgr/mmtk/BaseMmtkHeapManager.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/core/src/mmtk-vm/org/jnode/vm/memmgr/mmtk/BaseMmtkHeapManager.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,7 +21,7 @@
package org.jnode.vm.memmgr.mmtk;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -178,17 +178,15 @@
/**
* @see org.jnode.vm.memmgr.VmHeapManager#dumpStatistics(java.io.PrintStream)
*/
- public void dumpStatistics(PrintStream out) {
- // TODO Auto-generated method stub
-
+ public void dumpStatistics(PrintWriter out) {
+ // Default behavior is to do nothing
}
/**
* @see org.jnode.vm.memmgr.VmHeapManager#gc()
*/
public void gc() {
- // TODO Auto-generated method stub
-
+ // Default behavior is to do nothing
}
/**
Modified: trunk/gui/src/driver/org/jnode/driver/video/vesa/VESACommand.java
===================================================================
--- trunk/gui/src/driver/org/jnode/driver/video/vesa/VESACommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/gui/src/driver/org/jnode/driver/video/vesa/VESACommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -1,5 +1,7 @@
package org.jnode.driver.video.vesa;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
import java.nio.ByteBuffer;
import javax.naming.NameNotFoundException;
@@ -115,7 +117,8 @@
biosMemory.position(pos);
}
- VmProcessor.current().dumpStatistics(System.out);
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
+ VmProcessor.current().dumpStatistics(out);
System.out.println("after dumpStatistics");
if (pmInfoBlock != null) {
System.out.println("step4");
Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/driver/DeviceCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,8 +21,6 @@
package org.jnode.shell.command.driver;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.TreeMap;
@@ -37,7 +35,6 @@
import org.jnode.driver.DriverException;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
import org.jnode.shell.syntax.EnumArgument;
@@ -77,8 +74,9 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
if (ARG_ACTION.isSet()) {
if (!ARG_DEVICE.isSet()) {
err.println("No target device specified");
@@ -153,7 +151,7 @@
* @param out
* @param dev
*/
- protected void showDevice(PrintStream out, Device dev) {
+ protected void showDevice(PrintWriter out, Device dev) {
final String prefix = " ";
out.println("Device: " + dev.getId());
final String drvClassName = dev.getDriverClassName();
@@ -192,7 +190,7 @@
* @param out
* @throws NameNotFoundException
*/
- protected void showDevices(PrintStream out) throws NameNotFoundException {
+ protected void showDevices(PrintWriter out) throws NameNotFoundException {
// Create a sorted list
final TreeMap<String, Device> tm = new TreeMap<String, Device>();
final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/driver/system/acpi/AcpiCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,8 +21,6 @@
package org.jnode.shell.command.driver.system.acpi;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Collection;
@@ -31,7 +29,6 @@
import org.jnode.driver.DeviceUtils;
import org.jnode.driver.system.acpi.AcpiAPI;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
@@ -60,9 +57,9 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws ApiNotFoundException {
+ public void execute() throws ApiNotFoundException {
final Collection<Device> acpiDevs = DeviceUtils.getDevicesByAPI(AcpiAPI.class);
+ PrintWriter out = getOutput().getPrintWriter();
if (acpiDevs.isEmpty()) {
out.println("No ACPI devices are registered");
exit(1);
Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/system/bus/SMBusCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/driver/system/bus/SMBusCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/driver/system/bus/SMBusCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -22,15 +22,13 @@
package org.jnode.shell.command.driver.system.bus;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import javax.naming.NameNotFoundException;
import org.jnode.driver.bus.smbus.SMBusControler;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
/**
* @author Francois-Frederic Ozog
@@ -46,10 +44,9 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
SMBusControler smbusctrl = null;
-
+ PrintWriter out = getOutput().getPrintWriter();
try {
smbusctrl = InitialNaming.lookup(SMBusControler.NAME);
} catch (NameNotFoundException ex) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -24,8 +24,6 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
@@ -35,7 +33,6 @@
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -81,8 +78,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws IOException {
+ public void execute() throws IOException {
if (ARG_FILE.isSet()) {
// Set configuration from a file
final File configFile = ARG_FILE.getValue();
@@ -93,7 +89,7 @@
props.load(fis);
PropertyConfigurator.configure(props);
} catch (FileNotFoundException ex) {
- err.println("Cannot open configuration file '" +
+ getError().getPrintWriter().println("Cannot open configuration file '" +
configFile + "': " + ex.getMessage());
exit(1);
} finally {
@@ -114,7 +110,7 @@
String level = (logger.getLevel() == null) ?
("(" + logger.getEffectiveLevel().toString() + ")") :
logger.getLevel().toString();
- out.println(logger.getName() + ": " + level);
+ getOutput().getPrintWriter().println(logger.getName() + ": " + level);
}
} else if (FLAG_SET_LEVEL.isSet()) {
// Change the logging level for a specified logger or the root logger
Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/plugin/HaltCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,11 +21,7 @@
package org.jnode.shell.command.plugin;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.vm.VmSystem;
/**
@@ -44,8 +40,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
VmSystem.halt(false);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,8 +21,7 @@
package org.jnode.shell.command.plugin;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
@@ -42,7 +41,6 @@
import org.jnode.plugin.PluginRegistry;
import org.jnode.plugin.URLPluginLoader;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.shell.syntax.PluginArgument;
@@ -74,7 +72,7 @@
private final StringArgument ARG_VERSION =
new StringArgument("version", Argument.OPTIONAL, "plugin version");
- private PrintStream out;
+ private PrintWriter out;
private PluginManager mgr;
@@ -91,9 +89,8 @@
/**
* Execute this command
*/
- public void execute(CommandLine commandLine, InputStream in, PrintStream out,
- PrintStream err) throws Exception {
- this.out = out;
+ public void execute() throws Exception {
+ this.out = getOutput().getPrintWriter();
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {
Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/plugin/RebootCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,11 +21,7 @@
package org.jnode.shell.command.plugin;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.vm.VmSystem;
/**
@@ -42,8 +38,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
VmSystem.halt(true);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/system/CpuIDCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,11 +21,9 @@
package org.jnode.shell.command.system;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.vm.scheduler.VmProcessor;
/**
@@ -44,10 +42,10 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err) {
+ public void execute() {
final VmProcessor cpu = VmProcessor.current();
+ PrintWriter out = getOutput().getPrintWriter();
out.println(cpu.getCPUID());
out.println(cpu.getPerformanceCounters());
}
-
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/system/KdbCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -18,14 +18,11 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
package org.jnode.shell.command.system;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.vm.Unsafe;
@@ -55,8 +52,8 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
+ PrintWriter out = getOutput().getPrintWriter();
if (FLAG_OFF.isSet()) {
Unsafe.setKdbEnabled(false);
out.println("KDB disabled");
Modified: trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/system/LsIRQCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,11 +21,7 @@
package org.jnode.shell.command.system;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.vm.scheduler.IRQManager;
import org.jnode.vm.scheduler.VmProcessor;
@@ -43,13 +39,12 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
final VmProcessor proc = VmProcessor.current();
final IRQManager irqMgr = proc.getIRQManager();
final int max = irqMgr.getNumIRQs();
for (int i = 0; i < max; i++) {
- out.println("IRQ" + i + "\t" + irqMgr.getIrqCount(i) + "\t"
+ getOutput().getPrintWriter().println("IRQ" + i + "\t" + irqMgr.getIrqCount(i) + "\t"
+ irqMgr.getHandlerInfo(i));
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/system/VmInfoCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/system/VmInfoCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/system/VmInfoCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -21,12 +21,10 @@
package org.jnode.shell.command.system;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.List;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.vm.Vm;
@@ -51,10 +49,10 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
final Vm vm = Vm.getVm();
if (vm != null && !vm.isBootstrap()) {
+ PrintWriter out = getOutput().getPrintWriter();
out.println("JNode VM " + vm.getVersion());
vm.dumpStatistics(out);
vm.getSharedStatics().dumpStatistics(out);
Modified: trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-11-09 13:23:28 UTC (rev 4692)
+++ trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
@@ -22,8 +22,8 @@
package org.jnode.shell.command.unix;
import java.io.File;
-import java.io.InputStream;
import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Stack;
@@ -50,8 +50,7 @@
this.kind = kind;
}
}
-
- private PrintStream err;
+
private boolean bracketted;
private int pos;
private String[] args;
@@ -117,9 +116,10 @@
OPERATOR_MAP.put(")", new Operator(OP_RPAREN, 6, OP_SPECIAL));
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ public void execute()
throws Exception {
boolean res = false;
+ CommandLine commandLine = getCommandLine();
String commandName = commandLine.getCommandName();
bracketted = (commandName != null && commandName.equals("["));
args = commandLine.getArguments();
@@ -156,7 +156,7 @@
exit(1);
}
} catch (SyntaxErrorException ex) {
- err.println(ex.getMessage());
+ getError().getPrintWriter().println(ex.getMessage());
exit(2);
}
}
@@ -324,6 +324,7 @@
}
private void processAsOptions(String[] args) throws SyntaxErrorException {
+ PrintWriter err = getError().getPrintWriter();
for (String option : args) {
if (option.equals("--help")) {
err.println("Don't panic!");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-09 14:20:37
|
Revision: 4694
http://jnode.svn.sourceforge.net/jnode/?rev=4694&view=rev
Author: crawley
Date: 2008-11-09 14:20:31 +0000 (Sun, 09 Nov 2008)
Log Message:
-----------
Changing commands to use 'execute()' and PrintWriter were appropriate
Modified Paths:
--------------
trunk/all/conf/x86/menu-cdrom.lst
trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java
trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java
trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java
trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java
trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java
trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java
trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java
trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java
trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java
trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java
trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java
trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java
trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java
trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java
trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java
trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java
Modified: trunk/all/conf/x86/menu-cdrom.lst
===================================================================
(Binary files differ)
Modified: trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,13 +21,11 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Map;
import java.util.TreeMap;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.ShellUtils;
import org.jnode.shell.alias.AliasManager;
import org.jnode.shell.alias.NoSuchAliasException;
@@ -63,8 +61,7 @@
new AliasCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
final AliasManager aliasMgr = ShellUtils.getCurrentAliasManager();
if (ARG_REMOVE.isSet()) {
@@ -86,11 +83,11 @@
aliasMgr.add(ARG_ALIAS.getValue(), className);
} else {
// list the aliases
- showAliases(aliasMgr, out);
+ showAliases(aliasMgr, getOutput().getPrintWriter());
}
}
- private void showAliases(AliasManager aliasMgr, PrintStream out) throws NoSuchAliasException {
+ private void showAliases(AliasManager aliasMgr, PrintWriter out) throws NoSuchAliasException {
final TreeMap<String, String> map = new TreeMap<String, String>();
for (String alias : aliasMgr.aliases()) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/ClassCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,13 +21,11 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
import org.jnode.vm.classmgr.VmArrayClass;
@@ -49,15 +47,14 @@
registerArguments(ARG_CLASS);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
String className = ARG_CLASS.getValue();
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
final Class<?> type = cl.loadClass(className);
- showClass(type, out);
+ showClass(type, getOutput().getPrintWriter());
} catch (ClassNotFoundException ex) {
- err.println("Cannot find the requested class: " + className);
+ getError().getPrintWriter().println("Cannot find the requested class: " + className);
exit(1);
}
}
@@ -66,7 +63,7 @@
new ClassCommand().execute(args);
}
- private void showClass(final Class<?> type, final PrintStream out) {
+ private void showClass(final Class<?> type, final PrintWriter out) {
final VmType<?> vmType = AccessController.doPrivileged(
new PrivilegedAction<VmType<?>>() {
public VmType<?> run() {
Modified: trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,13 +21,11 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.net.URL;
import java.net.URLClassLoader;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.shell.syntax.URLArgument;
@@ -58,8 +56,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
if (ARG_ADD.isSet()) {
addToClassPath(ARG_ADD.getValue());
} else if (ARG_CLEAR.isSet()) {
@@ -67,7 +64,7 @@
} else if (ARG_REFRESH.isSet()) {
refreshClassPath();
} else {
- printClassPath(out);
+ printClassPath(getOutput().getPrintWriter());
}
}
@@ -101,7 +98,7 @@
}
}
- private void printClassPath(PrintStream out) {
+ private void printClassPath(PrintWriter out) {
getClassLoader().print(out);
}
@@ -128,7 +125,7 @@
addURL(url);
}
- public void print(PrintStream out) {
+ public void print(PrintWriter out) {
URL[] urls = getURLs();
for (int i = 0; i < urls.length; i++) {
out.println(urls[i]);
Modified: trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/CompileCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -61,12 +59,12 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
final String className = ARG_CLASS.getValue();
final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0;
final boolean test = ARG_TEST.isSet();
-
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
if (test) {
if (maxTestLevel == -1) {
err.println("No test compilers are currently registered");
Modified: trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/DateCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,12 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.util.Date;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
/**
* A shell command to access the display the system date.
@@ -40,9 +37,8 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
- out.println(new Date());
+ public void execute() throws Exception {
+ getOutput().getPrintWriter().println(new Date());
}
/**
Modified: trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/DisassembleCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,12 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -65,8 +62,9 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
+ final PrintWriter out = getOutput().getPrintWriter();
+ final PrintWriter err = getError().getPrintWriter();
final String className = ARG_CLASS.getValue();
final String methodName = ARG_METHOD.isSet() ? ARG_METHOD.getValue() : null;
final int level = ARG_LEVEL.isSet() ? ARG_LEVEL.getValue() : 0;
@@ -96,7 +94,7 @@
exit(1);
}
final long start = System.currentTimeMillis();
- final int count = type.disassemble(methodName, level, test, new OutputStreamWriter(out));
+ final int count = type.disassemble(methodName, level, test, out);
final long end = System.currentTimeMillis();
out.println("Disassembling " + count + " methods took " + (end - start) + "ms");
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.StringArgument;
@@ -37,7 +35,8 @@
*/
public class EchoCommand extends AbstractCommand {
- private final StringArgument ARG_WORDS = new StringArgument("text", Argument.MULTIPLE, "the text to be printed");
+ private final StringArgument ARG_WORDS =
+ new StringArgument("text", Argument.MULTIPLE, "the text to be printed");
public EchoCommand() {
super("Print the argument text to standard output");
@@ -51,8 +50,8 @@
/**
* Execute the command
*/
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ final PrintWriter out = getOutput().getPrintWriter();
String[] words = ARG_WORDS.getValues();
for (int i = 0; i < words.length; i++) {
if (i > 0) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -23,15 +23,13 @@
import gnu.java.security.action.GetPropertiesAction;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.security.AccessController;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
/**
* @author epr
@@ -49,14 +47,13 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
final Properties ps = (Properties) AccessController.doPrivileged(new GetPropertiesAction());
final TreeMap<Object, Object> sortedPs = new TreeMap<Object, Object>(ps);
+ final PrintWriter out = getOutput().getPrintWriter();
for (Map.Entry<Object, Object> entry : sortedPs.entrySet()) {
final String key = entry.getKey().toString();
final String value = entry.getValue().toString();
-
out.println(key + '=' + value);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/ExitCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -1,11 +1,7 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.CommandShell;
import org.jnode.shell.ShellManager;
@@ -25,8 +21,7 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine,
- InputStream in, PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
((CommandShell) sm.getCurrentShell()).exit();
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
@@ -86,8 +87,8 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ final PrintWriter out = getOutput().getPrintWriter();
if (ARG_SET.isSet()) {
Vm.getHeapManager().setHeapFlags(getFlags());
} else if (ARG_CLEAR.isSet()) {
@@ -114,7 +115,7 @@
}
}
- private void showFlags(int flags, PrintStream out) {
+ private void showFlags(int flags, PrintWriter out) {
StringBuilder sb = new StringBuilder();
for (int flagBitMask = 1; flagBitMask != 0; flagBitMask = flagBitMask << 1) {
if ((flags & flagBitMask) != 0) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,14 +21,11 @@
package org.jnode.shell.command;
import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.shell.syntax.StringArgument;
@@ -63,8 +60,7 @@
/**
* Primary entry point
*/
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
boolean inverse = FLAG_INVERSE.isSet();
boolean useRegex = FLAG_REGEX.isSet();
@@ -81,15 +77,16 @@
pattern = Pattern.compile(Pattern.quote(expr));
}
} catch (PatternSyntaxException ex) {
- err.println("Invalid regex: " + ex.getMessage());
+ getError().getPrintWriter().println("Invalid regex: " + ex.getMessage());
exit(2);
}
- final BufferedReader r = new BufferedReader(new InputStreamReader(in));
+ final BufferedReader r = new BufferedReader(getInput().getReader());
// Read the input a line at a time, searching each line for the expression.
boolean found = false;
String line;
+ PrintWriter out = getOutput().getPrintWriter();
while ((line = r.readLine()) != null) {
if (pattern.matcher(line).find()) {
if (!inverse) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/HistoryCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -20,12 +20,10 @@
*/
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.driver.console.InputHistory;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.Shell;
import org.jnode.shell.ShellUtils;
import org.jnode.shell.syntax.Argument;
@@ -49,8 +47,8 @@
new FlagArgument("test", Argument.OPTIONAL, "If set, don't try to execute the history command");
private Shell shell;
- private PrintStream out;
- private PrintStream err;
+ private PrintWriter out;
+ private PrintWriter err;
private InputHistory history;
@@ -60,12 +58,11 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
shell = ShellUtils.getShellManager().getCurrentShell();
history = shell.getCommandHistory();
- this.out = out;
- this.err = err;
+ this.out = getOutput().getPrintWriter();
+ this.err = getError().getPrintWriter();
int index = ARG_INDEX.isSet() ? ARG_INDEX.getValue() : -1;
String prefix = ARG_PREFIX.isSet() ? ARG_PREFIX.getValue() : null;
Modified: trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/IsolateCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -3,11 +3,10 @@
*/
package org.jnode.shell.command;
+import java.io.PrintWriter;
+
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.vm.isolate.VmIsolate;
-import java.io.InputStream;
-import java.io.PrintStream;
/**
* The IsolateCommand provides information about the current isolates in the system.
@@ -15,8 +14,8 @@
*/
public class IsolateCommand extends AbstractCommand {
@Override
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ final PrintWriter out = getOutput().getPrintWriter();
out.println(" Id " + " Creator " + "State " + "Main class");
VmIsolate root = VmIsolate.getRoot();
if (root != null) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,8 +21,7 @@
package org.jnode.shell.command.test;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Set;
@@ -31,7 +30,6 @@
import org.jnode.driver.console.CompletionInfo;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.CommandSyntaxException;
import org.jnode.shell.syntax.FlagArgument;
@@ -68,10 +66,10 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
TestManager mgr = TestManager.getInstance();
if (FLAG_LIST.isSet()) {
+ PrintWriter out = getOutput().getPrintWriter();
for (Class<? extends Test> test : mgr.getTests()) {
out.print(test.getName() + " :");
for (String category : mgr.getCategories(test)) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -21,15 +21,11 @@
package org.jnode.shell.command.test;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
@@ -56,8 +52,7 @@
*
* @throws ClassNotFoundException
*/
- public void execute(CommandLine cmdLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
try {
Class<?> clazz = ARG_CLASS.getValueAsClass();
TestResult res = new TestRunner().doRun(new TestSuite(clazz));
@@ -65,7 +60,7 @@
exit(1);
}
} catch (ClassNotFoundException ex) {
- err.println("Class not found: " + ex.getMessage());
+ getError().getPrintWriter().println("Class not found: " + ex.getMessage());
exit(2);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-11-09 13:57:29 UTC (rev 4693)
+++ trunk/shell/src/shell/org/jnode/shell/command/unix/UnixTestCommand.java 2008-11-09 14:20:31 UTC (rev 4694)
@@ -22,7 +22,6 @@
package org.jnode.shell.command.unix;
import java.io.File;
-import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Stack;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-10 10:30:21
|
Revision: 4696
http://jnode.svn.sourceforge.net/jnode/?rev=4696&view=rev
Author: crawley
Date: 2008-11-10 10:30:17 +0000 (Mon, 10 Nov 2008)
Log Message:
-----------
More conversion of commands to use 'execute()' and PrintWriter(s)
Modified Paths:
--------------
trunk/gui/src/test/org/jnode/test/gui/FBTest.java
trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java
trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java
trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java
trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java
trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java
trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java
trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java
trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java
trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java
trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java
trunk/shell/src/shell/org/jnode/shell/command/SleepCommand.java
trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java
trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java
trunk/shell/src/test/org/jnode/test/shell/MyAliasCommand.java
trunk/shell/src/test/org/jnode/test/shell/MyCatCommand.java
trunk/shell/src/test/org/jnode/test/shell/MyCompileCommand.java
trunk/shell/src/test/org/jnode/test/shell/MyDirCommand.java
trunk/shell/src/test/org/jnode/test/shell/MyDuhCommand.java
trunk/shell/src/test/org/jnode/test/shell/help/DefaultHelpTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentBundleTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentTypesTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/CommandLineTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/MuParserTest2.java
trunk/shell/src/test/org/jnode/test/shell/syntax/MuSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSetSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/OptionSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/PowersetSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/RepeatedSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/SequenceSyntaxTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/TestAliasManager.java
trunk/shell/src/test/org/jnode/test/shell/syntax/TestSyntaxManager.java
Modified: trunk/gui/src/test/org/jnode/test/gui/FBTest.java
===================================================================
--- trunk/gui/src/test/org/jnode/test/gui/FBTest.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/gui/src/test/org/jnode/test/gui/FBTest.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -109,8 +109,7 @@
new FBTest().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) {
+ public void execute() {
Device dev = ARG_DEVICE.getValue();
count = ARG_LOOPS.isSet() ? ARG_LOOPS.getValue() : 100;
@@ -120,7 +119,7 @@
if (dev == null) {
final Collection<Device> devs = DeviceUtils.getDevicesByAPI(FrameBufferAPI.class);
if (devs.size() == 0) {
- err.println("No framebuffer devices to test");
+ getError().getPrintWriter().println("No framebuffer devices to test");
exit(1);
}
dev = new ArrayList<Device>(devs).get(0);
Modified: trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/GcCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,12 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.EnumArgument;
import org.jnode.shell.syntax.FlagArgument;
Modified: trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/JavaCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -24,8 +24,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -33,7 +32,6 @@
import java.net.URL;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
import org.jnode.shell.syntax.StringArgument;
@@ -66,13 +64,13 @@
/**
* Execute the command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
-
+ public void execute() throws Exception {
+ PrintWriter err = getError().getPrintWriter();
+
// Build our classloader
final ClassLoader parent_cl = Thread.currentThread().getContextClassLoader();
JCClassLoader cl = new JCClassLoader(parent_cl, new String[]{"./"});
-
+
Method mainMethod = null;
String className = ARG_CLASS.getValue();
try {
Modified: trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/KillCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.shell.syntax.IntegerArgument;
@@ -51,8 +49,8 @@
}
@SuppressWarnings("deprecation")
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getError().getPrintWriter();
boolean debug = FLAG_DEBUG.isSet();
int threadId = ARG_THREADID.getValue();
if (debug) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/LoadkeysCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,8 +21,7 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Collection;
import org.jnode.driver.Device;
@@ -33,7 +32,6 @@
import org.jnode.driver.input.KeyboardLayoutManager;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.help.SyntaxErrorException;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
@@ -90,8 +88,9 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out,
- PrintStream err) throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
final KeyboardLayoutManager mgr = InitialNaming.lookup(KeyboardLayoutManager.NAME);
final Collection<Device> kbDevs =
DeviceUtils.getDevicesByAPI(KeyboardAPI.class);
Modified: trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,15 +21,13 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.TreeSet;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.CountryArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -63,8 +61,8 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
if (ARG_LANGUAGE.isSet()) {
final String language = ARG_LANGUAGE.getValue();
@@ -73,7 +71,8 @@
Locale locale = findLocale(language, country, variant);
if (locale == null) {
- err.println("No Locale is available for " + language + " " + country + " " + variant);
+ getError().getPrintWriter().println(
+ "No Locale is available for " + language + " " + country + " " + variant);
exit(1);
}
out.println("Setting default Locale to " + formatLocale(locale));
@@ -90,7 +89,7 @@
*
* @param out destination for the listing
*/
- private void listLocales(PrintStream out) {
+ private void listLocales(PrintWriter out) {
// (The getAvailableLocales() method returns a cloned array ...)
Locale[] locales = Locale.getAvailableLocales();
TreeSet<Locale> treeSet = new TreeSet<Locale>(new Comparator<Locale>() {
Modified: trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/MemoryCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.util.NumberUtils;
/**
@@ -43,8 +41,8 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
final Runtime rt = Runtime.getRuntime();
out.println("Total memory " + NumberUtils.toBinaryByte(rt.totalMemory()));
out.println("Used memory " + NumberUtils.toBinaryByte(rt.totalMemory() - rt.freeMemory()));
Modified: trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/NamespaceCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,13 +21,11 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.Set;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
/**
* @author epr
@@ -45,9 +43,8 @@
/**
* Execute this command
*/
- public void execute(CommandLine cmdLine, InputStream in, PrintStream out,
- PrintStream err) throws Exception {
-
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
Set<Class< ? >> names = InitialNaming.nameSet();
for (Class< ? > name : names) {
out.println(name);
Modified: trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/OnHeapCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.IntegerArgument;
import org.jnode.shell.syntax.LongArgument;
@@ -56,8 +54,8 @@
* Execute this command
*/
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
out.println("on heap:");
final HeapStatistics stats = Vm.getHeapManager().getHeapStatistics();
Modified: trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/RunCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,13 +21,11 @@
package org.jnode.shell.command;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import javax.naming.NameNotFoundException;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.Shell;
import org.jnode.shell.ShellUtils;
import org.jnode.shell.syntax.Argument;
@@ -53,8 +51,8 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
+ final PrintWriter err = getError().getPrintWriter();
final File file = ARG_FILE.getValue();
Shell shell = null;
Modified: trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/SetCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.PropertyNameArgument;
import org.jnode.shell.syntax.StringArgument;
@@ -54,8 +52,8 @@
new SetCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
String key = keyArg.getValue();
if (!valueArg.isSet()) {
out.println("Removing " + key);
Modified: trunk/shell/src/shell/org/jnode/shell/command/SleepCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/SleepCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/SleepCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,7 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.IntegerArgument;
@@ -49,8 +45,7 @@
new SleepCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
Integer seconds = SECONDS_ARG.getValue();
if (seconds > 0) {
Thread.sleep(seconds * 1000);
Modified: trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/SyntaxCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -25,15 +25,11 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
-import java.io.Writer;
+import java.io.PrintWriter;
import java.util.Hashtable;
import org.jnode.nanoxml.XMLElement;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.ShellUtils;
import org.jnode.shell.syntax.AliasArgument;
import org.jnode.shell.syntax.Argument;
@@ -74,8 +70,9 @@
new SyntaxCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
SyntaxManager synMgr = ShellUtils.getCurrentSyntaxManager();
if (ARG_DUMP_ALL.isSet()) {
for (String alias : synMgr.getKeys()) {
@@ -130,7 +127,7 @@
return ARG_ALIAS.getValue();
}
- private void dumpSyntax(String alias, SyntaxBundle bundle, PrintStream out)
+ private void dumpSyntax(String alias, SyntaxBundle bundle, PrintWriter out)
throws IOException {
XMLElement element = new XMLElement(new Hashtable<String, Object>(), false, false);
element.setName("syntax");
@@ -143,9 +140,7 @@
for (Syntax syntax : syntaxes) {
element.addChild(syntax.toXML());
}
- Writer writer = new OutputStreamWriter(out);
- element.write(writer);
- writer.flush();
+ element.write(out);
out.println();
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/shell/org/jnode/shell/command/ThreadCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,9 @@
package org.jnode.shell.command;
-import java.io.InputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
import org.jnode.shell.syntax.ThreadNameArgument;
@@ -61,8 +59,7 @@
/**
* Execute this command
*/
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
// If threadName is null, we'll print all threads
String threadName = (ARG_NAME.isSet()) ? ARG_NAME.getValue() : null;
boolean dump = FLAG_GROUP_DUMP.isSet();
@@ -74,11 +71,13 @@
}
if (dump) {
- // Produce an ugly (but useful) ThreadGroup dump
+ // Produce an ugly (but useful) ThreadGroup dump. Unfortunately,
+ // it goes to System.out, and we cannot fix it w/o changing a Java
+ // standard API.
grp.list();
} else {
// Show the threads in the ThreadGroup tree.
- showThreads(grp, out, threadName);
+ showThreads(grp, getOutput().getPrintWriter(), threadName);
}
}
@@ -91,7 +90,7 @@
* @param out the destination for output
* @param threadName if non-null, only display this thread.
*/
- private void showThreads(ThreadGroup grp, PrintStream out, String threadName) {
+ private void showThreads(ThreadGroup grp, PrintWriter out, String threadName) {
if (threadName == null) {
out.println(GROUP + grp.getName());
}
Modified: trunk/shell/src/test/org/jnode/test/shell/MyAliasCommand.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/MyAliasCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/MyAliasCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,7 @@
package org.jnode.test.shell;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.AliasArgument;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
@@ -47,7 +43,6 @@
registerArguments(ARG_ALIAS, ARG_CLASS, ARG_REMOVE);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
}
}
Modified: trunk/shell/src/test/org/jnode/test/shell/MyCatCommand.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/MyCatCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/MyCatCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,7 @@
package org.jnode.test.shell;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.help.Help;
import org.jnode.shell.help.Parameter;
import org.jnode.shell.help.Syntax;
@@ -61,8 +57,7 @@
});
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
}
}
Modified: trunk/shell/src/test/org/jnode/test/shell/MyCompileCommand.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/MyCompileCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/MyCompileCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -1,10 +1,6 @@
package org.jnode.test.shell;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ClassNameArgument;
import org.jnode.shell.syntax.FlagArgument;
@@ -27,9 +23,7 @@
}
@Override
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
// nothing to see here, move along
}
Modified: trunk/shell/src/test/org/jnode/test/shell/MyDirCommand.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/MyDirCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/MyDirCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,7 @@
package org.jnode.test.shell;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.help.Help;
import org.jnode.shell.help.Parameter;
import org.jnode.shell.help.argument.FileArgument;
@@ -42,7 +38,7 @@
"List the entries of the given path",
new Parameter[]{new Parameter(ARG_PATH, Parameter.OPTIONAL)});
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ // suddenly ... nothing happened
}
}
Modified: trunk/shell/src/test/org/jnode/test/shell/MyDuhCommand.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/MyDuhCommand.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/MyDuhCommand.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,11 +21,7 @@
package org.jnode.test.shell;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
@@ -41,7 +37,7 @@
registerArguments(ARG_PATH);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
- throws Exception {
+ public void execute() throws Exception {
+ // Well duh ...
}
}
Modified: trunk/shell/src/test/org/jnode/test/shell/help/DefaultHelpTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/help/DefaultHelpTest.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/help/DefaultHelpTest.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -24,6 +24,7 @@
import java.io.PrintWriter;
import junit.framework.TestCase;
+
import org.jnode.shell.help.def.DefaultHelp;
/**
Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/syntax/AlternativesSyntaxTest.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,9 +21,8 @@
package org.jnode.test.shell.syntax;
-import java.io.InputStream;
-import java.io.PrintStream;
import junit.framework.TestCase;
+
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.Command;
import org.jnode.shell.CommandInfo;
@@ -52,8 +51,7 @@
registerArguments(fileArg, intArg, flagArg);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
+ public void execute() throws Exception {
}
}
Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentBundleTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentBundleTest.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentBundleTest.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -22,7 +22,9 @@
package org.jnode.test.shell.syntax;
import java.io.File;
+
import junit.framework.TestCase;
+
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.ArgumentBundle;
import org.jnode.shell.syntax.FileArgument;
Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java 2008-11-10 10:12:31 UTC (rev 4695)
+++ trunk/shell/src/test/org/jnode/test/shell/syntax/ArgumentMultiplicityTest.java 2008-11-10 10:30:17 UTC (rev 4696)
@@ -21,9 +21,8 @@
package org.jnode.test.shell.syntax;
-import java.io.InputStream;
-import java.io.PrintStream;
import junit.framework.TestCase;
+
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.Command;
import org.jnode.shell.CommandInfo;
@@ -44,9 +43,8 @@
registerArguments(arg);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
- out.print(arg.getValue());
+ public void execute() throws Exception {
+ getOutput().getPrintWriter().print(arg.getValue());
}
}
@@ -57,9 +55,8 @@
registerArguments(arg);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
- out.print(arg.getValue());
+ public void execute() throws Exception {
+ getOutput().getPrintWriter().print(arg.getValue());
}
}
@@ -71,9 +68,8 @@
registerArguments(arg);
}
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
- out.print(arg.getValue());
+ public void execute() throws Exception {
+ getOutput().getPrintWriter().print(arg.getValue());
}
}
@@ -85,9 +81,8 @@
registerArguments(arg);
}
- public v...
[truncated message content] |
|
From: <fd...@us...> - 2008-11-11 06:57:03
|
Revision: 4699
http://jnode.svn.sourceforge.net/jnode/?rev=4699&view=rev
Author: fduminy
Date: 2008-11-11 06:56:52 +0000 (Tue, 11 Nov 2008)
Log Message:
-----------
added junit 4 to classpath of JNode-Core
Modified Paths:
--------------
trunk/all/build.xml
trunk/core/.classpath
trunk/core/build.xml
Modified: trunk/all/build.xml
===================================================================
--- trunk/all/build.xml 2008-11-10 22:09:27 UTC (rev 4698)
+++ trunk/all/build.xml 2008-11-11 06:56:52 UTC (rev 4699)
@@ -80,6 +80,7 @@
<property name="asm-util.jar" value="${root.dir}/core/lib/asm-util-1.5.3.jar"/>
<property name="jcfe.jar" value="${root.dir}/core/lib/jcfe.jar"/>
<property name="jfunc.jar" value="${root.dir}/core/lib/jfunc.jar"/>
+ <property name="junit4.jar" value="${root.dir}/distr/lib/junit-4.1.jar"/>
<property name="log4j.jar" value="${root.dir}/core/lib/log4j-1.2.8.jar"/>
<property name="gnu-crypto.jar" value="${root.dir}/core/lib/gnu-crypto.jar"/>
Modified: trunk/core/.classpath
===================================================================
--- trunk/core/.classpath 2008-11-10 22:09:27 UTC (rev 4698)
+++ trunk/core/.classpath 2008-11-11 06:56:52 UTC (rev 4699)
@@ -29,5 +29,6 @@
<classpathentry exported="true" kind="lib" path="lib/asm-attrs-1.5.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-util-1.5.3.jar"/>
<classpathentry kind="lib" path="lib/mauve.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml 2008-11-10 22:09:27 UTC (rev 4698)
+++ trunk/core/build.xml 2008-11-11 06:56:52 UTC (rev 4699)
@@ -13,6 +13,7 @@
<!-- Subproject specific classpath -->
<path id="my-cp">
<path refid="cp"/>
+ <pathelement location="${junit4.jar}"/>
<pathelement location="${mmtk.jar}"/>
<pathelement location="${mauve.jar}"/>
</path>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-11-12 13:47:21
|
Revision: 4702
http://jnode.svn.sourceforge.net/jnode/?rev=4702&view=rev
Author: crawley
Date: 2008-11-12 13:47:18 +0000 (Wed, 12 Nov 2008)
Log Message:
-----------
This implements the input and shell-side parts of a "command help" keyboard
action: typing ESC at a partial command line will print help for the command.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java
trunk/shell/src/shell/org/jnode/shell/CommandLine.java
trunk/shell/src/shell/org/jnode/shell/CommandShell.java
trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java
trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
Modified: trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/core/src/driver/org/jnode/driver/console/InputCompleter.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -20,6 +20,8 @@
*/
package org.jnode.driver.console;
+import java.io.PrintWriter;
+
/**
* This interface is implemented by objects registered with a Console as
* input completers.
@@ -34,7 +36,16 @@
* @param partial the partial input line.
* @return a CompletionInfo that contains the possible completions.
*/
- CompletionInfo complete(String partial);
+ public CompletionInfo complete(String partial);
+
+ /**
+ * Show incremental syntax help for the supplied partial input line.
+ *
+ * @param partial the partial input line.
+ * @param out the PrintWriter that help information should be written to.
+ * @return <code>true</code> if any help information was written.
+ */
+ public boolean help(String partial, PrintWriter out);
/**
* Gets the completer's current InputHistory object. If the completer is modal,
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -63,6 +63,8 @@
res.setVKAction(KeyEvent.VK_TAB, 0, KeyboardReaderAction.KR_COMPLETE);
res.setVKAction(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_COMPLETE);
res.setCharAction('\t', KeyboardReaderAction.KR_COMPLETE);
+ res.setVKAction(KeyEvent.VK_ESCAPE, 0, KeyboardReaderAction.KR_HELP);
+ res.setVKAction(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_HELP);
res.setVKAction(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_SOFT_EOF);
res.setCharAction('\004', KeyboardReaderAction.KR_SOFT_EOF);
res.setVKAction(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK, KeyboardReaderAction.KR_KILL_LINE);
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -21,6 +21,7 @@
package org.jnode.driver.console.textscreen;
import java.awt.event.KeyEvent;
+import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
@@ -187,13 +188,23 @@
case KR_COMPLETE:
// Perform completion
if (completer != null) {
- if (currentLine.complete()) {
+ if (currentLine.complete(completer)) {
currentLine.start(true);
}
out.write(currentPrompt);
refreshCurrentLine();
}
break;
+ case KR_HELP:
+ // Request incremental help
+ if (completer != null) {
+ if (currentLine.help(completer)) {
+ currentLine.start(true);
+ }
+ out.write(currentPrompt);
+ refreshCurrentLine();
+ }
+ break;
case KR_SOFT_EOF:
// Set soft EOF status and commit
currentLine.moveEnd();
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -33,11 +33,18 @@
KR_KILL_LINE,
/**
- * This action causes the input completion to be performed.
+ * This action causes the input completion to be performed on the current
+ * partial input line.
*/
KR_COMPLETE,
/**
+ * This action causes incremental help to be output for the current
+ * partial input line.
+ */
+ KR_HELP,
+
+ /**
* This action causes the input line to be refreshed to the
* console.
*/
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -21,7 +21,9 @@
package org.jnode.driver.console.textscreen;
+import java.io.CharArrayWriter;
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.Arrays;
import java.util.SortedSet;
@@ -165,9 +167,16 @@
}
}
- public boolean complete() throws IOException {
+ /**
+ * Perform completion on the current input, output any completion alternatives
+ * then rebuild line the input with the common completion appended.
+ *
+ * @param completer the object (e.g. shell) responsible for completion.
+ * @return <code>true</code> if we output a list of completion alternatives.
+ * @throws IOException
+ */
+ public boolean complete(InputCompleter completer) throws IOException {
CompletionInfo info = null;
- InputCompleter completer = console.getCompleter();
String ending =
posOnCurrentLine != currentLine.length() ? currentLine.substring(posOnCurrentLine) : "";
info = completer.complete(currentLine.substring(0, posOnCurrentLine));
@@ -186,6 +195,38 @@
return res;
}
+ /**
+ * Get and output incremental help for the current input line.
+ *
+ * @param completer the object (e.g. shell) responsible for providing help.
+ * @return <code>true</code> if we output any help.
+ * @throws IOException
+ * @throws IOException
+ */
+ public boolean help(InputCompleter completer) throws IOException {
+ CharArrayWriter caw = new CharArrayWriter();
+ PrintWriter pw = new PrintWriter(caw);
+ boolean res = completer.help(currentLine.substring(0, posOnCurrentLine), pw);
+ if (!res) {
+ return false;
+ }
+ char[] chars = caw.toCharArray();
+ if (chars.length == 0 || chars.length == 1 && chars[0] == '\n') {
+ return false;
+ }
+
+ int oldPosOnCurrentLine = posOnCurrentLine;
+ moveEnd();
+ refreshCurrentLine();
+ out.write('\n');
+ out.write(chars);
+ if (chars[chars.length - 1] != '\n') {
+ out.write('\n');
+ }
+ posOnCurrentLine = oldPosOnCurrentLine;
+ return true;
+ }
+
protected boolean printList(CompletionInfo info) throws IOException {
SortedSet<String> completions = info.getCompletions();
if (completions == null || completions.size() <= 1) {
Modified: trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -21,6 +21,8 @@
package org.jnode.shell;
+import java.io.PrintWriter;
+
/**
* This is the API that a shell-based interpreter must implement.
*
@@ -50,7 +52,7 @@
* completed.
*
* @param shell the current CommandShell.
- * @param partial a input to the interpreter.
+ * @param partial a partial command line
* @return the CommandLine represent the fragment of the supplied command
* input to be completed.
* @throws ShellException
@@ -73,4 +75,15 @@
* @return the word with any necessary escaping or quoting added.
*/
String escapeWord(String word);
+
+ /**
+ * Get incremental help for the partial command line.
+ *
+ * @param shell the current CommandShell.
+ * @param partial a partial command line
+ * @param pw the destination for any help information
+ * @return <code>true</code> if useful help information was written to 'pw'
+ * @throws ShellException
+ */
+ boolean help(CommandShell shell, String partial, PrintWriter pw) throws ShellException;
}
Modified: trunk/shell/src/shell/org/jnode/shell/CommandLine.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -661,4 +661,16 @@
completion.setCompletionStart(commandToken == null ? 0 : commandToken.start);
}
}
+
+ public CommandInfo getCommandInfo(CommandShell shell) {
+ String cmd = (commandToken == null) ? "" : commandToken.token.trim();
+ if (cmd.equals("")) {
+ return null;
+ }
+ try {
+ return shell.getCommandInfo(cmd);
+ } catch (ClassNotFoundException ex) {
+ return null;
+ }
+ }
}
Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -51,6 +51,7 @@
import org.jnode.driver.console.InputHistory;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.console.textscreen.KeyboardReader;
+import org.jnode.driver.console.textscreen.KeyboardReaderAction;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.alias.AliasManager;
import org.jnode.shell.alias.NoSuchAliasException;
@@ -647,15 +648,11 @@
}
return result.toString();
}
-
- public Completable parseCommandLine(String cmdLineStr)
- throws ShellException {
- return interpreter.parsePartial(this, cmdLineStr);
- }
/**
* This method is called by the console input driver to perform command line
- * completion in response to a TAB character.
+ * completion in response to a {@link KeyboardReaderAction#KR_COMPLETE} action;
+ * typically a TAB character.
*/
public CompletionInfo complete(String partial) {
if (!readingCommand) {
@@ -674,7 +671,7 @@
// do command completion
completion = new CommandCompletions(interpreter);
try {
- Completable cl = parseCommandLine(partial);
+ Completable cl = interpreter.parsePartial(this, partial);
if (cl != null) {
cl.complete(completion, this);
}
@@ -682,12 +679,11 @@
outPW.println(); // next line
errPW.println("Cannot parse: " + ex.getMessage());
stackTrace(ex);
-
- } catch (CompletionException ex) {
+ } catch (Throwable ex) {
outPW.println(); // next line
errPW.println("Problem in completer: " + ex.getMessage());
stackTrace(ex);
- }
+ }
// Make sure that the shell's completion context gets nulled.
CompletionInfo myCompletion = completion;
@@ -695,6 +691,29 @@
return myCompletion;
}
+ /**
+ * This method is responsible for generating incremental help in response
+ * to a @link KeyboardReaderAction#KR_HELP} action.
+ */
+ public boolean help(String partial, PrintWriter pw) {
+ if (!readingCommand) {
+ return false;
+ }
+ try {
+ return interpreter.help(this, partial, pw);
+ } catch (ShellException ex) {
+ outPW.println(); // next line
+ errPW.println("Cannot parse: " + ex.getMessage());
+ stackTrace(ex);
+ return false;
+ } catch (Throwable ex) {
+ outPW.println(); // next line
+ errPW.println("Problem in incremental help: " + ex.getMessage());
+ stackTrace(ex);
+ return false;
+ }
+ }
+
public void addCommandToHistory(String cmdLineStr) {
// Add this command to the command history.
if (isHistoryEnabled() && !cmdLineStr.equals(lastCommandLine)) {
Modified: trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -21,6 +21,7 @@
package org.jnode.shell;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.NoSuchElementException;
@@ -76,31 +77,17 @@
private static final char ESCAPE_T = '\t';
private static final char T = 't';
+ @Override
public String getName() {
return "default";
}
+ @Override
public int interpret(CommandShell shell, String line) throws ShellException {
- LinkedList<CommandLine.Token> tokens =
- new LinkedList<CommandLine.Token>();
- Tokenizer tokenizer = new Tokenizer(line);
- while (tokenizer.hasNext()) {
- tokens.add(tokenizer.next());
- }
- int nosTokens = tokens.size();
- if (nosTokens == 0) {
+ CommandLine cmd = doParseCommandLine(line);
+ if (cmd == null) {
return 0;
}
- CommandLine cmd;
- if (nosTokens == 1) {
- cmd = new CommandLine(tokens.get(0), null, null);
- } else {
- CommandLine.Token commandToken = tokens.removeFirst();
- CommandLine.Token[] argTokens =
- new CommandLine.Token[nosTokens - 1];
- cmd = new CommandLine(
- commandToken, tokens.toArray(argTokens), null);
- }
shell.addCommandToHistory(line);
try {
CommandInfo cmdInfo = cmd.parseCommandLine(shell);
@@ -110,10 +97,29 @@
}
}
+ @Override
public Completable parsePartial(CommandShell shell, String line) throws ShellException {
+ CommandLine res = doParseCommandLine(line);
+ return res == null ? new CommandLine("", null) : res;
+ }
+
+ @Override
+ public boolean help(CommandShell shell, String line, PrintWriter pw) throws ShellException {
+ CommandLine cmd = doParseCommandLine(line);
+ CommandInfo cmdInfo = cmd.getCommandInfo(shell);
+ if (cmdInfo == null) {
+ return false;
+ } else {
+ // This will do for a start.
+ pw.println("Command class is " + cmdInfo.getCommandClass().getName());
+ return true;
+ }
+ }
+
+ private CommandLine doParseCommandLine(String line) throws ShellException {
Tokenizer tokenizer = new Tokenizer(line);
if (!tokenizer.hasNext()) {
- return new CommandLine("", null);
+ return null;
}
CommandLine.Token commandToken = tokenizer.next();
LinkedList<CommandLine.Token> tokenList =
@@ -127,7 +133,7 @@
res.setArgumentAnticipated(tokenizer.whitespaceAfterLast());
return res;
}
-
+
@Override
public String escapeWord(String word) {
return escapeWord(word, false);
Modified: trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -27,6 +27,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -56,11 +57,13 @@
return "redirecting";
}
};
-
+
+ @Override
public String getName() {
return "redirecting";
}
+ @Override
public int interpret(CommandShell shell, String line) throws ShellException {
Tokenizer tokenizer = new Tokenizer(line, REDIRECTS_FLAG);
List<CommandDescriptor> commands = new LinkedList<CommandDescriptor>();
@@ -77,6 +80,7 @@
}
}
+ @Override
public Completable parsePartial(CommandShell shell, String line)
throws ShellException {
Tokenizer tokenizer = new Tokenizer(line, REDIRECTS_FLAG);
@@ -85,6 +89,12 @@
}
@Override
+ public boolean help(CommandShell shell, String line, PrintWriter pw) throws ShellException {
+ pw.println("Don't panic!");
+ return true;
+ }
+
+ @Override
public String escapeWord(String word) {
return escapeWord(word, true);
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2008-11-11 12:45:05 UTC (rev 4701)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2008-11-12 13:47:18 UTC (rev 4702)
@@ -13,6 +13,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.io.PrintWriter;
import java.util.HashMap;
import org.jnode.shell.CommandInfo;
@@ -120,20 +121,29 @@
public BjorneInterpreter() {
}
+ @Override
public String getName() {
return "bjorne";
}
+ @Override
public int interpret(CommandShell shell, String command) throws ShellException {
return interpret(shell, command, null, false);
}
+ @Override
public Completable parsePartial(CommandShell shell, String partial) throws ShellSyntaxException {
// TODO Auto-generated method stub
return null;
}
@Override
+ public boolean help(CommandShell shell, String partial, PrintWriter pw) throws ShellException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
public String escapeWord(String word) {
// TODO Auto-generated method stub
return null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|