01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval;
13:
14: import java.util.Map;
15:
16: /**
17: * Partial implementation of check classes.
18: *
19: * @author Sebastian Thomschke
20: */
21: public abstract class AbstractCheck implements Check {
22: protected String errorCode;
23: protected String message;
24: protected int severity;
25: protected String[] profiles;
26:
27: public String getErrorCode() {
28: /*
29: * if the error code has not been initialized (which might be the case when using XML configuration),
30: * construct the string based on this class' name minus the appendix "Check"
31: */
32: if (errorCode == null) {
33: final String className = getClass().getName();
34: if (className.endsWith("Check"))
35: errorCode = className.substring(0, getClass().getName()
36: .length() - 5);
37: else
38: errorCode = className;
39: }
40: return errorCode;
41: }
42:
43: public String getMessage() {
44: /*
45: * if the message has not been initialized (which might be the case when using XML configuration),
46: * construct the string based on this class' name minus the appendix "Check" plus the appendix ".violated"
47: */
48: if (message == null) {
49: final String className = getClass().getName();
50: if (className.endsWith("Check"))
51: message = className.substring(0, getClass().getName()
52: .length() - 5)
53: + ".violated";
54: else
55: message = className + ".violated";
56: }
57: return message;
58: }
59:
60: public Map<String, String> getMessageVariables() {
61: return null;
62: }
63:
64: public String[] getProfiles() {
65: return profiles;
66: }
67:
68: public int getSeverity() {
69: return severity;
70: }
71:
72: public void setErrorCode(final String failureCode) {
73: errorCode = failureCode;
74: }
75:
76: public void setMessage(final String message) {
77: this .message = message;
78: }
79:
80: public void setProfiles(final String... profiles) {
81: this .profiles = profiles;
82: }
83:
84: public void setSeverity(final int severity) {
85: this.severity = severity;
86: }
87: }
|