Clover coverage report - Code Coverage for tapestry-contrib release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:15:40 EST
file stats: LOC: 140   Methods: 2
NCLOC: 80   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TableColumnModelSourceImpl.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.components;
 16   
 17    import java.util.ArrayList;
 18    import java.util.List;
 19    import java.util.StringTokenizer;
 20   
 21    import org.apache.hivemind.ApplicationRuntimeException;
 22    import org.apache.tapestry.IComponent;
 23    import org.apache.tapestry.contrib.table.model.IAdvancedTableColumn;
 24    import org.apache.tapestry.contrib.table.model.IAdvancedTableColumnSource;
 25    import org.apache.tapestry.contrib.table.model.ITableColumn;
 26    import org.apache.tapestry.contrib.table.model.ITableColumnModel;
 27    import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn;
 28    import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnModel;
 29    import org.apache.tapestry.services.ExpressionEvaluator;
 30   
 31    /**
 32    * A placeholder for a static methods related to the Table component
 33    *
 34    * @since 3.0
 35    * @author Mindbridge
 36    */
 37    public class TableColumnModelSourceImpl implements TableColumnModelSource
 38    {
 39    /** @since 4.0 */
 40    private ExpressionEvaluator _expressionEvaluator;
 41   
 42    /** @since 4.0 */
 43   
 44  0 public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator)
 45    {
 46  0 _expressionEvaluator = expressionEvaluator;
 47    }
 48   
 49    /**
 50    * Generate a table column model out of the description string provided. Entries in the
 51    * description string are separated by commas. Each column entry is of the format name,
 52    * name:expression, or name:displayName:expression. An entry prefixed with ! represents a
 53    * non-sortable column. If the whole description string is prefixed with *, it represents
 54    * columns to be included in a Form.
 55    *
 56    * @param strDesc
 57    * the description of the column model to be generated
 58    * @param objComponent
 59    * the component ordering the generation
 60    * @param objColumnSettingsContainer
 61    * the component containing the column settings
 62    * @return a table column model based on the provided parameters
 63    */
 64  0 public ITableColumnModel generateTableColumnModel(IAdvancedTableColumnSource objColumnSource,
 65    String strDesc, IComponent objComponent, IComponent objColumnSettingsContainer)
 66    {
 67  0 if (strDesc == null)
 68  0 return null;
 69   
 70  0 List arrColumns = new ArrayList();
 71   
 72  0 strDesc = strDesc.trim();
 73  0 boolean bFormColumns = false;
 74  0 while (strDesc.startsWith("*"))
 75    {
 76  0 strDesc = strDesc.substring(1);
 77  0 bFormColumns = true;
 78    }
 79   
 80  0 StringTokenizer objTokenizer = new StringTokenizer(strDesc, ",");
 81  0 while (objTokenizer.hasMoreTokens())
 82    {
 83  0 String strToken = objTokenizer.nextToken().trim();
 84   
 85  0 if (strToken.startsWith("="))
 86    {
 87  0 String strColumnExpression = strToken.substring(1);
 88   
 89  0 Object objColumn = _expressionEvaluator.read(
 90    objColumnSettingsContainer,
 91    strColumnExpression);
 92   
 93  0 if (!(objColumn instanceof ITableColumn))
 94  0 throw new ApplicationRuntimeException(TableMessages.notAColumn(
 95    objComponent,
 96    strColumnExpression));
 97   
 98  0 arrColumns.add(objColumn);
 99  0 continue;
 100    }
 101   
 102  0 boolean bSortable = true;
 103  0 if (strToken.startsWith("!"))
 104    {
 105  0 strToken = strToken.substring(1);
 106  0 bSortable = false;
 107    }
 108   
 109  0 StringTokenizer objColumnTokenizer = new StringTokenizer(strToken, ":");
 110   
 111  0 String strName = "";
 112  0 if (objColumnTokenizer.hasMoreTokens())
 113  0 strName = objColumnTokenizer.nextToken();
 114   
 115  0 String strExpression = strName;
 116  0 if (objColumnTokenizer.hasMoreTokens())
 117  0 strExpression = objColumnTokenizer.nextToken();
 118   
 119  0 String strDisplayName = strName;
 120  0 if (objColumnTokenizer.hasMoreTokens())
 121    {
 122  0 strDisplayName = strExpression;
 123  0 strExpression = objColumnTokenizer.nextToken();
 124    }
 125   
 126  0 IAdvancedTableColumn objColumn =
 127    objColumnSource.generateTableColumn(strName, strDisplayName,
 128    bSortable, strExpression);
 129  0 if (bFormColumns)
 130  0 objColumn.setColumnRendererSource(SimpleTableColumn.FORM_COLUMN_RENDERER_SOURCE);
 131  0 if (objColumnSettingsContainer != null)
 132  0 objColumn.loadSettings(objColumnSettingsContainer);
 133   
 134  0 arrColumns.add(objColumn);
 135    }
 136   
 137  0 return new SimpleTableColumnModel(arrColumns);
 138    }
 139   
 140    }