activePresenter can return null preprocess
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 25 Nov 2013 17:23:50 +0100
branchpreprocess
changeset 335c74fed864c9c
parent 334 ffdba74e8a35
child 336 81dcba7fa13d
activePresenter can return null
boot/src/main/java/org/apidesign/html/boot/impl/FnContext.java
boot/src/main/java/org/apidesign/html/boot/impl/FnUtils.java
boot/src/main/java/org/apidesign/html/boot/spi/Fn.java
     1.1 --- a/boot/src/main/java/org/apidesign/html/boot/impl/FnContext.java	Mon Nov 25 13:33:48 2013 +0100
     1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/impl/FnContext.java	Mon Nov 25 17:23:50 2013 +0100
     1.3 @@ -65,9 +65,9 @@
     1.4          return prev;
     1.5      }
     1.6  
     1.7 -    public static Fn.Presenter currentPresenter() {
     1.8 +    public static Fn.Presenter currentPresenter(boolean canReturnNull) {
     1.9          Fn.Presenter p = CURRENT.get();
    1.10 -        if (p == null) {
    1.11 +        if (p == null && !canReturnNull) {
    1.12              throw new IllegalStateException("No current WebView context around!");
    1.13          }
    1.14          return p;
     2.1 --- a/boot/src/main/java/org/apidesign/html/boot/impl/FnUtils.java	Mon Nov 25 13:33:48 2013 +0100
     2.2 +++ b/boot/src/main/java/org/apidesign/html/boot/impl/FnUtils.java	Mon Nov 25 17:23:50 2013 +0100
     2.3 @@ -150,7 +150,7 @@
     2.4              Reader isr = null;
     2.5              try {
     2.6                  isr = new InputStreamReader(script, "UTF-8");
     2.7 -                FnContext.currentPresenter().loadScript(isr);
     2.8 +                FnContext.currentPresenter(false).loadScript(isr);
     2.9              } finally {
    2.10                  if (isr != null) {
    2.11                      isr.close();
     3.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Mon Nov 25 13:33:48 2013 +0100
     3.2 +++ b/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Mon Nov 25 17:23:50 2013 +0100
     3.3 @@ -59,7 +59,7 @@
     3.4       * @return true, if proper presenter is used
     3.5       */
     3.6      public final boolean isValid() {
     3.7 -        return FnContext.currentPresenter() == presenter;
     3.8 +        return FnContext.currentPresenter(false) == presenter;
     3.9      }
    3.10      
    3.11      /** Helper method to check if the provided instance is valid function.
    3.12 @@ -84,7 +84,7 @@
    3.13       * @since 0.7
    3.14       */
    3.15      public static Fn define(Class<?> caller, String code, String... names) {
    3.16 -        return FnContext.currentPresenter().defineFn(code, names);
    3.17 +        return FnContext.currentPresenter(false).defineFn(code, names);
    3.18      }
    3.19      
    3.20      /** The currently active presenter.
    3.21 @@ -93,7 +93,7 @@
    3.22       * @since 0.7
    3.23       */
    3.24      public static Presenter activePresenter() {
    3.25 -        return FnContext.currentPresenter();
    3.26 +        return FnContext.currentPresenter(true);
    3.27      }
    3.28      
    3.29      /** Activates given presenter. Used by the code generated by