1 /*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.batch.sample.domain.order.internal.valang;
18
19 import java.util.Date;
20
21 import org.springmodules.validation.valang.functions.AbstractFunction;
22 import org.springmodules.validation.valang.functions.Function;
23
24
25 /**
26 * Returns Boolean.TRUE if given value is future date, else it returns Boolean.FALSE
27 * @author peter.zozom
28 */
29 public class FutureDateFunction extends AbstractFunction {
30
31 public FutureDateFunction(Function[] arguments, int line, int column) {
32 super(arguments, line, column);
33 definedExactNumberOfArguments(1);
34 }
35
36 /**
37 * @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
38 */
39 protected Object doGetResult(final Object target) throws Exception {
40 //get argument
41 final Object value = getArguments()[0].getResult(target);
42
43 Boolean result;
44
45 if (value instanceof Date) {
46 final Date now = new Date(System.currentTimeMillis());
47 final Date date = (Date) value;
48 result = (now.compareTo(date) < 0) ? Boolean.TRUE : Boolean.FALSE;
49 } else {
50 throw new Exception("No Date value for validation");
51 }
52
53 return result;
54 }
55 }