001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * You may obtain a copy of the License at 
008     * 
009     * http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS, 
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014     * See the License for the specific language governing permissions and 
015     * limitations under the License. 
016     * 
017     **/
018    
019    package org.activemq.filter;
020    
021    import javax.jms.JMSException;
022    import javax.jms.Message;
023    
024    /**
025     * Represents a property  expression
026     * 
027     * @version $Revision: 1.1.1.1 $
028     */
029    public class PropertyExpression implements Expression {
030    
031        private String name;
032    
033        public PropertyExpression(String name) {
034            this.name = name;
035        }
036    
037        public Object evaluate(Message message) throws JMSException {
038            Object result = null;
039            if (name != null) {
040                result = message.getObjectProperty(name);
041            }
042            if (result == null) {
043                //see if a defined header property
044                if (name.equals("JMSType")) {
045                    result = message.getJMSType();
046                }
047                else if (name.equals("JMSMessageID")) {
048                    result = message.getJMSMessageID();
049                }
050                else if (name.equals("JMSCorrelationID")) {
051                    result = message.getJMSCorrelationID();
052                }
053                else if (name.equals("JMSPriority")) {
054                    result = new Integer(message.getJMSPriority());
055                }
056                else if (name.equals("JMSTimestamp")) {
057                    result = new Long(message.getJMSTimestamp());
058                }
059            }
060            return result;
061        }
062    
063        public String getName() {
064            return name;
065        }
066    
067    
068        /**
069         * @see java.lang.Object#toString()
070         */
071        public String toString() {
072            return name;
073        }
074    
075        /**
076         * @see java.lang.Object#hashCode()
077         */
078        public int hashCode() {
079            return name.hashCode();
080        }
081    
082        /**
083         * @see java.lang.Object#equals(java.lang.Object)
084         */
085        public boolean equals(Object o) {
086    
087            if (o == null || !this.getClass().equals(o.getClass())) {
088                return false;
089            }
090            return name.equals(((PropertyExpression) o).name);
091    
092        }
093    
094    }