1 4 package com.tc.objectserver.mgmt; 5 6 import com.tc.object.ObjectID; 7 8 import java.io.Serializable ; 9 import java.util.ArrayList ; 10 import java.util.Arrays ; 11 import java.util.Collections ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 public class PhysicalManagedObjectFacade extends AbstractObjectFacade implements Serializable { 16 private static final String [] EMPTY_STRING_ARRAY = new String [] {}; 17 18 private final String className; 19 private final Map fields; 20 private final ObjectID objectID; 21 private final ObjectID parentID; 22 private final boolean isInner; 23 private final int arrayLength; 24 private final boolean isArray; 25 private final String [] fieldNames; 26 27 public PhysicalManagedObjectFacade(ObjectID id, ObjectID parentID, String className, Map data, boolean isInner, 28 int arrayLength, boolean isArray) { 29 this.className = className; 30 this.fields = Collections.unmodifiableMap(data); 31 this.objectID = id; 32 this.parentID = parentID; 33 this.isInner = isInner; 34 this.isArray = isArray; 35 this.arrayLength = arrayLength; 36 this.fieldNames = sortFieldNames((String []) this.fields.keySet().toArray(EMPTY_STRING_ARRAY)); 37 } 38 39 private String [] sortFieldNames(String [] names) { 40 List special = new ArrayList (); 41 List regular = new ArrayList (); 42 43 for (int i = 0; i < names.length; i++) { 44 if (names[i].indexOf('$') >= 0) { 45 special.add(names[i]); 46 } else { 47 regular.add(names[i]); 48 } 49 } 50 51 String [] first = (String []) special.toArray(EMPTY_STRING_ARRAY); 52 String [] second = (String []) regular.toArray(EMPTY_STRING_ARRAY); 53 Arrays.sort(first); 54 Arrays.sort(second); 55 56 String [] rv = new String [names.length]; 57 System.arraycopy(first, 0, rv, 0, first.length); 58 System.arraycopy(second, 0, rv, first.length, second.length); 59 60 return rv; 61 } 62 63 public String getClassName() { 64 return this.className; 65 } 66 67 public String [] getFields() { 68 return (String []) this.fieldNames.clone(); 69 } 70 71 protected Object basicGetFieldValue(String fieldName) { 72 checkValidName(fieldName); 73 return this.fields.get(fieldName); 74 } 75 76 public boolean isPrimitive(String fieldName) { 77 Object value = getFieldValue(fieldName); 78 return !(value instanceof ObjectID); 79 } 80 81 public ObjectID getObjectId() { 82 return this.objectID; 83 } 84 85 public boolean isInnerClass() { 86 return this.isInner; 87 } 88 89 public ObjectID getParentObjectId() { 90 if (!this.isInner) { throw new IllegalStateException ("Not an inner class"); } 91 return this.parentID; 92 } 93 94 public boolean isArray() { 95 return this.isArray; 96 } 97 98 public int getArrayLength() { 99 if (!this.isArray) { throw new IllegalStateException ("Not an array"); } 100 return this.arrayLength; 101 } 102 103 public boolean isList() { 104 return false; 105 } 106 107 public boolean isSet() { 108 return false; 109 } 110 111 public boolean isMap() { 112 return false; 113 } 114 115 public int getFacadeSize() { 116 throw new UnsupportedOperationException ("Not a collection"); 117 } 118 119 public int getTrueObjectSize() { 120 throw new UnsupportedOperationException ("Not a collection"); 121 } 122 123 private void checkValidName(String fieldName) { 124 if (this.fields.containsKey(fieldName)) { return; } 125 throw new IllegalArgumentException (className + "." + fieldName + " does not exist"); 126 } 127 128 } 129 | Popular Tags |