]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterUpdateProcessorBase2.java
Merge commit '2a46c55'
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / internal / ClusterUpdateProcessorBase2.java
1 package org.simantics.acorn.internal;
2
3 import org.simantics.acorn.exception.IllegalAcornStateException;
4 import org.simantics.db.service.Bytes;
5 import org.simantics.db.service.ClusterUID;
6
7 public abstract class ClusterUpdateProcessorBase2 {
8
9         final private byte[] bytes;
10         private int pos = 0;
11         final private int len;
12         final private ClusterUID uid;
13         
14         public ClusterUpdateProcessorBase2(byte[] operations) {
15                 this.bytes = operations;
16                 this.len = Bytes.readLE4(bytes, 0) + 4; // whatta?
17                 int version = Bytes.readLE4(bytes, 4);
18                 assert(version == ClusterChange2.VERSION);
19                 long cuid1 = Bytes.readLE8(bytes, 8);
20                 long cuid2 = Bytes.readLE8(bytes, 16);
21                 pos = 24;
22                 uid = ClusterUID.make(cuid1, cuid2);
23         }
24         
25         public ClusterUID getClusterUID() {
26                 return uid;
27         }
28
29         private void processSetImmutable(int op) {
30                 int value = bytes[pos++]&0xff;
31                 setImmutable(value > 0);
32         }
33
34         private void processUndoValue(int op) {
35                 Bytes.readLE4(bytes, pos);
36                 pos+=4;
37         }
38
39         public void process() throws IllegalAcornStateException {
40                 
41                 while(pos < len) {
42                 
43                         int op = bytes[pos++]&0xff;
44                         
45                         switch(op) {
46                         
47                         case ClusterChange2.SET_IMMUTABLE_OPERATION:
48                                 processSetImmutable(op);
49                                 break;
50                         case ClusterChange2.UNDO_VALUE_OPERATION:
51                                 processUndoValue(op);
52                                 break;
53                         default:
54                                 throw new IllegalAcornStateException("Can not process cluster " + uid);
55                                 
56                         }
57                 }
58         }
59         
60         abstract void setImmutable(boolean value);
61         
62 }