View Javadoc

1   package gov.nasa.pds.ltdt.testLabel;
2   
3   import java.text.SimpleDateFormat;
4   import java.util.Calendar;
5   import java.util.Date;
6   
7   import gov.nasa.pds.tools.dict.ElementDefinition;
8   import gov.nasa.pds.tools.dict.type.DateChecker;
9   import gov.nasa.pds.tools.dict.type.InvalidLengthException;
10  import gov.nasa.pds.tools.dict.type.InvalidTypeException;
11  
12  public class DateTestValue implements TestValue {
13  
14  	public Object getTestValue(ElementDefinition element) throws InvalidTypeException {
15  		DateChecker checker = new DateChecker();
16  		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
17  		Date date = Calendar.getInstance().getTime();
18  		String value = formatter.format(date);
19  		//TODO: Need to come up with new DATE values if we're out of range
20  		try {
21  			checker.checkMinLength(value, element.getMinLength());
22  		} catch(InvalidLengthException e) {
23  			return new String("\"NULL\"");
24  		}
25  		
26  		try {
27  			checker.checkMaxLength(value, element.getMaxLength());
28  		} catch(InvalidLengthException e) {
29  			return new String("\"NULL\"");
30  		}
31  		
32  		return checker.cast(value);
33  	}
34  
35  }