KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jdt.internal.core.index.Index;
18 import org.eclipse.jdt.internal.core.search.processing.JobManager;
19 import org.eclipse.jdt.internal.core.util.Util;
20
21 /*
22  * Save the index of a project.
23  */

24 public class SaveIndex extends IndexRequest {
25     public SaveIndex(IPath containerPath, IndexManager manager) {
26         super(containerPath, manager);
27     }
28     public boolean execute(IProgressMonitor progressMonitor) {
29
30         if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
31
32         /* ensure no concurrent write access to index */
33         Index index = this.manager.getIndex(this.containerPath, true /*reuse index file*/, false /*don't create if none*/);
34         if (index == null) return true;
35         ReadWriteMonitor monitor = index.monitor;
36         if (monitor == null) return true; // index got deleted since acquired
37

38         try {
39             monitor.enterWrite(); // ask permission to write
40
this.manager.saveIndex(index);
41         } catch (IOException JavaDoc e) {
42             if (JobManager.VERBOSE) {
43                 Util.verbose("-> failed to save index " + this.containerPath + " because of the following exception:", System.err); //$NON-NLS-1$ //$NON-NLS-2$
44
e.printStackTrace();
45             }
46             return false;
47         } finally {
48             monitor.exitWrite(); // free write lock
49
}
50         return true;
51     }
52     public String JavaDoc toString() {
53         return "saving index for " + this.containerPath; //$NON-NLS-1$
54
}
55 }
56
Popular Tags