KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > filesystem > CVSFileStore


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.filesystem;
12
13 import java.io.InputStream JavaDoc;
14 import java.net.URI JavaDoc;
15
16 import org.eclipse.core.filesystem.IFileInfo;
17 import org.eclipse.core.filesystem.IFileStore;
18 import org.eclipse.core.filesystem.provider.FileInfo;
19 import org.eclipse.core.filesystem.provider.FileStore;
20 import org.eclipse.core.resources.IStorage;
21 import org.eclipse.core.runtime.*;
22 import org.eclipse.team.core.TeamException;
23 import org.eclipse.team.core.variants.IResourceVariant;
24 import org.eclipse.team.internal.ccvs.core.*;
25
26 public class CVSFileStore extends FileStore {
27
28     
29     private final CVSURI uri;
30     private IFileInfo info;
31     
32     public CVSFileStore(CVSURI uri, IFileInfo info) {
33         this.uri = uri;
34         this.info = info;
35     }
36
37     public boolean canReturnFullTree() {
38         return true;
39     }
40
41     public String JavaDoc[] childNames(int options, IProgressMonitor monitor) throws CoreException {
42         monitor = Policy.monitorFor(monitor);
43         IFileInfo[] infos = childInfos(options, monitor);
44         String JavaDoc[] names = new String JavaDoc[infos.length];
45         for (int i = 0; i < infos.length; i++) {
46             names[i] = infos[i].getName();
47         }
48         return names;
49     }
50
51     public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
52         monitor = Policy.monitorFor(monitor);
53         if (info != null && !info.isDirectory()) {
54             return new IFileInfo[0];
55         }
56         ICVSRemoteFolder folder = uri.toFolder();
57         ICVSResource[] children = folder.fetchChildren(monitor);
58         
59         IFileInfo[] childInfos = new IFileInfo[children.length];
60         for (int i = 0; i < children.length; i++) {
61             ICVSResource child = children[i];
62             IFileInfo info = getFileInfo(child, monitor);
63             childInfos[i] = info;
64         }
65         return childInfos;
66     }
67
68     public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
69         monitor = Policy.monitorFor(monitor);
70         IFileInfo[] infos = childInfos(options, monitor);
71         IFileStore[] children = new IFileStore[infos.length];
72         for (int i = 0; i < infos.length; i++) {
73             children[i] = getChild(infos[i]);
74         }
75         return children;
76     }
77
78     private IFileStore getChild(IFileInfo info) {
79         return new CVSFileStore(uri.append(info.getName()), info);
80     }
81
82     public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
83         monitor = Policy.monitorFor(monitor);
84         ICVSRemoteFolder folder = uri.getParentFolder();
85         
86         if (folder == null) {
87             // this is the repo root so return an info that indicates this
88
FileInfo info = new FileInfo();
89             info.setExists(true);
90             info.setName(uri.getRepositoryName());
91             info.setDirectory(true);
92         }
93         ICVSResource[] children = folder.fetchChildren(monitor);
94         ICVSResource resource = null;
95         for (int i = 0; i < children.length; i++) {
96             ICVSResource child = children[i];
97             if (child.getName().equals(getName())) {
98                 resource = child;
99                 break;
100             }
101         }
102         return getFileInfo(resource, monitor);
103     }
104
105     private IFileInfo getFileInfo(ICVSResource resource, IProgressMonitor monitor) throws TeamException {
106         monitor = Policy.monitorFor(monitor);
107         if (resource == null)
108             return null;
109         FileInfo info = new FileInfo();
110         info.setExists(true);
111         info.setName(resource.getName());
112         if (!resource.isFolder()) {
113             ICVSRemoteFile file = (ICVSRemoteFile) resource;
114             ILogEntry entry = file.getLogEntry(monitor);
115             info.setLastModified(entry.getDate().getTime());
116         } else {
117             info.setLastModified(0);
118             info.setDirectory(true);
119         }
120         return info;
121     }
122
123     public IFileStore getChild(String JavaDoc name) {
124         if (info != null && !info.isDirectory()) {
125             return null;
126         }
127         return new CVSFileStore(uri.append(name), null);
128     }
129
130     public IFileStore getChild(IPath path) {
131         return new CVSFileStore(uri.append(path), null);
132     }
133
134
135     public String JavaDoc getName() {
136         return uri.getLastSegment();
137     }
138
139     public IFileStore getParent() {
140         if (uri.isRepositoryRoot()) {
141             return null;
142         }
143         return new CVSFileStore(uri.removeLastSegment(), null);
144     }
145
146     public InputStream JavaDoc openInputStream(int options, IProgressMonitor monitor) throws CoreException {
147         monitor = Policy.monitorFor(monitor);
148         ICVSRemoteFile file = uri.toFile();
149         IStorage storage = ((IResourceVariant) file).getStorage(monitor);
150         return storage.getContents();
151     }
152
153     public URI JavaDoc toURI() {
154         return uri.toURI();
155     }
156     
157     public CVSURI getCVSURI() {
158         return uri;
159     }
160
161 }
162
Popular Tags