1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.reflect.reflectors;
17
18 import javax.servlet.ServletRequest;
19
20 import net.sf.composite.util.ObjectUtils;
21 import net.sf.morph.reflect.ReflectionException;
22 import net.sf.morph.util.ContainerUtils;
23
24 /**
25 * Exposes servlet request parameters.
26 *
27 * @author Matt Sgarlata
28 * @since Nov 21, 2004
29 */
30 public class ServletRequestParameterReflector extends BaseServletReflector {
31
32 private static final Class[] REFLECTABLE_TYPES = new Class[] {
33 ServletRequest.class
34 };
35
36 private ServletRequest getRequest(Object bean) {
37 return (ServletRequest) bean;
38 }
39
40 protected String[] getPropertyNamesImpl(Object bean) throws Exception {
41 return enumerationToStringArray(getRequest(bean).getParameterNames());
42 }
43
44 protected Class getTypeImpl(Object bean, String propertyName)
45 throws Exception {
46 String[] values = getRequest(bean).getParameterValues(propertyName);
47 return ObjectUtils.isEmpty(values) || values.length == 1 ? String.class : String[].class;
48 }
49
50 protected boolean isReadableImpl(Object bean, String propertyName)
51 throws Exception {
52
53
54
55
56 return true;
57 }
58
59 protected boolean isWriteableImpl(Object bean, String propertyName)
60 throws Exception {
61 return false;
62 }
63
64 protected Object getImpl(Object bean, String propertyName) throws Exception {
65 String[] values = getRequest(bean).getParameterValues(propertyName);
66 return ObjectUtils.isEmpty(values) || values.length == 1 ? (Object) getRequest(bean).getParameter(propertyName) : values;
67 }
68
69 protected void setImpl(Object bean, String propertyName, Object value)
70 throws Exception {
71
72
73 throw new ReflectionException("Can't set HTTP request parameters");
74 }
75
76 public Class[] getReflectableClassesImpl() {
77 return REFLECTABLE_TYPES;
78 }
79
80 }