1 4 package com.tc.object.dna.impl; 5 6 import com.tc.object.ObjectID; 7 import com.tc.object.dna.api.DNA; 8 import com.tc.object.dna.api.DNACursor; 9 import com.tc.object.dna.api.DNAException; 10 import com.tc.object.dna.api.LogicalAction; 11 import com.tc.object.dna.api.PhysicalAction; 12 13 import java.io.IOException ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 public class VersionizedDNAWrapper implements DNA { 18 19 private final long version; 20 private final DNA dna; 21 private final boolean resetSupported; 22 23 public VersionizedDNAWrapper(DNA dna, long version) { 24 this(dna, version, false); 25 } 26 27 public VersionizedDNAWrapper(DNA dna, long version, boolean resetSupported) { 28 this.dna = dna; 29 this.version = version; 30 this.resetSupported = resetSupported; 31 } 32 33 public long getVersion() { 34 return version; 35 } 36 37 public boolean hasLength() { 38 return dna.hasLength(); 39 } 40 41 public int getArraySize() { 42 return dna.getArraySize(); 43 } 44 45 public String getTypeName() { 46 return dna.getTypeName(); 47 } 48 49 public ObjectID getObjectID() throws DNAException { 50 return dna.getObjectID(); 51 } 52 53 public ObjectID getParentObjectID() throws DNAException { 54 return dna.getParentObjectID(); 55 } 56 57 public DNACursor getCursor() { 58 return (resetSupported ? new ResetableDNACursor(dna.getCursor()) : dna.getCursor()); 59 } 60 61 public String getDefiningLoaderDescription() { 62 return dna.getDefiningLoaderDescription(); 63 } 64 65 public boolean isDelta() { 66 return dna.isDelta(); 67 } 68 69 public String toString() { 70 return dna.toString(); 71 } 72 73 private static class ResetableDNACursor implements DNACursor { 74 75 private final DNACursor cursor; 76 private final List actions = new ArrayList (); 77 private int index = -1; 78 79 public ResetableDNACursor(DNACursor cursor) { 80 this.cursor = cursor; 81 } 82 83 public int getActionCount() { 84 return cursor.getActionCount(); 85 } 86 87 public boolean next() throws IOException { 88 if(++index < actions.size()) { 89 return true; 90 } 91 boolean success = cursor.next(); 92 if (success) { 93 actions.add(cursor.getAction()); 94 } 95 return success; 96 } 97 98 public boolean next(DNAEncoding encoding) throws IOException , ClassNotFoundException { 99 if(++index < actions.size()) { 100 return true; 101 } 102 boolean success = cursor.next(encoding); 103 if (success) { 104 actions.add(cursor.getAction()); 105 } 106 return success; 107 } 108 109 public void reset() throws UnsupportedOperationException { 110 index = -1; 111 } 112 113 public LogicalAction getLogicalAction() { 114 return (index < actions.size() ? (LogicalAction) actions.get(index) : cursor.getLogicalAction()); 115 } 116 117 public PhysicalAction getPhysicalAction() { 118 return (index < actions.size() ? (PhysicalAction) actions.get(index) : cursor.getPhysicalAction()); 119 } 120 121 public Object getAction() { 122 return (index < actions.size() ? actions.get(index) : cursor.getAction()); 123 } 124 125 public String toString() { 126 return cursor.toString(); 127 } 128 129 } 130 } 131 | Popular Tags |