Skip to main content
summaryrefslogtreecommitdiffstats
blob: eee8e16a0f8b6abdf64d0839b7fdcb01ff3f43a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.common.componentcore.resources;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;


/**
 * <p>
 * Allows clients to work with flexible project structures 
 * using API similar to the Eclipse Platform IResource model.
 * </p>
 * <p>
 * IVirtualResource allows resources to be accessed through a
 * abstract path referred to as a "runtime path". 
 * A virtual resource may represent multiple underlying resources.
 * A virtual resource is contained by exactly one component.
 * A resource may be represented by multiple virtual resources, which
 * may be contained by one or more components. 
 * </p>
 * <p>
 * IVirtualResource allows clients to acquire
 * information about the underlying resource including the name, 
 * and the paths which are relevant to the current resource, such
 * as the {@link #getRuntimePath() runtime path}, the 
 * {@link #getWorkspaceRelativePath() workspace-relative path}
 * of the underlying resource, and the 
 * {@link #getProjectRelativePath() project-relative path}
 * of the underlying resource.
 * </p>
 * <a name="references" />
 * <p>Each IVirtualResource can represent an <b>implicit</b> reference or
 * an <b>explicit</b> reference. An <b>explicit</b> reference is a formal
 * mapping from some path within the file structure to a runtime path. Changing
 * or removing an explicit reference only requires model modifications. An 
 * <b>implicit</b> reference has a root which is derived from an explicit path,
 * but some fragment of the path towards the end is derived from the literal 
 * path within the file structure. Modifications to implicit paths may cause 
 * changes to structure on disk. For resource modifications that should not modify
 * structures on disk, use {@link #IGNORE_UNDERLYING_RESOURCE}.
 * </p>
 * <p>
 * This interface is not intended to be implemented by clients.
 * </p>
 * @plannedfor 1.0
 */
public interface IVirtualResource extends ISchedulingRule, IAdaptable {  
																	

	/*
	 * ==================================================================== 
	 * Constants defining resource types: There are four possible resource 
	 * types and their type constants are in the hex range 0x10 to 0x80 
	 * as defined below.
	 * ====================================================================
	 */

	/**
	 * Type constant (bit mask value 16) which identifies file resources.
	 * 
	 * @see IVirtualResource#getType()
	 * @see IVirtualFile
	 */
	public static final int FILE = 0x10;

	/**
	 * Type constant (bit mask value 32) which identifies folder resources.
	 * 
	 * @see IVirtualResource#getType()
	 * @see IVirtualFolder
	 */
	public static final int FOLDER = 0x20;

	/**
	 * Type constant (bit mask value 64) which identifies the root resource.
	 * 
	 * @see IVirtualResource#getType()
	 * @see IVirtualContainer
	 */
	public static final int COMPONENT = 0x40;
	
	/**
	 * General purpose zero-valued bit mask constant. Useful whenever you need to supply a bit mask
	 * with no bits set.
	 * <p>
	 * Example usage: <code>
	 * <pre>
	 * delete(IVirtualResource.NONE, null)
	 * </pre>
	 * </code>
	 * </p>
	 * 
	 * @plannedfor 2.0
	 */
	public static final int NONE = 0;

	/*
	 * ==================================================================== Constants for update
	 * flags for delete, move, copy, open, etc.:
	 * ====================================================================
	 */

	/**
	 * Update flag constant (bit mask value 256) indicating that the operation should proceed even if
	 * the resource is out of sync with the local file system.
	 * 
	 * @plannedfor 2.0
	 */
	public static final int FORCE = 0x100; 

	/**
	 * Indicates that exclusions enumerated in the model should be ignored. (bit mask value 512)  
	 */
	public static final int IGNORE_EXCLUSIONS = 0x200;

	/**
	 * Indicates that modifications should only modify the metamodel and ignore the underlying
	 * resources where applicable.  See the 
	 * <a href="IVirtualResource.html#references">documentation on references</a> 
	 * for more information on why this flag is relevant. (bit mask value 1024)  
	 */
	public static final int IGNORE_UNDERLYING_RESOURCE = 0x400;  
	
	/**
	 * Create a mapping from the supplied location to the runtime path of this 
	 * virtual resource. Model changes will occur as a result of this method, 
	 * and potentially resource-level creations as well.
	 * 
	 * @param aProjectRelativeLocation A project relative location that will be represented by the runtime path after this call
	 * @param updateFlags A bitmask of flags to supply to the method. 
	 * @param monitor
	 * @throws CoreException
	 */
	public void createLink(IPath aProjectRelativeLocation, int updateFlags, IProgressMonitor monitor) throws CoreException;

	/**
	 * Removes the mapping, if it exists, from the supplied location to the runtime path of this 
	 * virtual resource. Model changes will occur as a result of this method, 
	 * and potentially resource-level creations as well.
	 * 
	 * @param aProjectRelativeLocation A project relative location whose mapping to the runtime path of this object should be removed.
	 * @param updateFlags A bitmask of flags to supply to the method. 
	 * @param monitor
	 * @throws CoreException
	 */
	public void removeLink(IPath aProjectRelativeLocation, int updateFlags, IProgressMonitor monitor) throws CoreException;

	
	/**   
	 * Remove the resource from the flexible structure. Removing the resource could require
	 * changes to the underlying metamodel or changes to the file structure. To avoid
	 * changes the actual disk structure, use {@link #IGNORE_UNDERLYING_RESOURCE}.
	 * <p>
	 * Update flags supplied to this method will be passed into any IResource modification
	 * API which is called as a result of this method's invocation.  
	 * </p>
	 * @see #IGNORE_UNDERLYING_RESOURCE
	 * @see IResource#delete(int, org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException;

	/**
	 * Compares two objects for equality; for resources, equality is defined in terms of their
	 * handles: same resource type, equal full paths, and identical workspaces. Resources are not
	 * equal to objects other than resources.
	 * 
	 * @param other
	 *            the other object
	 * @return an indication of whether the objects are equals
	 * @see #getType()
	 * @see #getWorkspaceRelativePath() 
	 */
	public boolean equals(Object other);

	/**
	 * Returns whether this virtual resource is backed by an accessible IResource. 
	 * <p>
	 * <code>IVirtualResource</code> objects are lightweight handle objects used to access
	 * IResources. However, having an IVirtualResource handle does not necessarily mean the
	 * underlying resource represented by the handle exists in the workspace, or is accessible.
	 * For more detailed information concerning the existence or accessibility of the underlying 
	 * resource, {@link #getUnderlyingResource()}.
	 * </p>
	 * 
	 * @return <code>true</code> if the underlying resource exists and is accessible, otherwise <code>false</code>
	 * @see org.eclipse.core.resources.IResource#exists()
	 * @see #getUnderlyingResource();
	 */
	public boolean exists();

	/**
	 * Returns the file extension portion of this virtual resource's name, or <code>null</code> if it does
	 * not have one. The file extension of the virtual resource will be returned, which may or may not match
	 * that of the underlying resource. 
	 * <p>
	 * The file extension portion is defined as the string following the last period (".") character
	 * in the name. If there is no period in the name, the path has no file extension portion. If
	 * the name ends in a period, the file extension portion is the empty string.
	 * </p>
	 * <p>
	 * This is a resource handle operation; the resource need not exist.
	 * </p>
	 * 
	 * @return a string file extension
	 * @see #getName()
	 */
	public String getFileExtension();

	/**
	 * Returns the full, absolute path of the underlying resource relative to the workspace.
	 * <p>
	 * This is a resource handle operation; the resource need not exist. If this resource does
	 * exist, its path can be safely assumed to be valid.
	 * </p>
	 * 
	 * @return the absolute path of this resource
	 * @see #getProjectRelativePath()
	 * @see IResource#getFullPath()
	 */
	public IPath getWorkspaceRelativePath();


	/**
	 * Returns a relative path of the underlying resource with respect to its project.  
	 * <p>
	 * This is a resource handle operation; the resource need not exist. If this resource does
	 * exist, its path can be safely assumed to be valid.
	 * </p>
	 * <p>
	 * Project-relative paths are recommended over absolute paths, since the former are not affected
	 * if the project is renamed.
	 * </p>
	 * 
	 * @return the relative path of this resource with respect to its project
	 * @see #getWorkspaceRelativePath()
	 * @see #getProject()
	 * @see IResource#getProjectRelativePath()
	 */
	public IPath getProjectRelativePath();

	/**
	 * Returns the runtime path of this virtual resource. The runtime path
	 * is determined through the metamodel and represents the path that the
	 * underlying resource will be accessed at runtime. 
	 * 
	 * @return the runtime path of this virtual resource
	 */
	public IPath getRuntimePath();

	/**
	 * Returns the name of this virtual resource. The name of a virtual resource 
	 * is synonymous with the last segment of its runtime path.
	 * <p>
	 * This is a resource handle operation; the resource need not exist.
	 * </p>
	 * <p>
	 * If this resource exists, its name can be safely assumed to be valid.
	 * </p>
	 * 
	 * @return the name of the virtual resource
	 * @see #getRuntimePath()
	 */
	public String getName();

	/**
	 * Returns the name of the component that contains this virtual resource.
	 * <p>
	 * Each virtual resource is contained by at least one component. A component
	 * represents a logical collection of files. If the underlying resource is 
	 * contained by multiple components, then the component name returned by
	 * this method will be determined by how the virtual resource was created. 
	 * For each virtual resource, the component name will be the same as the 
	 * component name of the parent.
	 *  
	 * @return the name of the component that contains the virtual resource
	 */
	public IVirtualComponent getComponent();

	/**
	 * Returns the virtual resource which contains this virtual resource, or <code>null</code> if it has
	 * no parent (that is, the virtual resource represents the root of the component).
	 * <p>
	 * The full path of the parent resource is the same as this resource's full path with the last
	 * segment removed.
	 * </p>
	 * <p>
	 * This is a resource handle operation; neither the resource nor the resulting resource need
	 * exist.
	 * </p>
	 * 
	 * @return the container of the virtual resource, or <code>null</code> if this virtual resource represents the root of the component
	 */
	public IVirtualContainer getParent();

	/**
	 * Returns the project which contains the component which contains this virtual resource. 
	 * <p>
	 * The name of the project may not (and most likely will not) be referenced in the 
	 * runtime path of this virtual path, but will be referenced by the workspace-relative path. 
	 * </p>
	 * <p>
	 * This is a resource handle operation; neither the resource nor the resulting project need
	 * exist.
	 * </p>
	 * 
	 * @return the project handle
	 */
	public IProject getProject();

	/**
	 * Returns the type of this resource. The returned value will be one of <code>FILE</code>,
	 * <code>FOLDER</code>, <code>COMPONENT</code>
	 * <p>
	 * <ul>
	 * <li> All resources of type <code>FILE</code> implement <code>IVirtualFile</code>.</li>
	 * <li> All resources of type <code>FOLDER</code> implement <code>IVirtualFolder</code>.</li>
	 * <li> All resources of type <code>COMPONENT</code> implement <code>IVirtualContainer</code>.</li>
	 * </ul>
	 * </p>
	 * <p>
	 * This is a resource handle operation; the resource need not exist in the workspace.
	 * </p>
	 * 
	 * @return the type of this resource
	 * @see #FILE
	 * @see #FOLDER
	 * @see #COMPONENT
	 */
	public int getType();
	
	/**
	 * A virtual resource is a representation of one or more Eclipse Platform resources. 
	 * <p>
	 * Returns the "primary" underlying resource. The resource may or may not exist. The resource
	 * will be contained by the project returned by {@link #getProject()}.  
	 * </p>
	 * <p>
	 * Since a virtual resource could represent multiple resources, this method will return 
	 * the "primary" resource. For clients that wish to take advantage of the multiple resources
	 * at a single path, use {@link #getUnderlyingResources()}. 
	 * @return The primary resource that backs this virtual resource.
	 */
	public IResource getUnderlyingResource();
	
	/**
	 * A virtual resource is a representation of one or more Eclipse Platform resources. 
	 * <p>
	 * Returns all underlying resources. The resources may or may not exist. The resources
	 * will be contained by the project returned by {@link #getProject()}.  
	 * </p>
	 * <p>
	 * Since a virtual resource could represent multiple resources, this method will return 
	 * all underlying resources. For clients that prefer to acknowledge only one resource, 
	 * at a single path, use {@link #getUnderlyingResource()}. 
	 * @return All resources that back this virtual resource.
	 */
	public IResource[] getUnderlyingResources(); 

	/**
	 * Returns whether this resource is accessible. For files and folders, this is equivalent to
	 * existing; for projects, this is equivalent to existing and being open. The workspace root is
	 * always accessible.
	 * 
	 * @return <code>true</code> if this resource is accessible, and <code>false</code>
	 *         otherwise
	 * @see #exists()
	 * @see IProject#isOpen()
	 */
	public boolean isAccessible();
	
	/**
	 * The resourceType provides meta-information about the types of content this virtual resource may represent. Examples
	 * include "java", "resources", "bpel", etc. 
	 * <p>
	 * The resourceType may be null, and {@link IVirtualComponent} will always return null for this method. 
	 * </p>
	 * @return A client-set resourceType string
	 */
	public String getResourceType();
	
	/**
	 * The resourceType provides meta-information about the types of content this virtual resource may represent. Examples
	 * include "java", "resources", "bpel", etc. 
	 * <p>
	 * The resourceType may be null, and {@link IVirtualComponent} will always return null for this method. 
	 * </p>
	 * @param A client-set resourceType string
	 */
	public void setResourceType(String aResourceType);

}

Back to the top