1 23 package org.mdarad.framework.util.struts.criteria; 24 25 import java.io.Serializable ; 26 import java.util.Locale ; 27 28 import org.mdarad.framework.expr.Criterion; 29 import org.mdarad.framework.resources.ResourceMapped; 30 import org.mdarad.framework.resources.ResourcesUtils; 31 32 41 public abstract class FormCriterion implements Serializable , 42 ResourceMapped { 43 44 54 public FormCriterion(String name, Class associatedEntity, CriterionProperty property, String bundleName, Locale locale) { 55 this(name, associatedEntity, property, bundleName, locale, true); 56 } 57 58 69 public FormCriterion(String name, Class associatedEntity, CriterionProperty property, String bundleName, Locale locale, boolean isDynamic) { 70 if (associatedEntity == null || property == null) { 71 throw new IllegalArgumentException ("The associatedEntity class or " + 72 "the property should never be null"); 73 } 74 75 this.name = name; 76 this.property = property; 77 this.associatedEntity = associatedEntity; 78 setLocale(locale); 79 setBundle(bundleName); 80 setDynamic(new Boolean (isDynamic)); 81 } 82 83 91 public FormCriterion(FormCriterion criterion) { 92 if (criterion == null) { 94 throw new CriterionException("The criterion parameter should not be null"); 95 } 96 setName(criterion.getName()); 97 setProperty(criterion.getProperty()); 98 setLocale(criterion.getLocale()); 99 setBundle(criterion.getBundle()); 100 setAssociatedEntity(criterion.getAssociatedEntity()); 101 } 102 103 107 private CriterionProperty property; 108 109 public CriterionProperty getProperty() { 110 return property; 111 } 112 113 public void setProperty(CriterionProperty property) { 114 this.property = property; 115 } 116 117 122 private Object value; 123 124 protected Object getValue() { 125 return value; 126 } 127 128 protected void setValue(Object object) { 129 setValue(object, getObjectType()); 130 } 131 132 137 protected void setValue(Object object, Class type) { 138 if (!object.getClass().isAssignableFrom(type)) { 139 throw new CriterionException("The value of the criterion is of the wrong type, it must be " + type.getName()); 140 } 141 value = object; 142 } 143 144 149 public abstract void setPropertyValue(String object); 150 151 152 158 public String getPropertyValue() { 159 if (getValue() != null) { 160 return getValue().toString(); 161 } 162 163 return ""; 164 } 165 175 public abstract Class getObjectType(); 176 177 178 182 private String name; 183 184 public String getName() { 185 return name; 186 } 187 188 public void setName(String name) { 189 this.name = name; 190 } 191 192 202 public abstract CriterionFormPattern getFormPattern(); 203 204 211 public abstract Criterion getExprCriterion(); 212 213 214 217 private Locale locale; 218 219 220 public Locale getLocale() { 221 return locale; 222 } 223 224 public void setLocale(Locale locale) { 225 this.locale = locale; 226 } 227 228 231 private String bundleName = ""; 232 233 public String getBundle() { 234 return bundleName; 235 } 236 237 public void setBundle(String bundle) { 238 this.bundleName = bundle; 239 } 240 241 247 public String getPropertyLabel() { 248 return ResourcesUtils.getMessage(getBundle(), property.getKey(), getLocale()); 249 } 250 251 255 private Boolean dynamic = Boolean.TRUE; 256 257 public Boolean getDynamic() { 258 return dynamic; 259 } 260 261 public void setDynamic(Boolean dynamic) { 262 this.dynamic = dynamic; 263 } 264 265 270 private Class associatedEntity; 271 272 public Class getAssociatedEntity() { 273 return this.associatedEntity; 274 } 275 276 public void setAssociatedEntity(Class class1) { 277 associatedEntity = class1; 278 } 279 } | Popular Tags |