KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > dna > api > PhysicalAction


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.dna.api;
5
6 /**
7  * A physical object change action
8  */

9 public class PhysicalAction {
10   private final String JavaDoc field;
11   private final Object JavaDoc value;
12   private final int index;
13   private final boolean isReference;
14   private final int type;
15
16   private static final int TRUE_PHYSICAL = 1;
17   private static final int ARRAY_ELEMENT = 2;
18   private static final int ENTIRE_ARRAY = 3;
19   private static final int SUB_ARRAY = 4;
20
21   // TODO: These 3 constructors would probably be easier to use if they were static factory methods instead
22

23   public PhysicalAction(Object JavaDoc value) {
24     this(null, -1, value, false, ENTIRE_ARRAY);
25   }
26   
27   public PhysicalAction(Object JavaDoc value, int startPos) {
28     this(null, startPos, value, false, SUB_ARRAY);
29   }
30
31   public PhysicalAction(int index, Object JavaDoc value, boolean isReference) {
32     this(null, index, value, isReference, ARRAY_ELEMENT);
33   }
34
35   public PhysicalAction(String JavaDoc field, Object JavaDoc value, boolean isReference) {
36     this(field, -1, value, isReference, TRUE_PHYSICAL);
37   }
38
39   private PhysicalAction(String JavaDoc field, int index, Object JavaDoc value, boolean isReference, int type) {
40     this.field = field;
41     this.index = index;
42     this.value = value;
43     this.isReference = isReference;
44     this.type = type;
45   }
46
47   public String JavaDoc getFieldName() {
48     if (type != TRUE_PHYSICAL) { throw new IllegalStateException JavaDoc(String.valueOf(type)); }
49
50     return this.field;
51   }
52
53   public Object JavaDoc getObject() {
54     return this.value;
55   }
56
57   public boolean isReference() {
58     return isReference;
59   }
60
61   public int getArrayIndex() {
62     if (!((type == ARRAY_ELEMENT) || (type == SUB_ARRAY))) { throw new IllegalStateException JavaDoc(String.valueOf(type)); }
63     return this.index;
64   }
65
66   public boolean isTruePhysical() {
67     return type == TRUE_PHYSICAL;
68   }
69
70   public boolean isArrayElement() {
71     return type == ARRAY_ELEMENT;
72   }
73
74   public boolean isEntireArray() {
75     return type == ENTIRE_ARRAY;
76   }
77   
78   public boolean isSubArray() {
79     return type == SUB_ARRAY;
80   }
81
82 }
Popular Tags