KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > WorkspaceTreeReader_2


1 /*******************************************************************************
2  * Copyright (c) 2000, 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;
12
13 import java.io.DataInputStream JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17 import org.eclipse.core.internal.events.BuilderPersistentInfo;
18 import org.eclipse.core.internal.utils.Messages;
19 import org.eclipse.core.internal.utils.Policy;
20 import org.eclipse.core.internal.watson.ElementTree;
21 import org.eclipse.core.resources.IProject;
22 import org.eclipse.core.resources.IResourceStatus;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.IProgressMonitor;
25
26 /**
27  * Reads version 2 of the workspace tree file format.
28  *
29  * This version differs from version 1 in the amount of information that is persisted
30  * for each builder. Version 1 only stored builder names and trees. Version
31  * 2 stores builder names, project names, trees, and interesting projects for
32  * each builder.
33  */

34 public class WorkspaceTreeReader_2 extends WorkspaceTreeReader_1 {
35
36     public WorkspaceTreeReader_2(Workspace workspace) {
37         super(workspace);
38     }
39
40     protected int getVersion() {
41         return ICoreConstants.WORKSPACE_TREE_VERSION_2;
42     }
43
44     /*
45      * overwritten from WorkspaceTreeReader_1
46      */

47     protected void readBuildersPersistentInfo(IProject project, DataInputStream JavaDoc input, List JavaDoc builders, IProgressMonitor monitor) throws IOException JavaDoc {
48         monitor = Policy.monitorFor(monitor);
49         try {
50             int builderCount = input.readInt();
51             for (int i = 0; i < builderCount; i++) {
52                 BuilderPersistentInfo info = readBuilderInfo(project, input, i);
53                 // read interesting projects
54
int n = input.readInt();
55                 IProject[] projects = new IProject[n];
56                 for (int j = 0; j < n; j++)
57                     projects[j] = workspace.getRoot().getProject(input.readUTF());
58                 info.setInterestingProjects(projects);
59                 builders.add(info);
60             }
61         } finally {
62             monitor.done();
63         }
64     }
65
66     /*
67      * overwritten from WorkspaceTreeReader_1
68      */

69     public void readTree(IProject project, DataInputStream JavaDoc input, IProgressMonitor monitor) throws CoreException {
70         monitor = Policy.monitorFor(monitor);
71         String JavaDoc message;
72         try {
73             message = Messages.resources_reading;
74             monitor.beginTask(message, 10);
75
76             /* read in the builder infos */
77             List JavaDoc infos = new ArrayList JavaDoc(5);
78             readBuildersPersistentInfo(project, input, infos, Policy.subMonitorFor(monitor, 1));
79
80             /* read and link the trees */
81             ElementTree[] trees = readTrees(project.getFullPath(), input, Policy.subMonitorFor(monitor, 8));
82
83             /* map builder names to trees */
84             linkBuildersToTrees(infos, trees, 0, Policy.subMonitorFor(monitor, 1));
85
86         } catch (IOException JavaDoc e) {
87             message = Messages.resources_readProjectTree;
88             throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, message, e);
89         } finally {
90             monitor.done();
91         }
92     }
93 }
94
Popular Tags