KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet JavaDoc;
16 import java.util.Set JavaDoc;
17 import org.eclipse.core.internal.utils.Messages;
18 import org.eclipse.core.resources.IResourceStatus;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.QualifiedName;
21 import org.eclipse.osgi.util.NLS;
22
23 /**
24  * This class is used to read sync info from disk. Subclasses implement
25  * version specific reading code.
26  */

27 public class SyncInfoReader {
28     protected Workspace workspace;
29     protected Synchronizer synchronizer;
30
31     public SyncInfoReader(Workspace workspace, Synchronizer synchronizer) {
32         super();
33         this.workspace = workspace;
34         this.synchronizer = synchronizer;
35     }
36
37     /**
38      * Returns the appropriate reader for the given version.
39      */

40     protected SyncInfoReader getReader(int formatVersion) throws IOException JavaDoc {
41         switch (formatVersion) {
42             case 2 :
43                 return new SyncInfoReader_2(workspace, synchronizer);
44             case 3 :
45                 return new SyncInfoReader_3(workspace, synchronizer);
46             default :
47                 throw new IOException JavaDoc(NLS.bind(Messages.resources_format, new Integer JavaDoc(formatVersion)));
48         }
49     }
50
51     public void readPartners(DataInputStream JavaDoc input) throws CoreException {
52         try {
53             int size = input.readInt();
54             Set JavaDoc registry = new HashSet JavaDoc(size);
55             for (int i = 0; i < size; i++) {
56                 String JavaDoc qualifier = input.readUTF();
57                 String JavaDoc local = input.readUTF();
58                 registry.add(new QualifiedName(qualifier, local));
59             }
60             synchronizer.setRegistry(registry);
61         } catch (IOException JavaDoc e) {
62             String JavaDoc message = NLS.bind(Messages.resources_readSync, e);
63             throw new ResourceException(new ResourceStatus(IResourceStatus.INTERNAL_ERROR, message));
64         }
65     }
66
67     public void readSyncInfo(DataInputStream JavaDoc input) throws IOException JavaDoc, CoreException {
68         // dispatch to the appropriate reader depending
69
// on the version of the file
70
int formatVersion = readVersionNumber(input);
71         SyncInfoReader reader = getReader(formatVersion);
72         reader.readSyncInfo(input);
73     }
74
75     protected static int readVersionNumber(DataInputStream JavaDoc input) throws IOException JavaDoc {
76         return input.readInt();
77     }
78 }
79
Popular Tags