KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dependencies > ElementChange


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

11
12 package org.eclipse.core.internal.dependencies;
13
14
15 /**
16  * Represents a change that happened to an element's resolution status.
17  */

18 public class ElementChange {
19     /** State transitions. */
20     public final static int ADDED = 0x01;
21     public final static int LINKAGE_CHANGED = 0x10;
22     public final static int REMOVED = 0x02;
23     public final static int RESOLVED = 0x04;
24     public final static int UNRESOLVED = 0x08;
25     public final static int UPDATED = ADDED | REMOVED;
26     private Element element;
27     private int kind;
28
29     ElementChange(Element element, int kind) {
30         this.element = element;
31         this.kind = kind;
32     }
33
34     /**
35      * Returns the affected element.
36      */

37
38     public Element getElement() {
39         return element;
40     }
41     /**
42      * Returns the kind of the transition.
43      */

44
45     public int getKind() {
46         return kind;
47     }
48
49     private String JavaDoc getStatusName(int status) {
50         StringBuffer JavaDoc statusStr = new StringBuffer JavaDoc();
51         if ((status & ADDED) != 0)
52             statusStr.append("ADDED|"); //$NON-NLS-1$
53
if ((status & REMOVED) != 0)
54             statusStr.append("REMOVED|"); //$NON-NLS-1$
55
if ((status & RESOLVED) != 0)
56             statusStr.append("RESOLVED|"); //$NON-NLS-1$
57
if ((status & UNRESOLVED) != 0)
58             statusStr.append("UNRESOLVED|"); //$NON-NLS-1$
59
if ((status & LINKAGE_CHANGED) != 0)
60             statusStr.append("LINKAGE_CHANGED|"); //$NON-NLS-1$
61
if (statusStr.length() == 0)
62             statusStr.append("UNKNOWN"); //$NON-NLS-1$
63
else
64             statusStr.deleteCharAt(statusStr.length() - 1);
65         return statusStr.toString();
66     }
67
68     public Object JavaDoc getVersionId() {
69         return element.getVersionId();
70     }
71
72     void setKind(int kind) {
73         this.kind = kind;
74     }
75
76     public String JavaDoc toString() {
77         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
78         result.append(element.getId());
79         result.append('_');
80         result.append(getVersionId());
81         result.append(" ("); //$NON-NLS-1$
82
result.append(getStatusName(getKind()));
83         result.append(')');
84         return result.toString();
85     }
86 }
Popular Tags