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