Class ReflectiveAttribute<VALUE>
- Type Parameters:
VALUE
-
- All Implemented Interfaces:
Attribute
,ConfigurationObject
- Direct Known Subclasses:
FeaturesAttribute
,GenericMapAttribute
,HttpRequestHeadersAttribute
,LegendAttribute
,NorthArrowAttribute
,PagingAttribute
,ScalebarAttribute
,StaticLayersAttribute
,StyleAttribute
,TableAttribute
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default value of the attribute param in the optional params.static final String
If the parameter in the value object is another value object (and not a PObject or PArray) then this will be a json object describing the embedded param in the same way as each object in clientParams.static final String
Json field that declares if the param is an array.static final String
A string describing the type of the attribute param in the clientConfig.static final String
Name of the value suggestions object in the client config json.static final String
Name of the required parameters object in the client config json.static final String
Name of attribute in the client config json. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract VALUE
createValue
(Template template) Create an instance of a attribute value object.protected final String
Return a descriptive name of this attribute.protected Optional<org.json.JSONObject>
Return an object that will be added to the client config with the key clientInfo.final PObject
The YAML config default values.Get the attribute value.Return the type created bycreateValue(Template)
.final void
printClientConfig
(org.json.JSONWriter json, Template template) Uses reflection on the object created bycreateValue(Template)
to create the options.final void
setConfigName
(String configName) Set the name of the attribute as set in the configuration file.final void
setDefault
(Map<String, Object> defaultValue) Default values for this attribute.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.mapfish.print.config.ConfigurationObject
validate
-
Field Details
-
JSON_NAME
Name of attribute in the client config json. -
JSON_CLIENT_PARAMS
Name of the required parameters object in the client config json. -
JSON_CLIENT_INFO
Name of the value suggestions object in the client config json. -
JSON_ATTRIBUTE_TYPE
A string describing the type of the attribute param in the clientConfig.- See Also:
-
JSON_ATTRIBUTE_EMBEDDED_TYPE
If the parameter in the value object is another value object (and not a PObject or PArray) then this will be a json object describing the embedded param in the same way as each object in clientParams.- See Also:
-
JSON_ATTRIBUTE_DEFAULT
The default value of the attribute param in the optional params.- See Also:
-
JSON_ATTRIBUTE_IS_ARRAY
Json field that declares if the param is an array.- See Also:
-
-
Constructor Details
-
ReflectiveAttribute
public ReflectiveAttribute()
-
-
Method Details
-
getValueType
Return the type created bycreateValue(Template)
.- Specified by:
getValueType
in interfaceAttribute
- Returns:
- the value class
-
getDefaultValue
The YAML config default values.- Returns:
- the default values
-
setDefault
Default values for this attribute. Example:attributes: legend: !legend default: name: "Legend"
- Parameters:
defaultValue
- The default values.
-
setConfigName
Description copied from interface:Attribute
Set the name of the attribute as set in the configuration file.- Specified by:
setConfigName
in interfaceAttribute
- Parameters:
configName
- the name of the attribute
-
getAttributeName
Return a descriptive name of this attribute. -
createValue
Create an instance of a attribute value object. Each instance must be new and unique. Instances must NOT be shared.The object will be populated from the json. Each public field will be populated by looking up the value in the json.
If a field in the object has the
HasDefaultValue
annotation then no exception will be thrown if the json does not contain a value.Fields in the object with the
OneOf
annotation must have one of the fields in the request data.String
Integer
Float
Double
Short
Boolean
Character
Byte
Enum
- PJsonObject
- URL
- Any enum
- PJsonArray
- any type with a 0 argument constructor
- array of any of the above (String[], boolean[], PJsonObject[], ...)
"postConstruct"()
method then it will be called after the fields are all set.In the case where the a parameter type is a normal POJO (not a special case like PJsonObject, URL, enum, double, etc...) then it will be assumed that the json data is a json object and the parameters will be recursively parsed into the new object as if it is also MapLayer parameter object.
It is important to put values in the value object as public fields because reflection is used when printing client config as well as generating documentation. If a field is intended for the client software as information but is not intended to be set (or sent as part of the request data), the field can be a final field.
- Parameters:
template
- the template that this attribute is part of.
-
printClientConfig
public final void printClientConfig(org.json.JSONWriter json, Template template) throws org.json.JSONException Uses reflection on the object created bycreateValue(Template)
to create the options.The public final fields are written as the field name as the key and the value as the value.
The public (non-final) mandatory fields are written as part of clientParams and are written with the field name as the key and the field type as the value.
The public (non-final)
HasDefaultValue
fields are written as part of clientOptions and are written with the field name as the key and an object as a value with a type property with the type and a default property containing the default value.- Specified by:
printClientConfig
in interfaceAttribute
- Parameters:
json
- the json writer to write totemplate
- the template that this attribute is part of- Throws:
org.json.JSONException
-
getClientInfo
Return an object that will be added to the client config with the key clientInfo.- Throws:
org.json.JSONException
-
getValue
public Object getValue(@Nonnull Template template, @Nonnull String attributeName, @Nonnull PObject requestJsonAttributes) Description copied from interface:Attribute
Get the attribute value.
-