KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > ognl > OgnlTableColumnEvaluator


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.contrib.table.model.ognl;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19 import org.apache.tapestry.contrib.table.model.ITableColumn;
20 import org.apache.tapestry.contrib.table.model.simple.ITableColumnEvaluator;
21 import org.apache.tapestry.services.ExpressionEvaluator;
22
23 /**
24  * @author mindbridge
25  */

26 public class OgnlTableColumnEvaluator implements ITableColumnEvaluator
27 {
28     private static final long serialVersionUID = 1L;
29     
30     /** @since 4.0 */
31
32     private ExpressionEvaluator _expressionEvaluator;
33
34     private static final Log LOG = LogFactory.getLog(OgnlTableColumnEvaluator.class);
35
36     private String JavaDoc m_strExpression;
37
38     public OgnlTableColumnEvaluator(String JavaDoc strExpression, ExpressionEvaluator expressionEvaluator)
39     {
40         m_strExpression = strExpression;
41         _expressionEvaluator = expressionEvaluator;
42     }
43
44     /**
45      * @see org.apache.tapestry.contrib.table.model.simple.ITableColumnEvaluator#getColumnValue(ITableColumn,
46      * Object)
47      */

48     public synchronized Object JavaDoc getColumnValue(ITableColumn objColumn, Object JavaDoc objRow)
49     {
50         // If no expression is given, then this is a dummy column. Return something.
51
if (m_strExpression == null || m_strExpression.equals(""))
52             return "";
53
54         try
55         {
56             return _expressionEvaluator.read(objRow, m_strExpression);
57         }
58         catch (Exception JavaDoc e)
59         {
60             LOG.error("Cannot use column expression '" + m_strExpression + "' in row", e);
61             return "";
62         }
63     }
64 }
Popular Tags