KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > resources > RemoteFolderSandbox


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.resources;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.team.core.TeamException;
19 import org.eclipse.team.internal.ccvs.core.*;
20 import org.eclipse.team.internal.ccvs.core.client.Session;
21 import org.eclipse.team.internal.ccvs.core.client.Update;
22 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
23
24 /**
25  * This specialized remote folder supports the creation of a cached sandbox.
26  */

27 public class RemoteFolderSandbox extends RemoteFolder {
28
29     public RemoteFolderSandbox(RemoteFolder parent, ICVSRepositoryLocation repository, String JavaDoc repositoryRelativePath, CVSTag tag) {
30         super(parent, repository, repositoryRelativePath, tag);
31         setChildren(new ICVSRemoteResource[0]);
32     }
33
34     public RemoteFolderSandbox(RemoteFolder parent, String JavaDoc name, CVSRepositoryLocation repository, String JavaDoc repositoryRelativePath, CVSEntryLineTag tag, boolean isStatic) {
35         super(parent, name, repository, repositoryRelativePath, tag, isStatic);
36         setChildren(new ICVSRemoteResource[0]);
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.team.internal.ccvs.core.ICVSFolder#getFile(java.lang.String)
41      */

42     public ICVSFile getFile(String JavaDoc name) throws CVSException {
43         try {
44             return super.getFile(name);
45         } catch (CVSException e) {
46             if (e.getStatus().getCode() == CHILD_DOES_NOT_EXIST) {
47                 IPath path = new Path(null, name);
48                 String JavaDoc fileName = path.lastSegment();
49                 RemoteFolderSandbox parent = getParentFolder(path);
50                 RemoteFile file = new RemoteFile(parent, Update.STATE_NONE, fileName, null, null, getTag());
51                 parent.addChild(file);
52                 return file;
53             }
54             throw e;
55         }
56     }
57     
58     private void addChild(RemoteResource resource) {
59         ICVSRemoteResource[] children = getChildren();
60         ICVSRemoteResource[] newChildren = new ICVSRemoteResource[children.length + 1];
61         System.arraycopy(children, 0, newChildren, 0, children.length);
62         newChildren[children.length] = resource;
63         setChildren(newChildren);
64     }
65
66     private RemoteFolderSandbox getParentFolder(IPath path) throws CVSException {
67         IPath parentPath = path.removeLastSegments(1);
68         String JavaDoc parentString;
69         if (parentPath.isEmpty()) {
70             parentString = Session.CURRENT_LOCAL_FOLDER;
71         } else {
72             parentString = path.removeLastSegments(1).toString();
73         }
74         RemoteFolderSandbox parent = (RemoteFolderSandbox)getFolder(parentString);
75         return parent;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.team.internal.ccvs.core.ICVSFolder#getFolder(java.lang.String)
80      */

81     public ICVSFolder getFolder(String JavaDoc name) throws CVSException {
82         try {
83             return super.getFolder(name);
84         } catch (CVSException e) {
85             if (e.getStatus().getCode() == CHILD_DOES_NOT_EXIST) {
86                 IPath path = new Path(null, name);
87                 RemoteFolderSandbox parent = getParentFolder(path);
88                 String JavaDoc repoPath = new Path(null, parent.getRepositoryRelativePath()).append(path.lastSegment()).removeTrailingSeparator().toString();
89                 RemoteFolderSandbox folder = new RemoteFolderSandbox(parent, getRepository(), repoPath, getTag());
90                 parent.addChild(folder);
91                 return folder;
92             }
93             throw e;
94         }
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.team.internal.ccvs.core.resources.RemoteFolder#getMembers(org.eclipse.core.runtime.IProgressMonitor)
99      */

100     public ICVSRemoteResource[] getMembers(IProgressMonitor monitor) throws TeamException {
101         return getChildren();
102     }
103
104     /*
105      * @see ICVSFolder#acceptChildren(ICVSResourceVisitor)
106      */

107     public void acceptChildren(ICVSResourceVisitor visitor) throws CVSException {
108         ICVSRemoteResource[] children = getChildren();
109         if (children == null) return;
110         for (int i=0; i<children.length; i++) {
111             ((ICVSResource)children[i]).accept(visitor);
112         }
113     }
114
115     public void remove(RemoteFile file) {
116         ICVSRemoteResource[] children = getChildren();
117         ArrayList JavaDoc results = new ArrayList JavaDoc();
118         for (int i = 0; i < children.length; i++) {
119             if (children[i] != file){
120                 results.add(children[i]);
121             }
122         }
123         setChildren((ICVSRemoteResource[]) results.toArray(new ICVSRemoteResource[results.size()]));
124     }
125 }
126
Popular Tags