001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.granite.gravity.selector; 020 021import javax.jms.JMSException; 022 023import flex.messaging.messages.Message; 024 025/** 026 * Represents a property expression 027 * 028 * @version $Revision: 1.5 $ 029 */ 030public class PropertyExpression implements Expression { 031 032 interface SubExpression { 033 public Object evaluate(Message message); 034 } 035 036 private final String name; 037 038 public PropertyExpression(String name) { 039 this.name = name; 040 } 041 042 public Object evaluate(MessageEvaluationContext message) throws JMSException { 043 return message.getMessage().getHeader(name); 044 } 045 046 public Object evaluate(Message message) { 047 return message.getHeader(name); 048 } 049 050 public String getName() { 051 return name; 052 } 053 054 055 /** 056 * @see java.lang.Object#toString() 057 */ 058 @Override 059 public String toString() { 060 return name; 061 } 062 063 /** 064 * @see java.lang.Object#hashCode() 065 */ 066 @Override 067 public int hashCode() { 068 return name.hashCode(); 069 } 070 071 /** 072 * @see java.lang.Object#equals(java.lang.Object) 073 */ 074 @Override 075 public boolean equals(Object o) { 076 077 if (o == null || !this.getClass().equals(o.getClass())) { 078 return false; 079 } 080 return name.equals(((PropertyExpression) o).name); 081 082 } 083 084}