Class TemplateAttributeDefinition

All Implemented Interfaces:
AttributeDefinition, ResolverPlugin<IdPAttribute>, Component, DestructableComponent, IdentifiableComponent, IdentifiedComponent, InitializableComponent, UnmodifiableComponent, DisposableBean

@ThreadSafeAfterInit public class TemplateAttributeDefinition extends AbstractAttributeDefinition
An attribute definition that constructs its values based on the values of its dependencies using the Velocity Template Language. Dependencies may have multiple values, however multiple dependencies must have the same number of values. In the case of multi-valued dependencies, the template will be evaluated multiples times, iterating over each dependency.

The template is inserted into the engine with a unique name derived from this class and from the id supplied for this attribute.

  • Field Details

    • log

      @Nonnull private final org.slf4j.Logger log
      Class logger.
    • template

      @NonnullAfterInit private Template template
      Template to be evaluated.
    • templateText

      @NonnullAfterInit private String templateText
      Template (as Text) to be evaluated.
    • engine

      @NonnullAfterInit private engine
  • Constructor Details

    • TemplateAttributeDefinition

      public TemplateAttributeDefinition()
  • Method Details

    • getTemplate

      @NonnullAfterInit public Template getTemplate()
      Get the template text to be evaluated.
      the template
    • getTemplateText

      @NonnullAfterInit public String getTemplateText()
      Get the template text to be evaluated.
      the template
    • setTemplateText

      public void setTemplateText(@Nullable String velocityTemplate)
      Set the literal text of the template to be evaluated.
      velocityTemplate - template to be evaluated
    • getVelocityEngine

      @NonnullAfterInit public getVelocityEngine()
      Get the VelocityEngine to be used.
      the template
    • setVelocityEngine

      public void setVelocityEngine(@Nonnull velocityEngine)
      Set the VelocityEngine to be used.
      velocityEngine - engine to be used
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      doInitialize in class AbstractAttributeDefinition
    • doAttributeDefinitionResolve

      @Nonnull protected IdPAttribute doAttributeDefinitionResolve(@Nonnull AttributeResolutionContext resolutionContext, @Nonnull AttributeResolverWorkContext workContext) throws ResolutionException
      Creates and populates the values for the resolved attribute. Implementations should not set, or otherwise manage, the resolved attribute's display name, description or encoders. Nor should the resultant attribute be recorded in the given resolution context.
      Specified by:
      doAttributeDefinitionResolve in class AbstractAttributeDefinition
      resolutionContext - current attribute resolution context
      workContext - current resolver work context
      resolved attribute or null if nothing to resolve.
      ResolutionException - thrown if there is a problem resolving and creating the attribute
    • addAttributeValues

      private int addAttributeValues(@Nonnull String attributeName, @Nullable List<IdPAttributeValue> attributeValues, @Nonnull @NonnullElements Map<String,Iterator<IdPAttributeValue>> sourceValues, int curValueCount) throws ResolutionException
      Add values for a given attribute to the source Map. Helper function for setupSourceValues(AttributeResolverWorkContext, Map)
      attributeName - the attribute name under consideration
      attributeValues - The values to add.
      sourceValues - the Map to add to
      curValueCount - how many values to expect. 0 means never set
      the number of values to expect, 0 means still not set.
      ResolutionException - if there is a mismatched count of attributes
    • setupSourceValues

      private int setupSourceValues(@Nonnull AttributeResolverWorkContext workContext, @Nonnull @NonnullElements Map<String,Iterator<IdPAttributeValue>> sourceValues) throws ResolutionException
      Set up a map which can be used to populate the template. The key is the attribute name and the value is the iterator to give all the names. We also return how deep the iteration will be and throw an exception if there is a mismatch in number of elements in any attribute.
      workContext - source for dependencies
      sourceValues - to populate with the attribute iterators
      how many values in the attributes
      ResolutionException - if there is a mismatched count of attributes