KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > mapping > ProposedResourceDelta


1 /*******************************************************************************
2  * Copyright (c) 2006 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 package org.eclipse.core.internal.resources.mapping;
12
13 import java.util.*;
14 import org.eclipse.core.resources.*;
15 import org.eclipse.core.runtime.*;
16
17 /**
18  * Concrete implementation of IResourceDelta used for operation validation
19  */

20 public final class ProposedResourceDelta extends PlatformObject implements IResourceDelta {
21
22     protected static int KIND_MASK = 0xFF;
23
24     private HashMap children = new HashMap(8);
25     private IPath movedFromPath;
26     private IPath movedToPath;
27     private IResource resource;
28     private int status;
29
30     public ProposedResourceDelta(IResource resource) {
31         this.resource = resource;
32     }
33
34     /* (non-Javadoc)
35      * @see org.eclipse.core.resources.IResourceDelta#accept(org.eclipse.core.resources.IResourceDeltaVisitor)
36      */

37     public void accept(IResourceDeltaVisitor visitor) throws CoreException {
38         accept(visitor, 0);
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.core.resources.IResourceDelta#accept(org.eclipse.core.resources.IResourceDeltaVisitor, boolean)
43      */

44     public void accept(IResourceDeltaVisitor visitor, boolean includePhantoms) throws CoreException {
45         accept(visitor, includePhantoms ? IContainer.INCLUDE_PHANTOMS : 0);
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.core.resources.IResourceDelta#accept(org.eclipse.core.resources.IResourceDeltaVisitor, int)
50      */

51     public void accept(IResourceDeltaVisitor visitor, int memberFlags) throws CoreException {
52         if (!visitor.visit(this))
53             return;
54         for (Iterator iter = children.values().iterator(); iter.hasNext();) {
55             ProposedResourceDelta childDelta = (ProposedResourceDelta) iter.next();
56             childDelta.accept(visitor, memberFlags);
57         }
58     }
59
60     /**
61      * Adds a child delta to the list of children for this delta node.
62      * @param delta
63      */

64     protected void add(ProposedResourceDelta delta) {
65         if (children.size() == 0 && status == 0)
66             setKind(IResourceDelta.CHANGED);
67         children.put(delta.getResource().getName(), delta);
68     }
69
70     /**
71      * Adds the given flags to this delta.
72      * @param flags The flags to add
73      */

74     protected void addFlags(int flags) {
75         //make sure the provided flags don't influence the kind
76
this.status |= (flags & ~KIND_MASK);
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.core.resources.IResourceDelta#findMember(org.eclipse.core.runtime.IPath)
81      */

82     public IResourceDelta findMember(IPath path) {
83         int segmentCount = path.segmentCount();
84         if (segmentCount == 0)
85             return this;
86
87         //iterate over the path and find matching child delta
88
ProposedResourceDelta current = this;
89         for (int i = 0; i < segmentCount; i++) {
90             current = (ProposedResourceDelta) current.children.get(path.segment(i));
91             if (current == null)
92                 return null;
93         }
94         return current;
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.core.resources.IResourceDelta#getAffectedChildren()
99      */

100     public IResourceDelta[] getAffectedChildren() {
101         return getAffectedChildren(ADDED | REMOVED | CHANGED, IResource.NONE);
102     }
103
104     /* (non-Javadoc)
105      * @see org.eclipse.core.resources.IResourceDelta#getAffectedChildren(int)
106      */

107     public IResourceDelta[] getAffectedChildren(int kindMask) {
108         return getAffectedChildren(kindMask, IResource.NONE);
109     }
110
111     /* (non-Javadoc)
112      * @see org.eclipse.core.resources.IResourceDelta#getAffectedChildren(int, int)
113      */

114     public IResourceDelta[] getAffectedChildren(int kindMask, int memberFlags) {
115         List result = new ArrayList();
116         for (Iterator iter = children.values().iterator(); iter.hasNext();) {
117             ProposedResourceDelta child = (ProposedResourceDelta) iter.next();
118             if ((child.getKind() & kindMask) != 0)
119                 result.add(child);
120         }
121         return (IResourceDelta[]) result.toArray(new IResourceDelta[result.size()]);
122     }
123     
124     /**
125      * Returns the child delta corresponding to the given child resource name,
126      * or <code>null</code>.
127      */

128     ProposedResourceDelta getChild(String JavaDoc name) {
129         return (ProposedResourceDelta) children.get(name);
130     }
131
132     /* (non-Javadoc)
133      * @see org.eclipse.core.resources.IResourceDelta#getFlags()
134      */

135     public int getFlags() {
136         return status & ~KIND_MASK;
137     }
138
139     /* (non-Javadoc)
140      * @see org.eclipse.core.resources.IResourceDelta#getFullPath()
141      */

142     public IPath getFullPath() {
143         return getResource().getFullPath();
144     }
145
146     /* (non-Javadoc)
147      * @see org.eclipse.core.resources.IResourceDelta#getKind()
148      */

149     public int getKind() {
150         return status & KIND_MASK;
151     }
152
153     /* (non-Javadoc)
154      * @see org.eclipse.core.resources.IResourceDelta#getMarkerDeltas()
155      */

156     public IMarkerDelta[] getMarkerDeltas() {
157         return new IMarkerDelta[0];
158     }
159
160     /* (non-Javadoc)
161      * @see org.eclipse.core.resources.IResourceDelta#getMovedFromPath()
162      */

163     public IPath getMovedFromPath() {
164         return movedFromPath;
165     }
166
167     /* (non-Javadoc)
168      * @see org.eclipse.core.resources.IResourceDelta#getMovedToPath()
169      */

170     public IPath getMovedToPath() {
171         return movedToPath;
172     }
173
174     /* (non-Javadoc)
175      * @see org.eclipse.core.resources.IResourceDelta#getProjectRelativePath()
176      */

177     public IPath getProjectRelativePath() {
178         return getResource().getProjectRelativePath();
179     }
180
181     /* (non-Javadoc)
182      * @see org.eclipse.core.resources.IResourceDelta#getResource()
183      */

184     public IResource getResource() {
185         return resource;
186     }
187
188     public void setFlags(int flags) {
189         status = getKind() | (flags & ~KIND_MASK);
190     }
191
192     protected void setKind(int kind) {
193         status = getFlags() | (kind & KIND_MASK);
194     }
195
196     protected void setMovedFromPath(IPath path) {
197         movedFromPath = path;
198     }
199
200     protected void setMovedToPath(IPath path) {
201         movedToPath = path;
202     }
203
204     /**
205      * For debugging purposes only.
206      */

207     public String JavaDoc toString() {
208         return "ProposedDelta(" + resource + ')'; //$NON-NLS-1$
209
}
210 }
211
Popular Tags