1 4 package com.tc.objectserver.managedobject; 5 6 import com.tc.object.ObjectID; 7 8 import java.io.IOException ; 9 import java.io.ObjectInput ; 10 import java.io.ObjectOutput ; 11 import java.util.Collection ; 12 import java.util.Collections ; 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import java.util.Set ; 16 17 public abstract class LogicalManagedObjectState extends AbstractManagedObjectState { 18 19 private final long classID; 20 21 public LogicalManagedObjectState(long classID) { 22 this.classID = classID; 23 } 24 25 protected LogicalManagedObjectState(ObjectInput in) throws IOException { 26 this.classID = in.readLong(); 27 } 28 29 protected abstract void addAllObjectReferencesTo(Set refs); 30 31 protected void addAllObjectReferencesFromIteratorTo(Iterator i, Set refs) { 32 for (; i.hasNext();) { 33 Object o = i.next(); 34 if(o instanceof ObjectID) { 35 refs.add(o); 36 } 37 } 38 } 39 40 public final Set getObjectReferences() { 41 HashSet refs = new HashSet (); 42 addAllObjectReferencesTo(refs); 43 return refs; 44 } 45 46 protected Set getObjectReferencesFrom(Collection refs) { 47 if (refs == null || refs.size() == 0) { return Collections.EMPTY_SET; } 48 Set results = new HashSet (refs.size()); 49 for (Iterator i = refs.iterator(); i.hasNext();) { 50 Object o = i.next(); 51 if (o instanceof ObjectID) { 52 results.add(o); 53 } 54 } 55 return results; 56 } 57 58 59 public void addObjectReferencesTo(ManagedObjectTraverser traverser) { 61 traverser.addRequiredObjectIDs(getObjectReferences()); 62 } 63 64 public final void writeTo(ObjectOutput out) throws IOException { 65 out.writeLong(classID); 66 basicWriteTo(out); 67 } 68 69 protected abstract void basicWriteTo(ObjectOutput out) throws IOException ; 70 71 public final String getClassName() { 72 return getStateFactory().getClassName(classID); 73 } 74 75 public final String getLoaderDescription() { 76 return getStateFactory().getLoaderDescription(classID); 77 } 78 79 protected final boolean basicEquals(AbstractManagedObjectState o) { 80 LogicalManagedObjectState lmo = ((LogicalManagedObjectState) o); 81 return lmo.classID == classID && basicEquals(lmo); 82 } 83 84 protected abstract boolean basicEquals(LogicalManagedObjectState o); 85 } 86 | Popular Tags |