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