jaroslav@934: /** jaroslav@934: * Back 2 Browser Bytecode Translator jaroslav@934: * Copyright (C) 2012 Jaroslav Tulach jaroslav@934: * jaroslav@934: * This program is free software: you can redistribute it and/or modify jaroslav@934: * it under the terms of the GNU General Public License as published by jaroslav@934: * the Free Software Foundation, version 2 of the License. jaroslav@934: * jaroslav@934: * This program is distributed in the hope that it will be useful, jaroslav@934: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@934: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@934: * GNU General Public License for more details. jaroslav@934: * jaroslav@934: * You should have received a copy of the GNU General Public License jaroslav@934: * along with this program. Look for COPYING file in the top folder. jaroslav@934: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@934: */ jaroslav@934: package org.apidesign.bck2brwsr.htmlpage.api; jaroslav@934: jaroslav@934: import java.lang.annotation.ElementType; jaroslav@934: import java.lang.annotation.Retention; jaroslav@934: import java.lang.annotation.RetentionPolicy; jaroslav@934: import java.lang.annotation.Target; jaroslav@934: jaroslav@964: /** Static methods in classes annotated by {@link Page} jaroslav@964: * can be marked by this annotation to establish a jaroslav@964: * JSON jaroslav@964: * communication point. jaroslav@934: * The associated model page then gets new method to invoke a network jaroslav@964: * connection. Example follows: jaroslav@964: * jaroslav@964: *
jaroslav@964:  * {@link Page @Page}(className="MyModel", xhtml="page.html", properties={
jaroslav@964:  *   {@link Property @Property}(name = "people", type=Person.class, array=true)
jaroslav@964:  * })
jaroslav@964:  * class MyModelImpl {
jaroslav@964:  *   {@link Model @Model}(className="Person", properties={
jaroslav@964:  *     {@link Property @Property}(name = "firstName", type=String.class),
jaroslav@964:  *     {@link Property @Property}(name = "lastName", type=String.class)
jaroslav@964:  *   })
jaroslav@964:  *   static class PersonImpl {
jaroslav@964:  *     {@link ComputedProperty @ComputedProperty}
jaroslav@964:  *     static String fullName(String firstName, String lastName) {
jaroslav@964:  *       return firstName + " " + lastName;
jaroslav@964:  *     }
jaroslav@964:  *   }
jaroslav@964:  * 
jaroslav@964:  *   {@link OnReceive @OnReceive}(url = "{protocol}://your.server.com/person/{name}")
jaroslav@964:  *   static void getANewPerson(MyModel m, Person p) {
jaroslav@964:  *     {@link Element#alert Element.alert}("Adding " + p.getFullName() + '!');
jaroslav@964:  *     m.getPeople().add(p);
jaroslav@964:  *   }
jaroslav@964:  * 
jaroslav@964:  *   // the above will generate method getANewPerson in class MyModel.
jaroslav@964:  *   // with protocol and name arguments
jaroslav@964:  *   // which asynchronously contacts the server and in case of success calls
jaroslav@964:  *   // your {@link OnReceive @OnReceive} with parsed in data
jaroslav@964:  * 
jaroslav@964:  *   {@link On @On}(event={@link OnEvent#CLICK OnEvent.CLICK}, id="rqst")
jaroslav@964:  *   static void requestSmith(MyModel m) {
jaroslav@964:  *     m.getANewPerson("http", "Smith");
jaroslav@964:  *   }
jaroslav@964:  * }
jaroslav@964:  * 
jaroslav@964: * When the server returns { "firstName" : "John", "lastName" : "Smith" } jaroslav@964: * the browser will show alert message Adding John Smith!. jaroslav@934: * jaroslav@934: * @author Jaroslav Tulach jaroslav@964: * @since 0.6 jaroslav@934: */ jaroslav@934: @Retention(RetentionPolicy.SOURCE) jaroslav@934: @Target(ElementType.METHOD) jaroslav@934: public @interface OnReceive { jaroslav@934: /** The URL to connect to. Can contain variable names surrounded by '{' and '}'. jaroslav@934: * Those parameters will then become variables of the associated method. jaroslav@934: * jaroslav@934: * @return the (possibly parametrized) url to connect to jaroslav@934: */ jaroslav@934: String url(); jaroslav@954: jaroslav@954: /** Support for JSONP requires jaroslav@954: * a callback from the server generated page to a function defined in the jaroslav@954: * system. The name of such function is usually specified as a property jaroslav@954: * (of possibly different names). By defining the jsonp attribute jaroslav@954: * one turns on the JSONP jaroslav@954: * transmission and specifies the name of the property. The property should jaroslav@954: * also be used in the {@link #url()} attribute on appropriate place. jaroslav@954: * jaroslav@954: * @return name of a property to carry the name of JSONP jaroslav@954: * callback function. jaroslav@954: */ jaroslav@954: String jsonp() default ""; jaroslav@934: }