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.object;
005:
006: import com.tc.object.dna.api.DNA;
007: import com.tc.object.dna.api.DNAWriter;
008: import com.tc.object.field.TCField;
009: import com.tc.object.tx.optimistic.OptimisticTransactionManager;
010:
011: import java.io.IOException;
012: import java.lang.reflect.Constructor;
013: import java.lang.reflect.Field;
014: import java.util.Map;
015:
016: /**
017: * Interface for peer to java.lang.Class. The Class of every object under management is represented by an instance of
018: * TCClass. Keeping a peer of each Class object allows us to organize the class elements in useful ways and to cache
019: * that organization so we only have to do it once per class.
020: * <p>
021: * <b>Important </b>-- It is likely that we will enforce the Serializable contract and only manage those classes which
022: * implement Serializable.
023: * <p>
024: * TODO: Add support for using a serialized instance of classes with no nullary constructor to rehydrate into. <br>
025: *
026: * @author Orion Letizi
027: */
028: public interface TCClass {
029:
030: /**
031: * Get the class this TCClass is a peer for
032: * @return Peer class, never null
033: */
034: public Class getPeerClass();
035:
036: /**
037: * Determine whether this class has a BeanShell script to execute on class load
038: * @return True if has script
039: */
040: public boolean hasOnLoadExecuteScript();
041:
042: /**
043: * Determine whether this class has a method to execute on class loade
044: * @return True if has load method
045: */
046: public boolean hasOnLoadMethod();
047:
048: /**
049: * Get name of method to execute on load
050: * @return Method name
051: */
052: public String getOnLoadMethod();
053:
054: /**
055: * Get script to execute on load
056: * @return Execute script
057: */
058: public String getOnLoadExecuteScript();
059:
060: /**
061: * If the class is an inner class, get the field referring to the parent "this object.
062: * @return The field referring to the parent this
063: */
064: public Field getParentField();
065:
066: /**
067: * If the class is an inner class, get the name of the field referring to the parent "this"
068: * object.
069: * @return The field name referring to the parent this
070: */
071: public String getParentFieldName();
072:
073: /**
074: * Get all portable fields in the class
075: * @return Fields, never null
076: */
077: public TCField[] getPortableFields();
078:
079: /**
080: * Connects the original object to the copy object and creates new copies of referened objects but leaves them
081: * unconnected (mostly this is about doing a deep connected clone without recurrsion so that we don't get stack
082: * overflows
083: * @param source Source object
084: * @param dest Copy object
085: * @param visited Note already visited objects
086: * @param txManager Transaction manager
087: * @return Map of original to copy key that were cloned while executing the method
088: */
089: public Map connectedCopy(Object source, Object dest, Map visited,
090: OptimisticTransactionManager txManager);
091:
092: /**
093: * Traverse a graph of objects to find the portable ones
094: * @param pojo The object to walk
095: * @param addTo The traversed references collected so far
096: * @return The addTo collection
097: */
098: public TraversedReferences getPortableObjects(Object pojo,
099: TraversedReferences addTo);
100:
101: /**
102: * Get constructor for the class
103: * @return The constructor
104: * @throws NoSuchMethodException If there is no constructor
105: * @throws SecurityException If the constructor cannot be accessed in the current security model
106: */
107: public Constructor getConstructor() throws NoSuchMethodException,
108: SecurityException;
109:
110: /**
111: * @return Name of peer or proxy class
112: */
113: public String getName();
114:
115: /**
116: * @return If this is an array, the type of array elements
117: */
118: public Class getComponentType();
119:
120: /**
121: * @return True if this is a logically instrumented class
122: */
123: public boolean isLogical();
124:
125: /**
126: * @return The client object manager for this client
127: */
128: public ClientObjectManager getObjectManager();
129:
130: /**
131: * @return TCClass of the super class of the peer
132: */
133: public TCClass getSuperclass();
134:
135: /**
136: * @return True if this is a non-static inner class and has a parent
137: */
138: public boolean isNonStaticInner();
139:
140: /**
141: * @return True if this is an enum
142: */
143: public boolean isEnum();
144:
145: /**
146: * @return True if should use a non-default constructor when creating new instances
147: */
148: public boolean isUseNonDefaultConstructor();
149:
150: /**
151: * Construct a new instance from a DNA strand using a non-default constructor
152: * @param dna The DNA with the data to use
153: * @return The new instance
154: * @throws IOException Reading DNA
155: * @throws ClassNotFoundException Can't instantiate a class
156: */
157: public Object getNewInstanceFromNonDefaultConstructor(DNA dna)
158: throws IOException, ClassNotFoundException;
159:
160: /**
161: * Get TCField for this class
162: * @param name Field name
163: * @return TCField
164: */
165: public TCField getField(String name);
166:
167: /**
168: * @return True if this is an array and indexed
169: */
170: public boolean isIndexed();
171:
172: /**
173: * Reconstitute object from DNA
174: * @param tcObject The object manager
175: * @param dna The DNA to read
176: * @param pojo The new instance of the pojo to reconstitute (will be modified)
177: * @param force Set to true to force an update to the DNA version, regardless of the local version
178: */
179: public void hydrate(TCObject tcObject, DNA dna, Object pojo,
180: boolean force) throws IOException, ClassNotFoundException;
181:
182: /**
183: * Write an object to DNA
184: * @param tcObject The object manager
185: * @param writer The writer to write to
186: * @param pojo The instance to write
187: */
188: public void dehydrate(TCObject tcObject, DNAWriter writer,
189: Object pojo);
190:
191: /**
192: * @return Name of defining classloader
193: */
194: public String getDefiningLoaderDescription();
195:
196: /**
197: * Create a new TCObject
198: * @param id The object identifier
199: * @param peer The object
200: */
201: public TCObject createTCObject(ObjectID id, Object peer);
202:
203: /**
204: * Get a field name by offset into an index of fields
205: * @param fieldOffset The index
206: * @return The fully-qualified field name at that index
207: */
208: public String getFieldNameByOffset(long fieldOffset);
209:
210: /**
211: * @return True if this class uses a proxy class
212: */
213: public boolean isProxyClass();
214:
215: /**
216: * Returns special generated name for classes extending logical classes
217: * @return Special generated logical extending class name or just the normal class name if not extending logical
218: */
219: public String getExtendingClassName();
220:
221: /**
222: * Returns true if the field represented by the offset is a portable field, i.e., not static and not dso transient
223: * @param fieldOffset The index
224: * @return true if the field is portable and false otherwise
225: */
226: public boolean isPortableField(long fieldOffset);
227: }
|