1.1 --- a/boot-fx/src/main/java/org/apidesign/html/boot/fx/AbstractFXPresenter.java Thu Sep 12 09:33:50 2013 +0200
1.2 +++ b/boot-fx/src/main/java/org/apidesign/html/boot/fx/AbstractFXPresenter.java Thu Sep 12 11:31:04 2013 +0200
1.3 @@ -145,7 +145,7 @@
1.4 }
1.5
1.6 @Override
1.7 - public Object handleInvoke(Object thiz, Object... args) throws Exception {
1.8 + public Object invoke(Object thiz, Object... args) throws Exception {
1.9 try {
1.10 if (LOG.isLoggable(Level.FINE)) {
1.11 LOG.log(Level.FINE, "calling {0} function #{1}", new Object[]{++call, id});
2.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java Thu Sep 12 09:33:50 2013 +0200
2.2 +++ b/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java Thu Sep 12 11:31:04 2013 +0200
2.3 @@ -24,30 +24,80 @@
2.4 import java.net.URL;
2.5 import org.apidesign.html.boot.impl.FnUtils;
2.6
2.7 -/**
2.8 +/** Represents single JavaScript function that can be invoked.
2.9 + * Created via {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
2.10 *
2.11 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.12 */
2.13 public abstract class Fn {
2.14 private final Presenter presenter;
2.15
2.16 + /**
2.17 + * @deprecated Ineffective as of 0.6.
2.18 + * Provide a presenter via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}
2.19 + * constructor
2.20 + */
2.21 + @Deprecated
2.22 + protected Fn() {
2.23 + this(null);
2.24 + }
2.25 +
2.26 + /** Creates new function object and associates it with given presenter.
2.27 + *
2.28 + * @param presenter the browser presenter associated with this function
2.29 + * @since 0.6
2.30 + */
2.31 protected Fn(Presenter presenter) {
2.32 this.presenter = presenter;
2.33 }
2.34 -
2.35 +
2.36 + /** True, if currently active presenter is the same as presenter this
2.37 + * function has been created for via {@link #Fn(org.apidesign.html.boot.spi.Fn.Presenter)}.
2.38 + *
2.39 + * @return true, if proper presenter is used
2.40 + */
2.41 public final boolean isValid() {
2.42 return FnUtils.currentPresenter() == presenter;
2.43 }
2.44
2.45 - public final Object invoke(Object thiz, Object... args) throws Exception {
2.46 - return handleInvoke(thiz, args);
2.47 - }
2.48 -
2.49 - protected abstract Object handleInvoke(Object thiz, Object... args) throws Exception;
2.50 -
2.51 + /** Invokes the defined function with specified <code>this</code> and
2.52 + * appropriate arguments.
2.53 + *
2.54 + * @param thiz the meaning of <code>this</code> inside of the JavaScript
2.55 + * function - can be <code>null</code>
2.56 + * @param args arguments for the function
2.57 + * @return return value from the function
2.58 + * @throws Exception if something goes wrong, as exception may be thrown
2.59 + */
2.60 + public abstract Object invoke(Object thiz, Object... args) throws Exception;
2.61 +
2.62 + /** The representation of a <em>presenter</em> - usually a browser window.
2.63 + */
2.64 public interface Presenter {
2.65 + /** Creates new function with given parameter names and provided body.
2.66 + *
2.67 + * @param code the body of the function. Can refer to variables named
2.68 + * as <code>names</code>
2.69 + * @param names names of parameters of the function - these will be
2.70 + * available when the <code>code</code> body executes
2.71 + *
2.72 + * @return function that can be later invoked
2.73 + */
2.74 public Fn defineFn(String code, String... names);
2.75 +
2.76 + /** Opens the browser, loads provided page and when the
2.77 + * page is ready, it calls back to the provider runnable.
2.78 + *
2.79 + * @param page the URL for the page to display
2.80 + * @param onPageLoad callback when the page is ready
2.81 + */
2.82 public void displayPage(URL page, Runnable onPageLoad);
2.83 +
2.84 + /** Loads a script into the browser JavaScript interpreter and
2.85 + * executes it.
2.86 + * @param code the script to execute
2.87 + * @throws Exception if something goes wrong, throw an exception
2.88 + */
2.89 public void loadScript(Reader code) throws Exception;
2.90 }
2.91 }
3.1 --- a/boot/src/test/java/org/apidesign/html/boot/impl/FnTest.java Thu Sep 12 09:33:50 2013 +0200
3.2 +++ b/boot/src/test/java/org/apidesign/html/boot/impl/FnTest.java Thu Sep 12 11:31:04 2013 +0200
3.3 @@ -83,7 +83,7 @@
3.4 final Object val = eng.eval(sb.toString());
3.5 return new Fn(this) {
3.6 @Override
3.7 - public Object handleInvoke(Object thiz, Object... args) throws Exception {
3.8 + public Object invoke(Object thiz, Object... args) throws Exception {
3.9 List<Object> all = new ArrayList<Object>(args.length + 1);
3.10 all.add(thiz == null ? val : thiz);
3.11 all.addAll(Arrays.asList(args));
4.1 --- a/boot/src/test/java/org/apidesign/html/boot/impl/JsClassLoaderTest.java Thu Sep 12 09:33:50 2013 +0200
4.2 +++ b/boot/src/test/java/org/apidesign/html/boot/impl/JsClassLoaderTest.java Thu Sep 12 11:31:04 2013 +0200
4.3 @@ -80,7 +80,7 @@
4.4 final Object val = eng.eval(sb.toString());
4.5 return new Fn(this) {
4.6 @Override
4.7 - public Object handleInvoke(Object thiz, Object... args) throws Exception {
4.8 + public Object invoke(Object thiz, Object... args) throws Exception {
4.9 List<Object> all = new ArrayList<Object>(args.length + 1);
4.10 all.add(thiz == null ? val : thiz);
4.11 all.addAll(Arrays.asList(args));