001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest;
006:
007: import com.tc.object.bytecode.ClassAdapterBase;
008: import com.tc.object.bytecode.Manageable;
009: import com.tc.object.config.ConfigVisitor;
010: import com.tc.object.config.DSOClientConfigHelper;
011: import com.tc.object.config.Root;
012: import com.tc.object.util.ReadOnlyException;
013: import com.tc.simulator.app.ApplicationConfig;
014: import com.tc.simulator.listener.ListenerProvider;
015: import com.tc.util.Assert;
016:
017: import java.awt.Color;
018: import java.lang.reflect.Field;
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: public class ReflectionFieldTestApp extends GenericTestApp {
025: // This field is used by reflection.
026: private DataRoot reflectionRoot = null;
027: private Integer literalRoot; // used by reflection.
028: private int primitiveRoot; // used by reflection.
029:
030: private DataRoot nonShared = new DataRoot();
031: private NonInstrumentedTestObject nonInstrumentedObject = new NonInstrumentedTestObject();
032:
033: private NonInstrumented nonInstrumented = new NonInstrumented();
034:
035: public ReflectionFieldTestApp(String appId, ApplicationConfig cfg,
036: ListenerProvider listenerProvider) {
037: super (appId, cfg, listenerProvider, DataRoot.class);
038: }
039:
040: protected Object getTestObject(String testName) {
041: DataRoot root = (DataRoot) sharedMap.get("root");
042: return root;
043: }
044:
045: protected void setupTestObject(String testName) {
046: sharedMap.put("root", new DataRoot(Long.MIN_VALUE));
047: }
048:
049: void testBasicModifyRoot(DataRoot root, boolean validate) {
050: if (validate) {
051: Assert.assertEquals(12, root.getLongValue());
052: } else {
053: synchronized (root) {
054: root.setLongValue(12);
055: }
056: }
057: }
058:
059: void testModifyPhysicalInstrumentedObjectWithStaticManager(
060: DataRoot root, boolean validate) throws Exception {
061: if (validate) {
062: Assert.assertEquals(12, root.getLongValue());
063: } else {
064: synchronized (root) {
065: Field longValueField = root.getClass()
066: .getDeclaredField("longValue");
067: longValueField.setAccessible(true);
068: longValueField.setLong(root, 12);
069: }
070: }
071: }
072:
073: void testModifyPhysicalInstrumentedObjectWithNonStaticManager(
074: DataRoot root, boolean validate) throws Exception {
075: if (validate) {
076: Assert.assertEquals(200, root.getColor().getRGB());
077: } else {
078: synchronized (root) {
079: Color color = root.getColor();
080: Field colorField = color.getClass().getDeclaredField(
081: "value");
082: colorField.setAccessible(true);
083: Assert.assertEquals(100, colorField.getInt(color));
084: colorField.setInt(color, 200);
085: }
086: }
087: }
088:
089: void testModifyObjectReference(DataRoot root, boolean validate)
090: throws Exception {
091: if (validate) {
092: Assert.assertEquals(200, root.getColor().getRGB());
093: } else {
094: synchronized (root) {
095: Field colorField = root.getClass().getDeclaredField(
096: "color");
097: colorField.setAccessible(true);
098: colorField.set(root, new Color(200, true));
099: }
100: }
101: }
102:
103: void testModifyBoolean(DataRoot root, boolean validate)
104: throws Exception {
105: if (validate) {
106: Assert.assertTrue(root.isBooleanValue());
107: } else {
108: synchronized (root) {
109: Field booleanField = root.getClass().getDeclaredField(
110: "booleanValue");
111: booleanField.setAccessible(true);
112: booleanField.setBoolean(root, true);
113: }
114: }
115: }
116:
117: void testModifyByte(DataRoot root, boolean validate)
118: throws Exception {
119: if (validate) {
120: Assert.assertEquals(Byte.MAX_VALUE, root.getByteValue());
121: } else {
122: synchronized (root) {
123: Field byteField = root.getClass().getDeclaredField(
124: "byteValue");
125: byteField.setAccessible(true);
126: byteField.setByte(root, Byte.MAX_VALUE);
127: }
128: }
129: }
130:
131: void testModifyCharacter(DataRoot root, boolean validate)
132: throws Exception {
133: if (validate) {
134: Assert.assertEquals(Character.MAX_VALUE, root
135: .getCharValue());
136: } else {
137: synchronized (root) {
138:
139: Field charField = root.getClass().getDeclaredField(
140: "charValue");
141: charField.setAccessible(true);
142: charField.setChar(root, Character.MAX_VALUE);
143:
144: }
145: }
146: }
147:
148: void testModifyDoubleWithFloatValue(DataRoot root, boolean validate)
149: throws Exception {
150: if (validate) {
151: Assert.assertEquals(Float.MAX_VALUE, root.getDoubleValue());
152: } else {
153: synchronized (root) {
154:
155: Field doubleField = root.getClass().getDeclaredField(
156: "doubleValue");
157: doubleField.setAccessible(true);
158: doubleField.setFloat(root, Float.MAX_VALUE);
159: }
160: }
161: }
162:
163: void testModifyDoubleWithIntValue(DataRoot root, boolean validate)
164: throws Exception {
165: if (validate) {
166: Assert.assertEquals(4, root.getDoubleValue());
167: } else {
168: synchronized (root) {
169:
170: Field doubleField = root.getClass().getDeclaredField(
171: "doubleValue");
172: doubleField.setAccessible(true);
173: doubleField.setInt(root, 4);
174: }
175: }
176: }
177:
178: void testModifyDoubleWithLongValue(DataRoot root, boolean validate)
179: throws Exception {
180: if (validate) {
181: Assert.assertEquals(4L, root.getDoubleValue());
182: } else {
183: synchronized (root) {
184:
185: Field doubleField = root.getClass().getDeclaredField(
186: "doubleValue");
187: doubleField.setAccessible(true);
188: doubleField.setLong(root, 4L);
189: }
190: }
191: }
192:
193: void testModifyDouble(DataRoot root, boolean validate)
194: throws Exception {
195: if (validate) {
196: Assert
197: .assertEquals(Double.MAX_VALUE, root
198: .getDoubleValue());
199: } else {
200: synchronized (root) {
201:
202: Field doubleField = root.getClass().getDeclaredField(
203: "doubleValue");
204: doubleField.setAccessible(true);
205: doubleField.setDouble(root, Double.MAX_VALUE);
206: }
207: }
208: }
209:
210: void testModifyFloat(DataRoot root, boolean validate)
211: throws Exception {
212: if (validate) {
213: Assert.assertEquals(Float.MAX_VALUE, root.getFloatValue());
214: } else {
215: synchronized (root) {
216:
217: Field floatField = root.getClass().getDeclaredField(
218: "floatValue");
219: floatField.setAccessible(true);
220: floatField.setFloat(root, Float.MAX_VALUE);
221: }
222: }
223: }
224:
225: void testModifyShort(DataRoot root, boolean validate)
226: throws Exception {
227: if (validate) {
228: Assert.assertEquals(Short.MAX_VALUE, root.getShortValue());
229: } else {
230: synchronized (root) {
231:
232: Field shortField = root.getClass().getDeclaredField(
233: "shortValue");
234: shortField.setAccessible(true);
235: shortField.setShort(root, Short.MAX_VALUE);
236: }
237: }
238: }
239:
240: void testModifyIntWithShortValue(DataRoot root, boolean validate)
241: throws Exception {
242: if (validate) {
243: Assert.assertEquals(Short.MAX_VALUE, root.getIntValue());
244: } else {
245: synchronized (root) {
246:
247: Field intField = root.getClass().getDeclaredField(
248: "intValue");
249: intField.setAccessible(true);
250: intField.setInt(root, Short.MAX_VALUE);
251: }
252: }
253: }
254:
255: void testModifyIntWithByteValue(DataRoot root, boolean validate)
256: throws Exception {
257: if (validate) {
258: Assert.assertEquals(Byte.MAX_VALUE, root.getIntValue());
259: } else {
260: synchronized (root) {
261:
262: Field intField = root.getClass().getDeclaredField(
263: "intValue");
264: intField.setAccessible(true);
265: intField.setInt(root, Byte.MAX_VALUE);
266: }
267: }
268: }
269:
270: void testModifyIntWithCharValue(DataRoot root, boolean validate)
271: throws Exception {
272: if (validate) {
273: Assert
274: .assertEquals(Character.MAX_VALUE, root
275: .getIntValue());
276: } else {
277: synchronized (root) {
278:
279: Field intField = root.getClass().getDeclaredField(
280: "intValue");
281: intField.setAccessible(true);
282: intField.setInt(root, Character.MAX_VALUE);
283: }
284: }
285: }
286:
287: void testModifyInt(DataRoot root, boolean validate)
288: throws Exception {
289: if (validate) {
290: Assert.assertEquals(Integer.MAX_VALUE, root.getIntValue());
291: } else {
292: synchronized (root) {
293:
294: Field intField = root.getClass().getDeclaredField(
295: "intValue");
296: intField.setAccessible(true);
297: intField.setInt(root, Integer.MAX_VALUE);
298: }
299: }
300: }
301:
302: void testModifyLongWithIntValue(DataRoot root, boolean validate)
303: throws Exception {
304: if (validate) {
305: Assert.assertEquals(Integer.MAX_VALUE, root.getLongValue());
306: } else {
307: synchronized (root) {
308:
309: Field longField = root.getClass().getDeclaredField(
310: "longValue");
311: longField.setAccessible(true);
312: longField.setInt(root, Integer.MAX_VALUE);
313: }
314: }
315: }
316:
317: void testModifyLongWithShortValue(DataRoot root, boolean validate)
318: throws Exception {
319: if (validate) {
320: Assert.assertEquals(Short.MAX_VALUE, root.getLongValue());
321: } else {
322: synchronized (root) {
323:
324: Field longField = root.getClass().getDeclaredField(
325: "longValue");
326: longField.setAccessible(true);
327: longField.setShort(root, Short.MAX_VALUE);
328: }
329: }
330: }
331:
332: void testModifyLongWithByteValue(DataRoot root, boolean validate)
333: throws Exception {
334: if (validate) {
335: Assert.assertEquals(Byte.MAX_VALUE, root.getLongValue());
336: } else {
337: synchronized (root) {
338:
339: Field longField = root.getClass().getDeclaredField(
340: "longValue");
341: longField.setAccessible(true);
342: longField.setByte(root, Byte.MAX_VALUE);
343: }
344: }
345: }
346:
347: void testModifyLongWithCharValue(DataRoot root, boolean validate)
348: throws Exception {
349: if (validate) {
350: Assert.assertEquals(Character.MAX_VALUE, root
351: .getLongValue());
352: } else {
353: synchronized (root) {
354:
355: Field longField = root.getClass().getDeclaredField(
356: "longValue");
357: longField.setAccessible(true);
358: longField.setChar(root, Character.MAX_VALUE);
359: }
360: }
361: }
362:
363: void testModifyLongWithFloatValue(DataRoot root, boolean validate)
364: throws Exception {
365: if (validate) {
366: Assert.assertEquals(Long.MIN_VALUE, root.getLongValue());
367: } else {
368: synchronized (root) {
369: try {
370: Field longField = root.getClass().getDeclaredField(
371: "longValue");
372: longField.setAccessible(true);
373: longField.setFloat(root, Float.MAX_VALUE);
374: throw new AssertionError(
375: "should have thrown an exception");
376: } catch (IllegalArgumentException re) {
377: // Expected.
378: }
379: }
380: }
381: }
382:
383: void testModifyLongWithDoubleValue(DataRoot root, boolean validate)
384: throws Exception {
385: if (validate) {
386: Assert.assertEquals(Long.MIN_VALUE, root.getLongValue());
387: } else {
388: synchronized (root) {
389: try {
390: Field longField = root.getClass().getDeclaredField(
391: "longValue");
392: longField.setAccessible(true);
393: longField.setDouble(root, Double.MAX_VALUE);
394: throw new AssertionError(
395: "should have thrown an exception");
396: } catch (IllegalArgumentException re) {
397: // Expected.
398: }
399: }
400: }
401: }
402:
403: void testModifyLong(DataRoot root, boolean validate)
404: throws Exception {
405: if (validate) {
406: Assert.assertEquals(Long.MAX_VALUE, root.getLongValue());
407: } else {
408: synchronized (root) {
409: Field longField = root.getClass().getDeclaredField(
410: "longValue");
411: longField.setAccessible(true);
412: longField.setLong(root, Long.MAX_VALUE);
413: }
414: }
415: }
416:
417: void testModifyNonSharedTCManagedField(DataRoot root,
418: boolean validate) throws Exception {
419: Field tcManaged = nonShared.getClass().getDeclaredField(
420: ClassAdapterBase.MANAGED_FIELD_NAME);
421: tcManaged.setAccessible(true);
422: if (validate) {
423: Object tcManagedObject = tcManaged.get(nonShared);
424: Assert.assertNull(tcManagedObject);
425: Assert.assertNull(((Manageable) nonShared).__tc_managed());
426: } else {
427: Assert.assertNotNull(((Manageable) root).__tc_managed());
428: Assert.assertNull(((Manageable) nonShared).__tc_managed());
429: tcManaged
430: .set(nonShared, ((Manageable) root).__tc_managed());
431: Assert.assertNull(((Manageable) nonShared).__tc_managed());
432: }
433: }
434:
435: void testModifySharedTCManagedField(DataRoot root, boolean validate)
436: throws Exception {
437: Field tcManaged = root.getClass().getDeclaredField(
438: ClassAdapterBase.MANAGED_FIELD_NAME);
439: tcManaged.setAccessible(true);
440: if (validate) {
441: Object tcManagedObject = tcManaged.get(root);
442: Assert.assertNull(tcManagedObject);
443: Assert.assertNotNull(((Manageable) root).__tc_managed());
444: } else {
445: Assert.assertNotNull(((Manageable) root).__tc_managed());
446: tcManaged.set(root, null);
447: Assert.assertNotNull(((Manageable) root).__tc_managed());
448: }
449: }
450:
451: void testModifyAndGetLiteralRoot(DataRoot root, boolean validate)
452: throws Exception {
453: Field literalRootField = getClass().getDeclaredField(
454: "literalRoot");
455: literalRootField.setAccessible(true);
456:
457: Field primitiveRootField = getClass().getDeclaredField(
458: "primitiveRoot");
459: primitiveRootField.setAccessible(true);
460:
461: if (validate) {
462: Integer localLiteralRoot = (Integer) literalRootField
463: .get(this );
464: Assert.assertNotNull(localLiteralRoot);
465: Assert.assertEquals(new Integer(100), localLiteralRoot);
466:
467: Integer localPrimitiveRoot = (Integer) primitiveRootField
468: .get(this );
469: Assert.assertNotNull(localPrimitiveRoot);
470: Assert.assertEquals(new Integer(200), localPrimitiveRoot);
471: } else {
472: Object value = literalRootField.get(this );
473: Assert.assertNull(value);
474:
475: // don't need DSO lock to set roots
476: literalRootField.set(this , new Integer(100));
477:
478: value = primitiveRootField.get(this );
479: Assert.assertEquals(new Integer(0), value);
480: primitiveRootField.set(this , new Integer(200));
481: }
482: }
483:
484: void testModifyAndGetRoot(DataRoot root, boolean validate)
485: throws Exception {
486: Field rootField = getClass().getDeclaredField("reflectionRoot");
487: rootField.setAccessible(true);
488:
489: if (validate) {
490: DataRoot dataRoot = (DataRoot) rootField.get(this );
491: Assert.assertNotNull(dataRoot);
492: Assert.assertEquals(200, dataRoot.getLongValue());
493: Assert.assertEquals(200, reflectionRoot.getLongValue());
494: } else {
495: Object value = rootField.get(this );
496: Assert.assertNull(value);
497:
498: // don't need DSO lock to set roots
499: rootField.set(this , new DataRoot(200));
500: }
501: }
502:
503: void testModifyNonSharedObject(DataRoot root, boolean validate)
504: throws Exception {
505: if (!validate) {
506: synchronized (nonShared) {
507:
508: Field longValueField = nonShared.getClass()
509: .getDeclaredField("longValue");
510: longValueField.setAccessible(true);
511: longValueField.setLong(nonShared, Long.MAX_VALUE);
512: }
513: Assert.assertEquals(Long.MAX_VALUE, nonShared
514: .getLongValue());
515: }
516: }
517:
518: void testModifyNonInstrumentedObject(DataRoot root, boolean validate)
519: throws Exception {
520: if (!validate) {
521: synchronized (nonInstrumentedObject) {
522: Field longValueField = nonInstrumentedObject.getClass()
523: .getDeclaredField("longValue");
524: longValueField.setAccessible(true);
525: longValueField.setLong(nonInstrumentedObject,
526: Long.MAX_VALUE);
527: }
528: Assert.assertEquals(Long.MAX_VALUE, nonInstrumentedObject
529: .getLongValue());
530: }
531: }
532:
533: void testModifyLogicalInstrumentedObject(DataRoot root,
534: boolean validate) throws Exception {
535: if (validate) {
536: Assert.assertEquals(0, root.getList().size());
537: } else {
538: synchronized (root) {
539: List list = root.getList();
540: try {
541: Field sizeField = list.getClass().getDeclaredField(
542: "size");
543: sizeField.setAccessible(true);
544: sizeField.setInt(list, 10);
545: throw new AssertionError(
546: "should have thrown an exception");
547: } catch (IllegalAccessException re) {
548: // Checking the exact text of the exception isn't great, but unless we want to create a unique
549: // expception type for this condition, this is how we differentiate between other potential
550: // IllegalAccessExceptions being thrown here
551: Assert.assertEquals(
552: "Field modification through reflection for non-physical shared object of type "
553: + list.getClass().getName()
554: + " is not supported!", re
555: .getMessage());
556: }
557: }
558:
559: }
560: }
561:
562: void testModifyNonInstrumentedObjectRoot(DataRoot root,
563: boolean validate) throws Exception {
564: Field nonInstrumentedRootField = nonInstrumented.getClass()
565: .getDeclaredField("nonInstrumentedRoot");
566: nonInstrumentedRootField.setAccessible(true);
567: if (validate) {
568: Assert.assertEquals(root, nonInstrumented
569: .getNonInstrumentedRoot());
570:
571: Object nonInstrumentedRoot = nonInstrumentedRootField
572: .get(nonInstrumented);
573: Assert.assertEquals(root, nonInstrumentedRoot);
574: } else {
575: nonInstrumentedRootField.set(nonInstrumented, root);
576: }
577: }
578:
579: void testGetObjectReference(DataRoot root, boolean validate)
580: throws Exception {
581: if (validate) {
582: Field colorField = root.getClass()
583: .getDeclaredField("color");
584: colorField.setAccessible(true);
585: Object color = colorField.get(root);
586: Assert.assertNotNull(color);
587: Assert.assertEquals(new Color(100, true), color);
588: }
589: }
590:
591: void testLogicalClasses(DataRoot root, boolean validate)
592: throws Exception {
593: Map map = root.getMap();
594: Map subMap = root.getSubMap();
595:
596: Field sizeField = HashMap.class.getDeclaredField("size");
597: Field iField = subMap.getClass().getDeclaredField("i");
598: sizeField.setAccessible(true);
599: iField.setAccessible(true);
600:
601: if (validate) {
602: int size = sizeField.getInt(map);
603: Assert.assertEquals(1, size);
604: size = ((Integer) sizeField.get(subMap)).intValue();
605:
606: int i = iField.getInt(subMap);
607: Assert.assertEquals(5, i);
608:
609: } else {
610: int i = iField.getInt(subMap);
611: Assert.assertEquals(3, i);
612:
613: synchronized (subMap) {
614: iField.setInt(subMap, 5);
615: }
616: }
617:
618: }
619:
620: /*
621: * A static field of a non-root shared object is not shared. This test case is to make sure that we could use the
622: * current reflection instrumentation to set a static field.
623: */
624: void testModifyNonRootStaticField(DataRoot root, boolean validate)
625: throws Exception {
626: Field staticLongField = root.getClass().getDeclaredField(
627: "staticLong");
628: staticLongField.setAccessible(true);
629: if (!validate) {
630: staticLongField.set(null, new Long(33L));
631: Assert
632: .assertEquals(new Long(33L), DataRoot
633: .getStaticLong());
634:
635: Object staticLongFieldValue = staticLongField.get(null);
636: Assert.assertEquals(new Long(33L), staticLongFieldValue);
637:
638: staticLongField.set(null, new Long(50L));
639: Assert
640: .assertEquals(new Long(50L), DataRoot
641: .getStaticLong());
642:
643: staticLongFieldValue = staticLongField.get(null);
644: Assert.assertEquals(new Long(50L), staticLongFieldValue);
645: }
646: }
647:
648: void testModifyRootStaticField(DataRoot root, boolean validate)
649: throws Exception {
650: Field nonInstrumentedStaticRootField = nonInstrumented
651: .getClass().getDeclaredField(
652: "nonInstrumentedStaticRoot");
653: nonInstrumentedStaticRootField.setAccessible(true);
654: if (validate) {
655: Assert.assertEquals(root, NonInstrumented
656: .getNonInstrumentedStaticRoot());
657:
658: Object nonInstrumentedStaticRootValue = nonInstrumentedStaticRootField
659: .get(null);
660: Assert.assertEquals(root, nonInstrumentedStaticRootValue);
661: } else {
662: nonInstrumentedStaticRootField.set(null, root);
663: }
664: }
665:
666: // ReadOnly test.
667: void testReadOnlyModifyLong(DataRoot root, boolean validate)
668: throws Exception {
669: if (validate) {
670: Assert.assertEquals(Long.MIN_VALUE, root.getLongValue());
671: } else {
672: synchronized (root) {
673: try {
674: Field longField = root.getClass().getDeclaredField(
675: "longValue");
676: longField.setAccessible(true);
677: longField.setLong(root, Long.MAX_VALUE);
678: throw new AssertionError(
679: "I should have thrown a ReadOnlyException.");
680: } catch (ReadOnlyException t) {
681: // expected
682: }
683: }
684: }
685: }
686:
687: public static void visitL1DSOConfig(ConfigVisitor visitor,
688: DSOClientConfigHelper config) {
689: String testClass = ReflectionFieldTestApp.class.getName();
690: config.getOrCreateSpec(testClass);
691:
692: config.getOrCreateSpec(SubMap.class.getName());
693:
694: String writeAllowedMethodExpression = "* " + testClass
695: + "*.*(..)";
696: config.addWriteAutolock(writeAllowedMethodExpression);
697: String readOnlyMethodExpression = "* " + testClass
698: + "*.*ReadOnly*(..)";
699: config.addReadAutolock(readOnlyMethodExpression);
700:
701: config.addRoot(new Root(testClass, "reflectionRoot",
702: "reflectionRoot"), true);
703: config
704: .addRoot(new Root(testClass, "literalRoot",
705: "literalRoot"), true);
706: config.addRoot(new Root(testClass, "primitiveRoot",
707: "primitiveRoot"), true);
708: config.addIncludePattern(DataRoot.class.getName());
709:
710: config.addRoot(new Root(NonInstrumented.class.getName(),
711: "nonInstrumentedRoot", "nonInstrumentedRoot"), false);
712: config.addRoot(new Root(NonInstrumented.class.getName(),
713: "nonInstrumentedStaticRoot",
714: "nonInstrumentedStaticRoot"), false);
715: }
716:
717: protected void silenceCompilerWarnings() {
718: if (false && literalRoot != literalRoot
719: && primitiveRoot != primitiveRoot) {
720: // silence eclipse warnings about not directly reading the root fields
721: throw new AssertionError("Don't call this method");
722: }
723: }
724:
725: private static class NonInstrumented extends
726: NonInstrumentedTestObject {
727: private static DataRoot nonInstrumentedStaticRoot;
728:
729: private DataRoot nonInstrumentedRoot;
730:
731: public NonInstrumented() {
732: super ();
733: }
734:
735: public static DataRoot getNonInstrumentedStaticRoot() {
736: return nonInstrumentedStaticRoot;
737: }
738:
739: public static void setNonInstrumentedStaticRoot(
740: DataRoot nonInstrumentedStaticRoot) {
741: NonInstrumented.nonInstrumentedStaticRoot = nonInstrumentedStaticRoot;
742: }
743:
744: public DataRoot getNonInstrumentedRoot() {
745: return nonInstrumentedRoot;
746: }
747:
748: public void setNonInstrumentedRoot(DataRoot nonInstrumentedRoot) {
749: this .nonInstrumentedRoot = nonInstrumentedRoot;
750: }
751: }
752:
753: private static class SubMap extends HashMap {
754: private int i = 3;
755:
756: public SubMap() {
757: put("key", "value");
758: if (i == 5) { // silence compiler warning
759: throw new RuntimeException();
760: }
761: }
762: }
763:
764: private static class DataRoot {
765: private static Long staticLong;
766:
767: private ArrayList list = new ArrayList();
768: private Color color = new Color(100, true);
769: private long longValue = Long.MIN_VALUE;
770: private int intValue = Integer.MIN_VALUE;
771: private short shortValue = Short.MIN_VALUE;
772: private boolean booleanValue = false;
773: private byte byteValue = Byte.MIN_VALUE;
774: private char charValue = Character.MIN_VALUE;
775: private double doubleValue = Double.MIN_VALUE;
776: private float floatValue = Float.MIN_VALUE;
777:
778: private final Map map = new HashMap();
779: {
780: map.put("key", "value");
781: }
782:
783: private final Map subMap = new SubMap();
784:
785: public DataRoot(long longValue) {
786: this .longValue = longValue;
787: }
788:
789: public DataRoot() {
790: //
791: }
792:
793: public Map getSubMap() {
794: return subMap;
795: }
796:
797: public Map getMap() {
798: return map;
799: }
800:
801: public static Long getStaticLong() {
802: return staticLong;
803: }
804:
805: public static void setStaticLong(Long staticLong) {
806: DataRoot.staticLong = staticLong;
807: }
808:
809: protected ArrayList getList() {
810: return list;
811: }
812:
813: protected void setList(ArrayList list) {
814: this .list = list;
815: }
816:
817: protected Color getColor() {
818: return color;
819: }
820:
821: protected void setColor(Color color) {
822: this .color = color;
823: }
824:
825: protected long getLongValue() {
826: return longValue;
827: }
828:
829: protected void setLongValue(long longValue) {
830: this .longValue = longValue;
831: }
832:
833: protected int getIntValue() {
834: return intValue;
835: }
836:
837: protected void setIntValue(int intValue) {
838: this .intValue = intValue;
839: }
840:
841: protected boolean isBooleanValue() {
842: return booleanValue;
843: }
844:
845: protected void setBooleanValue(boolean booleanValue) {
846: this .booleanValue = booleanValue;
847: }
848:
849: protected byte getByteValue() {
850: return byteValue;
851: }
852:
853: protected void setByteValue(byte byteValue) {
854: this .byteValue = byteValue;
855: }
856:
857: protected char getCharValue() {
858: return charValue;
859: }
860:
861: protected void setCharValue(char charValue) {
862: this .charValue = charValue;
863: }
864:
865: protected double getDoubleValue() {
866: return doubleValue;
867: }
868:
869: protected void setDoubleValue(double doubleValue) {
870: this .doubleValue = doubleValue;
871: }
872:
873: protected float getFloatValue() {
874: return floatValue;
875: }
876:
877: protected void setFloatValue(float floatValue) {
878: this .floatValue = floatValue;
879: }
880:
881: protected short getShortValue() {
882: return shortValue;
883: }
884:
885: protected void setShortValue(short shortValue) {
886: this.shortValue = shortValue;
887: }
888: }
889: }
|