El mié, 05-12-2007 a las 02:06 -0300, Aldrin Gonzalo Martoq Ahumada escribió: > On Dec 4, 2007 2:30 PM, Franco Catrin L. <[EMAIL PROTECTED]> wrote: > > Veamos un simple cambio de este sencillo ejemplo. Ahora queremos > > pasar el nombre del "saludado" por parametro. En Java quedaria como : > > (sin validar)
[...] > Y que es eso de NON-NLS??? Ah claro, olvidaba la i18n.... > > ---------- Ultima version, espero ------ > package hello; > > public class HelloWorld { > private static final String _STR_HELLO = > Messages.getString("HelloWorld.HELLO"); //$NON-NLS-1$ > > private static final String _STR_USAGE = > Messages.getString("HelloWorld.USAGE"); //$NON-NLS-1$ > > public static void main(String[] args) { > if (args.length != 1) { > System.err.println(_STR_USAGE); > return; > } > System.out.println(_STR_HELLO + args[0]); > } > > import java.util.MissingResourceException; > import java.util.ResourceBundle; > > public class Messages { > private static final String BUNDLE_NAME = > "hello.messages"; //$NON-NLS-1$ > > private static final ResourceBundle RESOURCE_BUNDLE = > ResourceBundle.getBundle(BUNDLE_NAME); > > private Messages() { > } > > public static String getString(String key) { > try { > return RESOURCE_BUNDLE.getString(key); > } catch (MissingResourceException e) { > return '!' + key + '!'; > } > } > } > > ---- messages.properties ---- > HelloWorld.HELLO=Hello > HelloWorld.USAGE=Usage: java hello.HelloWorld <your_name> > ----------------------------------- > > > Alguien en java llega a algo tan elaborado??? Y eso que ni siquiera > hemos llegado a J2EE.... > > Algun contraejemplo en otro lenguaje, anyone??? ;) Aqui tengo un ejemplo para hacer lo mismo que trataste de hacer en .... Java :D import java.util.*; public class HelloWorld { static final String USAGE = "usage", HELLO="hello"; static public void main (String args[]) { ResourceBundle messages = ResourceBundle.getBundle("messages"); System.out.println(args.length!=1? messages.getString(USAGE):messages.getString(HELLO) + args[0]); } } -- Franco Catrin L. TUXPAN Software S.A. http://www.tuxpan.com/fcatrin