KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > dso > DSOObject


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.admin.dso;
5
6 import com.tc.admin.ConnectionContext;
7 import com.tc.object.ObjectID;
8 import com.tc.objectserver.mgmt.ManagedObjectFacade;
9 import com.tc.objectserver.mgmt.MapEntryFacade;
10
11 import java.beans.PropertyChangeListener JavaDoc;
12 import java.beans.PropertyChangeSupport JavaDoc;
13
14 public abstract class DSOObject {
15   protected ConnectionContext m_cc;
16   protected DSOObject m_parent;
17   protected PropertyChangeSupport JavaDoc m_changeHelper;
18   protected int m_batchSize;
19   
20   public DSOObject(ConnectionContext cc) {
21     m_cc = cc;
22     m_changeHelper = new PropertyChangeSupport JavaDoc(this);
23     m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE;
24   }
25
26   public DSOObject(ConnectionContext cc, DSOObject parent) {
27     this(cc);
28     m_parent = parent;
29   }
30
31   public abstract Object JavaDoc getFacade();
32   public abstract void accept(DSOObjectVisitor visitor);
33   
34   public DSOObject getParent() {
35     return m_parent;
36   }
37
38   public void setBatchSize(int batchSize) {
39     m_batchSize = batchSize;
40   }
41   
42   public abstract String JavaDoc getName();
43
44   public DSORoot getRoot() {
45     DSOObject obj = this;
46
47     while(obj != null) {
48       if(obj.getParent() == null) {
49         return (DSORoot)obj;
50       }
51       obj = obj.getParent();
52     }
53
54     return null;
55   }
56
57   protected DSOObject createField(String JavaDoc fieldName, Object JavaDoc value)
58     throws Exception JavaDoc
59   {
60     DSOObject result = null;
61     String JavaDoc type = null;
62
63     if(value instanceof MapEntryFacade) {
64       MapEntryFacade mef = (MapEntryFacade)value;
65
66       result = new DSOMapEntryField(m_cc, fieldName, mef, this);
67     }
68     else if(value instanceof ObjectID) {
69       ObjectID id = (ObjectID)value;
70
71       if(!id.isNull()) {
72         value = DSOHelper.getHelper().lookupFacade(m_cc, id, m_batchSize);
73         type = ((ManagedObjectFacade)value).getClassName();
74       }
75       else {
76         value = null;
77         type = null;
78       }
79
80       result = new DSOField(m_cc, fieldName, false, type, value, this);
81     }
82     else {
83       type = value.getClass().getName();
84       result = new DSOField(m_cc, fieldName, true, type, value, this);
85     }
86
87     return result;
88   }
89
90   public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
91     m_changeHelper.addPropertyChangeListener(listener);
92   }
93
94   public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
95     m_changeHelper.removePropertyChangeListener(listener);
96   }
97 }
98
Popular Tags