KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > CorrelationPropertiesExtractor


1 /*
2  * $Id: CorrelationPropertiesExtractor.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.util.properties.MessagePropertyExtractor;
15 import org.mule.umo.UMOMessage;
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 JavaDoc getProperty(String JavaDoc name, Object JavaDoc message)
28     {
29         Object JavaDoc 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 JavaDoc("Property name: " + name
48                                                    + " not recognised by the Correlation Property Extractor");
49             }
50             if (result == null)
51             {
52                 throw new NullPointerException JavaDoc(
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 JavaDoc getMessageId(UMOMessage message)
64     {
65         return message.getUniqueId();
66     }
67
68     public String JavaDoc getCorrelationId(UMOMessage message)
69     {
70         String JavaDoc id = message.getCorrelationId();
71         if (id == null)
72         {
73             id = message.getUniqueId();
74         }
75         return id;
76     }
77 }
78
Popular Tags