01: /*
02: * $Id: CorrelationPropertiesExpressionEvaluator.java 11231 2008-03-06 21:17:37Z rossmason $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.routing;
12:
13: import org.mule.api.config.MuleProperties;
14: import org.mule.api.transport.MessageAdapter;
15: import org.mule.util.expression.MessageHeaderExpressionEvaluator;
16:
17: /**
18: * <code>CorrelationPropertiesExpressionEvaluator</code> is a default implementation used for
19: * getting the Correlation information from a message. This object is only used when
20: * getting a specific property to be set on the message. When reading the property
21: * the getProperty(...) or the direct property accessor will be used i.e.
22: * message.getCorrelationId() or
23: * message.getProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY)
24: */
25: public class CorrelationPropertiesExpressionEvaluator extends
26: MessageHeaderExpressionEvaluator {
27: public final Object evaluate(String name, Object message) {
28: Object result;
29: MessageAdapter msg = null;
30: if (message instanceof MessageAdapter) {
31: msg = (MessageAdapter) message;
32: }
33: if (msg != null) {
34: if (MuleProperties.MULE_CORRELATION_ID_PROPERTY
35: .equals(name)) {
36: result = getCorrelationId(msg);
37: } else if (MuleProperties.MULE_MESSAGE_ID_PROPERTY
38: .equals(name)) {
39: result = getMessageId(msg);
40: } else {
41: throw new IllegalArgumentException(
42: "Property name: "
43: + name
44: + " not recognised by the Correlation Property Extractor");
45: }
46: if (result == null) {
47: throw new IllegalArgumentException(
48: "Property Extractor cannot return a null value. Extractor is: "
49: + getClass().getName());
50: }
51: } else {
52: return super .evaluate(name, message);
53: }
54: return result;
55: }
56:
57: public String getMessageId(MessageAdapter message) {
58: return message.getUniqueId();
59: }
60:
61: public String getCorrelationId(MessageAdapter message) {
62: String id = message.getCorrelationId();
63: if (id == null) {
64: id = message.getUniqueId();
65: }
66: return id;
67: }
68: }
|