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. |