2 * HTML via Java(tm) Language Bindings
3 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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
21 package org.apidesign.html.boot.spi;
23 import java.io.Reader;
25 import org.apidesign.html.boot.impl.FnUtils;
29 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
31 public abstract class Fn {
32 private final Presenter presenter;
34 protected Fn(Presenter presenter) {
35 this.presenter = presenter;
38 public final boolean isValid() {
39 return FnUtils.currentPresenter() == presenter;
42 public final Object invoke(Object thiz, Object... args) throws Exception {
43 return handleInvoke(thiz, args);
46 protected abstract Object handleInvoke(Object thiz, Object... args) throws Exception;
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;