View Javadoc

1   /*
2    * Copyright 2010 Capgemini and Contributors
3    *
4    * Licensed under the Apache License, Version 2.0 (the
5    * "License"); 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.appstatus.core.check;
17  
18  import java.util.Locale;
19  import java.util.Properties;
20  
21  import net.sf.appstatus.core.check.impl.StatusResultImpl;
22  
23  /**
24   * @author Nicolas Richeton
25   *
26   */
27  public abstract class AbstractCheck implements ICheck, IConfigurationAware {
28  
29  	protected static final int FATAL = 2;
30  	protected static final int OK = 0;
31  	protected static final int WARN = 1;
32  	private Properties configuration;
33  
34  	/**
35  	 * @deprecated use {@link #checkStatus(Locale)} instead.
36  	 * @return
37  	 */
38  	@Deprecated
39  	public ICheckResult checkStatus() {
40  		return null;
41  	}
42  
43  	/**
44  	 * This method must be overriden and implemented by Checks.
45  	 * <p>
46  	 * Note: default implementation ensure compatibility with old check by
47  	 * calling {@link #checkStatus()}
48  	 *
49  	 * @param locale
50  	 *            locale to used for description and resolution steps.
51  	 *
52  	 * @return check result.
53  	 */
54  	public ICheckResult checkStatus(Locale locale) {
55  		return checkStatus();
56  	}
57  
58  	/**
59  	 * Create result. Details can then be added using
60  	 * {@link ICheckResult#setDescription(String)} and
61  	 * {@link ICheckResult#setResolutionSteps(String)}.
62  	 *
63  	 * @deprecated use {@link CheckResultBuilder} instead.
64  	 * @param code
65  	 *            {@link AbstractCheck#OK} or {@link AbstractCheck#FATAL}
66  	 * @return ICheckResult object
67  	 */
68  	@Deprecated
69  	protected ICheckResult createResult(int code) {
70  		StatusResultImpl result = new StatusResultImpl();
71  		result.setProbeName(getName());
72  		result.setGroup(getGroup());
73  
74  		switch (code) {
75  		case OK:
76  			result.setCode(ICheckResult.OK);
77  			result.setFatal(false);
78  
79  			break;
80  		case FATAL:
81  			result.setFatal(true);
82  			result.setCode(ICheckResult.ERROR);
83  			break;
84  		default:
85  			// WARN
86  			result.setFatal(false);
87  			result.setCode(ICheckResult.ERROR);
88  			break;
89  		}
90  
91  		return result;
92  	}
93  
94  	public Properties getConfiguration() {
95  		return configuration;
96  	}
97  
98  	/**
99  	 * Create a generic result. name and group are NOT set and it's up to the
100 	 * caller to call {@link CheckResultBuilder#from(ICheck)}
101 	 *
102 	 * @return CheckResultBuilder to use.
103 	 */
104 	protected CheckResultBuilder result() {
105 		return new CheckResultBuilder();
106 	}
107 
108 	/**
109 	 * Create a generic result.
110 	 *
111 	 * @param
112 	 *
113 	 * @return CheckResultBuilder to use.
114 	 */
115 	protected CheckResultBuilder result(ICheck check) {
116 		return new CheckResultBuilder().from(check);
117 	}
118 
119 	public void setConfiguration(Properties configuration) {
120 		this.configuration = configuration;
121 	}
122 }