1 4 package com.tc.object.applicator; 5 6 import com.tc.object.ClientObjectManager; 7 import com.tc.object.SerializationUtil; 8 import com.tc.object.TCObject; 9 import com.tc.object.TraversedReferences; 10 import com.tc.object.bytecode.Manageable; 11 import com.tc.object.dna.api.DNA; 12 import com.tc.object.dna.api.DNACursor; 13 import com.tc.object.dna.api.DNAWriter; 14 import com.tc.object.dna.api.LogicalAction; 15 import com.tc.object.dna.impl.DNAEncoding; 16 import com.tc.object.tx.optimistic.OptimisticTransactionManager; 17 import com.tc.object.tx.optimistic.TCObjectClone; 18 import com.tc.util.Assert; 19 20 import java.io.IOException ; 21 import java.sql.Timestamp ; 22 import java.util.Collections ; 23 import java.util.Date ; 24 import java.util.Map ; 25 26 29 public class DateApplicator extends BaseApplicator { 30 31 public DateApplicator(DNAEncoding encoding) { 32 super(encoding); 33 } 34 35 public void hydrate(ClientObjectManager objectManager, TCObject tcObject, DNA dna, Object pojo) throws IOException , 36 ClassNotFoundException { 37 Date date = (Date ) pojo; 38 DNACursor cursor = dna.getCursor(); 39 40 while (cursor.next(encoding)) { 41 LogicalAction action = cursor.getLogicalAction(); 42 int method = action.getMethod(); 43 Object [] params = action.getParameters(); 44 switch (method) { 45 case SerializationUtil.SET_TIME: 46 Assert.assertNotNull(params[0]); 47 date.setTime(((Long ) params[0]).longValue()); 48 break; 49 case SerializationUtil.SET_NANOS: 50 if (date instanceof Timestamp ) { 51 Assert.assertNotNull(params[0]); 52 ((Timestamp ) date).setNanos(((Integer ) params[0]).intValue()); 53 } 54 break; 55 default: 56 throw new AssertionError ("invalid action:" + method); 57 } 58 } 59 } 60 61 public void dehydrate(ClientObjectManager objectManager, TCObject tcObject, DNAWriter writer, Object pojo) { 62 Date date = (Date ) pojo; 63 writer.addLogicalAction(SerializationUtil.SET_TIME, new Object [] { new Long (date.getTime()) }); 64 } 65 66 public TraversedReferences getPortableObjects(Object pojo, TraversedReferences addTo) { 67 addTo.addAnonymousReference(pojo); 68 return addTo; 69 } 70 71 public Object getNewInstance(ClientObjectManager objectManager, DNA dna) { 72 throw new UnsupportedOperationException (); 73 } 74 75 public Map connectedCopy(Object source, Object dest, Map visited, ClientObjectManager objectManager, 76 OptimisticTransactionManager txManager) { 77 Date sourceDate = (Date ) source; 78 Date destDate = (Date ) dest; 79 destDate.setTime(sourceDate.getTime()); 80 if (source instanceof Timestamp ) { 81 ((Timestamp ) destDate).setNanos(((Timestamp ) sourceDate).getNanos()); 82 } 83 84 ((Manageable) destDate).__tc_managed(new TCObjectClone(((Manageable) sourceDate).__tc_managed(), txManager)); 85 return Collections.EMPTY_MAP; 86 } 87 } 88 | Popular Tags |