public final class Proto extends Object
Model annotation. Contains methods the generated class can
use to communicate with behind the scene associated Technology.
Each Proto object is associated with
singletonizer-like interface Proto.Type which provides the
associated Technology the necessary information about the
generated Model class.| Modifier and Type | Class and Description |
|---|---|
static class |
Proto.Type<Model>
Functionality used by the code generated by annotation
processor for the
Model annotation. |
| Modifier and Type | Method and Description |
|---|---|
void |
acquireLock()
Before doing modification of the model properties, the
generated code enters write lock by calling this method.
|
void |
applyBindings()
Initializes the associated model in the current
context. |
<T> void |
cloneList(Collection<T> to,
BrwsrCtx ctx,
Collection<T> from)
Copies content of one collection to another, re-assigning all its
elements from their current context to the new
ctx. |
<T> List<T> |
createList(String propName,
int onChange,
String... dependingProps)
Creates new JSON like observable list.
|
void |
extract(Object json,
String[] props,
Object[] values)
Takes an object representing JSON result and extract some of its
properties.
|
BrwsrCtx |
getContext()
Browser context this proto object and its associated model
are operating-in.
|
void |
initTo(Collection<?> to,
Object array)
Initializes the provided collection with a content of the
array. |
void |
loadJSON(int index,
String urlBefore,
String urlAfter,
String method,
Object data)
Initializes asynchronous JSON connection to specified URL.
|
<T> T |
read(Class<T> modelClass,
Object data)
Converts raw JSON
data into a Java Model class. |
void |
releaseLock()
When modifications are over, the model is switched into
unlocked state by calling this method.
|
void |
runInBrowser(Runnable run)
Invokes the provided runnable in the
context
of the browser. |
<T> T |
toModel(Class<T> type,
Object data)
Converts raw JSON data into a
Model class representation. |
Number |
toNumber(Object data,
String propName)
Converts raw data (one of its properties) to a number representation.
|
String |
toString(Object data,
String propName)
Converts raw data (one of its properties) to string representation.
|
void |
valueHasMutated(String propName)
Whenever model changes a property.
|
void |
verifyUnlocked()
Verifies the model is not locked otherwise throws an exception.
|
Object |
wsOpen(int index,
String url,
Object data)
Opens new WebSocket connection to the specified URL.
|
void |
wsSend(Object webSocket,
String url,
Object data)
Sends a message to existing socket.
|
public BrwsrCtx getContext()
public void acquireLock()
throws IllegalStateException
IllegalStateException - if already lockedpublic void verifyUnlocked()
throws IllegalStateException
IllegalStateException - if the model is lockedpublic void releaseLock()
public void valueHasMutated(String propName)
propName - name of the changed propertypublic void applyBindings()
context.
In case of knockout.js technology, applies given bindings
of the current model to the body element of the page.public void runInBrowser(Runnable run)
context
of the browser. If the caller is already on the right thread, the
run.run() is invoked immediately and synchronously.
Otherwise the method returns immediately and the run()
method is performed laterrun - the action to executepublic void initTo(Collection<?> to, Object array)
array.
The initialization can only be done soon after the the collection
is created, otherwise an exception is throwto - the collection to initialize (assumed to be empty)array - the array to add to the collectionIllegalStateException - if the system has already been initializedpublic void extract(Object json, String[] props, Object[] values)
props and
values arrays have the same length.json - the JSON object (actual type depends on the associated
Technology)props - list of properties to extractvalues - array that will be filled with extracted valuespublic <T> T read(Class<T> modelClass, Object data)
data into a Java Model class.T - type of the model classmodelClass - the type of the class to createdata - the raw JSON datapublic void loadJSON(int index,
String urlBefore,
String urlAfter,
String method,
Object data)
index - the callback index to be used when a reply is received
to call Proto.Type.onMessage(java.lang.Object, int, int, java.lang.Object).urlBefore - the part of the URL before JSON-P callback parameterurlAfter - the rest of the URL or null if no JSON-P is usedmethod - method to use for connection to the serverdata - string, number or a Model generated class to send to
the server when doing a querypublic Object wsOpen(int index, String url, Object data)
index - the index to use later during callbacks to
Proto.Type.onMessage(java.lang.Object, int, int, java.lang.Object)url - the ws:// or wss:// URL to connect todata - data to send to server (usually null)wsSend(java.lang.Object, java.lang.String, java.lang.Object)public void wsSend(Object webSocket, String url, Object data)
webSocket - the socket to send message tourl - the ws:// or wss:// URL to connect to,
preferably the same as the one used when the socket was
openeddata - the data to send or null if the socket is
supposed to be closedpublic String toString(Object data, String propName)
data - the objectpropName - the name of object property or null
if the whole object should be convertedpublic Number toNumber(Object data, String propName)
data - the objectpropName - the name of object property or null
if the whole object should be convertedpublic <T> T toModel(Class<T> type, Object data)
Model class representation.T - type of the model to createtype - class of the model to createdata - raw JSON data (depends on associated Technology)data objectpublic <T> List<T> createList(String propName, int onChange, String... dependingProps)
T - the type of the list elementspropName - name of a property this list is associated withonChange - index of the property to use when the list is modified
during callback to Proto.Type.onChange(java.lang.Object, int)dependingProps - the array of derived properties
that depend on the value of the listpublic <T> void cloneList(Collection<T> to, BrwsrCtx ctx, Collection<T> from)
ctx.T - type of the collectionsto - the target collection to be filled with cloned valuesctx - context for the new collectionfrom - original collection with its dataCopyright © 2014 NetBeans. All Rights Reserved.