org.jboss.soa.esb.message.mapping
Class ObjectMapper
java.lang.Object
org.jboss.soa.esb.message.mapping.ObjectMapper
public class ObjectMapper
- extends java.lang.Object
Extracts objects from an ESB message and puts them into a Map, which can be
used for later processsing, based on expressions. This class is used internally
within the jBPM and Rules integrations. It may be useful elsewhere.
Likewise, it can be used to take a list of Objects and place them into a Message
based on the same type of expressions.
It is based on the notion of an ESB Message Object Path (MOP). The path
should follow the syntax:
location.objectname....
location : one of [body, property, attachment]
objectname: name of the object. Since attachments can be named or numbered, this can be a
number too and will be converted to an integer value. If a stringified number is used elsewhere
to name an object then it will not be interpreted as an integer, i.e., it will remain as a string.
The objectname can be hierarchical if required, but should be quoted in that case, e.g., 'foo.bar.a.b.c'.
: optionally you traverse a bean graph by specifying bean names.
examples :
properties.Order, gets the property object named "Order"
attachment.1, gets the first attachment Object
attachment.FirstAttachment, gets the attachment named 'FirstAttachment'
body.foo, gets the named Object foo
body.1 gets the named Object 1
body.'foo.bar.a.b.c' looks for the Object named foo.bar.a.b.c in the body
- Author:
- kurt.stam@jboss.com
Field Summary |
static java.lang.String |
BODY_CONTENT
Name to get the byte[] content |
Method Summary |
java.util.List<java.lang.Object> |
createObjectList(Message message,
java.util.List<java.lang.String> messageObjectPathList)
Given a message and a series of MOPs, traverse the content and create
a list of Objects. |
static MessagePayloadProxy |
createPayloadProxy(ConfigTree config)
|
byte[] |
getBytes(java.io.Serializable object)
Turns an object into a byte[]. |
java.lang.Object |
getObjectFromMessage(Message message,
java.lang.String expression)
Extracts objects from the message, using a ESB Message Object Path. |
void |
setObjectOnMessage(Message message,
java.lang.String expression,
java.lang.Object object)
Sets an object somewhere on the Message, based on the value of the expression (MOP). |
Message |
setObjectsOnMessage(Message message,
java.util.Map<java.lang.Object,java.lang.String> expressionAndObject)
Set objects on the message using a OGNL expression syntax to describe the position
in the message where the object needs to be attached. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BODY_CONTENT
public static final java.lang.String BODY_CONTENT
- Name to get the byte[] content
- See Also:
- Constant Field Values
ObjectMapper
public ObjectMapper()
ObjectMapper
public ObjectMapper(ConfigTree config)
createObjectList
public java.util.List<java.lang.Object> createObjectList(Message message,
java.util.List<java.lang.String> messageObjectPathList)
throws ObjectMappingException
- Given a message and a series of MOPs, traverse the content and create
a list of Objects.
For example:
body.myObject MOP will add 'myObject', while
body.myObject.mySubObject MOP will create an entry of 'mySubObject'.
body.'myObject.mySubObject' MOP will create an entry of 'myObject.mySubject' in body.
in the returned List.
- Parameters:
message
- - the messagemessageObjectPathList
- - the key represents the query to get the object from
from the message.
- Returns:
- List of Objects pulled from the input Message. Will never be null, but could be
of zero length.
- Throws:
ObjectMappingException
setObjectsOnMessage
public Message setObjectsOnMessage(Message message,
java.util.Map<java.lang.Object,java.lang.String> expressionAndObject)
throws ObjectMappingException
- Set objects on the message using a OGNL expression syntax to describe the position
in the message where the object needs to be attached.
Each Object within the supplied Map should be associated with an expression that
will be used to determine where in the Message it should be placed.
location.objectname...
location : one of [body, property, attachment, header]
objectname: name of the object name, attachments can be named or numbered, so for
attachments this can be a number too.
- Parameters:
message
- - the message on which the objects will be placedexpressionAndObject
- map containing objects with their expression
- Returns:
- the message with the objects attached.
- Throws:
ObjectMappingException
getObjectFromMessage
public java.lang.Object getObjectFromMessage(Message message,
java.lang.String expression)
throws ObjectMappingException
- Extracts objects from the message, using a ESB Message Object Path. The
path should follow the syntax:
location.objectname....
location : one of [body, property, attachment]
objectname: name of the object name, attachments can be named or numbered, so for
attachments this can be a number too.
: optionally you traverse a bean graph by specifying bean names;
examples :
properties.Order, gets the property object named "Order"
attachment.1, gets the first attachment Object
attachment.FirstAttachment, gets the attachment named 'FirstAttachment'
attachment.1.Order, calls getOrder() on the attached Object.
body.BODY_CONTENT, gets the byte[] of the body.
body.Order1.lineitem, obtains the object named "Order1"
from the body of the message. Next it will call getLineitem() on this object.
More elements can be added to the query to traverse the bean graph.
- Parameters:
message
- - an ESB Message.expression
- - path to the object.
- Returns:
- Object obtained from the message.
- Throws:
ObjectMappingException
setObjectOnMessage
public void setObjectOnMessage(Message message,
java.lang.String expression,
java.lang.Object object)
throws ObjectMappingException
- Sets an object somewhere on the Message, based on the value of the expression (MOP).
The expression is OGNL based. MVEL is used to do the actual mapping.
- Parameters:
message
- - on which the object will be placed.expression
- - desribes the place in the Message where the object should be placedobject
- - the object which will be attached to the message.
- Throws:
ObjectMappingException
getBytes
public byte[] getBytes(java.io.Serializable object)
throws ObjectMappingException
- Turns an object into a byte[].
- Parameters:
object
- to be serialized to bytes.
- Returns:
- byte[] representation of the object passed in
- Throws:
ObjectMappingException
createPayloadProxy
public static MessagePayloadProxy createPayloadProxy(ConfigTree config)