View Javadoc

1   //Copyright 2006-2007, by the California Institute of Technology.
2   //ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   //Any commercial use must be negotiated with the Office of Technology Transfer
4   //at the California Institute of Technology.
5   //
6   //This software is subject to U. S. export control laws and regulations
7   //(22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   //is subject to U.S. export control laws and regulations, the recipient has
9   //the responsibility to obtain export licenses or other export authority as
10  //may be required before exporting such information to foreign countries or
11  //providing access to foreign nationals.
12  
13  package gov.nasa.pds.vtool.status;
14  
15  import gov.nasa.pds.vtool.validate.ValidationRecord;
16  
17  /***
18   * Exit Status values
19   * <ul>
20   *  <li>0 = Success</li>
21   *  <li>1 = Application error</li>
22   *  <li>2 = System error</li>
23   *  <li>32 = One or more files skipped the validation run</li>
24   *  <li>64 = One or more validation warnings encountered during the
25   *  validation run</li>
26   *  <li>96 = One or more files skipped and validation warnings encountered
27   *  during the validation run</li>
28   *  <li>128 = One or more validation errors encountered during the validation
29   *  run</li>
30   *  <li>160 = One or more files skipped and validation errors encountered
31   *  during the validation run</li>
32   *  <li>192 = One or more validation warnings and errors encountered during
33   *  the validation run</li>
34   *  <li>224 = One or more files skipped, validation warnings and errors
35   *  encountered during the validation run</li>
36   * </ul>
37   *     
38   * @author mcayanan
39   *
40   */
41  public class ExitStatus implements ExitStatusType {
42  	private int status;
43  	private String ERROR = "ERROR";
44  	
45  	/***
46  	 * Constructor
47  	 *
48  	 *@param verboseLevel The severity level and above to include when
49  	 * determining the exit status. Valid values are "INFO", "WARNING"
50  	 * or "ERROR".
51  	 *
52  	 *@throws IllegalArgumentException If the verbose level 
53  	 */
54  	public ExitStatus() throws IllegalArgumentException {
55  		status = 0;
56  	}
57  	
58  	/***
59  	 * Get the status
60  	 * 
61  	 * @param severity The severity level and above to include when
62  	 * determining the exit status.
63  	 * 
64  	 * @return The exit status value.
65  	 */
66  	public int getStatus(String severity) {
67  		//If the severity level and above is ERROR, then warnings
68  		//will be excluded.
69  		if(ERROR.equalsIgnoreCase(severity)) {
70  			status = (status & 191);
71  		}
72  		return status;
73  	}
74  	
75  	/***
76  	 * Set the status
77  	 * @param value integer value that would represent the status.
78  	 * @throws IndexOutOfBoundsException
79  	 */
80  	public void setStatus(int value) throws IndexOutOfBoundsException {
81  		status = (status | value);
82  	}
83  	
84  	/***
85  	 * Set the status
86  	 * 
87  	 * @param record A ValidationRecord containing the results of a validaiton run.
88  	 */
89  	public void setStatus(ValidationRecord record) {
90  		if(record.getFilesSkipped() != 0)
91  			status = (status | SKIPPED_FILES);
92  		if(record.hasWarnings())
93  			status = (status | WARNINGS_FOUND);
94  		if(record.hasErrors())
95  			status = (status | ERRORS_FOUND);
96  	}
97  }