KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > core > text > TypedResourceVisitor


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.search.internal.core.text;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.IResourceProxy;
15 import org.eclipse.core.resources.IResourceProxyVisitor;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.MultiStatus;
18
19 import org.eclipse.jface.util.Assert;
20
21 public class TypedResourceVisitor implements IResourceProxyVisitor {
22
23     private MultiStatus fStatus;
24
25     TypedResourceVisitor(MultiStatus status) {
26         Assert.isNotNull(status);
27         fStatus= status;
28     }
29     
30     protected boolean visitFile(IResourceProxy proxy) throws CoreException {
31         return true;
32     }
33
34     protected boolean visitProject(IResourceProxy proxy) throws CoreException {
35         return true;
36     }
37     
38     protected boolean visitFolder(IResourceProxy proxy) throws CoreException {
39         return true;
40     }
41     
42     protected void addToStatus(CoreException ex) {
43         fStatus.add(ex.getStatus());
44     }
45
46     /*
47      * @see org.eclipse.core.resources.IResourceProxyVisitor#visit(org.eclipse.core.resources.IResourceProxy)
48      */

49     public boolean visit(IResourceProxy proxy) {
50         try {
51             switch(proxy.getType()) {
52                 case IResource.FILE:
53                     return visitFile(proxy);
54                 case IResource.FOLDER:
55                     return visitFolder(proxy);
56                 case IResource.PROJECT:
57                     return visitProject(proxy);
58                 default:
59                     Assert.isTrue(false, "unknown resource type"); //$NON-NLS-1$
60
}
61             return false;
62         } catch (CoreException ex) {
63             addToStatus(ex);
64             return false;
65         }
66     }
67 }
68
Popular Tags