View Javadoc

1   /*
2    * $Id: CorrelationPropertiesExtractor.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.routing;
12  
13  import org.mule.config.MuleProperties;
14  import org.mule.umo.UMOMessage;
15  import org.mule.util.properties.MessagePropertyExtractor;
16  
17  /**
18   * <code>CorrelationPropertiesExtractor</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 CorrelationPropertiesExtractor extends MessagePropertyExtractor
26  {
27      public final Object getProperty(String name, Object message)
28      {
29          Object result;
30          UMOMessage msg = null;
31          if (message instanceof UMOMessage)
32          {
33              msg = (UMOMessage) message;
34          }
35          if (msg != null)
36          {
37              if (MuleProperties.MULE_CORRELATION_ID_PROPERTY.equals(name))
38              {
39                  result = getCorrelationId(msg);
40              }
41              else if (MuleProperties.MULE_MESSAGE_ID_PROPERTY.equals(name))
42              {
43                  result = getMessageId(msg);
44              }
45              else
46              {
47                  throw new IllegalArgumentException("Property name: " + name
48                                                     + " not recognised by the Correlation Property Extractor");
49              }
50              if (result == null)
51              {
52                  throw new IllegalArgumentException(
53                      "Property Extractor cannot return a null value. Extractor is: " + getClass().getName());
54              }
55          }
56          else
57          {
58              return super.getProperty(name, message);
59          }
60          return result;
61      }
62  
63      public String getMessageId(UMOMessage message)
64      {
65          return message.getUniqueId();
66      }
67  
68      public String getCorrelationId(UMOMessage message)
69      {
70          String id = message.getCorrelationId();
71          if (id == null)
72          {
73              id = message.getUniqueId();
74          }
75          return id;
76      }
77  }