1 11 package org.eclipse.core.internal.resources; 12 13 import java.io.*; 14 import java.util.*; 15 import org.eclipse.core.internal.utils.Messages; 16 import org.eclipse.core.resources.IResourceDelta; 17 import org.eclipse.core.resources.IResourceStatus; 18 import org.eclipse.core.runtime.*; 19 20 24 public class MarkerReader_2 extends MarkerReader { 25 26 public static final byte INDEX = 1; 28 public static final byte QNAME = 2; 29 30 public static final byte ATTRIBUTE_NULL = 0; 32 public static final byte ATTRIBUTE_BOOLEAN = 1; 33 public static final byte ATTRIBUTE_INTEGER = 2; 34 public static final byte ATTRIBUTE_STRING = 3; 35 36 public MarkerReader_2(Workspace workspace) { 37 super(workspace); 38 } 39 40 60 public void read(DataInputStream input, boolean generateDeltas) throws IOException, CoreException { 61 try { 62 List readTypes = new ArrayList(5); 63 while (true) { 64 IPath path = new Path(input.readUTF()); 65 int markersSize = input.readInt(); 66 MarkerSet markers = new MarkerSet(markersSize); 67 for (int i = 0; i < markersSize; i++) 68 markers.add(readMarkerInfo(input, readTypes)); 69 ResourceInfo info = workspace.getResourceInfo(path, false, false); 73 if (info == null) 74 continue; 75 info.setMarkers(markers); 76 if (generateDeltas) { 77 Resource resource = workspace.newResource(path, info.getType()); 80 IMarkerSetElement[] infos = markers.elements; 81 ArrayList deltas = new ArrayList(infos.length); 82 for (int i = 0; i < infos.length; i++) 83 if (infos[i] != null) 84 deltas.add(new MarkerDelta(IResourceDelta.ADDED, resource, (MarkerInfo) infos[i])); 85 workspace.getMarkerManager().changedMarkers(resource, (IMarkerSetElement[]) deltas.toArray(new IMarkerSetElement[deltas.size()])); 86 } 87 } 88 } catch (EOFException e) { 89 } 91 } 92 93 private Map readAttributes(DataInputStream input) throws IOException { 94 int attributesSize = input.readShort(); 95 if (attributesSize == 0) 96 return null; 97 Map result = new MarkerAttributeMap(attributesSize); 98 for (int j = 0; j < attributesSize; j++) { 99 String key = input.readUTF(); 100 byte type = input.readByte(); 101 Object value = null; 102 switch (type) { 103 case ATTRIBUTE_INTEGER : 104 value = new Integer (input.readInt()); 105 break; 106 case ATTRIBUTE_BOOLEAN : 107 value = input.readBoolean() ? Boolean.TRUE : Boolean.FALSE; 108 break; 109 case ATTRIBUTE_STRING : 110 value = input.readUTF(); 111 break; 112 case ATTRIBUTE_NULL : 113 break; 115 } 116 if (value != null) 117 result.put(key, value); 118 } 119 return result.isEmpty() ? null : result; 120 } 121 122 private MarkerInfo readMarkerInfo(DataInputStream input, List readTypes) throws IOException, CoreException { 123 MarkerInfo info = new MarkerInfo(); 124 info.setId(input.readLong()); 125 byte constant = input.readByte(); 126 switch (constant) { 127 case QNAME : 128 String type = input.readUTF(); 129 info.setType(type); 130 readTypes.add(type); 131 break; 132 case INDEX : 133 info.setType((String ) readTypes.get(input.readInt())); 134 break; 135 default : 136 String msg = Messages.resources_readMarkers; 138 throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, msg, null); 139 } 140 info.internalSetAttributes(readAttributes(input)); 141 return info; 142 } 143 } 144 | Popular Tags |