json/src/main/java/net/java/html/json/Model.java
changeset 1023 4f906bde3a2e
parent 1017 10427ce1c0ee
child 1024 558934b8b835
     1.1 --- a/json/src/main/java/net/java/html/json/Model.java	Thu Nov 05 23:38:18 2015 +0100
     1.2 +++ b/json/src/main/java/net/java/html/json/Model.java	Wed Dec 09 21:39:13 2015 +0100
     1.3 @@ -247,4 +247,46 @@
     1.4       * @since 1.3
     1.5       */
     1.6      String builder() default "";
     1.7 +    
     1.8 +    /** Controls keeping of per-instance private state. Sometimes
     1.9 +     * the class generated by the {@link Model @Model annotation} needs to
    1.10 +     * keep non-public, or non-JSON like state. One can achieve that by
    1.11 +     * specifying <code>instance=true</code> when using the annotation. Then
    1.12 +     * the generated class gets a pointer to the instance of the annotated
    1.13 +     * class (there needs to be default constructor) and all the {@link ModelOperation @ModelOperation},
    1.14 +     * {@link Function @Function}, {@link OnPropertyChange @OnPropertyChange}
    1.15 +     * and {@link OnReceive @OnReceive} methods may be non-static. The
    1.16 +     * instance of the implementation class isn't accessible directly, just
    1.17 +     * through calls to above defined (non-static) methods. Example:
    1.18 +     * <pre>
    1.19 +     * {@link Model @Model}(className="Data", instance=<b>true</b>, properties={
    1.20 +     *   {@link Property @Property}(name="message", type=String.<b>class</b>)
    1.21 +     * })
    1.22 +     * <b>final class</b> DataPrivate {
    1.23 +     *   <b>private int</b> count;
    1.24 +     * 
    1.25 +     *   {@link ModelOperation @ModelOperation} <b>void</b> increment(Data model) {
    1.26 +     *     count++;
    1.27 +     *   }
    1.28 +     * 
    1.29 +     *   {@link ModelOperation @ModelOperation} <b>void</b> hello(Data model) {
    1.30 +     *     model.setMessage("Hello " + count + " times!");
    1.31 +     *   }
    1.32 +     * }
    1.33 +     * Data data = <b>new</b> Data();
    1.34 +     * data.increment();
    1.35 +     * data.increment();
    1.36 +     * data.increment();
    1.37 +     * data.hello();
    1.38 +     * <b>assert</b> data.getMessage().equals("Hello 3 times!");
    1.39 +     * </pre>
    1.40 +     * The methods annotated by {@link ComputedProperty} need to remain static, as 
    1.41 +     * they are supposed to be <em>pure</em> functions (e.g. depend only on their parameters)
    1.42 +     * and shouldn't use any internal state.
    1.43 +     * 
    1.44 +     * @return <code>true</code> if the model class should keep pointer to
    1.45 +     *   instance of the implementation class
    1.46 +     * @since 1.3
    1.47 +     */
    1.48 +    boolean instance() default false;
    1.49  }