001: /*
002: * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
003: * Copyright (C) 2006 - Javolution (http://javolution.org/)
004: * All rights reserved.
005: *
006: * Permission to use, copy, modify, and distribute this software is
007: * freely granted, provided that this notice is preserved.
008: */
009: package javolution;
010:
011: import j2me.lang.CharSequence;
012:
013: import javolution.context.LogContext;
014: import javolution.testing.TestContext;
015: import javolution.testing.TimeContext;
016: import javolution.text.Text;
017:
018: /**
019: * <p> This class contains the library {@link #main} method for
020: * versionning, self-tests, and performance analysis.</p>
021: * <p> It is also the base class for the library benchmarks and
022: * self-tests.</p>
023: *
024: * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
025: * @version 1.0, September 14, 2004
026: */
027: public class Javolution {
028:
029: /**
030: * Holds the version information.
031: */
032: public final static String VERSION = "@VERSION@";
033:
034: /**
035: * Default constructor.
036: */
037: protected Javolution() {
038: }
039:
040: /**
041: * The library {@link #main} method.
042: * The archive <code>javolution.jar</code> is auto-executable.
043: * [code]
044: * java -jar javolution.jar version <i>(show version information)</i>
045: * java -jar javolution.jar test <i>(perform self-tests)</i>
046: * java -jar javolution.jar perf <i>(run benchmark)</i>
047: * [/code]
048: * Configurable are read from system properties.
049: *
050: *
051: * @param args the option arguments.
052: * @throws Exception if a problem occurs.
053: */
054: public static void main(String[] args) throws Exception {
055: LogContext.enter(LogContext.SYSTEM_OUT); // Output results to System.out
056: try {
057: LogContext
058: .info("Javolution - Java(TM) Solution for Real-Time and Embedded Systems");
059: LogContext.info("Version " + VERSION
060: + " (http://javolution.org)");
061: LogContext.info("");
062: if (args.length > 0) {
063: if (args[0].equals("version")) {
064: return;
065: } else if (args[0].equals("test")) {
066: builtInTests();
067: return;
068: } else if (args[0].equals("perf")) {
069: TimeContext.enter();
070: try {
071: builtInTests();
072: } finally {
073: TimeContext.exit();
074: }
075: return;
076: }
077: }
078: LogContext.info("Usage: java -jar javolution.jar [arg]");
079: LogContext.info("where arg is one of:");
080: LogContext
081: .info(" version (to show version information only)");
082: LogContext.info(" test (to perform self-tests)");
083: LogContext.info(" perf (to run benchmark)");
084: } finally {
085: LogContext.exit();
086: }
087: }
088:
089: /**
090: * Performs Built-In-Tests.
091: */
092: private static void builtInTests() {
093:
094: /*@JVM-1.4+@
095: LogContext.info("Load Configurable Parameters from System.getProperties()...");
096: javolution.lang.Configurable.read(System.getProperties());
097: LogContext.info("");
098: /**/
099:
100: Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
101: new ContextTestSuite().run();
102: new UtilTestSuite().run();
103:
104: TestContext.info("More tests coming soon...");
105:
106: }
107:
108: ///////////////////////////////////////////////
109: // Utilities for J2ME Backward Compatibility //
110: ///////////////////////////////////////////////
111:
112: /**
113: * Returns the class having the specified name; for
114: * backward compatibility with CLDC 1.0 (cannot use .class as exception
115: * java.lang.NoClassDefFoundError does not exist for that platform).
116: */
117: public static Class j2meGetClass(String name) {
118: Class cls = null;
119: try {
120: cls = Class.forName(name); // Caller class loader.
121: } catch (ClassNotFoundException e0) { // Try context class loader.
122: /*@JVM-1.4+@
123: try {
124: ClassLoader cl = Thread.currentThread().getContextClassLoader();
125: cls = Class.forName(name, true, cl);
126: } catch (ClassNotFoundException e1) { // Try system class loader.
127: ClassLoader cl = ClassLoader.getSystemClassLoader();
128: try {
129: cls = Class.forName(name, true, cl);
130: } catch (ClassNotFoundException e) {
131: }
132: }
133: /**/
134: }
135: if (cls == null)
136: throw new JavolutionError("Class " + name + " not found");
137: return cls;
138: }
139:
140: /**
141: * Converts the specified String as CharSequence (String is a
142: * CharSequence only for J2SE 1.4+).
143: *
144: * @param str the String to convert.
145: * @return <code>this</code> or a text wrapper.
146: */
147: public static CharSequence j2meToCharSeq(Object str) {
148: /*@JVM-1.4+@
149: if (true) return (CharSequence) str;
150: /**/
151: return Text.valueOf(str);
152: }
153: }
|