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  	 * @throws IllegalArgumentException If the verbose level 
49  	 */
50  	public ExitStatus() throws IllegalArgumentException {
51  		status = 0;
52  	}
53  	
54  	/***
55  	 * Get the status
56  	 * 
57  	 * @param severity The severity level and above to include when
58  	 * determining the exit status.
59  	 * 
60  	 * @return The exit status value.
61  	 */
62  	public int getStatus(String severity) {
63  		//If the severity level and above is ERROR, then warnings
64  		//will be excluded.
65  		if(ERROR.equalsIgnoreCase(severity)) {
66  			status = (status & 191);
67  		}
68  		return status;
69  	}
70  	
71  	/***
72  	 * Set the status
73  	 * @param value integer value that would represent the status.
74  	 * @throws IndexOutOfBoundsException
75  	 */
76  	public void setStatus(int value) throws IndexOutOfBoundsException {
77  		status = (status | value);
78  	}
79  	
80  	/***
81  	 * Set the status
82  	 * 
83  	 * @param record A ValidationRecord containing the results of a validaiton run.
84  	 */
85  	public void setStatus(ValidationRecord record) {
86  		if(record.getFilesSkipped() != 0)
87  			status = (status | SKIPPED_FILES);
88  		if(record.hasWarnings())
89  			status = (status | WARNINGS_FOUND);
90  		if(record.hasErrors())
91  			status = (status | ERRORS_FOUND);
92  	}
93  }