Class TransformerContextPropertiesWrapper

  • All Implemented Interfaces:
    TransformerContext

    public class TransformerContextPropertiesWrapper
    extends Object
    implements TransformerContext

    A specialized implementation of the TransformerContext interface that allows wrapping an existing context and extending its properties.

    One important feature of a TransformerContext is to provide a set of properties that can be queried by transformers or validators. While these properties are typically global, in some situations it is useful to override or extend them on a local basis, e.g. to define some special properties for a single transformer only.

    This class supports exactly this use case: An instance is created by specifying a TransformerContext to wrap and a map with (additional) properties. The properties() method is implemented to construct a union from the properties of the original context and the map of this instance. The remaining methods simply delegate to the wrapped context.

    Version:
    $Id: TransformerContextPropertiesWrapper.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • TransformerContextPropertiesWrapper

        public TransformerContextPropertiesWrapper​(TransformerContext orgCtx,
                                                   Map<String,​Object> newProps)
        Creates a new instance of TransformerContextPropertiesWrapper and initializes it.
        Parameters:
        orgCtx - the context to be wrapped (must not be null)
        newProps - the new properties (must not be null)
        Throws:
        IllegalArgumentException - if the original context or the map with the new properties is null
    • Method Detail

      • getWrappedContext

        public TransformerContext getWrappedContext()
        Returns the wrapped context.
        Returns:
        the wrapped context
      • getLocale

        public Locale getLocale()
        Returns the current locale. This implementation delegates to the wrapped context.
        Specified by:
        getLocale in interface TransformerContext
        Returns:
        the current locale
      • properties

        public Map<String,​Object> properties()
        Returns a map with properties. This implementation constructs a union from the properties of the wrapped context and the properties stored in this object.
        Specified by:
        properties in interface TransformerContext
        Returns:
        a map with properties
      • getTypedProperty

        public <T> T getTypedProperty​(Class<T> propCls)
        Returns the value of the specified typed property. This implementation delegates to the wrapped context.
        Specified by:
        getTypedProperty in interface TransformerContext
        Type Parameters:
        T - the type of the property
        Parameters:
        propCls - the property class
        Returns:
        the value of this property