jtulach@0
|
1 |
/**
|
jaroslav@358
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jtulach@0
|
3 |
*
|
jaroslav@551
|
4 |
* Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
|
jtulach@0
|
5 |
*
|
jaroslav@358
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jaroslav@358
|
7 |
* Other names may be trademarks of their respective owners.
|
jtulach@0
|
8 |
*
|
jaroslav@358
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
jaroslav@358
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
jaroslav@358
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
jaroslav@358
|
12 |
* "License"). You may not use this file except in compliance with the
|
jaroslav@358
|
13 |
* License. You can obtain a copy of the License at
|
jaroslav@358
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
jaroslav@358
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jaroslav@358
|
16 |
* specific language governing permissions and limitations under the
|
jaroslav@358
|
17 |
* License. When distributing the software, include this License Header
|
jaroslav@358
|
18 |
* Notice in each file and include the License file at
|
jaroslav@358
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
jaroslav@358
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@358
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
jaroslav@358
|
22 |
* accompanied this code. If applicable, add the following below the
|
jaroslav@358
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jaroslav@358
|
24 |
* your own identifying information:
|
jaroslav@358
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jaroslav@358
|
26 |
*
|
jaroslav@358
|
27 |
* Contributor(s):
|
jaroslav@358
|
28 |
*
|
jaroslav@358
|
29 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
jaroslav@551
|
30 |
* Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
|
jaroslav@358
|
31 |
*
|
jaroslav@358
|
32 |
* If you wish your version of this file to be governed by only the CDDL
|
jaroslav@358
|
33 |
* or only the GPL Version 2, indicate your decision by adding
|
jaroslav@358
|
34 |
* "[Contributor] elects to include this software in this distribution
|
jaroslav@358
|
35 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jaroslav@358
|
36 |
* single choice of license, a recipient has the option to distribute
|
jaroslav@358
|
37 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jaroslav@358
|
38 |
* to extend the choice of license to its licensees as provided above.
|
jaroslav@358
|
39 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jaroslav@358
|
40 |
* Version 2 license, then the option applies only if the new code is
|
jaroslav@358
|
41 |
* made subject to such option by the copyright holder.
|
jtulach@0
|
42 |
*/
|
jtulach@0
|
43 |
package net.java.html.json;
|
jtulach@0
|
44 |
|
jtulach@0
|
45 |
import java.lang.annotation.ElementType;
|
jtulach@0
|
46 |
import java.lang.annotation.Retention;
|
jtulach@0
|
47 |
import java.lang.annotation.RetentionPolicy;
|
jtulach@0
|
48 |
import java.lang.annotation.Target;
|
jtulach@0
|
49 |
|
jaroslav@240
|
50 |
/** The threading model of classes generated by {@link Model @Model} requires
|
jaroslav@240
|
51 |
* that all operations are perform from the originating thread - unless they
|
jaroslav@240
|
52 |
* are invoked as {@link ModelOperation @ModelOperation} methods.
|
jaroslav@240
|
53 |
* <p>
|
jaroslav@240
|
54 |
* A method in a class annotated by {@link Model @Model} annotation may be
|
jaroslav@240
|
55 |
* annotated by {@link ModelOperation @ModelOperation}. The method has
|
jaroslav@240
|
56 |
* to be static, non-private and return <code>void</code>. The first parameter
|
jaroslav@240
|
57 |
* of the method must be the {@link Model#className() model class} followed
|
jaroslav@240
|
58 |
* by any number of additional arguments.
|
jaroslav@240
|
59 |
* <p>
|
jaroslav@240
|
60 |
* As a result method of the same name and the same list of additional arguments
|
jaroslav@240
|
61 |
* (e.g. without the first model class one) will be generated into the
|
jaroslav@240
|
62 |
* {@link Model#className() model class}. This method can be invoked on any
|
jaroslav@240
|
63 |
* thread, any time and it is the responsibility of model manipulating
|
jaroslav@240
|
64 |
* technology to ensure the model is available and only then call back to
|
jaroslav@240
|
65 |
* the original method annotated by {@link ModelOperation @ModelOperation}.
|
jaroslav@240
|
66 |
* The call may happen synchronously (if possible), or be delayed and invoked
|
jaroslav@240
|
67 |
* later (on appropriate dispatch thread), without blocking the caller.
|
jaroslav@233
|
68 |
* <pre>
|
jaroslav@233
|
69 |
*
|
jaroslav@233
|
70 |
* {@link Model @Model}(className="Names", properties={
|
jaroslav@233
|
71 |
* {@link Property @Property}(name = "names", type=String.class, array = true)
|
jaroslav@233
|
72 |
* })
|
jaroslav@233
|
73 |
* static class NamesModel {
|
jaroslav@240
|
74 |
* {@link ModelOperation @ModelOperation} static void <b>updateNames</b>(Names model, {@link java.util.List}<String> arr) {
|
jaroslav@240
|
75 |
* <em>// can safely access the model</em>
|
jaroslav@240
|
76 |
* model.getNames().addAll(arr);
|
jaroslav@233
|
77 |
* }
|
jaroslav@233
|
78 |
*
|
jaroslav@233
|
79 |
* static void initialize() {
|
jaroslav@240
|
80 |
* final Names pageModel = new Names();
|
jaroslav@233
|
81 |
* pageModel.applyBindings();
|
jaroslav@240
|
82 |
*
|
jaroslav@240
|
83 |
* <em>// spawn to different thread</em>
|
jaroslav@240
|
84 |
* {@link java.util.concurrent.Executors}.newSingleThreadExecutor().execute({
|
jaroslav@240
|
85 |
* List<String> arr = <em>// ... obtain the names somewhere from network</em>
|
jaroslav@240
|
86 |
* pageModel.<b>updateNames</b>(arr);
|
jaroslav@240
|
87 |
* // returns immediately, later it invokes the model operation
|
jaroslav@240
|
88 |
* });
|
jaroslav@240
|
89 |
*
|
jaroslav@233
|
90 |
* }
|
jaroslav@233
|
91 |
* }
|
jaroslav@233
|
92 |
*
|
jtulach@0
|
93 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jtulach@0
|
94 |
*/
|
jtulach@0
|
95 |
@Target(ElementType.METHOD)
|
jtulach@0
|
96 |
@Retention(RetentionPolicy.SOURCE)
|
jaroslav@240
|
97 |
public @interface ModelOperation {
|
jtulach@0
|
98 |
}
|