1 11 package org.eclipse.team.core.variants; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.team.core.TeamException; 19 20 29 public class PersistantResourceVariantByteStore extends ResourceVariantByteStore { 30 31 private static final byte[] NO_REMOTE = new byte[0]; 32 33 private QualifiedName syncName; 34 35 42 public PersistantResourceVariantByteStore(QualifiedName name) { 43 syncName = name; 44 getSynchronizer().add(syncName); 45 } 46 47 50 public void dispose() { 51 getSynchronizer().remove(getSyncName()); 52 } 53 54 58 public QualifiedName getSyncName() { 59 return syncName; 60 } 61 62 65 public byte[] getBytes(IResource resource) throws TeamException { 66 byte[] syncBytes = internalGetSyncBytes(resource); 67 if (syncBytes != null && equals(syncBytes, NO_REMOTE)) { 68 return null; 70 } 71 return syncBytes; 72 } 73 74 77 public boolean setBytes(IResource resource, byte[] bytes) throws TeamException { 78 Assert.isNotNull(bytes); 79 byte[] oldBytes = internalGetSyncBytes(resource); 80 if (oldBytes != null && equals(oldBytes, bytes)) return false; 81 try { 82 getSynchronizer().setSyncInfo(getSyncName(), resource, bytes); 83 return true; 84 } catch (CoreException e) { 85 throw TeamException.asTeamException(e); 86 } 87 } 88 89 92 public boolean flushBytes(IResource resource, int depth) throws TeamException { 93 if (resource.exists() || resource.isPhantom()) { 94 try { 95 if (depth != IResource.DEPTH_ZERO || internalGetSyncBytes(resource) != null) { 96 getSynchronizer().flushSyncInfo(getSyncName(), resource, depth); 97 return true; 98 } 99 } catch (CoreException e) { 100 throw TeamException.asTeamException(e); 101 } 102 } 103 return false; 104 } 105 106 115 public boolean isVariantKnown(IResource resource) throws TeamException { 116 return internalGetSyncBytes(resource) != null; 117 } 118 119 126 public boolean deleteBytes(IResource resource) throws TeamException { 127 return setBytes(resource, NO_REMOTE); 128 } 129 130 133 public IResource[] members(IResource resource) throws TeamException { 134 if(resource.getType() == IResource.FILE) { 135 return new IResource[0]; 136 } 137 try { 138 IResource[] members = ((IContainer)resource).members(true ); 140 List filteredMembers = new ArrayList (members.length); 141 for (int i = 0; i < members.length; i++) { 142 IResource member = members[i]; 143 if(getBytes(member) != null) { 144 filteredMembers.add(member); 145 } 146 } 147 return (IResource[]) filteredMembers.toArray(new IResource[filteredMembers.size()]); 148 } catch (CoreException e) { 149 throw TeamException.asTeamException(e); 150 } 151 } 152 153 private ISynchronizer getSynchronizer() { 154 return ResourcesPlugin.getWorkspace().getSynchronizer(); 155 } 156 157 private byte[] internalGetSyncBytes(IResource resource) throws TeamException { 158 try { 159 return getSynchronizer().getSyncInfo(getSyncName(), resource); 160 } catch (CoreException e) { 161 throw TeamException.asTeamException(e); 162 } 163 } 164 165 168 public void run(IResource root, IWorkspaceRunnable runnable, IProgressMonitor monitor) 169 throws TeamException { 170 try { 171 ResourcesPlugin.getWorkspace().run(runnable, root, 0, monitor); 172 } catch (CoreException e) { 173 throw TeamException.asTeamException(e); 174 } 175 } 176 } 177 | Popular Tags |