Class AdaptrisMessageImp

  • All Implemented Interfaces:
    AdaptrisMessage, InterlokMessage, java.lang.Cloneable
    Direct Known Subclasses:
    DefaultAdaptrisMessageImp, MultiPayloadAdaptrisMessageImp

    public abstract class AdaptrisMessageImp
    extends java.lang.Object
    implements AdaptrisMessage, java.lang.Cloneable

    Standard implementation of AdaptrisMessage interface.

    When referring to metadata items by key you can use a form of indirection by specifying a prefix to your key ("$$").
    Using this prefix on any metadata key will not perform an action (retrieve, add etc) to that metadata item but instead will look up the value of that metadata key and use the value as the metadata item key to be performed on.
    Example:
    Calling addMetadata("myKey", "myValue");
    Will create a new metadata item with the key "myKey" and the value "myValue".
    However calling addMetadata("$$myKey", "myValue") will lookup the value of the metadata key named "myKey" and use that value as the key for the addMetadata() method.

    See Also:
    DefaultMessageFactory, AdaptrisMessageFactory, AdaptrisMessage
    • Field Detail

      • METADATA_RESOLVE_REGEXP

        public static final java.lang.String METADATA_RESOLVE_REGEXP
        See Also:
        Constant Field Values
      • OBJECT_RESOLVE_REGEXP

        public static final java.lang.String OBJECT_RESOLVE_REGEXP
        See Also:
        Constant Field Values
      • SIZE_RESOLVE_KEY

        public static final java.lang.String SIZE_RESOLVE_KEY
        See Also:
        Constant Field Values
      • PAYLOAD_RESOLVE_KEY

        public static final java.lang.String PAYLOAD_RESOLVE_KEY
        See Also:
        Constant Field Values
    • Constructor Detail

      • AdaptrisMessageImp

        protected AdaptrisMessageImp​(IdGenerator guid,
                                     AdaptrisMessageFactory fac)

        Creates a new instance.

        Parameters:
        guid - a GuidGenerator that will be used to create unique-ids.
    • Method Detail

      • addMetadata

        public void addMetadata​(java.lang.String key,
                                java.lang.String value)
        Description copied from interface: AdaptrisMessage

        Puts the passed value into the metadata against the passed key. If a value has previously been set against this key it will be overwritten.

        Specified by:
        addMetadata in interface AdaptrisMessage
        Parameters:
        key - the key
        value - the value
      • addMessageHeader

        public void addMessageHeader​(java.lang.String key,
                                     java.lang.String value)
        Specified by:
        addMessageHeader in interface InterlokMessage
      • addMetadata

        public void addMetadata​(MetadataElement e)
        Description copied from interface: AdaptrisMessage

        Puts the passed MetadataElement into the metadata. If a value has previously been set with the same key it will be overwritten and a message to that effect should be logged.

        Specified by:
        addMetadata in interface AdaptrisMessage
        Parameters:
        e - the MetadataElement to add
      • removeMetadata

        public void removeMetadata​(MetadataElement element)
        Description copied from interface: AdaptrisMessage

        Removes the passed MetadataElement from the metadata if it is present.

        Specified by:
        removeMetadata in interface AdaptrisMessage
        Parameters:
        element - the MetadataElement to remove
      • setMessageHeaders

        public void setMessageHeaders​(java.util.Map<java.lang.String,​java.lang.String> metadata)
        Specified by:
        setMessageHeaders in interface InterlokMessage
      • getMetadataValue

        public java.lang.String getMetadataValue​(java.lang.String key)
        Description copied from interface: AdaptrisMessage

        Returns the String value associated with the passed key or null if the key does not exist. NB may also return null if null was explicitly set as the value of the key. Use containsKey to differentiate these cases.

        Specified by:
        getMetadataValue in interface AdaptrisMessage
        Parameters:
        key - the key to look for
        Returns:
        the value associated with the key
      • getMetadata

        public MetadataElement getMetadata​(java.lang.String key)
        Description copied from interface: AdaptrisMessage

        Returns the MetadataElement containing the passed key or null if the key does not exist. NB may also return null if null was explicitly set as the value of the key. Use containsKey to differentiate these cases.

        Specified by:
        getMetadata in interface AdaptrisMessage
        Parameters:
        key - the key to look for
        Returns:
        the MetadataElement containing the key
      • getMessageHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getMessageHeaders()
        Specified by:
        getMessageHeaders in interface InterlokMessage
      • getReader

        public java.io.Reader getReader()
                                 throws java.io.IOException
        Specified by:
        getReader in interface InterlokMessage
        Throws:
        java.io.IOException
      • getWriter

        public java.io.Writer getWriter()
                                 throws java.io.IOException
        Specified by:
        getWriter in interface InterlokMessage
        Throws:
        java.io.IOException
      • getWriter

        public java.io.Writer getWriter​(java.lang.String encoding)
                                 throws java.io.IOException
        Specified by:
        getWriter in interface InterlokMessage
        Throws:
        java.io.IOException
      • addEvent

        public void addEvent​(MessageEventGenerator meg,
                             boolean wasSuccessful)
        Description copied from interface: AdaptrisMessage

        Adds an event to this AdaptrisMessage's MessageLifecycleEvent.

        Specified by:
        addEvent in interface AdaptrisMessage
        Parameters:
        meg - the MessageEventGenerator
        wasSuccessful - the status of the event
      • encode

        public byte[] encode​(AdaptrisMessageEncoder encoder)
                      throws CoreException
        Description copied from interface: AdaptrisMessage

        Uses the passed AdaptrisMessageEncoder to create an encoded version of this AdaptrisMessage. If null is passed this method returns this.getPayload().

        Specified by:
        encode in interface AdaptrisMessage
        Parameters:
        encoder - the AdaptrisMessageEncoder to use
        Returns:
        a byte[] representation of this message
        Throws:
        CoreException - wrapping any underlying Exceptions that may occur
      • addObjectHeader

        public void addObjectHeader​(java.lang.Object key,
                                    java.lang.Object object)

        Adds an Object to this message as metadata. Object metadata is intended to be used within a single Workflow only and will not be encoded or otherwise transported between Workflows.

        Specified by:
        addObjectHeader in interface InterlokMessage
        Parameters:
        object - the Object to set as metadata
        key - the key to store this object against.
      • getObjectHeaders

        public java.util.Map<java.lang.Object,​java.lang.Object> getObjectHeaders()
        Specified by:
        getObjectHeaders in interface InterlokMessage
      • toString

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

        public java.lang.String getNextServiceId()
        Description copied from interface: AdaptrisMessage

        Returns the unique ID of the next Service to apply to the message. Optional, used by BranchingServiceCollection and possibly others later.

        Specified by:
        getNextServiceId in interface AdaptrisMessage
        Returns:
        the unique ID of the next Service to apply
      • setNextServiceId

        public void setNextServiceId​(java.lang.String s)
        Description copied from interface: AdaptrisMessage

        Sets the unique ID of the next Service to apply to the message.

        Specified by:
        setNextServiceId in interface AdaptrisMessage
        Parameters:
        s - the unique ID of the next Service to apply to the message
      • resolve

        public java.lang.String resolve​(java.lang.String s,
                                        boolean dotAll)
        Specified by:
        resolve in interface InterlokMessage
      • resolveObject

        public java.lang.Object resolveObject​(java.lang.String s)
        Retrieve an object from headers/metadata using an expression: %messageObject{some_key}
        Specified by:
        resolveObject in interface InterlokMessage
        Parameters:
        s - The expression to use to resolve the object.
        Returns:
        The header/metadata object, or null.
      • getMetadataValueIgnoreKeyCase

        public java.lang.String getMetadataValueIgnoreKeyCase​(java.lang.String key)
        Description copied from interface: AdaptrisMessage

        First looks for a metadata value stored against the passed key taking account of the passed key's case. If a value is found it is returned. Next looks for a metadata value stored against the passed key ignoring. The valued stored against the first key which matches the passed key ignoring case is returned. As the underlying store is unordered, which key will match first is undefined. If no key matches the passed key ignoring case, null is returned.

        E.g. where a message has the metdadata values "1" and "2" set against keys "AAA" and "aaa" respectively, calling getMetadataValueIgnoreKeyCase("AAA") will return "1', calling getMetadataValueIgnoreKeyCase("aaa") will return "2', and calling getMetadataValueIgnoreKeyCase("aAA") will return either "1' or "2".

        Specified by:
        getMetadataValueIgnoreKeyCase in interface AdaptrisMessage
        Parameters:
        key - the key to look for
        Returns:
        the value associated with the key or null
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Description copied from interface: AdaptrisMessage

        Returns a deep clone of this object.

        Specified by:
        clone in interface AdaptrisMessage
        Overrides:
        clone in class java.lang.Object
        Returns:
        a deep clone of this object
        Throws:
        java.lang.CloneNotSupportedException - if the implementation does not support cloning
      • copyPayload

        @Deprecated
        public static void copyPayload​(AdaptrisMessage src,
                                       AdaptrisMessage dest)
                                throws java.io.IOException
        Deprecated.
        since 3.11.0 use MessageHelper#copyPayload(AdaptrisMessage, AdaptrisMessage) instead.
        Copy the payload from one AdaptrisMessage to another.
        Throws:
        java.io.IOException