01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.applicator;
05:
06: import com.tc.exception.TCNotSupportedMethodException;
07: import com.tc.object.ClientObjectManager;
08: import com.tc.object.TCClass;
09: import com.tc.object.TCObject;
10: import com.tc.object.TraversedReferences;
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.DNAEncoding;
15: import com.tc.object.dna.api.LiteralAction;
16: import com.tc.object.tx.optimistic.OptimisticTransactionManager;
17: import com.tc.util.Assert;
18:
19: import java.io.IOException;
20: import java.util.Map;
21:
22: public class LiteralTypesApplicator extends BaseApplicator {
23:
24: public LiteralTypesApplicator(TCClass clazz, DNAEncoding encoding) {
25: super (encoding);
26: }
27:
28: public TraversedReferences getPortableObjects(Object pojo,
29: TraversedReferences addTo) {
30: // if (pojo instanceof TransparentAccess) { throw new AssertionError("Instance of Literal Type: " + clazz.getName()
31: // + " should not implement TransparentAccess."); }
32: return addTo;
33: }
34:
35: public void hydrate(ClientObjectManager objectManager,
36: TCObject tcObject, DNA dna, Object po) throws IOException,
37: ClassNotFoundException {
38: DNACursor cursor = dna.getCursor();
39: Assert.eval(cursor.getActionCount() <= 1);
40:
41: if (cursor.next(encoding)) {
42: LiteralAction a = (LiteralAction) cursor.getAction();
43: Object value = a.getObject();
44:
45: tcObject.setLiteralValue(value);
46: }
47: }
48:
49: public void dehydrate(ClientObjectManager objectManager,
50: TCObject tcObject, DNAWriter writer, Object pojo) {
51: if (!objectManager.isPortableInstance(pojo)) {
52: return;
53: }
54: writer.addLiteralValue(pojo);
55: }
56:
57: public Object getNewInstance(ClientObjectManager objectManager,
58: DNA dna) throws IOException, ClassNotFoundException {
59: DNACursor cursor = dna.getCursor();
60: Assert.assertEquals(1, cursor.getActionCount());
61:
62: cursor.next(encoding);
63: LiteralAction a = (LiteralAction) cursor.getAction();
64: Object value = a.getObject();
65:
66: return value;
67: }
68:
69: public Map connectedCopy(Object source, Object dest, Map visited,
70: ClientObjectManager objectManager,
71: OptimisticTransactionManager txManager) {
72: throw new TCNotSupportedMethodException();
73: }
74: }
|