01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.expression;
18:
19: import javax.jbi.messaging.MessageExchange;
20: import javax.jbi.messaging.MessagingException;
21: import javax.jbi.messaging.NormalizedMessage;
22:
23: /**
24: * A simple expression which returns the value of a property on the message.
25: *
26: * @version $Revision: 451186 $
27: */
28: public class PropertyExpression implements Expression {
29: private String property;
30: private Object defaultValue;
31:
32: public PropertyExpression() {
33: }
34:
35: public PropertyExpression(String property) {
36: this .property = property;
37: }
38:
39: public PropertyExpression(String property, Object defaultValue) {
40: this .property = property;
41: this .defaultValue = defaultValue;
42: }
43:
44: /**
45: * @return the defaultValue
46: */
47: public Object getDefaultValue() {
48: return defaultValue;
49: }
50:
51: /**
52: * @param defaultValue the defaultValue to set
53: */
54: public void setDefaultValue(Object defaultValue) {
55: this .defaultValue = defaultValue;
56: }
57:
58: /**
59: * @return the property
60: */
61: public String getProperty() {
62: return property;
63: }
64:
65: /**
66: * @param property the property to set
67: */
68: public void setProperty(String property) {
69: this .property = property;
70: }
71:
72: public Object evaluate(MessageExchange exchange,
73: NormalizedMessage message) throws MessagingException {
74: Object answer = message.getProperty(property);
75: if (answer == null) {
76: answer = exchange.getProperty(property);
77: if (answer == null) {
78: answer = defaultValue;
79: }
80: }
81: return answer;
82: }
83: }
|