KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > mgmt > LogicalManagedObjectFacade


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.objectserver.mgmt;
5
6 import com.tc.object.ObjectID;
7
8 import java.io.Serializable JavaDoc;
9
10 public class LogicalManagedObjectFacade extends AbstractObjectFacade implements Serializable JavaDoc {
11   private static final int MAP = 1;
12   private static final int LIST = 2;
13   private static final int SET = 3;
14
15   private final boolean isMap;
16   private final boolean isSet;
17   private final boolean isList;
18   private final int trueSize;
19   private final ObjectID objectID;
20   private final String JavaDoc className;
21   private final int facadeSize;
22   private final Object JavaDoc[] data;
23
24   public static LogicalManagedObjectFacade createSetInstance(ObjectID id, String JavaDoc className, Object JavaDoc[] data, int trueSize) {
25     return new LogicalManagedObjectFacade(id, className, SET, data, trueSize);
26   }
27
28   public static LogicalManagedObjectFacade createListInstance(ObjectID id, String JavaDoc className, Object JavaDoc[] data, int trueSize) {
29     return new LogicalManagedObjectFacade(id, className, LIST, data, trueSize);
30   }
31
32   public static LogicalManagedObjectFacade createMapInstance(ObjectID id, String JavaDoc className, MapEntryFacade[] data,
33                                                              int trueSize) {
34     return new LogicalManagedObjectFacade(id, className, MAP, data, trueSize);
35   }
36
37   private LogicalManagedObjectFacade(ObjectID objectID, String JavaDoc className, int type, Object JavaDoc[] data, int trueObjectSize) {
38     if (type != MAP && type != SET && type != LIST) { throw new IllegalArgumentException JavaDoc("Bad type: " + type); }
39     this.isMap = type == MAP;
40     this.isSet = type == SET;
41     this.isList = type == LIST;
42     this.objectID = objectID;
43     this.className = className;
44     this.data = data;
45     this.facadeSize = data.length;
46     this.trueSize = trueObjectSize;
47   }
48
49   public String JavaDoc getClassName() {
50     return this.className;
51   }
52
53   public String JavaDoc[] getFields() {
54     String JavaDoc[] names = new String JavaDoc[this.facadeSize];
55     for (int i = 0; i < facadeSize; i++) {
56       names[i] = String.valueOf(i);
57     }
58     return names;
59   }
60
61   protected Object JavaDoc basicGetFieldValue(String JavaDoc fieldName) {
62     int index = Integer.valueOf(fieldName).intValue();
63     return this.data[index];
64   }
65
66   public boolean isPrimitive(String JavaDoc fieldName) {
67     // Logical classes cannot have "primitive" fields
68
return false;
69   }
70
71   public ObjectID getObjectId() {
72     return this.objectID;
73   }
74
75   public boolean isInnerClass() {
76     return false;
77   }
78
79   public ObjectID getParentObjectId() {
80     throw new IllegalStateException JavaDoc("Not an inner class");
81   }
82
83   public boolean isArray() {
84     return false;
85   }
86
87   public int getArrayLength() {
88     throw new IllegalStateException JavaDoc("Not an array");
89   }
90
91   public boolean isList() {
92     return this.isList;
93   }
94
95   public boolean isSet() {
96     return this.isSet;
97   }
98
99   public boolean isMap() {
100     return this.isMap;
101   }
102
103   public int getFacadeSize() {
104     return this.facadeSize;
105   }
106
107   public int getTrueObjectSize() {
108     return this.trueSize;
109   }
110
111 }
112
Popular Tags