Class ConfigPath

java.lang.Object
ru.vyarus.dropwizard.guice.module.yaml.ConfigPath

public class ConfigPath extends Object
Сonfiguration path's value. Value is resolved using type information from configuration class and actual instance analysis. This means that item declaration could change if configuration changes. The most obvious example is property-dependent mapping, like server object (when one property could completely change available configuration paths (simple and usual servers)).

One edge case is possible (but assumed to never happen): when property declared as Object in class, actual type could be resolved from value. But that means that if value become null, property binding type would change to Object. Assume no one would ever use Object for configuration property (or, if so, value will never be null because otherwise there will be no binding available in both cases).

Item contains root and child references and might be traversed like a tree.

Since:
04.05.2018
  • Constructor Details

    • ConfigPath

      public ConfigPath(ConfigPath root, Class declarationClass, Class declaredType, Class valueType, List<Type> declaredTypeGenerics, List<Type> valueTypeGenerics, String path, Object value, boolean customType, boolean objectDeclaration, Annotation qualifier)
      Create a parsed configuration path.
      Parameters:
      root - root path
      declarationClass - configuration field declaration class
      declaredType - field type
      valueType - actual value type
      declaredTypeGenerics - declared generics
      valueTypeGenerics - value generics
      path - full property path
      value - value object
      customType - object type (not primitive, enum or array)
      objectDeclaration - raw Object declared
      qualifier - field qualifier annotation (to use)
  • Method Details

    • getRoot

      public ConfigPath getRoot()
      For example, if current path is "some.long.path" then method returns "some.long" path item.
      Returns:
      parent config level or null for root level
    • getChildren

      public List<ConfigPath> getChildren()
      For example, if current path is "sub" then returned items would be next level paths: "sub.val1", "sub.val2" etc. Useful for manual config analysis.
      Returns:
      list of child properties
    • getDeclarationClass

      public Class getDeclarationClass()
      Note that this would be last path's part (property) declaration class. For example, for path "some.path" it would be class of "some" (sub object of configuration).
      Returns:
      class where property was declared
    • getDeclaredType

      public Class getDeclaredType()
      If property is declared as collection implementation then collection interface will be used instead. For example, ArrayList<String> then declaration type would be List<String>.

      Edge case possible: if class declaration is Object and value is not null then actual value would be taken from value. This case should never appear, because it's insane to use Object to declare property type.

      Returns:
      type declaration from class
    • getValueType

      public Class getValueType()
      When value is null, type may be still different from getDeclaredType() if declared type was actually some collection implementation.
      Returns:
      actual path value type (from actual instance or declared type, when instance is null)
    • getDeclaredTypeGenerics

      public List<Type> getDeclaredTypeGenerics()
      For example, if value is List then one parameter will be available with list generic type.

      When actual generics are not set then upper bounds of declared generics will be used. For example, for List it will be [Object] and for class Some<T extends Comparable> - [Comparable].

      Returns:
      binding type generics or empty list if not generified type
      See Also:
    • getValueTypeGenerics

      public List<Type> getValueTypeGenerics()
      Even when value is null, generics could differ from declared type generics. For example, declaration is ExtraList<String, Integer>, declaration type List<String> (so it's generics just [List]). And type generics would be [String, Integer].
      Returns:
      generics of value type or empty list if not generified type
    • getPath

      public String getPath()
      E.g. "some.property.path".
      Returns:
      full yaml path of property
    • getValue

      public Object getValue()
      Returns:
      property value (may be null)
    • isCustomType

      public boolean isCustomType()
      Type considered custom when it's not primitive, collection and few other simple types. In essence, this is type which contains (or might contain) sub paths.
      Returns:
      true when value is sub-configuration object, false when value is just a value
    • isObjectDeclaration

      public boolean isObjectDeclaration()
      True means that property declared as Object. In this case type could be resolved from actual value (if it's not null). This should be next to impossible case for sane configurations (who would use Object for configuration property?).

      Indicator might be important because in this case binding would be of Object type when value is null and with value type for not null value.

      Returns:
      true when property is declared as Object in class, false otherwise
    • getQualifier

      public Annotation getQualifier()
      Custom qualifiers might be used to simplify configuration bindings (because @Config qualifier requires the exact yaml path).
      Returns:
      custom qualifier annotation declared on config class or null
    • getDeclaredTypeGenericClasses

      public List<Class> getDeclaredTypeGenericClasses()
      Useful for quick analysis when deeper generic type knowledge is not important (e.g. to know type in list, set or map).
      Returns:
      declared type generics as class or empty map if not generics
      See Also:
    • getValueTypeGenericClasses

      public List<Class> getValueTypeGenericClasses()
      Useful for quick analysis when deeper generic type knowledge is not important..
      Returns:
      value type generics as class or empty map if not generics
    • getRootDeclarationClass

      public Class getRootDeclarationClass()
      Useful to filter out core dropwizard properties (where root type would be Configuration.
      Returns:
      root configuration class where entire path started
    • getDeclaredTypeWithGenerics

      public Type getDeclaredTypeWithGenerics()
      Returns:
      declared type with known generics (parameterized type) or simple class if no generics provided
    • getTypeWithGenerics

      public Type getTypeWithGenerics()
      When value null will be the same as getDeclaredTypeWithGenerics(). If types are different (value not null), then actual type generics will be tracked from known definition generics.
      Returns:
      value type with generics (parameterized type) or simple clas if not generics provided
    • getLastPathLevel

      public String getLastPathLevel()
      Returns:
      last path element (e.g. for "some.long.path" return "path")
    • toStringDeclaredType

      public String toStringDeclaredType()
      Returns:
      declared type string including generics
    • toStringType

      public String toStringType()
      Returns:
      value type string including generics
    • toStringValue

      public String toStringValue()
      Only put string values other than null into quotes (to be more obvious).
      Returns:
      value as string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object