Interface PropertySource

All Known Subinterfaces:
Renderer, Rule
All Known Implementing Classes:
AbstractAccumulatingRenderer, AbstractIncrementingRenderer, AbstractPropertySource, AbstractRenderer, AbstractRule, AbstractVisitorRule, CodeClimateRenderer, CSVRenderer, EmacsRenderer, EmptyRenderer, HTMLRenderer, IDEAJRenderer, JsonRenderer, JvmLanguagePropertyBundle, LanguagePropertyBundle, RuleReference, SarifRenderer, SummaryHTMLRenderer, TextColorRenderer, TextPadRenderer, TextRenderer, UnnecessaryPmdSuppressionRule, VBHTMLRenderer, XMLRenderer, XPathRule, XSLTRenderer, YAHTMLRenderer

public interface PropertySource
Entity that manages a list of properties. Properties are described by property descriptors. A property source maintains a mapping of property descriptors to property values. The value of a property can be set by setProperty(PropertyDescriptor, Object). If the property wasn't set with this method, then the property is assumed to take a default value, which is specified by the property descriptor.

Bad configuration of the properties may be reported by dysfunctionReason().

Notable instances of this interface are rules and renderers.

Author:
Brian Remedios
  • Method Details

    • definePropertyDescriptor

      void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) throws IllegalArgumentException
      Defines a new property. Properties must be defined before they can be set a value.
      Parameters:
      propertyDescriptor - The property descriptor.
      Throws:
      IllegalArgumentException - If there is already a property defined the same name.
    • getName

      String getName()
      Gets the name of this property source. This is e.g. the name of the rule or renderer.
      Returns:
      The name
    • getPropertyDescriptor

      PropertyDescriptor<?> getPropertyDescriptor(String name)
      Get the PropertyDescriptor for the given property name.
      Parameters:
      name - The name of the property.
      Returns:
      The PropertyDescriptor for the named property, null if there is no such property defined.
    • getPropertyDescriptors

      List<PropertyDescriptor<?>> getPropertyDescriptors()
      Get the descriptors of all defined properties. The properties are returned sorted by UI order.
      Returns:
      The PropertyDescriptors in UI order.
    • getOverriddenPropertyDescriptors

      List<PropertyDescriptor<?>> getOverriddenPropertyDescriptors()
      Returns a modifiable list of the property descriptors that don't use default values.
      Returns:
      The descriptors that don't use default values
    • getProperty

      <T> T getProperty(PropertyDescriptor<T> propertyDescriptor)
      Get the typed value for the given property. Multi valued properties return immutable lists.
      Type Parameters:
      T - The underlying type of the property descriptor.
      Parameters:
      propertyDescriptor - The property descriptor.
      Returns:
      The property value.
    • isPropertyOverridden

      boolean isPropertyOverridden(PropertyDescriptor<?> propertyDescriptor)
      Returns true if the given property has been set to a value somewhere in the XML.
      Parameters:
      propertyDescriptor - The descriptor
      Returns:
      True if the property has been set
    • setProperty

      <T> void setProperty(PropertyDescriptor<T> propertyDescriptor, T value)
      Set the property value specified. This is also referred to as "overriding" the (default) value of a property.
      Type Parameters:
      T - The underlying type of the property descriptor.
      Parameters:
      propertyDescriptor - The property descriptor.
      value - The value to set.
    • getPropertiesByPropertyDescriptor

      Map<PropertyDescriptor<?>,Object> getPropertiesByPropertyDescriptor()
      Returns an unmodifiable map of descriptors to property values for the current receiver. The returned map has an entry for every defined descriptor (getPropertyDescriptors()), if they were not specified explicitly, then default values are used.
      Returns:
      An unmodifiable map of descriptors to property values
    • getOverriddenPropertiesByPropertyDescriptor

      Map<PropertyDescriptor<?>,Object> getOverriddenPropertiesByPropertyDescriptor()
      Returns a modifiable map of the property descriptors that don't use default values, to their overridden value. Modifications on the returned map don't affect this property source.
      Returns:
      The descriptors that don't use default values
    • hasDescriptor

      boolean hasDescriptor(PropertyDescriptor<?> descriptor)
      Returns whether the specified property is defined on this property source, in which case it can be set or retrieved with getProperty(PropertyDescriptor) and setProperty(PropertyDescriptor, Object).
      Parameters:
      descriptor - The descriptor to look for
      Returns:
      true if the descriptor is defined, false otherwise.
    • dysfunctionReason

      default String dysfunctionReason()
      Returns a description of why the receiver may be dysfunctional. Usually due to missing property values or some kind of conflict between values. Returns null if the receiver is ok.
      Returns:
      String