1 12 package org.displaytag.decorator; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 import javax.servlet.jsp.PageContext ; 19 20 import org.apache.commons.beanutils.PropertyUtils; 21 import org.apache.commons.lang.BooleanUtils; 22 import org.displaytag.model.TableModel; 23 24 25 37 abstract class Decorator 38 { 39 40 43 private static final char CLASS_PROPERTY_SEPARATOR = '#'; 44 45 48 private static Map propertyMap = new HashMap (); 49 50 53 private PageContext pageContext; 54 55 58 private Object decoratedObject; 59 60 64 protected TableModel tableModel; 65 66 73 public void init(PageContext context, Object decorated) 74 { 75 this.pageContext = context; 76 this.decoratedObject = decorated; 77 } 78 79 85 public void init(PageContext context, Object decorated, TableModel tableModel) 86 { 87 init(pageContext, decorated); 89 this.tableModel = tableModel; 92 } 93 94 98 public PageContext getPageContext() 99 { 100 return this.pageContext; 101 } 102 103 107 public Object getDecoratedObject() 108 { 109 return this.decoratedObject; 110 } 111 112 116 public void finish() 117 { 118 this.pageContext = null; 119 this.decoratedObject = null; 120 } 121 122 129 public boolean hasGetterFor(String propertyName) 130 { 131 String simpleProperty = propertyName; 132 133 int indexOfDot = simpleProperty.indexOf('.'); 135 if (indexOfDot > 0) 136 { 137 simpleProperty = simpleProperty.substring(0, indexOfDot); 138 } 139 140 Boolean cachedResult = (Boolean ) propertyMap.get(getClass().getName() 141 + CLASS_PROPERTY_SEPARATOR 142 + simpleProperty); 143 144 if (cachedResult != null) 145 { 146 return cachedResult.booleanValue(); 147 } 148 149 boolean hasGetter = searchGetterFor(propertyName); 151 152 propertyMap.put(getClass().getName() + CLASS_PROPERTY_SEPARATOR + simpleProperty, BooleanUtils 154 .toBooleanObject(hasGetter)); 155 156 return hasGetter; 158 159 } 160 161 166 public boolean searchGetterFor(String propertyName) 167 { 168 169 Class type = null; 170 171 try 172 { 173 type = PropertyUtils.getPropertyType(this, propertyName); 177 } 178 catch (IllegalAccessException e) 179 { 180 } 182 catch (InvocationTargetException e) 183 { 184 } 186 catch (NoSuchMethodException e) 187 { 188 } 190 191 return type != null; 192 193 } 194 195 } | Popular Tags |