KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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 org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.IResourceVisitor;
15 import org.eclipse.core.runtime.CoreException;
16
17 /**
18  * A resource traversal is simply a set of resources and the depth to which
19  * each is to be traversed. A set of traversals is used to describe the
20  * resources that constitute a model element.
21  * <p>
22  * The flags of the traversal indicate which special resources should be
23  * included or excluded from the traversal. The flags used are the same as
24  * those passed to the <code>IResource#accept(IResourceVisitor, int, int)</code> method.
25  *
26  * <p>
27  * This class may be instantiated or subclassed by clients.
28  * </p>
29
30  * @see org.eclipse.core.resources.IResource
31  * @since 3.1
32  */

33 public class ResourceTraversal {
34
35     private int depth;
36     private int flags;
37     private IResource[] resources;
38
39     /**
40      * Creates a new resource traversal.
41      * @param resources The resources in the traversal
42      * @param depth The traversal depth
43      *
44      * @deprecated Use {@link #ResourceTraversal(IResource[], int, int)} instead.
45      */

46     public ResourceTraversal(IResource[] resources, int depth) {
47         this(resources, depth, 0);
48     }
49
50     /**
51      * Creates a new resource traversal.
52      * @param resources The resources in the traversal
53      * @param depth The traversal depth
54      * @param flags the flags for this traversal. The traversal flags match those
55      * that are passed to the <code>IResource#accept</code> method.
56      */

57     public ResourceTraversal(IResource[] resources, int depth, int flags) {
58         this.resources = resources;
59         this.depth = depth;
60         this.flags = flags;
61     }
62
63     /**
64      * Visit the resources of this traversal.
65      *
66      * @param visitor a resource visitor
67      * @exception CoreException if this method fails. Reasons include:
68      * <ul>
69      * <li> A resource in this traversal does not exist.</li>
70      * <li> The visitor failed with this exception.</li>
71      * </ul>
72      */

73     public void accept(IResourceVisitor visitor) throws CoreException {
74         for (int i = 0; i < resources.length; i++) {
75             IResource resource = resources[i];
76             resource.accept(visitor, depth, flags);
77         }
78     }
79
80     /**
81      * Returns the depth to which the resources should be traversed.
82      *
83      * @return the depth to which the physical resources are to be traversed
84      * (one of IResource.DEPTH_ZERO, IResource.DEPTH_ONE or
85      * IResource.DEPTH_INFINITE)
86      */

87     public int getDepth() {
88         return depth;
89     }
90
91     /**
92      * Return the flags for this traversal.
93      * The flags of the traversal indicate which special resources should be
94      * included or excluded from the traversal. The flags used are the same as
95      * those passed to the <code>IResource#accept(IResourceVisitor, int, int)</code> method.
96      * Clients who traverse the resources manually (i.e. without calling <code>accept</code>)
97      * should respect the flags when determining which resources are included
98      * in the traversal.
99      *
100      * @return the flags for this traversal
101      */

102     public int getFlags() {
103         return flags;
104     }
105
106     /**
107      * Returns the file system resource(s) for this traversal. The returned
108      * resources must be contained within the same project and need not exist in
109      * the local file system. The traversal of the returned resources should be
110      * done considering the flag returned by getDepth. If a resource returned by
111      * a traversal is a file, it should always be visited. If a resource of a
112      * traversal is a folder then files contained in the folder can only be
113      * visited if the folder is IResource.DEPTH_ONE or IResource.DEPTH_INFINITE.
114      * Child folders should only be visited if the depth is
115      * IResource.DEPTH_INFINITE.
116      *
117      * @return The resources in this traversal
118      */

119     public IResource[] getResources() {
120         return resources;
121     }
122 }
123
Popular Tags