1 4 package com.tc.objectserver.managedobject; 5 6 import com.tc.object.ObjectID; 7 import com.tc.object.SerializationUtil; 8 import com.tc.object.dna.api.DNA; 9 import com.tc.object.dna.api.DNACursor; 10 import com.tc.object.dna.api.DNAWriter; 11 import com.tc.object.dna.api.LogicalAction; 12 import com.tc.objectserver.mgmt.ManagedObjectFacade; 13 import com.tc.objectserver.mgmt.PhysicalManagedObjectFacade; 14 import com.tc.util.Assert; 15 16 import java.io.IOException ; 17 import java.io.ObjectInput ; 18 import java.io.ObjectOutput ; 19 import java.util.Date ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 27 public class DateManagedObjectState extends LogicalManagedObjectState { 28 29 private long referenceTime; 30 private int referenceNanoTime; 31 32 public DateManagedObjectState(long classID) { 33 super(classID); 34 } 35 36 protected DateManagedObjectState(ObjectInput in) throws IOException { 37 super(in); 38 } 39 40 public void apply(ObjectID objectID, DNACursor cursor, BackReferences includeIDs) throws IOException { 41 while (cursor.next()) { 42 LogicalAction action = cursor.getLogicalAction(); 43 int method = action.getMethod(); 44 Object [] params = action.getParameters(); 45 46 switch (method) { 47 case SerializationUtil.SET_TIME: 48 Assert.assertNotNull(params[0]); 49 referenceTime = ((Long ) params[0]).longValue(); 50 break; 51 case SerializationUtil.SET_NANOS: 52 Assert.assertNotNull(params[0]); 53 referenceNanoTime = ((Integer ) params[0]).intValue(); 54 break; 55 default: 56 throw new AssertionError ("Invalid action:" + method); 57 } 58 } 59 } 60 61 public void dehydrate(ObjectID objectID, DNAWriter writer) { 62 writer.addLogicalAction(SerializationUtil.SET_TIME, new Object [] { new Long (referenceTime) }); 63 writer.addLogicalAction(SerializationUtil.SET_NANOS, new Object [] { new Integer (referenceNanoTime) }); 64 } 65 66 protected void addAllObjectReferencesTo(Set refs) { 67 return; 68 } 69 70 public ManagedObjectFacade createFacade(ObjectID objectID, String className, int limit) { 71 Map dataCopy = new HashMap (); 72 dataCopy.put("date", new Date (referenceTime)); 73 74 return new PhysicalManagedObjectFacade(objectID, ObjectID.NULL_ID, className, dataCopy, false, DNA.NULL_ARRAY_SIZE, 75 false); 76 } 77 78 protected void basicWriteTo(ObjectOutput o) throws IOException { 79 o.writeLong(referenceTime); 80 o.writeInt(referenceNanoTime); 81 } 82 83 static DateManagedObjectState readFrom(ObjectInput in) throws IOException { 84 DateManagedObjectState state = new DateManagedObjectState(in); 85 state.referenceTime = in.readLong(); 86 state.referenceNanoTime = in.readInt(); 87 return state; 88 } 89 90 protected boolean basicEquals(LogicalManagedObjectState o) { 91 DateManagedObjectState dms = (DateManagedObjectState) o; 92 return dms.referenceTime == referenceTime && dms.referenceNanoTime == referenceNanoTime; 93 } 94 95 public byte getType() { 96 return DATE_TYPE; 97 } 98 } 99 | Popular Tags |