boot/src/main/java/org/apidesign/html/boot/spi/Fn.java
changeset 323 86aabecda7a3
parent 322 4a93f2679691
child 335 c74fed864c9c
child 349 53634fd10e30
     1.1 --- a/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Tue Nov 05 23:06:32 2013 +0100
     1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/spi/Fn.java	Wed Nov 06 15:15:54 2013 +0100
     1.3 @@ -62,6 +62,31 @@
     1.4          return FnContext.currentPresenter() == presenter;
     1.5      }
     1.6      
     1.7 +    /** Helper method to check if the provided instance is valid function.
     1.8 +     * Checks if the parameter is non-null and if so, does {@link #isValid()}
     1.9 +     * check.
    1.10 +     * 
    1.11 +     * @param fnOrNull function or <code>null</code>
    1.12 +     * @return true if the parameter is non-null and valid
    1.13 +     * @since 0.7
    1.14 +     */
    1.15 +    public static boolean isValid(Fn fnOrNull) {
    1.16 +        return fnOrNull != null && fnOrNull.isValid();
    1.17 +    }
    1.18 +
    1.19 +    /** Helper method to find current presenter and ask it to define new
    1.20 +     * function by calling {@link Presenter#defineFn(java.lang.String, java.lang.String...)}.
    1.21 +     * 
    1.22 +     * @param caller the class who wishes to define the function
    1.23 +     * @param code the body of the function (can reference <code>this</code> and <code>names</code> variables)
    1.24 +     * @param names names of individual parameters
    1.25 +     * @return the function object that can be {@link Fn#invoke(java.lang.Object, java.lang.Object...) invoked}
    1.26 +     * @since 0.7
    1.27 +     */
    1.28 +    public static Fn define(Class<?> caller, String code, String... names) {
    1.29 +        return FnContext.currentPresenter().defineFn(code, names);
    1.30 +    }
    1.31 +    
    1.32      /** The currently active presenter.
    1.33       * 
    1.34       * @return the currently active presenter or <code>null</code>