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