KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > BindingStatus


1 /*******************************************************************************
2  * Copyright (c) 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  ******************************************************************************/

11
12 package org.eclipse.core.internal.databinding;
13
14 import java.util.Arrays JavaDoc;
15
16 import org.eclipse.core.databinding.util.Policy;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.MultiStatus;
19
20 /**
21  * A <code>MultiStatus</code> implementation that copies that state of the
22  * added status to this instance if it is >= the current severity.
23  *
24  * @since 1.0
25  */

26 public class BindingStatus extends MultiStatus {
27     /**
28      * Constructs a new instance.
29      *
30      * @param pluginId
31      * @param code
32      * @param message
33      * @param exception
34      */

35     public BindingStatus(String JavaDoc pluginId, int code, String JavaDoc message,
36             Throwable JavaDoc exception) {
37         super(pluginId, code, message, exception);
38     }
39
40     /**
41      * Adds the status to the multi status. The details of the status will be
42      * copied to the multi status if the severity is >= the current severity.
43      *
44      * @see org.eclipse.core.runtime.MultiStatus#add(org.eclipse.core.runtime.IStatus)
45      */

46     public void add(IStatus status) {
47         if (status.getSeverity() >= getSeverity()) {
48             setMessage((status.getMessage() != null) ? status.getMessage() : ""); //$NON-NLS-1$
49
setException(status.getException());
50             setPlugin(status.getPlugin());
51             setCode(status.getCode());
52         }
53
54         super.add(status);
55     }
56
57     /**
58      * Instance initialized with the following values:
59      * <ul>
60      * <li>plugin = Policy.JFACE_DATABINDING</li>
61      * <li>severity = 0</li>
62      * <li>code = 0</li>
63      * <li>message = ""</li>
64      * <li>exception = null</li>
65      * </ul>
66      *
67      * @return status
68      */

69     public static BindingStatus ok() {
70         return new BindingStatus(Policy.JFACE_DATABINDING, 0, "", null); //$NON-NLS-1$
71
}
72     
73     private static int hashCode(Object JavaDoc[] array) {
74         final int prime = 31;
75         if (array == null)
76             return 0;
77         int result = 1;
78         for (int index = 0; index < array.length; index++) {
79             result = prime * result
80                     + (array[index] == null ? 0 : array[index].hashCode());
81         }
82         return result;
83     }
84     
85     public int hashCode() {
86         final int prime = 31;
87         int result = 1;
88         result = prime * result + BindingStatus.hashCode(getChildren());
89         return result;
90     }
91
92     public boolean equals(Object JavaDoc obj) {
93         if (this == obj)
94             return true;
95         if (obj == null)
96             return false;
97         if (getClass() != obj.getClass())
98             return false;
99         final BindingStatus other = (BindingStatus) obj;
100         if (!Arrays.equals(getChildren(), other.getChildren()))
101             return false;
102         return true;
103     }
104 }
105
Popular Tags