Class ItemToMapConversionContext


  • public class ItemToMapConversionContext
    extends java.lang.Object
    This class encapsulates the context of a conversion from an ItemModel to a Map
    • Constructor Detail

      • ItemToMapConversionContext

        public ItemToMapConversionContext​(ItemModel data,
                                          IntegrationObjectItemModel metadata)
        Instantiates a top level context. The top level context does not have parent context associated with it.
        Parameters:
        data - item being converted.
        metadata - integration object item describing the structure of the conversion result, e.g. if the data is being converted to a Map, then what attributes the map should have.
        See Also:
        getParentContext()
      • ItemToMapConversionContext

        public ItemToMapConversionContext​(ItemModel data,
                                          TypeDescriptor metadata)
        Instantiates a top level context. The top level context does not have parent context associated with it.
        Parameters:
        data - item being converted.
        metadata - integration object item descriptor defining the structure of the conversion result, e.g. if the data is being converted to a Map, then what attributes the map should have.
        See Also:
        getParentContext()
    • Method Detail

      • getItemModel

        public ItemModel getItemModel()
        Retrieves the item being converted.
        Returns:
        item being converted.
      • getTypeDescriptor

        public TypeDescriptor getTypeDescriptor()
        Retrieves the integration object item descriptor associated with the conversion.
        Returns:
        metadata describing the structure of the conversion result.
      • createSubContext

        public ItemToMapConversionContext createSubContext​(ItemModel itemModel,
                                                           IntegrationObjectItemModel objItemModel)
        Creates sub-context from this context.
        Parameters:
        itemModel - data item to be used in the context to create
        objItemModel - integration object item to be used in the context to create
        Returns:
        a new conversion context with current context as its parent.
      • createSubContext

        public ItemToMapConversionContext createSubContext​(ItemModel itemModel,
                                                           TypeDescriptor descriptor)
        Creates sub-context from this context.
        Parameters:
        itemModel - data item to be used in the context to create
        descriptor - integration object item descriptor to be used in the context to create
        Returns:
        a new conversion context with current context as its parent.
      • setConversionResult

        public void setConversionResult​(java.util.Map<java.lang.String,​java.lang.Object> result)
        Sets conversion result for the item in this context.
        Parameters:
        result - map, to which the getItemModel() was converted.
      • getConversionResult

        public java.util.Map<java.lang.String,​java.lang.Object> getConversionResult()
        Retrieves a conversion result for the item in this context. Because this method is used to retrieve result of current item conversion in the parent contexts, so that it can be injected to a nested item, this method returns only a map containing only key attribute values of the previously converted item. Without limiting the conversion result to key attributes there is a risk of causing an infinite loop in the conversion result structure.

        Consider this. We need to convert an Order, which has code attribute (its key) and a collection of OrderEntry items. Each OrderEntry has a reference back to the Order it belongs to, some entryNumber attribute, which makes the entry unique when combined with the Order, and some other meaningful attributes, e.g. Product the line is associated with, quantity (how many products purchased), etc. During conversion when we will get to OrderEntry conversion and will attempt to convert its order attribute value we will detect that the Order has been converted already into a map. However, if we just take that map "as is" it will contain the orderEntries, each OrderEntry refers to the Order again and thus an infinite loop is formed. For that reason, for OrderEntries we include Order map with key attribute values only, i.e. code attribute.

        Returns:
        a map containing key attribute values for the previous conversion result that was added to this context or to the parent(s) of this context. If the specified item was not converted yet, then null is returned.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object