Modifier | Constructor and Description |
---|---|
protected |
Type(Class<? extends Model> clazz,
Class<?> modelFor,
int properties,
int functions)
Constructor for subclasses generated by the annotation processor
associated with
Model annotation. |
Modifier and Type | Method and Description |
---|---|
Boolean |
boolValue(Object val)
Converts the value to boolean.
|
protected abstract void |
call(Model model,
int index,
Object data,
Object event)
Invokes a
Proto.Type.registerFunction(java.lang.String, int) registered function
on given object. |
Character |
charValue(Object val)
Converts the value to character.
|
protected abstract Model |
cloneTo(Model model,
BrwsrCtx ctx)
Re-binds the model object to new browser context.
|
<T> void |
copyJSON(BrwsrCtx context,
Object[] src,
Class<T> destType,
T[] dest)
Converts and array of raw JSON objects into an array of typed
Java
Model classes. |
Proto |
createProto(Object obj,
BrwsrCtx context)
Creates new proto-object for given
Model class bound to
provided context. |
<T> T |
extractValue(Class<T> type,
Object val)
Extracts value of specific type from given object.
|
protected abstract Object |
getValue(Model model,
int index)
Obtains and returns value of a
registered property . |
int |
hashPlus(Object o,
int h)
Cumulative hash function.
|
boolean |
isSame(double a,
double b)
Compares two objects that can be converted to (floating point)
numbers.
|
boolean |
isSame(int a,
int b)
Compares two objects that can be converted to integers.
|
boolean |
isSame(Object a,
Object b)
Compares two objects for being the same - e.g.
|
Number |
numberValue(Object val)
Converts the value to number.
|
protected abstract void |
onChange(Model model,
int index)
Called when a
registered property
changes its value. |
protected void |
onMessage(Model model,
int index,
int type,
Object data)
Called to report results of asynchronous over-the-wire
communication.
|
protected void |
onMessage(Model model,
int index,
int type,
Object data,
Object[] params)
Called to report results of asynchronous over-the-wire
communication.
|
protected abstract Proto |
protoFor(Object object)
Finds out if there is an associated proto-object for given
object.
|
protected abstract Model |
read(BrwsrCtx c,
Object json)
Reads raw JSON data and converts them to our model class.
|
protected void |
registerFunction(String name,
int index)
Registers function of given name at given index.
|
protected void |
registerProperty(String name,
int index,
boolean readOnly)
Registers property for the type.
|
protected void |
registerProperty(String name,
int index,
boolean readOnly,
boolean constant)
Registers property for the type.
|
<T> void |
replaceValue(Collection<? super T> arr,
Class<T> type,
Object value)
Special dealing with array &
List values. |
protected abstract void |
setValue(Model model,
int index,
Object value)
Sets value of a
registered property
to new value. |
String |
stringValue(Object val)
Converts the value to string.
|
String |
toJSON(Object obj)
Converts an object to its JSON value.
|
protected Type(Class<? extends Model> clazz, Class<?> modelFor, int properties, int functions)
Model
annotation.clazz
- the generated model classmodelFor
- the original class annotated by the Model
annotation.properties
- number of properties the class hasfunctions
- number of functions the class hasprotected final void registerProperty(String name, int index, boolean readOnly)
name
- name of the propertyindex
- index of the propertyreadOnly
- is the property read only?protected final void registerProperty(String name, int index, boolean readOnly, boolean constant)
readOnly
and constant
is: The constant
value is
assigned only at the beginning and never changed then - like the
non-mutable
property. On the other
hand, a readOnly
property can change its value,
but not via a setter - just like ComputedProperty
.
This method isn't synchronized. Synchronization is up to the caller.
name
- name of the propertyindex
- index of the propertyreadOnly
- is the property read only?constant
- is the property assigned once and never changed again?protected final void registerFunction(String name, int index)
name
- name of the functionindex
- name of the typepublic Proto createProto(Object obj, BrwsrCtx context)
Model
class bound to
provided context.obj
- instance of appropriate Model
classcontext
- the browser contextprotected abstract void setValue(Model model, int index, Object value)
registered property
to new value.model
- the instance of model class
index
- index of the property used during registrationvalue
- the value to set the property toprotected abstract Object getValue(Model model, int index)
registered property
.model
- the instance of model class
index
- index of the property used during registrationprotected abstract void call(Model model, int index, Object data, Object event) throws Exception
Proto.Type.registerFunction(java.lang.String, int)
registered function
on given object.model
- the instance of model class
index
- index of the property used during registrationdata
- the currently selected object the function is about to operate onevent
- the event that triggered the eventException
- the method can throw exception which is then loggedprotected abstract Model cloneTo(Model model, BrwsrCtx ctx)
model
- the instance of model class
ctx
- browser context to clone the object toprotected abstract Model read(BrwsrCtx c, Object json)
c
- the browser context to work injson
- raw JSON data to get values fromprotected abstract void onChange(Model model, int index)
registered property
changes its value.model
- the object that has the propertyindex
- the index of the property during registrationprotected abstract Proto protoFor(Object object)
object
- an object, presumably (but not necessarily) instance of Model classnull
protected void onMessage(Model model, int index, int type, Object data)
Proto.wsOpen(int, java.lang.String, java.lang.Object)
or Proto.loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)
.model
- the instance of the model classindex
- index used during initiating the communication (via loadJSON
or wsOpen
calls)type
- type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose -
not all messages are applicable to all communication protocols (JSON has only 1 and 2).data
- null
or string, number or a Model
class
obtained to the server as a responseprotected void onMessage(Model model, int index, int type, Object data, Object[] params)
Proto.wsOpen(int, java.lang.String, java.lang.Object)
or Proto.loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)
.model
- the instance of the model classindex
- index used during initiating the communication (via loadJSON
or wsOpen
calls)type
- type of the message: 0 - onOpen, 1 - onMessage, 2 - onError, 3 - onClose -
not all messages are applicable to all communication protocols (JSON has only 1 and 2).data
- null
or string, number or a Model
class
obtained to the server as a responseparams
- extra parameters as passed for example to
Proto.loadJSON(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object, java.lang.Object...)
methodpublic <T> void copyJSON(BrwsrCtx context, Object[] src, Class<T> destType, T[] dest)
Model
classes.T
- the type of the destination arraycontext
- browser context to usesrc
- array of raw JSON objectsdestType
- type of the individual array elementsdest
- array to be filled with read type instancespublic final boolean isSame(int a, int b)
a
- first valueb
- second valuepublic final boolean isSame(double a, double b)
a
- first valueb
- second valuepublic final boolean isSame(Object a, Object b)
==
or equals
.a
- first valueb
- second valuepublic final int hashPlus(Object o, int h)
o
- the object (or null
)h
- the previous value of the hashpublic final String toJSON(Object obj)
obj
- the object to convertpublic final String stringValue(Object val)
val
- the valuepublic final Number numberValue(Object val)
val
- the valuepublic final Character charValue(Object val)
val
- the valuepublic final Boolean boolValue(Object val)
val
- the valuepublic final <T> T extractValue(Class<T> type, Object val)
T
- the type of object one is interested intype
- the typeval
- the object to convert to typepublic final <T> void replaceValue(Collection<? super T> arr, Class<T> type, Object value)
List
values. This method
takes the provided collection, empties it and fills it again
with values extracted from value
(which is supposed
to be an array).T
- the type of list elementsarr
- collection to fill with elements in valuetype
- the type of elements in the collectionvalue
- array of elements to put into the collecition. If
value is not an array it is wrapped into array with only elementCopyright © 2021 The Apache Software Foundation. All rights reserved.