KickJava   Java API By Example, From Geeks To Geeks.

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


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  
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.team.core.TeamException;
17 import org.eclipse.team.core.variants.CachedResourceVariant;
18 import org.eclipse.team.internal.ccvs.core.*;
19 import org.eclipse.team.internal.ccvs.core.client.Update;
20 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
21 import org.eclipse.team.internal.ccvs.core.util.Util;
22
23 /**
24  * The purpose of this class and its subclasses is to implement the corresponding
25  * ICVSRemoteResource interfaces for the purpose of communicating information about
26  * resources that reside in a CVS repository but have not necessarily been loaded
27  * locally.
28  */

29 public abstract class RemoteResource extends CachedResourceVariant implements ICVSRemoteResource {
30
31     protected RemoteFolder parent;
32     protected String JavaDoc name;
33
34     // relative synchronization state calculated by server of this remote file compare to the current local
35
// workspace copy.
36
private int workspaceSyncState = Update.STATE_NONE;
37
38     /**
39      * Constructor for RemoteResource.
40      */

41     public RemoteResource(RemoteFolder parent, String JavaDoc name) {
42         this.parent = parent;
43         this.name = name;
44     }
45
46     /*
47      * @see ICVSRemoteResource#getName()
48      */

49     public String JavaDoc getName() {
50         return name;
51     }
52
53     /*
54      * @see ICVSResource#getRelativePath(ICVSFolder)
55      */

56     public String JavaDoc getRelativePath(ICVSFolder ancestor) throws CVSException {
57         return Util.appendPath(parent.getRelativePath(ancestor), getName());
58     }
59     
60     /*
61      * @see ICVSRemoteResource#getParent()
62      */

63     public ICVSRemoteResource getRemoteParent() {
64         return parent;
65     }
66             
67     public abstract String JavaDoc getRepositoryRelativePath();
68     
69     public abstract ICVSRepositoryLocation getRepository();
70     
71     public int getWorkspaceSyncState() {
72         return workspaceSyncState;
73     }
74     
75     public void setWorkspaceSyncState(int workspaceSyncState) {
76         this.workspaceSyncState = workspaceSyncState;
77     }
78     
79     /*
80      * @see ICVSResource#delete()
81      */

82     public void delete() {
83         // For now, do nothing but we could provide this in the future.
84
}
85
86     /*
87      * @see ICVSResource#exists()
88      *
89      * This method is used by the Command framework so it must return true so that
90      * the proper information gets sent to the server. (i.e. it is used to fake that
91      * the file exists locally so cvs commands can be used to retrieve information about
92      * the remote resource from the server)
93      */

94     public boolean exists() {
95         return true;
96     }
97     
98     /*
99      * @see ICVSRemoteResource#exists(IProgressMonitor)
100      */

101     public boolean exists(IProgressMonitor monitor) throws TeamException {
102         return parent.exists(this, monitor);
103     }
104
105     /*
106      * @see ICVSResource#getParent()
107      */

108     public ICVSFolder getParent() {
109         return parent;
110     }
111
112     /*
113      * @see ICVSResource#isIgnored()
114      */

115     public boolean isIgnored() {
116         return false;
117     }
118
119     /*
120      * @see ICVSResource#isManaged()
121      */

122     public boolean isManaged() {
123         return parent != null;
124     }
125
126     public boolean isModified(IProgressMonitor monitor) throws CVSException {
127         // it is safe to always consider a remote file handle as modified. This will cause any
128
// CVS command to fetch new contents from the server.
129
return true;
130     }
131     
132     /*
133      * @see ICVSResource#unmanage()
134      */

135     public void unmanage(IProgressMonitor monitor) throws CVSException {
136         // do nothing
137
}
138
139     /*
140      * @see ICVSResource#getSyncInfo()
141      */

142     public abstract ResourceSyncInfo getSyncInfo();
143     
144     public boolean equals(Object JavaDoc target) {
145         if (this == target)
146             return true;
147         if (!(target instanceof RemoteResource))
148             return false;
149         RemoteResource remote = (RemoteResource) target;
150         return remote.isContainer() == isContainer()
151         && remote.getRepository().equals(getRepository())
152         && remote.getRepositoryRelativePath().equals(getRepositoryRelativePath());
153     }
154
155     /*
156      * @see ICVSResource#setIgnoredAs(String)
157      */

158     public void setIgnoredAs(String JavaDoc pattern) throws CVSException {
159         // ensure that clients are not trying to set sync info on remote handles.
160
Assert.isTrue(false);
161     }
162
163     /**
164      * @see org.eclipse.team.internal.ccvs.core.ICVSResource#getIResource()
165      */

166     public IResource getIResource() {
167         return null;
168     }
169     
170     /**
171      * Return a copy of the receiver that is associated with the given tag. The parent
172      * should be a copy of the receiver's parent which has been copied to the same tag.
173      *
174      * @param parent
175      * @param tagName
176      * @return ICVSRemoteFolder
177      */

178     public abstract ICVSRemoteResource forTag(ICVSRemoteFolder parent, CVSTag tagName);
179
180     /**
181      * @see java.lang.Object#hashCode()
182      */

183     public int hashCode() {
184         return getRepositoryRelativePath().hashCode();
185     }
186     
187     /**
188      * Method which returns an array of bytes that can be used to recreate the remote handle.
189      * To recreate the remote handle, invoke the <code>fromBytes</code> method on either
190      * RemoteFolder or RemoteFile.
191      *
192      * TODO: It would be nice to have a method on RmeoteResource to recreate the handles
193      * but the file requires the bytes for the parent folder since this folder may not
194      * exist locally.
195      *
196      * @return
197      */

198     abstract public byte[] getSyncBytes();
199
200     public String JavaDoc toString() {
201         return "Remote " + (isContainer() ? "Folder: " : "File: ") + getName(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
202
}
203     
204     /* (non-Javadoc)
205      * @see org.eclipse.team.core.synchronize.ResourceVariant#getUniquePath()
206      */

207     public String JavaDoc getCachePath() {
208         ICVSRepositoryLocation location = getRepository();
209         IPath path = new Path(null, location.getHost());
210         path = path.append(location.getRootDirectory());
211         path = path.append(parent.getRepositoryRelativePath());
212         path = path.append(getName() + ' ' + getContentIdentifier());
213         return path.toString();
214     }
215
216     /* (non-Javadoc)
217      * @see org.eclipse.team.core.synchronize.ResourceVariant#getCacheId()
218      */

219     protected String JavaDoc getCacheId() {
220         return CVSProviderPlugin.ID;
221     }
222     
223     /* (non-Javadoc)
224      * @see org.eclipse.team.core.variants.IResourceVariant#asBytes()
225      */

226     public byte[] asBytes() {
227         return getSyncBytes();
228     }
229 }
230
Popular Tags