class WidgetConfigDef
extends java.lang.Object
To minimize the data transferred when changes need to be sent to a remote side, this class
allows a "state synchronization" of the two sides: each field in a certain class is associated
a numeric ID, which is the same on both sides. With the help of the WidgetConfigUpdates
class, this allows transferring to the remote side of only the WidgetId
and a bit set,
where the bit position gives the field ID in the fieldNames
list.
When resolving the fields, is necessary to process them from the parent class down to the child sub-classes, until the concrete implementation is reached. This allows correct resolution of any custom setters which may defined in the class hierarchy, and also allows a pre-determined processing of the fields, when applying the updates: processing will always start from the base class and move up to the child sub-classes.
When processing the fields directly defined in a certain class, their order is undetermined.
If widget config classes require post-processing dependent on applying the changes in a
certain order, use the ConfigOwner.afterConfigUpdate(WidgetConfig)
method.
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.Class<? extends WidgetConfig> |
cfgCls
The widget configuration class defined by this instance.
|
(package private) java.lang.invoke.MethodHandle[] |
customFieldSetters
A map of field IDs to their associated
custom setters . |
(package private) int |
fieldCount
The number of fields in this widget configuration.
|
(package private) java.util.Map<java.lang.String,java.lang.Integer> |
fieldIds
A map of field names to field IDs.
|
(package private) java.util.List<java.lang.String> |
fieldNames
The list of field names in the configuration.
|
(package private) java.util.Map<java.lang.Class<? extends WidgetConfig>,java.util.Set<java.lang.Integer>> |
fieldsByClass
Mapping of fields by their defining class.
|
(package private) java.lang.invoke.MethodHandle[] |
getters
Getters for fields.
|
(package private) boolean[] |
ignoredFields
A set of field IDs which can be ignored when the configuration is copied from one side
to another.
|
(package private) static java.lang.invoke.MethodHandles.Lookup |
mhfactory
Helper class for method-handle processing.
|
(package private) java.lang.invoke.MethodHandle[] |
setters
Setters for fields.
|
(package private) NativeTypeSerializer[] |
workers |
Constructor and Description |
---|
WidgetConfigDef(java.lang.Class<? extends WidgetConfig> cfgCls)
Constructor used on the side which resolves widget config definition from the concrete
config impl class.
|
WidgetConfigDef(java.lang.Class<? extends WidgetConfig> cfgCls,
java.util.List<java.lang.String> fieldNames)
Constructor used on the receiving side.
|
Modifier and Type | Method and Description |
---|---|
<T extends WidgetConfig> |
newInstance()
Create a new
WidgetConfig instance for the widget config associated with this
definition . |
private void |
postprocess(java.lang.Class<? extends WidgetConfig> cls)
Performs postprocessing of the fields defining in the class or one of the parent classes
of the given class.
|
private void |
readFields(java.lang.Class<? extends WidgetConfig> cls,
java.util.Set<java.lang.String> allFields)
Read all the public fields (which are not static or native) from the entire class hierarchy,
starting from the base class down to sub-classes.
|
static final java.lang.invoke.MethodHandles.Lookup mhfactory
final int fieldCount
final java.util.List<java.lang.String> fieldNames
final java.util.Map<java.lang.String,java.lang.Integer> fieldIds
final java.util.Map<java.lang.Class<? extends WidgetConfig>,java.util.Set<java.lang.Integer>> fieldsByClass
final java.lang.invoke.MethodHandle[] getters
final java.lang.invoke.MethodHandle[] setters
final java.lang.invoke.MethodHandle[] customFieldSetters
custom setters
.final boolean[] ignoredFields
final java.lang.Class<? extends WidgetConfig> cfgCls
final NativeTypeSerializer[] workers
public WidgetConfigDef(java.lang.Class<? extends WidgetConfig> cfgCls)
This will read the fields from the entire class hierarchy (from base class to sub-classes), resolve any custom setters and populate the various maps.
The order of the fields is initially given by the fieldNames
list, and later on
saved in the fieldIds
map.
cfgCls
- The widget configuration class which needs to be resolved.public WidgetConfigDef(java.lang.Class<? extends WidgetConfig> cfgCls, java.util.List<java.lang.String> fieldNames)
WidgetConfigDef(Class)
c'tor is that the field order is given by the list of
field names received as parameter, to synchronize it with the side which sent this
configuration.cfgCls
- The widget configuration class which needs to be resolved.fieldNames
- The list of field names, which also gives the field order.public <T extends WidgetConfig> T newInstance()
WidgetConfig
instance for the widget config associated with this
definition
.
This is a heavy-duty method. Do not use reflection to instantiate it.
private void postprocess(java.lang.Class<? extends WidgetConfig> cls)
cls
- The widget class from where the fields will be read.private void readFields(java.lang.Class<? extends WidgetConfig> cls, java.util.Set<java.lang.String> allFields)
cls
- The class from which fields need to be collected.allFields
- All collected fields will be added to this set.