KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > search > indexing > RemoveFromIndex


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.core.search.indexing;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.jdt.internal.core.index.Index;
16
17 class RemoveFromIndex extends IndexRequest {
18     String JavaDoc resourceName;
19
20     public RemoveFromIndex(String JavaDoc resourceName, IPath containerPath, IndexManager manager) {
21         super(containerPath, manager);
22         this.resourceName = resourceName;
23     }
24     public boolean execute(IProgressMonitor progressMonitor) {
25
26         if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
27
28         /* ensure no concurrent write access to index */
29         Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ false /*create if none*/);
30         if (index == null) return true;
31         ReadWriteMonitor monitor = index.monitor;
32         if (monitor == null) return true; // index got deleted since acquired
33

34         try {
35             monitor.enterWrite(); // ask permission to write
36
index.remove(resourceName);
37         } finally {
38             monitor.exitWrite(); // free write lock
39
}
40         return true;
41     }
42     public String JavaDoc toString() {
43         return "removing " + this.resourceName + " from index " + this.containerPath; //$NON-NLS-1$ //$NON-NLS-2$
44
}
45 }
46
Popular Tags