KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > managedobject > LogicalManagedObjectState


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.managedobject;
5
6 import com.tc.object.ObjectID;
7
8 import java.io.IOException JavaDoc;
9 import java.io.ObjectInput JavaDoc;
10 import java.io.ObjectOutput JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.HashSet JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Set JavaDoc;
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 JavaDoc in) throws IOException JavaDoc {
26     this.classID = in.readLong();
27   }
28
29   protected abstract void addAllObjectReferencesTo(Set JavaDoc refs);
30
31   protected void addAllObjectReferencesFromIteratorTo(Iterator JavaDoc i, Set JavaDoc refs) {
32     for (; i.hasNext();) {
33       Object JavaDoc o = i.next();
34       if(o instanceof ObjectID) {
35         refs.add(o);
36       }
37     }
38   }
39
40   public final Set JavaDoc getObjectReferences() {
41     HashSet JavaDoc refs = new HashSet JavaDoc();
42     addAllObjectReferencesTo(refs);
43     return refs;
44   }
45   
46   protected Set JavaDoc getObjectReferencesFrom(Collection JavaDoc refs) {
47     if (refs == null || refs.size() == 0) { return Collections.EMPTY_SET; }
48     Set JavaDoc results = new HashSet JavaDoc(refs.size());
49     for (Iterator JavaDoc i = refs.iterator(); i.hasNext();) {
50       Object JavaDoc o = i.next();
51       if (o instanceof ObjectID) {
52         results.add(o);
53       }
54     }
55     return results;
56   }
57
58   
59   // XXX:: This default behavior needs to be overridden by class that needs specific behavior (like MapManagedObjectState)
60
public void addObjectReferencesTo(ManagedObjectTraverser traverser) {
61     traverser.addRequiredObjectIDs(getObjectReferences());
62   }
63
64   public final void writeTo(ObjectOutput JavaDoc out) throws IOException JavaDoc {
65     out.writeLong(classID);
66     basicWriteTo(out);
67   }
68
69   protected abstract void basicWriteTo(ObjectOutput JavaDoc out) throws IOException JavaDoc;
70   
71   public final String JavaDoc getClassName() {
72     return getStateFactory().getClassName(classID);
73   }
74
75   public final String JavaDoc 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