1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IWorkspaceRunnable; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.variants.*; 21 22 39 public abstract class DescendantResourceVariantByteStore extends ResourceVariantByteStore { 40 41 ResourceVariantByteStore baseStore, remoteStore; 42 43 public DescendantResourceVariantByteStore(ResourceVariantByteStore baseCache, ResourceVariantByteStore remoteCache) { 44 this.baseStore = baseCache; 45 this.remoteStore = remoteCache; 46 } 47 48 52 public void dispose() { 53 remoteStore.dispose(); 54 } 55 56 59 public byte[] getBytes(IResource resource) throws TeamException { 60 byte[] remoteBytes = remoteStore.getBytes(resource); 61 byte[] baseBytes = baseStore.getBytes(resource); 62 if (baseBytes == null) { 63 return remoteBytes; 65 } 66 if (remoteBytes == null) { 67 if (isVariantKnown(resource)) { 68 return remoteBytes; 71 } else { 72 return baseBytes; 75 } 76 } 77 if (isDescendant(resource, baseBytes, remoteBytes)) { 78 return remoteBytes; 80 } 81 return baseBytes; 84 } 85 86 89 public boolean setBytes(IResource resource, byte[] bytes) throws TeamException { 90 byte[] baseBytes = baseStore.getBytes(resource); 91 if (baseBytes != null && equals(baseBytes, bytes)) { 92 return remoteStore.flushBytes(resource, IResource.DEPTH_ZERO); 94 } else { 95 return remoteStore.setBytes(resource, bytes); 96 } 97 } 98 99 102 public boolean flushBytes(IResource resource, int depth) throws TeamException { 103 return remoteStore.flushBytes(resource, depth); 104 } 105 106 118 public abstract boolean isVariantKnown(IResource resource) throws TeamException; 119 120 130 protected abstract boolean isDescendant(IResource resource, byte[] baseBytes, byte[] remoteBytes) throws TeamException; 131 132 135 public boolean deleteBytes(IResource resource) throws TeamException { 136 return remoteStore.deleteBytes(resource); 137 } 138 139 143 protected ResourceVariantByteStore getBaseStore() { 144 return baseStore; 145 } 146 147 152 protected ResourceVariantByteStore getRemoteStore() { 153 return remoteStore; 154 } 155 156 159 public IResource[] members(IResource resource) throws TeamException { 160 IResource[] remoteMembers = getRemoteStore().members(resource); 161 IResource[] baseMembers = getBaseStore().members(resource); 162 Set members = new HashSet (); 163 for (int i = 0; i < remoteMembers.length; i++) { 164 members.add(remoteMembers[i]); 165 } 166 for (int i = 0; i < baseMembers.length; i++) { 167 IResource member = baseMembers[i]; 168 if (!isVariantKnown(member)) { 171 members.add(member); 172 } 173 } 174 return (IResource[]) members.toArray(new IResource[members.size()]); 175 } 176 177 180 public void run(IResource root, IWorkspaceRunnable runnable, IProgressMonitor monitor) throws TeamException { 181 remoteStore.run(root, runnable, monitor); 182 } 183 } 184 | Popular Tags |