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 |
accessProperty(String propName)
A property on this proto object is about to be accessed.
|
void |
acquireLock()
Acquires global lock to compute a
derived property
on this proto object. |
void |
acquireLock(String propName)
Acquires global lock to compute a
derived property
on this proto object. |
void |
applyBindings()
Initializes the associated model in the current
context . |
void |
applyBindings(String id)
Initializes the associated model to the specified element's subtree.
|
<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.
|
void |
loadJSON(int index,
String urlBefore,
String urlAfter,
String method,
Object data,
Object... params)
Initializes asynchronous JSON connection to specified URL.
|
void |
loadJSONWithHeaders(int index,
String headers,
String urlBefore,
String urlAfter,
String method,
Object data,
Object... params)
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(int index,
Object... args)
Invokes the specified function index in the
context
of the browser. |
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 |
valueHasMutated(String propName,
Object oldValue,
Object newValue)
Whenever model changes a propertyit should notify the
associated technology.
|
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
derived property
on this proto object. This proto object must not be locked yet. No
dependency tracking is performed.IllegalStateException
- if already lockedpublic void acquireLock(String propName) throws IllegalStateException
derived property
on this proto object. This proto object must not be locked yet. The
name of the property is used to track dependencies on own
properties of other proto objects - when they are changed, this
property is changed too
.propName
- name of property we are about to computeIllegalStateException
- thrown when there is a cyclic
call is detectedpublic void accessProperty(String propName) throws IllegalStateException
locked yet
. If everything is OK, the
propName
is recorded in the chain of dependencies
tracked by Proto.acquireLock(java.lang.String)
and watched by
Proto.valueHasMutated(java.lang.String)
.propName
- name of the property that is requestedIllegalStateException
- if the model is lockedpublic void verifyUnlocked() throws IllegalStateException
IllegalStateException
- if the model is lockedpublic void releaseLock()
public void valueHasMutated(String propName)
BrwsrCtx.execute(java.lang.Runnable)
.propName
- name of the changed propertypublic void valueHasMutated(String propName, Object oldValue, Object newValue)
Proto.valueHasMutated(java.lang.String)
method.
Since 0.8.3: This method may be called by any thread - it reschedules
its actual execution into appropriate one by using
BrwsrCtx.execute(java.lang.Runnable)
.propName
- name of the changed propertyoldValue
- provides previous value of the propertynewValue
- provides new value of the 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 applyBindings(String id)
context
and
in case of knockout.js applies given bindings
of the current model to the element of the page with 'id' attribute
set to the specified id
value.id
- the id of element to apply the binding toTechnology.ApplyId
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 runInBrowser(int index, Object... args)
context
of the browser. If the caller is already on the right thread, the
index-th function is invoked immediately and synchronously.
Otherwise the method returns immediately and the function is invoked
later.index
- the index of the function as will be passed to
Proto.Type.call(java.lang.Object, int, java.lang.Object, java.lang.Object)
methodargs
- array of arguments that will be passed as
data
argument of the call
method.public 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)
Proto.loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)
with no extra parameters.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 void loadJSON(int index, String urlBefore, String urlAfter, String method, Object data, Object... params)
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 queryparams
- extra params to pass back when calling
Proto.Type.onMessage(java.lang.Object, int, int, java.lang.Object, java.lang.Object[])
public void loadJSONWithHeaders(int index, String headers, String urlBefore, String urlAfter, String method, Object data, Object... params)
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)
.headers
- headers to use for the request or null
to use default onesurlBefore
- 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 queryparams
- extra params to pass back when calling
Proto.Type.onMessage(java.lang.Object, int, int, java.lang.Object, java.lang.Object[])
public 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
)Proto.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
opened
data
- 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)
.
If the value is Integer.MIN_VALUE
, then the list is
not fully Property.mutable()
and throws UnsupportedOperationException
on such attempts.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 © 2018 NetBeans. All rights reserved.