Class Description

java.lang.Object
org.apache.rat.config.parameters.Description

public class Description extends Object
A description of a component.
  • Constructor Details

    • Description

      public Description(ComponentType type, String name, String desc, boolean isCollection, Class<?> childClass, Collection<Description> children, boolean required)
      Constructor.
      Parameters:
      type - the type of the component.
      name - the name of the component.
      desc - the description of the component.
      isCollection - true if the getter/setter expects a collection
      childClass - the class for expected for the getter/setter.
      children - the collection of descriptions for all the components that are children of the described component.
      required - If true the component is required.
    • Description

      public Description(ConfigComponent configComponent, boolean isCollection, Class<?> childClass, Collection<Description> children)
      Constructor
      Parameters:
      configComponent - the configuration component.
      isCollection - the collection flag.
      childClass - the type of object that the method getter/setter expects.
      children - the collection of descriptions for all the components that are children the described component.
  • Method Details

    • isRequired

      public boolean isRequired()
      Get the canBeChild flag.
      Returns:
      true if this item can be a child of the containing item.
    • getType

      public ComponentType getType()
      Gets the type of the component.
      Returns:
      the component type.
    • isCollection

      public boolean isCollection()
      Get the isCollection flag.
      Returns:
      true if this is a collection.
    • getChildType

      public Class<?> getChildType()
      Get the class of the objects for the getter/setter methods.
      Returns:
      the getter/setter param class.
    • getCommonName

      public String getCommonName()
      Gets the common name for the matcher. (e.g. 'text', 'spdx', etc.) May not be null.
      Returns:
      The common name for the item being inspected.
    • getDescription

      public String getDescription()
      Gets the description of descriptive text for the component. May be an empty string or null.
      Returns:
      the descriptive text;
    • getParamValue

      public String getParamValue(Object object)
      Retrieve the value of the described parameter from the specified object. If the parameter is a collection return null.
      Parameters:
      object - the object that contains the value.
      Returns:
      the string value.
    • getChildren

      public Map<String,Description> getChildren()
      Gets a map of the parameters that the object contains. For example Copyright has 'start', 'stop', and 'owner' parameters. Some IHeaderMatchers have simple text values (e.g. 'regex' or 'text' types) these should list an unnamed parameter (empty string) with the text value.
      Returns:
      the map of parameters to the objects that represent them.
    • childrenOfType

      public Collection<Description> childrenOfType(ComponentType type)
      Get all the children of a specific type
      Parameters:
      type - the type to return
      Returns:
      the collection of children of the specified type.
    • filterChildren

      public Collection<Description> filterChildren(Predicate<Description> filter)
      Gets a filtered collection of the child descriptions.
      Parameters:
      filter - the filter to apply to the child descriptions.
      Returns:
      the collection of children that matches the filter.
    • methodName

      public String methodName(String prefix)
      Generate a method name for this description.
      Parameters:
      prefix - the start of the method name (e.g. "set", "get" )
      Returns:
      the method name.
    • getter

      public Method getter(Class<?> clazz) throws NoSuchMethodException, SecurityException
      Returns the getter for the component in the specified class.
      Parameters:
      clazz - the Class to get the getter from.
      Returns:
      the getter Method.
      Throws:
      NoSuchMethodException - if the class does not have the getter.
      SecurityException - if the getter can not be accessed.
    • setter

      public Method setter(Class<?> clazz) throws NoSuchMethodException, SecurityException
      Returns the setter for the component in the specified class. Notes:
      • License can not be set in components. They are top level components.
      • Matcher expects an "add" method that accepts an IHeaderMatcher.Builder.
      • Parameter expects a set(String) method.
      • Unlabeled expects a set(String) method.
      • BuilderParam expects a set method that takes a childClass argument.
      Parameters:
      clazz - the Class to get the getter from, generally a Builder class.
      Returns:
      the getter Method.
      Throws:
      NoSuchMethodException - if the class does not have the getter.
      SecurityException - if the getter can not be accessed.
    • setChildren

      public void setChildren(IHeaderMatcher.Builder builder, Map<String,String> attributes)
      Sets the children of values in the builder. Sets the parameters to the values specified in the map. Only children that accept string arguments should be specified.
      Parameters:
      builder - The Matcher builder to set the values in.
      attributes - a Map of parameter names to values.
    • setChild

      public void setChild(IHeaderMatcher.Builder builder, String name, String value)
      Sets the child value in the builder.
      Parameters:
      builder - The Matcher builder to set the values in.
      name - the name of the child to set
      value - the value of the parameter.
    • toString

      public String toString()
      Overrides:
      toString in class Object