01: /**
02: *
03: * Copyright 2004 Protique Ltd
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * 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.activemq.filter.mockrunner;
18:
19: import javax.jms.JMSException;
20: import javax.jms.Message;
21:
22: /**
23: * Alwin Ibba: Changed package
24: *
25: * Represents a property expression
26: *
27: * @version $Revision: 1.3 $
28: */
29: public class PropertyExpression implements Expression {
30:
31: private String name;
32:
33: public PropertyExpression(String name) {
34: this .name = name;
35: }
36:
37: public Object evaluate(Message message) throws JMSException {
38: Object result = null;
39: if (name != null) {
40: result = message.getObjectProperty(name);
41: }
42: if (result == null) {
43: //see if a defined header property
44: if (name.equals("JMSType")) {
45: result = message.getJMSType();
46: } else if (name.equals("JMSMessageID")) {
47: result = message.getJMSMessageID();
48: } else if (name.equals("JMSCorrelationID")) {
49: result = message.getJMSCorrelationID();
50: } else if (name.equals("JMSPriority")) {
51: result = new Integer(message.getJMSPriority());
52: } else if (name.equals("JMSTimestamp")) {
53: result = new Long(message.getJMSTimestamp());
54: }
55: }
56: return result;
57: }
58:
59: public String getName() {
60: return name;
61: }
62:
63: /**
64: * @see java.lang.Object#toString()
65: */
66: public String toString() {
67: return name;
68: }
69:
70: /**
71: * @see java.lang.Object#hashCode()
72: */
73: public int hashCode() {
74: return name.hashCode();
75: }
76:
77: /**
78: * @see java.lang.Object#equals(java.lang.Object)
79: */
80: public boolean equals(Object o) {
81:
82: if (o == null || !this .getClass().equals(o.getClass())) {
83: return false;
84: }
85: return name.equals(((PropertyExpression) o).name);
86:
87: }
88:
89: }
|