KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > managedobject > DateManagedObjectState


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
17 import java.io.ObjectInput JavaDoc;
18 import java.io.ObjectOutput JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23
24 /**
25  * ManagedObjectState for sets.
26  */

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 JavaDoc in) throws IOException JavaDoc {
37     super(in);
38   }
39
40   public void apply(ObjectID objectID, DNACursor cursor, BackReferences includeIDs) throws IOException JavaDoc {
41     while (cursor.next()) {
42       LogicalAction action = cursor.getLogicalAction();
43       int method = action.getMethod();
44       Object JavaDoc[] params = action.getParameters();
45
46       switch (method) {
47         case SerializationUtil.SET_TIME:
48           Assert.assertNotNull(params[0]);
49           referenceTime = ((Long JavaDoc) params[0]).longValue();
50           break;
51         case SerializationUtil.SET_NANOS:
52           Assert.assertNotNull(params[0]);
53           referenceNanoTime = ((Integer JavaDoc) params[0]).intValue();
54           break;
55         default:
56           throw new AssertionError JavaDoc("Invalid action:" + method);
57       }
58     }
59   }
60
61   public void dehydrate(ObjectID objectID, DNAWriter writer) {
62     writer.addLogicalAction(SerializationUtil.SET_TIME, new Object JavaDoc[] { new Long JavaDoc(referenceTime) });
63     writer.addLogicalAction(SerializationUtil.SET_NANOS, new Object JavaDoc[] { new Integer JavaDoc(referenceNanoTime) });
64   }
65
66   protected void addAllObjectReferencesTo(Set JavaDoc refs) {
67     return;
68   }
69
70   public ManagedObjectFacade createFacade(ObjectID objectID, String JavaDoc className, int limit) {
71     Map JavaDoc dataCopy = new HashMap JavaDoc();
72     dataCopy.put("date", new Date JavaDoc(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 JavaDoc o) throws IOException JavaDoc {
79     o.writeLong(referenceTime);
80     o.writeInt(referenceNanoTime);
81   }
82
83   static DateManagedObjectState readFrom(ObjectInput JavaDoc in) throws IOException JavaDoc {
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