Class ReflectiveAttribute<VALUE>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String JSON_ATTRIBUTE_DEFAULT
      The default value of the attribute param in the optional params.
      static java.lang.String 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.
      static java.lang.String JSON_ATTRIBUTE_IS_ARRAY
      Json field that declares if the param is an array.
      static java.lang.String JSON_ATTRIBUTE_TYPE
      A string describing the type of the attribute param in the clientConfig.
      static java.lang.String JSON_CLIENT_INFO
      Name of the value suggestions object in the client config json.
      static java.lang.String JSON_CLIENT_PARAMS
      Name of the required parameters object in the client config json.
      static java.lang.String JSON_NAME
      Name of attribute in the client config json.
    • Field Detail

      • JSON_ATTRIBUTE_TYPE

        public static final java.lang.String JSON_ATTRIBUTE_TYPE
        A string describing the type of the attribute param in the clientConfig.
        See Also:
        Constant Field Values
      • JSON_ATTRIBUTE_EMBEDDED_TYPE

        public static final java.lang.String 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:
        Constant Field Values
      • JSON_ATTRIBUTE_DEFAULT

        public static final java.lang.String JSON_ATTRIBUTE_DEFAULT
        The default value of the attribute param in the optional params.
        See Also:
        Constant Field Values
      • JSON_ATTRIBUTE_IS_ARRAY

        public static final java.lang.String JSON_ATTRIBUTE_IS_ARRAY
        Json field that declares if the param is an array.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ReflectiveAttribute

        public ReflectiveAttribute()
    • Method Detail

      • getDefaultValue

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

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

        public final void setConfigName​(java.lang.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 java.lang.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.

        • 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[], ...)
        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 java.util.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 java.lang.Object getValue​(@Nonnull
                                         Template template,
                                         @Nonnull
                                         java.lang.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