CVS: Tapestry/contrib/src/net/sf/tapestry/contrib/table/model/ognl OgnlTableColumnEvaluator.java,NONE,1.1 ExpressionTableColumn.java,1.3,1.4

Mind Bridge <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/contrib/src/net/sf/tapestry/contrib/table/model/ognl
In directory sc8-pr-cvs1:/tmp/cvs-serv6509/contrib/src/net/sf/tapestry/contrib/table/model/ognl

Modified Files:
	ExpressionTableColumn.java 
Added Files:
	OgnlTableColumnEvaluator.java 
Log Message:


--- NEW FILE: OgnlTableColumnEvaluator.java ---
package net.sf.tapestry.contrib.table.model.ognl;

import net.sf.tapestry.contrib.table.model.ITableColumn;
import net.sf.tapestry.contrib.table.model.simple.ITableColumnEvaluator;
import net.sf.tapestry.util.prop.OgnlUtils;
import ognl.Ognl;
import ognl.OgnlException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author mindbridge
 *
 */
public class OgnlTableColumnEvaluator implements ITableColumnEvaluator
{
	private static final Log LOG =
		LogFactory.getLog(ExpressionTableColumn.class);

	private String m_strExpression;
	transient private Object m_objParsedExpression = null;

	public OgnlTableColumnEvaluator(String strExpression)
	{
		m_strExpression = strExpression;
	}

	/**
	 * @see net.sf.tapestry.contrib.table.model.simple.ITableColumnEvaluator#getColumnValue(ITableColumn, Object)
	 */
	public Object getColumnValue(ITableColumn objColumn, Object objRow)
	{
		// If no expression is given, then this is dummy column. Return something.
		if (m_strExpression == null || m_strExpression.equals(""))
			return "";

		if (m_objParsedExpression == null)
		{
			synchronized (this)
			{
				if (m_objParsedExpression == null)
					m_objParsedExpression =
						OgnlUtils.getParsedExpression(m_strExpression);
			}
		}

		try
		{
			Object objValue = Ognl.getValue(m_objParsedExpression, objRow);
			return objValue;
		}
		catch (OgnlException e)
		{
			LOG.error(
				"Cannot use column expression '" + m_strExpression + "' in row",
				e);
			return "";
		}
	}
}

Index: ExpressionTableColumn.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/contrib/src/net/sf/tapestry/contrib/table/model/ognl/ExpressionTableColumn.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ExpressionTableColumn.java	12 Oct 2002 17:30:32 -0000	1.3
--- ExpressionTableColumn.java	23 Dec 2002 12:40:28 -0000	1.4
***************
*** 9,12 ****
--- 9,14 ----
  import ognl.OgnlException;
  
+ import net.sf.tapestry.contrib.table.model.ITableColumn;
+ import net.sf.tapestry.contrib.table.model.simple.ITableColumnEvaluator;
  import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumn;
  import net.sf.tapestry.util.prop.OgnlUtils;
***************
*** 20,26 ****
      private static final Log LOG = LogFactory.getLog(ExpressionTableColumn.class);
  
-     private String m_strExpression;
-     transient private Object m_objParsedExpression = null;
-     
      public ExpressionTableColumn(String strColumnName, String strExpression) {
          this(strColumnName, strExpression, false);
--- 22,25 ----
***************
*** 37,71 ****
      public ExpressionTableColumn(String strColumnName, String strDisplayName, String strExpression, boolean bSortable) {
          super(strColumnName, strDisplayName, bSortable);
!         m_strExpression = strExpression;
      }
- 
- 	/**
- 	 * @see net.sf.tapestry.contrib.table.model.simple.SimpleTableColumn#getColumnValue(Object)
- 	 */
- 	public Object getColumnValue(Object objRow)
- 	{
-         // If no expression is given, then this is dummy column. Return something.
-         if (m_strExpression == null || m_strExpression.equals(""))
-             return "";
-         
-         if (m_objParsedExpression == null) {
-             synchronized (this) {
-                 if (m_objParsedExpression == null) {
-                     // no need to synchronize, since the results should be identical
-                     m_objParsedExpression = OgnlUtils.getParsedExpression(m_strExpression);
-                 }
-             }
-         }
-         
- 		try
- 		{
- 			return Ognl.getValue(m_objParsedExpression, objRow);
- 		}
- 		catch (OgnlException e)
- 		{
-             LOG.error("Cannot use column expression '" + m_strExpression + "' in row", e);
-             return "";
- 		}
- 	}
- 
  }
--- 36,40 ----
      public ExpressionTableColumn(String strColumnName, String strDisplayName, String strExpression, boolean bSortable) {
          super(strColumnName, strDisplayName, bSortable);
!         setEvaluator(new OgnlTableColumnEvaluator(strExpression));
      }
  }



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.