1 20 package org.enhydra.barracuda.contrib.dbroggisch.display.filters; 21 22 import java.util.*; 23 import java.text.DateFormat ; 24 import java.text.SimpleDateFormat ; 25 import org.enhydra.barracuda.contrib.dbroggisch.display.filters.dtd.*; 26 import java.lang.reflect.Field ; 27 import org.apache.log4j.*; 28 29 public class CountFilter implements Filter { 30 private static Logger logger = Logger.getLogger(CountFilter.class.getName()); 31 32 33 public Object filter(Object obj, FilterContext context) 34 throws FilterException 35 { 36 if(obj == null) { 37 return null; 38 } 39 if(obj instanceof java.util.Collection ) { 40 return new Integer (((Collection)obj).size()); 41 } else { 42 try { 43 return new Integer (java.lang.reflect.Array.getLength(obj)); 44 } catch(IllegalArgumentException ex) { 45 throw new FilterException("Not a countable object."); 46 } 47 } 48 } 49 50 public Filter configure(Object obj) 51 throws FilterException 52 { 53 return this; 54 } 55 } 56 | Popular Tags |