Clover coverage report - Code Coverage for tapestry-contrib release 4.0-beta-10
Coverage timestamp: Sat Oct 8 2005 19:13:41 EDT
file stats: LOC: 148   Methods: 4
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ExpressionTableColumnModel.java 0% 0% 0% 0%
coverage
 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.tapestry.contrib.table.model.ITableColumn;
 18    import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnModel;
 19    import org.apache.tapestry.services.ExpressionEvaluator;
 20   
 21    /**
 22    * @author mindbridge
 23    */
 24    public class ExpressionTableColumnModel extends SimpleTableColumnModel
 25    {
 26    private static final long serialVersionUID = 1L;
 27   
 28    /**
 29    * Constructs a table column model containting OGNL expression columns. <br>
 30    * The data for the columns is provided in the form of a string array, where the info of each
 31    * column is stored in two consecutive fields in the array, hence its size must be even. The
 32    * expected info is the following:
 33    * <ul>
 34    * <li>Column Name
 35    * <li>OGNL expression
 36    * </ul>
 37    *
 38    * @param arrColumnInfo
 39    * The information to construct the columns from
 40    * @param bSorted
 41    * Whether all columns are sorted or not
 42    */
 43  0 public ExpressionTableColumnModel(String[] arrColumnInfo, boolean bSorted,
 44    ExpressionEvaluator expressionEvaluator)
 45    {
 46  0 this(convertToDetailedArray(arrColumnInfo, bSorted), expressionEvaluator);
 47    }
 48   
 49    /**
 50    * Constructs a table column model containting OGNL expression columns. <br>
 51    * The data for the columns is provided in the form of a string array, where the info of each
 52    * column is stored in four consecutive fields in the array, hence its size must be divisible by
 53    * 4.<br>
 54    * The expected info is the following:
 55    * <ul>
 56    * <li>Column Name
 57    * <li>Display Name
 58    * <li>OGNL expression
 59    * <li>Sorting of the column. This is either a Boolean, or a String representation of a
 60    * boolean.
 61    * </ul>
 62    *
 63    * @param arrColumnInfo
 64    */
 65  0 public ExpressionTableColumnModel(Object[] arrColumnInfo,
 66    ExpressionEvaluator expressionEvaluator)
 67    {
 68  0 super(convertToColumns(arrColumnInfo, expressionEvaluator));
 69    }
 70   
 71    /**
 72    * Method convertToDetailedArray.
 73    *
 74    * @param arrColumnInfo
 75    * @param bSorted
 76    * @return Object[]
 77    */
 78  0 protected static Object[] convertToDetailedArray(String[] arrColumnInfo, boolean bSorted)
 79    {
 80  0 int nColumns = arrColumnInfo.length / 2;
 81  0 int nSize = nColumns * 4;
 82  0 Object[] arrDetailedInfo = new Object[nSize];
 83   
 84  0 for (int i = 0; i < nColumns; i++)
 85    {
 86  0 int nInputBaseIndex = 2 * i;
 87  0 String strColumnName = arrColumnInfo[nInputBaseIndex];
 88  0 String strExpression = arrColumnInfo[nInputBaseIndex + 1];
 89   
 90  0 int nOutputBaseIndex = 4 * i;
 91  0 arrDetailedInfo[nOutputBaseIndex] = strColumnName;
 92  0 arrDetailedInfo[nOutputBaseIndex + 1] = strColumnName;
 93  0 arrDetailedInfo[nOutputBaseIndex + 2] = strExpression;
 94  0 arrDetailedInfo[nOutputBaseIndex + 3] = bSorted ? Boolean.TRUE : Boolean.FALSE;
 95    }
 96   
 97  0 return arrDetailedInfo;
 98    }
 99   
 100    /**
 101    * Method convertToColumns.
 102    *
 103    * @param arrDetailedInfo
 104    * @return ITableColumn[]
 105    */
 106  0 protected static ITableColumn[] convertToColumns(Object[] arrDetailedInfo,
 107    ExpressionEvaluator expressionEvaluator)
 108    {
 109  0 int nColumns = arrDetailedInfo.length / 4;
 110  0 ITableColumn[] arrColumns = new ITableColumn[nColumns];
 111   
 112  0 for (int i = 0; i < nColumns; i++)
 113    {
 114  0 Object objTempValue;
 115  0 int nBaseIndex = 4 * i;
 116   
 117  0 String strColumnName = "";
 118  0 objTempValue = arrDetailedInfo[nBaseIndex];
 119  0 if (objTempValue != null)
 120  0 strColumnName = objTempValue.toString();
 121   
 122  0 String strDisplayName = "";
 123  0 objTempValue = arrDetailedInfo[nBaseIndex + 1];
 124  0 if (objTempValue != null)
 125  0 strDisplayName = objTempValue.toString();
 126   
 127  0 String strExpression = "";
 128  0 objTempValue = arrDetailedInfo[nBaseIndex + 2];
 129  0 if (objTempValue != null)
 130  0 strExpression = objTempValue.toString();
 131   
 132  0 boolean bSorted = false;
 133  0 objTempValue = arrDetailedInfo[nBaseIndex + 3];
 134  0 if (objTempValue != null)
 135    {
 136  0 if (objTempValue instanceof Boolean)
 137  0 bSorted = ((Boolean) objTempValue).booleanValue();
 138    else
 139  0 bSorted = Boolean.valueOf(objTempValue.toString()).booleanValue();
 140    }
 141   
 142  0 arrColumns[i] = new ExpressionTableColumn(strColumnName, strDisplayName, strExpression,
 143    bSorted, expressionEvaluator);
 144    }
 145   
 146  0 return arrColumns;
 147    }
 148    }