KickJava   Java API By Example, From Geeks To Geeks.

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


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.team.internal.ccvs.core.client;
12
13
14 import org.eclipse.team.internal.ccvs.core.CVSException;
15 import org.eclipse.team.internal.ccvs.core.ICVSFile;
16 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
17 import org.eclipse.team.internal.ccvs.core.ICVSResource;
18 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
19
20 /**
21  * Visitor to send the local file structure to the CVS Server.
22  *
23  * Files are sent as Unchanged or Modified.
24  * Folders are sent if they contain files unless sendEmptyFolders is true
25  * in which case all folders are sent.
26  *
27  * @param sendEmptyFolders sends the folder-entrie even if there is no file
28           to send in it
29  */

30
31 class FileStructureVisitor extends AbstractStructureVisitor {
32
33     private boolean sendEmptyFolders;
34
35     public FileStructureVisitor(Session session, LocalOption[] localOptions, boolean sendEmptyFolders, boolean sendModifiedContents) {
36         this(session, localOptions, sendEmptyFolders, sendModifiedContents, true);
37     }
38
39     public FileStructureVisitor(Session session, LocalOption[] localOptions, boolean sendEmptyFolders, boolean sendModifiedContents, boolean sendBinary) {
40         super(session, localOptions, true, sendModifiedContents, sendBinary);
41         this.sendEmptyFolders = sendEmptyFolders;
42     }
43
44     /**
45      * @see ICVSResourceVisitor#visitFile(IManagedFile)
46      */

47     public void visitFile(ICVSFile mFile) throws CVSException {
48         sendFile(mFile);
49     }
50
51     /**
52      * @see ICVSResourceVisitor#visitFolder(ICVSFolder)
53      */

54     public void visitFolder(ICVSFolder mFolder) throws CVSException {
55
56         if (sendEmptyFolders) {
57             // If we want to send empty folder, that just send it when
58
// we come to it
59
sendFolder(mFolder);
60         }
61
62         boolean exists = mFolder.exists();
63         boolean isCVSFolder = mFolder.isCVSFolder();
64         
65         // We are only interested in CVS folders
66
// A folder could be a non-existant CVS folder if it is a holder for outgoing file deletions
67
if ( ! isCVSFolder) return;
68         
69         if (exists && isOrphanedSubtree(mFolder)) {
70             return;
71         }
72
73         // Send files, then the questionable folders, then the managed folders
74
ICVSResource[] children = mFolder.members(ICVSFolder.ALL_UNIGNORED_MEMBERS);
75         sendFiles(children);
76         sendQuestionableFolders(children);
77         if (isRecurse()) {
78             sendManagedFolders(children);
79         }
80     }
81
82     /**
83      * Method sendManagedFolders.
84      * @param children
85      */

86     private void sendManagedFolders(ICVSResource[] children) throws CVSException {
87         for (int i = 0; i < children.length; i++) {
88             ICVSResource resource = children[i];
89             if (resource.isFolder() && resource.isManaged()) {
90                 resource.accept(this);
91             }
92         }
93     }
94
95     /**
96      * Method sendQuestionableFolders.
97      * @param children
98      */

99     private void sendQuestionableFolders(ICVSResource[] children) throws CVSException {
100         for (int i = 0; i < children.length; i++) {
101             ICVSResource resource = children[i];
102             if (resource.isFolder() && ! resource.isManaged()) {
103                 resource.accept(this);
104             }
105         }
106     }
107
108     /**
109      * Method sendFiles.
110      * @param children
111      */

112     private void sendFiles(ICVSResource[] children) throws CVSException {
113         for (int i = 0; i < children.length; i++) {
114             ICVSResource resource = children[i];
115             if (!resource.isFolder()) {
116                 resource.accept(this);
117             }
118         }
119     }
120
121 }
122
Popular Tags