KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > applicator > LiteralTypesApplicator


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.object.applicator;
5
6 import com.tc.exception.TCNotSupportedMethodException;
7 import com.tc.object.ClientObjectManager;
8 import com.tc.object.TCClass;
9 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.LiteralAction;
15 import com.tc.object.dna.impl.DNAEncoding;
16 import com.tc.object.tx.optimistic.OptimisticTransactionManager;
17 import com.tc.util.Assert;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Map JavaDoc;
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 JavaDoc pojo, TraversedReferences addTo) {
29     // if (pojo instanceof TransparentAccess) { throw new AssertionError("Instance of Literal Type: " + clazz.getName()
30
// + " should not implement TransparentAccess."); }
31
return addTo;
32   }
33
34   public void hydrate(ClientObjectManager objectManager, TCObject tcObject, DNA dna, Object JavaDoc po) throws IOException JavaDoc,
35       ClassNotFoundException JavaDoc {
36     DNACursor cursor = dna.getCursor();
37     Assert.eval(cursor.getActionCount() <= 1);
38
39     if (cursor.next(encoding)) {
40       LiteralAction a = (LiteralAction) cursor.getAction();
41       Object JavaDoc value = a.getObject();
42
43       tcObject.setLiteralValue(value);
44     }
45   }
46   
47   public void dehydrate(ClientObjectManager objectManager, TCObject tcObject, DNAWriter writer, Object JavaDoc pojo) {
48     if (!objectManager.isPortableInstance(pojo)) { return; }
49     writer.addLiteralValue(pojo);
50   }
51
52   public Object JavaDoc getNewInstance(ClientObjectManager objectManager, DNA dna) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
53     DNACursor cursor = dna.getCursor();
54     Assert.assertEquals(1, cursor.getActionCount());
55
56     cursor.next(encoding);
57     LiteralAction a = (LiteralAction) cursor.getAction();
58     Object JavaDoc value = a.getObject();
59
60     return value;
61   }
62
63   public Map JavaDoc connectedCopy(Object JavaDoc source, Object JavaDoc dest, Map JavaDoc visited, ClientObjectManager objectManager,
64                            OptimisticTransactionManager txManager) {
65     throw new TCNotSupportedMethodException();
66   }
67 }
68
Popular Tags