Running inside OSGi container nicely reveals what packages need to be public...
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;
27 /** Represents single JavaScript function that can be invoked.
28 * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
30 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
32 public abstract class Fn {
33 private final Presenter presenter;
36 * @deprecated Ineffective as of 0.6.
37 * Provide a presenter via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}
45 /** Creates new function object and associates it with given presenter.
47 * @param presenter the browser presenter associated with this function
50 protected Fn(Presenter presenter) {
51 this.presenter = presenter;
54 /** True, if currently active presenter is the same as presenter this
55 * function has been created for via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}.
57 * @return true, if proper presenter is used
59 public final boolean isValid() {
60 return FnContext.currentPresenter() == presenter;
63 /** Invokes the defined function with specified <code>this</code> and
64 * appropriate arguments.
66 * @param thiz the meaning of <code>this</code> inside of the JavaScript
67 * function - can be <code>null</code>
68 * @param args arguments for the function
69 * @return return value from the function
70 * @throws Exception if something goes wrong, as exception may be thrown
72 public abstract Object invoke(Object thiz, Object... args) throws Exception;
74 /** The representation of a <em>presenter</em> - usually a browser window.
75 * Should be provided by a library included in the application and registered
76 * in <code>META-INF/services</code>, for example with
77 * <code>@ServiceProvider(service = Fn.Presenter.class)</code> annotation.
79 public interface Presenter {
80 /** Creates new function with given parameter names and provided body.
82 * @param code the body of the function. Can refer to variables named
83 * as <code>names</code>
84 * @param names names of parameters of the function - these will be
85 * available when the <code>code</code> body executes
87 * @return function that can be later invoked
89 public Fn defineFn(String code, String... names);
91 /** Opens the browser, loads provided page and when the
92 * page is ready, it calls back to the provider runnable.
94 * @param page the URL for the page to display
95 * @param onPageLoad callback when the page is ready
97 public void displayPage(URL page, Runnable onPageLoad);
99 /** Loads a script into the browser JavaScript interpreter and
101 * @param code the script to execute
102 * @throws Exception if something goes wrong, throw an exception
104 public void loadScript(Reader code) throws Exception;