public final class Proto
extends java.lang.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(java.lang.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(java.lang.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(java.lang.String id)
Initializes the associated model to the specified element's subtree.
|
<T> void |
cloneList(java.util.Collection<T> to,
BrwsrCtx ctx,
java.util.Collection<T> from)
Copies content of one collection to another, re-assigning all its
elements from their current context to the new
ctx . |
<T> java.util.List<T> |
createList(java.lang.String propName,
int onChange,
java.lang.String... dependingProps)
Creates new JSON like observable list.
|
void |
extract(java.lang.Object json,
java.lang.String[] props,
java.lang.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(java.util.Collection<?> to,
java.lang.Object array)
Initializes the provided collection with a content of the
array . |
void |
loadJSON(int index,
java.lang.String urlBefore,
java.lang.String urlAfter,
java.lang.String method,
java.lang.Object data)
Initializes asynchronous JSON connection to specified URL.
|
void |
loadJSON(int index,
java.lang.String urlBefore,
java.lang.String urlAfter,
java.lang.String method,
java.lang.Object data,
java.lang.Object... params)
Initializes asynchronous JSON connection to specified URL.
|
void |
loadJSONWithHeaders(int index,
java.lang.String headers,
java.lang.String urlBefore,
java.lang.String urlAfter,
java.lang.String method,
java.lang.Object data,
java.lang.Object... params)
Initializes asynchronous JSON connection to specified URL.
|
<T> T |
read(java.lang.Class<T> modelClass,
java.lang.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,
java.lang.Object... args)
Invokes the specified function index in the
context
of the browser. |
void |
runInBrowser(java.lang.Runnable run)
Invokes the provided runnable in the
context
of the browser. |
<T> T |
toModel(java.lang.Class<T> type,
java.lang.Object data)
Converts raw JSON data into a
Model class representation. |
java.lang.Number |
toNumber(java.lang.Object data,
java.lang.String propName)
Converts raw data (one of its properties) to a number representation.
|
java.lang.String |
toString(java.lang.Object data,
java.lang.String propName)
Converts raw data (one of its properties) to string representation.
|
void |
valueHasMutated(java.lang.String propName)
Whenever model changes a property.
|
void |
valueHasMutated(java.lang.String propName,
java.lang.Object oldValue,
java.lang.Object newValue)
Whenever model changes a property it should notify the
associated technology.
|
void |
verifyUnlocked()
Verifies the model is not locked otherwise throws an exception.
|
java.lang.Object |
wsOpen(int index,
java.lang.String url,
java.lang.Object data)
Opens new WebSocket connection to the specified URL.
|
void |
wsSend(java.lang.Object webSocket,
java.lang.String url,
java.lang.Object data)
Sends a message to existing socket.
|
public BrwsrCtx getContext()
public void acquireLock() throws java.lang.IllegalStateException
derived property
on this proto object. This proto object must not be locked yet. No
dependency tracking is performed.java.lang.IllegalStateException
- if already lockedpublic void acquireLock(java.lang.String propName) throws java.lang.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 computejava.lang.IllegalStateException
- thrown when there is a cyclic
call is detectedpublic void accessProperty(java.lang.String propName) throws java.lang.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 requestedjava.lang.IllegalStateException
- if the model is lockedpublic void verifyUnlocked() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the model is lockedpublic void releaseLock()
public void valueHasMutated(java.lang.String propName)
BrwsrCtx.execute(java.lang.Runnable)
.propName
- name of the changed propertypublic void valueHasMutated(java.lang.String propName, java.lang.Object oldValue, java.lang.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(java.lang.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(java.lang.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, java.lang.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(java.util.Collection<?> to, java.lang.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 collectionjava.lang.IllegalStateException
- if the system has already been initializedpublic void extract(java.lang.Object json, java.lang.String[] props, java.lang.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(java.lang.Class<T> modelClass, java.lang.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, java.lang.String urlBefore, java.lang.String urlAfter, java.lang.String method, java.lang.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, java.lang.String urlBefore, java.lang.String urlAfter, java.lang.String method, java.lang.Object data, java.lang.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, java.lang.String headers, java.lang.String urlBefore, java.lang.String urlAfter, java.lang.String method, java.lang.Object data, java.lang.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 java.lang.Object wsOpen(int index, java.lang.String url, java.lang.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(java.lang.Object webSocket, java.lang.String url, java.lang.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 java.lang.String toString(java.lang.Object data, java.lang.String propName)
data
- the objectpropName
- the name of object property or null
if the whole object should be convertedpublic java.lang.Number toNumber(java.lang.Object data, java.lang.String propName)
data
- the objectpropName
- the name of object property or null
if the whole object should be convertedpublic <T> T toModel(java.lang.Class<T> type, java.lang.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> java.util.List<T> createList(java.lang.String propName, int onChange, java.lang.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(java.util.Collection<T> to, BrwsrCtx ctx, java.util.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 © 2021 The Apache Software Foundation. All rights reserved.