KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > client > StaticHandler


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.team.internal.ccvs.core.client;
12
13
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.team.internal.ccvs.core.CVSException;
17 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
18 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
19 import org.eclipse.team.internal.ccvs.core.syncinfo.MutableFolderSyncInfo;
20
21 /**
22  * Handles any "Set-static-directory" and "Clear-static-directory" responses
23  * from the CVS server.
24  * <p>
25  * Suppose as a result of performing a command the CVS server responds
26  * as follows:<br>
27  * <pre>
28  * [...]
29  * Set-static-directory myproject/ \n
30  * /u/cvsroot/myproject/ \n
31  * [...]
32  * </pre>
33  * Then we set or clear the static flag of the folder "myproject",
34  * automatically creating it if it does not exist locally,
35  * </p>
36  */

37 class StaticHandler extends ResponseHandler {
38     private final boolean setStaticDirectory;
39
40     public StaticHandler(boolean setStaticDirectory) {
41         this.setStaticDirectory = setStaticDirectory;
42     }
43
44     public String JavaDoc getResponseID() {
45         if (setStaticDirectory) {
46             return "Set-static-directory"; //$NON-NLS-1$
47
} else {
48             return "Clear-static-directory"; //$NON-NLS-1$
49
}
50     }
51
52     public void handle(Session session, String JavaDoc localDir,
53         IProgressMonitor monitor) throws CVSException {
54         // read additional data for the response
55
String JavaDoc repositoryDir = session.readLine();
56
57         // create the directory then set or clear the static flag
58
Assert.isTrue(repositoryDir.endsWith("/")); //$NON-NLS-1$
59
repositoryDir = repositoryDir.substring(0, repositoryDir.length() - 1);
60         try {
61             ICVSFolder folder = createFolder(session, localDir, repositoryDir);
62             FolderSyncInfo syncInfo = folder.getFolderSyncInfo();
63             // Added to ignore sync info for workspace root
64
if (syncInfo == null) return;
65             MutableFolderSyncInfo newInfo = syncInfo.cloneMutable();
66             newInfo.setStatic(setStaticDirectory);
67             // only set the sync info if it has changed
68
if (!syncInfo.equals(newInfo))
69                 folder.setFolderSyncInfo(newInfo);
70         } catch (CVSException e) {
71             if (!handleInvalidResourceName(session, session.getLocalRoot().getFolder(localDir), e)) {
72                 throw e;
73             }
74         }
75     }
76 }
77
78
Popular Tags