boot/src/main/java/org/apidesign/html/boot/spi/Fn.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 12 Sep 2013 09:33:50 +0200
changeset 288 8c5b40231d26
parent 163 2652760705d6
child 289 5fe8b52d74f9
permissions -rw-r--r--
Support for multiple FX WebViews running at once in isolation
jaroslav@123
     1
/**
jaroslav@123
     2
 * HTML via Java(tm) Language Bindings
jaroslav@123
     3
 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@123
     4
 *
jaroslav@123
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@123
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@123
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@123
     8
 *
jaroslav@123
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@123
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@123
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@123
    12
 * GNU General Public License for more details. apidesign.org
jaroslav@123
    13
 * designates this particular file as subject to the
jaroslav@123
    14
 * "Classpath" exception as provided by apidesign.org
jaroslav@123
    15
 * in the License file that accompanied this code.
jaroslav@123
    16
 *
jaroslav@123
    17
 * You should have received a copy of the GNU General Public License
jaroslav@123
    18
 * along with this program. Look for COPYING file in the top folder.
jaroslav@123
    19
 * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
jaroslav@123
    20
 */
jaroslav@123
    21
package org.apidesign.html.boot.spi;
jaroslav@123
    22
jaroslav@163
    23
import java.io.Reader;
jaroslav@123
    24
import java.net.URL;
jaroslav@288
    25
import org.apidesign.html.boot.impl.FnUtils;
jaroslav@123
    26
jaroslav@123
    27
/**
jaroslav@123
    28
 *
jaroslav@123
    29
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@123
    30
 */
jaroslav@123
    31
public abstract class Fn {
jaroslav@288
    32
    private final Presenter presenter;
jaroslav@288
    33
    
jaroslav@288
    34
    protected Fn(Presenter presenter) {
jaroslav@288
    35
        this.presenter = presenter;
jaroslav@288
    36
    }
jaroslav@288
    37
    
jaroslav@288
    38
    public final boolean isValid() {
jaroslav@288
    39
        return FnUtils.currentPresenter() == presenter;
jaroslav@288
    40
    }
jaroslav@288
    41
    
jaroslav@288
    42
    public final Object invoke(Object thiz, Object... args) throws Exception {
jaroslav@288
    43
        return handleInvoke(thiz, args);
jaroslav@288
    44
    }
jaroslav@288
    45
    
jaroslav@288
    46
    protected abstract Object handleInvoke(Object thiz, Object... args) throws Exception;
jaroslav@123
    47
    
jaroslav@127
    48
    public interface Presenter {
jaroslav@127
    49
        public Fn defineFn(String code, String... names);
jaroslav@128
    50
        public void displayPage(URL page, Runnable onPageLoad);
jaroslav@163
    51
        public void loadScript(Reader code) throws Exception;
jaroslav@123
    52
    }
jaroslav@123
    53
}