src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java

changeset 75
33b6843fdf8a
parent 74
91d1fc2a3a14
child 78
bb4c52bf3439
equal deleted inserted replaced
74:91d1fc2a3a14 75:33b6843fdf8a
293 */ 293 */
294 protected <T> Optional<T> getParameter(HttpServletRequest req, Class<T> clazz, String name) { 294 protected <T> Optional<T> getParameter(HttpServletRequest req, Class<T> clazz, String name) {
295 final String paramValue = req.getParameter(name); 295 final String paramValue = req.getParameter(name);
296 if (paramValue == null) return Optional.empty(); 296 if (paramValue == null) return Optional.empty();
297 if (clazz.equals(String.class)) return Optional.of((T) paramValue); 297 if (clazz.equals(String.class)) return Optional.of((T) paramValue);
298 if (java.sql.Date.class.isAssignableFrom(clazz)) {
299 try {
300 return Optional.of((T)java.sql.Date.valueOf(paramValue));
301 } catch (IllegalArgumentException ex) {
302 return Optional.empty();
303 }
304 }
298 try { 305 try {
299 final Constructor<T> ctor = clazz.getConstructor(String.class); 306 final Constructor<T> ctor = clazz.getConstructor(String.class);
300 return Optional.of(ctor.newInstance(paramValue)); 307 return Optional.of(ctor.newInstance(paramValue));
301 } catch (ReflectiveOperationException e) { 308 } catch (ReflectiveOperationException e) {
302 throw new RuntimeException(e); 309 throw new RuntimeException(e);

mercurial