Class ReflectiveAttribute<VALUE>

java.lang.Object
org.mapfish.print.attribute.ReflectiveAttribute<VALUE>
Type Parameters:
VALUE -
All Implemented Interfaces:
Attribute, ConfigurationObject
Direct Known Subclasses:
FeaturesAttribute, GenericMapAttribute, HttpRequestHeadersAttribute, LegendAttribute, NorthArrowAttribute, PagingAttribute, ScalebarAttribute, StaticLayersAttribute, StyleAttribute, TableAttribute

public abstract class ReflectiveAttribute<VALUE> extends Object implements Attribute
Used for attribute that can have defaults specified in the YAML config file.
  • Field Details

  • Constructor Details

    • ReflectiveAttribute

      public ReflectiveAttribute()
  • Method Details

    • getValueType

      public abstract Class<? extends VALUE> getValueType()
      Return the type created by createValue(Template).
      Specified by:
      getValueType in interface Attribute
      Returns:
      the value class
    • getDefaultValue

      public final PObject getDefaultValue()
      The YAML config default values.
      Returns:
      the default values
    • setDefault

      public final void setDefault(Map<String,Object> defaultValue)
      Default values for this attribute. Example:
      
       attributes:
         legend: !legend
           default:
             name: "Legend"
      Parameters:
      defaultValue - The default values.
    • setConfigName

      public final void setConfigName(String configName)
      Description copied from interface: Attribute
      Set the name of the attribute as set in the configuration file.
      Specified by:
      setConfigName in interface Attribute
      Parameters:
      configName - the name of the attribute
    • getAttributeName

      protected final String getAttributeName()
      Return a descriptive name of this attribute.
    • createValue

      public abstract VALUE createValue(Template template)
      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.

      If there is a public "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 by createValue(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 interface Attribute
      Parameters:
      json - the json writer to write to
      template - the template that this attribute is part of
      Throws:
      org.json.JSONException
    • getClientInfo

      protected Optional<org.json.JSONObject> getClientInfo() throws org.json.JSONException
      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.
      Specified by:
      getValue in interface Attribute
      Parameters:
      template - the template of the current request.
      attributeName - the name of the attribute
      requestJsonAttributes - the json data for populating the attribute values
      Returns:
      the value