FnUtils are bloated and contain references to Asm classes. Separate the code needed by generated JsCallbacks into own class
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.FnContext;
26 import org.apidesign.html.boot.impl.FnUtils;
28 /** Represents single JavaScript function that can be invoked.
29 * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
31 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
33 public abstract class Fn {
34 private final Presenter presenter;
37 * @deprecated Ineffective as of 0.6.
38 * Provide a presenter via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}
46 /** Creates new function object and associates it with given presenter.
48 * @param presenter the browser presenter associated with this function
51 protected Fn(Presenter presenter) {
52 this.presenter = presenter;
55 /** True, if currently active presenter is the same as presenter this
56 * function has been created for via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}.
58 * @return true, if proper presenter is used
60 public final boolean isValid() {
61 return FnContext.currentPresenter() == presenter;
64 /** Invokes the defined function with specified <code>this</code> and
65 * appropriate arguments.
67 * @param thiz the meaning of <code>this</code> inside of the JavaScript
68 * function - can be <code>null</code>
69 * @param args arguments for the function
70 * @return return value from the function
71 * @throws Exception if something goes wrong, as exception may be thrown
73 public abstract Object invoke(Object thiz, Object... args) throws Exception;
75 /** The representation of a <em>presenter</em> - usually a browser window.
77 public interface Presenter {
78 /** Creates new function with given parameter names and provided body.
80 * @param code the body of the function. Can refer to variables named
81 * as <code>names</code>
82 * @param names names of parameters of the function - these will be
83 * available when the <code>code</code> body executes
85 * @return function that can be later invoked
87 public Fn defineFn(String code, String... names);
89 /** Opens the browser, loads provided page and when the
90 * page is ready, it calls back to the provider runnable.
92 * @param page the URL for the page to display
93 * @param onPageLoad callback when the page is ready
95 public void displayPage(URL page, Runnable onPageLoad);
97 /** Loads a script into the browser JavaScript interpreter and
99 * @param code the script to execute
100 * @throws Exception if something goes wrong, throw an exception
102 public void loadScript(Reader code) throws Exception;