ko/fx/src/main/java/org/apidesign/bck2brwsr/kofx/Console.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 26 Jun 2013 19:57:38 +0200
branchclassloader
changeset 1230 466c30fd9cb0
permissions -rw-r--r--
Adding in launcher based support for knockout
jaroslav@1230
     1
/**
jaroslav@1230
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1230
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1230
     4
 *
jaroslav@1230
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1230
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1230
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1230
     8
 *
jaroslav@1230
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1230
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1230
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1230
    12
 * GNU General Public License for more details.
jaroslav@1230
    13
 *
jaroslav@1230
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1230
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1230
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1230
    17
 */
jaroslav@1230
    18
package org.apidesign.bck2brwsr.kofx;
jaroslav@1230
    19
jaroslav@1230
    20
import java.util.logging.Logger;
jaroslav@1230
    21
import net.java.html.js.JavaScriptBody;
jaroslav@1230
    22
jaroslav@1230
    23
/** This is an implementation package - just
jaroslav@1230
    24
 * include its JAR on classpath and use official {@link Context} API
jaroslav@1230
    25
 * to access the functionality.
jaroslav@1230
    26
 * <p>
jaroslav@1230
    27
 * Redirects JavaScript's messages to Java's {@link Logger}.
jaroslav@1230
    28
 *
jaroslav@1230
    29
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1230
    30
 */
jaroslav@1230
    31
public final class Console {
jaroslav@1230
    32
    private static final Logger LOG = Logger.getLogger(Console.class.getName());
jaroslav@1230
    33
    
jaroslav@1230
    34
    private Console() {
jaroslav@1230
    35
    }
jaroslav@1230
    36
jaroslav@1230
    37
    static void register() {
jaroslav@1230
    38
        registerImpl(new Console());
jaroslav@1230
    39
    }
jaroslav@1230
    40
    
jaroslav@1230
    41
    @JavaScriptBody(args = { "jconsole" }, body = 
jaroslav@1230
    42
        "console.log = function(m) { jconsole.log(m); };" +
jaroslav@1230
    43
        "console.info = function(m) { jconsole.log(m); };" +
jaroslav@1230
    44
        "console.error = function(m) { jconsole.log(m); };" +
jaroslav@1230
    45
        "console.warn = function(m) { jconsole.log(m); };"
jaroslav@1230
    46
    )
jaroslav@1230
    47
    private static native void registerImpl(Console c);
jaroslav@1230
    48
    
jaroslav@1230
    49
    public void log(String msg) {
jaroslav@1230
    50
        LOG.info(msg);
jaroslav@1230
    51
    }
jaroslav@1230
    52
}