KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > databinding > validation > ValidationStatus


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Brad Reynolds - bug 164134
11  *******************************************************************************/

12 package org.eclipse.core.databinding.validation;
13
14 import org.eclipse.core.databinding.util.Policy;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17
18 /**
19  * Convenience class for creating status objects.
20  *
21  * @since 3.3
22  *
23  */

24 public class ValidationStatus extends Status {
25
26     /**
27      * Creates a new validation status with the given severity, message, and
28      * exception.
29      *
30      * @param severity
31      * @param message
32      * @param exception
33      */

34     private ValidationStatus(int severity, String JavaDoc message, Throwable JavaDoc exception) {
35         super(severity, Policy.JFACE_DATABINDING, IStatus.OK, message, exception);
36     }
37
38     /**
39      * Creates a new validation status with the given severity and message.
40      *
41      * @param severity
42      * @param message
43      */

44     private ValidationStatus(int severity, String JavaDoc message) {
45         super(severity, Policy.JFACE_DATABINDING,IStatus.OK, message, null);
46     }
47
48     /**
49      * Creates a new validation error status with the given message.
50      *
51      * @param message
52      * @return a new error status with the given message
53      */

54     public static IStatus error(String JavaDoc message) {
55         return new ValidationStatus(IStatus.ERROR, message);
56     }
57
58     /**
59      * Creates a new validation cancel status with the given message.
60      *
61      * @param message
62      * @return a new cancel status with the given message
63      */

64     public static IStatus cancel(String JavaDoc message) {
65         return new ValidationStatus(IStatus.CANCEL, message);
66     }
67     
68     /**
69      * Creates a new validation error status with the given message and
70      * exception.
71      *
72      * @param message
73      * @param exception
74      * @return a new error status with the given message and exception
75      */

76     public static IStatus error(String JavaDoc message, Throwable JavaDoc exception) {
77         return new ValidationStatus(IStatus.ERROR, message, exception);
78     }
79
80     /**
81      * Creates a new validation warning status with the given message.
82      *
83      * @param message
84      * @return a new warning status with the given message
85      */

86     public static IStatus warning(String JavaDoc message) {
87         return new ValidationStatus(IStatus.WARNING, message);
88     }
89     
90     /**
91      * Creates a new validation info status with the given message.
92      *
93      * @param message
94      * @return a new info status with the given message
95      */

96     public static IStatus info(String JavaDoc message) {
97         return new ValidationStatus(IStatus.INFO, message);
98     }
99     
100     /**
101      * Returns an OK status.
102      *
103      * @return an ok status
104      */

105     public static IStatus ok() {
106         return Status.OK_STATUS;
107     }
108
109     /*
110      * (non-Javadoc)
111      *
112      * @see java.lang.Object#hashCode()
113      */

114     public int hashCode() {
115         final int prime = 31;
116         int result = 1;
117
118         String JavaDoc message = getMessage();
119         int severity = getSeverity();
120         Throwable JavaDoc throwable = getException();
121
122         result = prime * result + ((message == null) ? 0 : message.hashCode());
123         result = prime * result + severity;
124         result = prime * result
125                 + ((throwable == null) ? 0 : throwable.hashCode());
126         return result;
127     }
128
129     /**
130      * Equality is based upon instance equality rather than identity.
131      *
132      * @see java.lang.Object#equals(java.lang.Object)
133      */

134     public boolean equals(Object JavaDoc obj) {
135         if (this == obj)
136             return true;
137         if (obj == null)
138             return false;
139         if (getClass() != obj.getClass())
140             return false;
141         final ValidationStatus other = (ValidationStatus) obj;
142
143         if (getSeverity() != other.getSeverity())
144             return false;
145         if (getMessage() == null) {
146             if (other.getMessage() != null)
147                 return false;
148         } else if (!getMessage().equals(other.getMessage()))
149             return false;
150         if (getException() == null) {
151             if (other.getException() != null)
152                 return false;
153         } else if (!getException().equals(other.getException()))
154             return false;
155         return true;
156     }
157 }
158
Popular Tags