001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.objectserver.mgmt;
005:
006: import com.tc.object.ObjectID;
007:
008: import java.io.Serializable;
009:
010: public class LogicalManagedObjectFacade extends AbstractObjectFacade
011: implements Serializable {
012: private static final int MAP = 1;
013: private static final int LIST = 2;
014: private static final int SET = 3;
015:
016: private final boolean isMap;
017: private final boolean isSet;
018: private final boolean isList;
019: private final int trueSize;
020: private final ObjectID objectID;
021: private final String className;
022: private final int facadeSize;
023: private final Object[] data;
024:
025: public static LogicalManagedObjectFacade createSetInstance(
026: ObjectID id, String className, Object[] data, int trueSize) {
027: return new LogicalManagedObjectFacade(id, className, SET, data,
028: trueSize);
029: }
030:
031: public static LogicalManagedObjectFacade createListInstance(
032: ObjectID id, String className, Object[] data, int trueSize) {
033: return new LogicalManagedObjectFacade(id, className, LIST,
034: data, trueSize);
035: }
036:
037: public static LogicalManagedObjectFacade createMapInstance(
038: ObjectID id, String className, MapEntryFacade[] data,
039: int trueSize) {
040: return new LogicalManagedObjectFacade(id, className, MAP, data,
041: trueSize);
042: }
043:
044: private LogicalManagedObjectFacade(ObjectID objectID,
045: String className, int type, Object[] data,
046: int trueObjectSize) {
047: if (type != MAP && type != SET && type != LIST) {
048: throw new IllegalArgumentException("Bad type: " + type);
049: }
050: this .isMap = type == MAP;
051: this .isSet = type == SET;
052: this .isList = type == LIST;
053: this .objectID = objectID;
054: this .className = className;
055: this .data = data;
056: this .facadeSize = data.length;
057: this .trueSize = trueObjectSize;
058: }
059:
060: public String getClassName() {
061: return this .className;
062: }
063:
064: public String[] getFields() {
065: String[] names = new String[this .facadeSize];
066: for (int i = 0; i < facadeSize; i++) {
067: names[i] = String.valueOf(i);
068: }
069: return names;
070: }
071:
072: protected Object basicGetFieldValue(String fieldName) {
073: int index = Integer.valueOf(fieldName).intValue();
074: return this .data[index];
075: }
076:
077: public boolean isPrimitive(String fieldName) {
078: // Logical classes cannot have "primitive" fields
079: return false;
080: }
081:
082: public ObjectID getObjectId() {
083: return this .objectID;
084: }
085:
086: public boolean isInnerClass() {
087: return false;
088: }
089:
090: public ObjectID getParentObjectId() {
091: throw new IllegalStateException("Not an inner class");
092: }
093:
094: public boolean isArray() {
095: return false;
096: }
097:
098: public int getArrayLength() {
099: throw new IllegalStateException("Not an array");
100: }
101:
102: public boolean isList() {
103: return this .isList;
104: }
105:
106: public boolean isSet() {
107: return this .isSet;
108: }
109:
110: public boolean isMap() {
111: return this .isMap;
112: }
113:
114: public int getFacadeSize() {
115: return this .facadeSize;
116: }
117:
118: public int getTrueObjectSize() {
119: return this.trueSize;
120: }
121:
122: }
|