rt/emul/compact/src/main/java/java/lang/System.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 07 Nov 2013 09:44:51 +0100
changeset 1410 7a021349afec
parent 1362 b37e6e49d9d6
child 1416 a0a31f8f7dc1
permissions -rw-r--r--
Not very useful set and get properties
jaroslav@1260
     1
/**
jaroslav@1260
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1260
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1260
     4
 *
jaroslav@1260
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1260
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1260
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1260
     8
 *
jaroslav@1260
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1260
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1260
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1260
    12
 * GNU General Public License for more details.
jaroslav@1260
    13
 *
jaroslav@1260
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1260
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1260
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1260
    17
 */
jaroslav@1260
    18
package java.lang;
jaroslav@1260
    19
jaroslav@1322
    20
import java.io.ByteArrayInputStream;
jaroslav@1322
    21
import java.io.ByteArrayOutputStream;
jaroslav@1322
    22
import java.io.InputStream;
jaroslav@1322
    23
import java.io.PrintStream;
jaroslav@1410
    24
import java.util.Properties;
jaroslav@1279
    25
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@1279
    26
jaroslav@1260
    27
/** Poor man's re-implementation of most important System methods.
jaroslav@1260
    28
 *
jaroslav@1260
    29
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1260
    30
 */
jaroslav@1260
    31
public class System {
jaroslav@1260
    32
    private System() {
jaroslav@1260
    33
    }
jaroslav@1260
    34
    
jaroslav@1260
    35
    public static void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count) {
jaroslav@1260
    36
        org.apidesign.bck2brwsr.emul.lang.System.arraycopy(value, srcBegin, dst, dstBegin, count);
jaroslav@1260
    37
    }
jaroslav@1260
    38
    
jaroslav@1260
    39
    public static long currentTimeMillis() {
jaroslav@1260
    40
        return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
jaroslav@1260
    41
    }
jaroslav@1260
    42
    
jaroslav@1260
    43
    public static int identityHashCode(Object obj) {
jaroslav@1260
    44
        return obj.defaultHashCode();
jaroslav@1260
    45
    }
jaroslav@1260
    46
jaroslav@1260
    47
    public static String getProperty(String name) {
jaroslav@1328
    48
        if ("os.name".equals(name)) {
jaroslav@1328
    49
            return userAgent();
jaroslav@1328
    50
        }
jaroslav@1260
    51
        return null;
jaroslav@1260
    52
    }
jaroslav@1260
    53
    
jaroslav@1362
    54
    @JavaScriptBody(args = {}, body = "return (typeof navigator !== 'undefined') ? navigator.userAgent : 'unknown';")
jaroslav@1328
    55
    private static native String userAgent();
jaroslav@1328
    56
    
jaroslav@1260
    57
    public static String getProperty(String key, String def) {
jaroslav@1260
    58
        return def;
jaroslav@1260
    59
    }
jaroslav@1260
    60
    
jaroslav@1410
    61
    public static Properties getProperties() {
jaroslav@1410
    62
        throw new SecurityException();
jaroslav@1410
    63
    }
jaroslav@1410
    64
    
jaroslav@1410
    65
    public static void setProperties(Properties p) {
jaroslav@1410
    66
        throw new SecurityException();
jaroslav@1410
    67
    }
jaroslav@1410
    68
    
jaroslav@1260
    69
    /**
jaroslav@1260
    70
     * Returns the system-dependent line separator string.  It always
jaroslav@1260
    71
     * returns the same value - the initial value of the {@linkplain
jaroslav@1260
    72
     * #getProperty(String) system property} {@code line.separator}.
jaroslav@1260
    73
     *
jaroslav@1260
    74
     * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
jaroslav@1260
    75
     * Windows systems it returns {@code "\r\n"}.
jaroslav@1260
    76
     */
jaroslav@1260
    77
    public static String lineSeparator() {
jaroslav@1260
    78
        return "\n";
jaroslav@1260
    79
    }
jaroslav@1279
    80
jaroslav@1279
    81
    @JavaScriptBody(args = { "exitCode" }, body = "window.close();")
jaroslav@1279
    82
    public static void exit(int exitCode) {
jaroslav@1279
    83
    }
jaroslav@1322
    84
    
jaroslav@1322
    85
    public final static InputStream in;
jaroslav@1322
    86
jaroslav@1322
    87
    public final static PrintStream out;
jaroslav@1322
    88
jaroslav@1322
    89
    public final static PrintStream err;
jaroslav@1322
    90
    
jaroslav@1322
    91
    static {
jaroslav@1322
    92
        in = new ByteArrayInputStream(new byte[0]);
jaroslav@1322
    93
        out = err = new PrintStream(new ByteArrayOutputStream());
jaroslav@1322
    94
    }
jaroslav@1322
    95
    
jaroslav@1260
    96
}