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.contrib.table.model.ognl;
016
017 import org.apache.commons.logging.Log;
018 import org.apache.commons.logging.LogFactory;
019 import org.apache.tapestry.contrib.table.model.ITableColumn;
020 import org.apache.tapestry.contrib.table.model.simple.ITableColumnEvaluator;
021 import org.apache.tapestry.services.ExpressionEvaluator;
022
023 /**
024 * @author mindbridge
025 */
026 public class OgnlTableColumnEvaluator implements ITableColumnEvaluator
027 {
028 private static final long serialVersionUID = 1L;
029
030 /** @since 4.0 */
031
032 private ExpressionEvaluator _expressionEvaluator;
033
034 private static final Log LOG = LogFactory.getLog(OgnlTableColumnEvaluator.class);
035
036 private String m_strExpression;
037
038 public OgnlTableColumnEvaluator(String strExpression, ExpressionEvaluator expressionEvaluator)
039 {
040 m_strExpression = strExpression;
041 _expressionEvaluator = expressionEvaluator;
042 }
043
044 /**
045 * @see org.apache.tapestry.contrib.table.model.simple.ITableColumnEvaluator#getColumnValue(ITableColumn,
046 * Object)
047 */
048 public synchronized Object getColumnValue(ITableColumn objColumn, Object objRow)
049 {
050 // If no expression is given, then this is a dummy column. Return something.
051 if (m_strExpression == null || m_strExpression.equals(""))
052 return "";
053
054 try
055 {
056 return _expressionEvaluator.read(objRow, m_strExpression);
057 }
058 catch (Exception e)
059 {
060 LOG.error("Cannot use column expression '" + m_strExpression + "' in row", e);
061 return "";
062 }
063 }
064 }