KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > ShadowVariableTestApp


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.tctest;
5
6 import com.tc.object.config.ConfigVisitor;
7 import com.tc.object.config.DSOClientConfigHelper;
8 import com.tc.object.config.TransparencyClassSpec;
9 import com.tc.simulator.app.ApplicationConfig;
10 import com.tc.simulator.listener.ListenerProvider;
11 import com.tc.util.Assert;
12 import com.tctest.runner.AbstractTransparentApp;
13
14 /**
15  * Test that makes sure "shadowed" variables work correctly with DSO
16  */

17 public class ShadowVariableTestApp extends AbstractTransparentApp {
18   private ShadowSub root;
19
20   public ShadowVariableTestApp(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
21     super(appId, cfg, listenerProvider);
22   }
23
24   public void run() {
25
26     root = new ShadowSub();
27     synchronized (root) {
28       if (root.getBaseMyNumber() == null) {
29         root.setBaseMyNumber(new Integer JavaDoc(1));
30         root.setSubMyNumber(new Integer JavaDoc(2));
31       }
32     }
33
34     Assert.assertNotNull(root.getBaseMyNumber());
35     Assert.assertNotNull(root.getSubMyNumber());
36
37     Assert.eval(root.getBaseMyNumber().equals(new Integer JavaDoc(1)));
38     Assert.eval(root.getSubMyNumber().equals(new Integer JavaDoc(2)));
39   }
40
41   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
42     String JavaDoc testClass = ShadowVariableTestApp.class.getName();
43     TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
44     config.addIncludePattern(ShadowBase.class.getName());
45     config.addIncludePattern(ShadowSub.class.getName());
46
47     String JavaDoc methodExpression = "* " + testClass + "*.*(..)";
48     config.addWriteAutolock(methodExpression);
49     spec.addRoot("root", "shadowTestRoot");
50   }
51
52   private static class ShadowBase {
53     // NOTE: It is very important that the shadow fields be of the exact same type
54
private Integer JavaDoc myNumber = null;
55
56     protected final int finalInt = 1;
57     
58     public int publicInt = 10;
59
60     public int getFinalInt() {
61       return finalInt;
62     }
63
64     public void setBaseMyNumber(Integer JavaDoc value) {
65       this.myNumber = value;
66     }
67
68     public Integer JavaDoc getBaseMyNumber() {
69       return this.myNumber;
70     }
71   }
72
73   private static class ShadowSub extends ShadowBase {
74     // NOTE: It is very important that the shadow fields be of the exact same type
75
private Integer JavaDoc myNumber = null;
76
77     protected final int finalInt = 2;
78     
79     public int publicInt = 20;
80
81     public int getFinalInt() {
82       return finalInt;
83     }
84
85     public void setSubMyNumber(Integer JavaDoc value) {
86       this.myNumber = value;
87     }
88
89     public Integer JavaDoc getSubMyNumber() {
90       return this.myNumber;
91     }
92     
93     public int getPublicInt() {
94       return publicInt;
95     }
96     
97     public void setPublicInt(int i) {
98       publicInt = i;
99       super.publicInt = i;
100     }
101   }
102
103 }
104
Popular Tags