KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.*;
17 import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag;
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-sticky" and "Clear-stick" responses from the CVS server.
23  * <p>
24  * Suppose as a result of performing a command the CVS server responds
25  * as follows:<br>
26  * <pre>
27  * [...]
28  * Set-sticky myproject/ \n
29  * /u/cvsroot/myproject/ \n
30  * Tsometag \n
31  * [...]
32  * </pre>
33  * Then we set or clear the sticky tag property of the folder "myproject",
34  * automatically creating it if it does not exist locally,
35  * </p>
36  */

37 class StickyHandler extends ResponseHandler {
38     private final boolean setSticky;
39         
40     public StickyHandler(boolean setSticky) {
41         this.setSticky = setSticky;
42     }
43
44     public String JavaDoc getResponseID() {
45         if (setSticky) {
46             return "Set-sticky"; //$NON-NLS-1$
47
} else {
48             return "Clear-sticky"; //$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         String JavaDoc tag = null;
57         if (setSticky) {
58             tag = session.readLine();
59             if (tag != null && tag.length() == 0) tag = null;
60         }
61
62         // create the directory then set or clear the sticky tag
63
Assert.isTrue(repositoryDir.endsWith("/")); //$NON-NLS-1$
64
repositoryDir = repositoryDir.substring(0, repositoryDir.length() - 1);
65         try {
66             ICVSFolder folder = createFolder(session, localDir, repositoryDir);
67             FolderSyncInfo syncInfo = folder.getFolderSyncInfo();
68             // Added to ignore sync info for workspace root
69
if (syncInfo == null) return;
70             MutableFolderSyncInfo newInfo = syncInfo.cloneMutable();
71             newInfo.setTag(tag != null ? new CVSEntryLineTag(tag) : null);
72             /* if we are reverting to BASE we do not change anything here
73              * see bug 106876 */

74             if(tag != null && tag.equals("TBASE")) //$NON-NLS-1$
75
newInfo.setTag(syncInfo.getTag());
76             // only set the sync info if it has changed
77
if (!syncInfo.equals(newInfo))
78                 folder.setFolderSyncInfo(newInfo);
79         } catch (CVSException e) {
80             if (!handleInvalidResourceName(session, session.getLocalRoot().getFolder(localDir), e)) {
81                 throw e;
82             }
83         }
84     }
85 }
86
87
Popular Tags