1 jls.loader.provide('jls.lang.System');
  2 
  3 jls.loader.requireLibrary('jls_io');
  4 jls.loader.require('jls.lang.Runtime');
  5 jls.loader.require('jls.io.PrintStream');
  6 jls.loader.require('jls.io.FileInputStream');
  7 
  8 /**
  9  * @class The System class provides access to data and operations of the underlying OS.
 10  * Access to system properties, environnement variables and default standard IO streams.
 11  * Operation such as the exit method, the garbage collection and the ability to load native library.
 12  */
 13 jls.lang.System = jls.lang.Class.create({});
 14 
 15 Object.extend(jls.lang.System, /** @lends jls.lang.System */
 16 {
 17     _systemProperties : null,
 18     _commandLineArguments : null,
 19     _mainClassname : null,
 20     /**
 21      * Initialize the system class.
 22      * @private
 23      */
 24     _initialize : function() {
 25         jls.lang.System.err = new jls.io.PrintStream(_native.io.stderr);
 26         jls.lang.System.in = new jls.io.FileInputStream(_native.io.stdin);
 27         jls.lang.System.out = new jls.io.PrintStream(_native.io.stdout);
 28         jls.lang.System._systemProperties = _native.core.properties;
 29         jls.lang.System._commandLineArguments = Array.from(_native.core.arguments);
 30         jls.lang.System._mainClassname = jls.lang.System._commandLineArguments.shift();
 31     },
 32     /**
 33      * Gets the system command-line arguments.
 34      * 
 35      * @returns {Array} The system arguments.
 36      */
 37     getArguments : function() {
 38         return jls.lang.System._commandLineArguments;
 39     },
 40     /**
 41      * Gets the system properties.
 42      * 
 43      * @returns {Object} The system properties.
 44      */
 45     getProperties : function() {
 46         return jls.lang.System._systemProperties;
 47     },
 48     /**
 49      * Gets a specific system property.
 50      * 
 51      * @param {String} name The name of the property to get.
 52      * @returns {String} The system property.
 53      */
 54     getProperty : function(name, def) {
 55     	if (name in jls.lang.System._systemProperties) {
 56             return jls.lang.System._systemProperties[name];
 57     	}
 58     	return def;
 59     },
 60     /**
 61      * Removes a specific system property.
 62      * 
 63      * @param {String} name The name of the property to remove.
 64      * @returns {String} The system property removed.
 65      */
 66     clearProperty : function(name) {
 67         var cleared = null;
 68         if (name in jls.lang.System._systemProperties) {
 69             cleared = jls.lang.System._systemProperties[name];
 70             delete jls.lang.System._systemProperties[name];
 71         }
 72         return cleared;
 73     },
 74     /**
 75      * Sets a specific system property.
 76      * 
 77      * @param {String} name The name of the property to set.
 78      * @param {String} value The value of the property to set.
 79      */
 80     setProperty : function(name, value) {
 81         jls.lang.System._systemProperties[name] = value;
 82     },
 83     /**
 84      * Gets a specific environnement property.
 85      * 
 86      * @param {String} name The name of the property to get.
 87      * @returns {String} The environnement property.
 88      */
 89     getenv : function(name) {
 90         return _native.core.getEnv(name);
 91     },
 92     /**
 93      * Returns the current time in milliseconds.
 94      * 
 95      * @returns {Number} The current time in milliseconds.
 96      */
 97     currentTimeMillis : function() {
 98         return new Date().getTime();
 99     },
100     /**
101      * The standard error stream.
102      * @type jls.io.PrintStream
103      */
104     err : null,
105     /**
106      * The standard input stream.
107      * @type jls.io.FileInputStream
108      */
109     'in' : null,
110     /**
111      * The standard output stream.
112      * @type jls.io.PrintStream
113      */
114     out : null,
115 
116     /**
117      * Terminates the program and returns a value to the OS.
118      * 
119      * @param {Number} status The exit status to return to the OS.
120      * @function
121      */
122     exit : jls.lang.Runtime.exit,
123     /**
124      * Runs the garbage collector.
125      * @function
126      */
127     gc : jls.lang.Runtime.gc,
128     /**
129      * Loads a native library compliant with the JLS native engine.
130      * 
131      * @param {String} name The name of the library to load.
132      * @function
133      */
134     loadLibrary : jls.lang.Runtime.loadLibrary
135 });
136 
137