001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.services; 016 017 import ognl.OgnlContext; 018 import ognl.enhance.ExpressionAccessor; 019 020 /** 021 * Wrapper around the OGNL library. 022 * 023 * @author Howard M. Lewis Ship 024 * @since 4.0 025 */ 026 public interface ExpressionEvaluator 027 { 028 029 /** 030 * Reads a property of the target, defined by the expression. 031 * 032 * @throws org.apache.hivemind.ApplicationRuntimeException 033 * if the expression can not be parsed, or if some other error 034 * occurs during evaluation of the expression. 035 */ 036 Object read(Object target, String expression); 037 038 /** 039 * Reads a property of the target, defined by the (previously compiled) 040 * expression. 041 * 042 * @throws org.apache.hivemind.ApplicationRuntimeException 043 * if some other error occurs during evaluation of the 044 * expression. 045 */ 046 Object readCompiled(Object target, Object expression); 047 048 /** 049 * Reads a property of the target, defined by the (previously compiled) 050 * expression. 051 * 052 * @param target 053 * The object to resolve the expression against. 054 * @param expression 055 * The compiled expression. 056 * @return 057 * The result of reading on the expression. 058 */ 059 Object read(Object target, ExpressionAccessor expression); 060 061 /** 062 * Updates a property of the target, defined by the expression. 063 * 064 * @throws org.apache.hivemind.ApplicationRuntimeException 065 * if the expression can not be parsed, or if some other error 066 * occurs during evaluation of the expression. 067 */ 068 void write(Object target, String expression, Object value); 069 070 /** 071 * Updates a property of the target, defined by the (previously compiled) 072 * expression. 073 * 074 * @throws org.apache.hivemind.ApplicationRuntimeException 075 * if some other error occurs during evaluation of the 076 * expression. 077 */ 078 void writeCompiled(Object target, Object expression, Object value); 079 080 /** 081 * Updates a property of the target, defined by the (previously compiled) 082 * expression. 083 * 084 * @param target 085 * The target object to set a value on. 086 * @param expression 087 * The pre-compiled expression. 088 * @param value 089 * The value to set. 090 */ 091 void write(Object target, ExpressionAccessor expression, Object value); 092 093 /** 094 * Returns true if the expression evaluates to a constant or other literal 095 * value. 096 * 097 * @throws org.apache.hivemind.ApplicationRuntimeException 098 * if the expression is not valid 099 */ 100 boolean isConstant(String expression); 101 102 /** 103 * Returns true if the expression evaluates to a constant or other literal 104 * value. 105 * 106 * @throws org.apache.hivemind.ApplicationRuntimeException 107 * if the expression is not valid 108 */ 109 boolean isConstant(Object target, String expression); 110 111 /** 112 * Creates a default OGNL context object that can be used against 113 * the specified object for expression evaluation. 114 * 115 * @param target 116 * The object to get a context for. 117 * @return 118 * An ognl context map. 119 */ 120 OgnlContext createContext(Object target); 121 }