View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.expression;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.expression.ExpressionEnricher;
11  import org.mule.api.transport.PropertyScope;
12  
13  public class MessageHeaderExpressionEnricher implements ExpressionEnricher
14  {
15  
16      public static final String NAME = "header";
17  
18      public void enrich(String expression, MuleMessage message, Object object)
19      {
20          String propertyName = expression;
21          PropertyScope scope = ExpressionUtils.getScope(expression);
22          if (scope != null)
23          {
24              // cut-off leading scope and separator
25              propertyName = expression.substring(scope.getScopeName().length() + 1);
26          }
27          else
28          {
29              // default
30              scope = PropertyScope.OUTBOUND;
31          }
32  
33          message.setProperty(propertyName, object, scope);
34      }
35  
36      public String getName()
37      {
38          return NAME;
39      }
40  
41      public void setName(String name)
42      {
43          throw new UnsupportedOperationException();
44      }
45  
46  }