KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > MyOodbProxy


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb;
25
26 public class MyOodbProxy implements MyOodbRemote, java.io.Externalizable JavaDoc
27 {
28     protected transient int m_timeout = -1;
29     protected transient org.myoodb.core.AbstractDatabase m_database = null;
30
31     private org.myoodb.core.Identifier m_objectId = null;
32
33     public MyOodbProxy()
34     {
35         org.myoodb.core.MyOodbManager manager = org.myoodb.core.MyOodbManager.getTheManager();
36         if (manager != null)
37         {
38             m_database = manager.getDatabase();
39         }
40     }
41
42     public MyOodbProxy(org.myoodb.core.Identifier id, org.myoodb.core.AbstractDatabase db)
43     {
44         m_objectId = id;
45         m_database = db;
46     }
47
48     public final MyOodbProxy getSelf()
49     {
50         return this;
51     }
52
53     public final org.myoodb.core.AbstractDatabase getDatabase()
54     {
55         return m_database;
56     }
57
58     public final org.myoodb.core.Identifier getDatabaseHandle()
59     {
60         return m_objectId;
61     }
62
63     public final void setTimeout(int timeout)
64     {
65         m_timeout = timeout;
66     }
67
68     public final int getTimeout()
69     {
70         return m_timeout;
71     }
72
73     public final void setBean(MyOodbBean bean)
74     {
75         m_database.setBean(getDatabaseHandle(), bean);
76     }
77
78     public final MyOodbBean getBean()
79     {
80         return m_database.getBean(getDatabaseHandle());
81     }
82
83     public final void setXML(String JavaDoc xml)
84     {
85         m_database.setXML(getDatabaseHandle(), xml);
86     }
87
88     public final String JavaDoc getXML()
89     {
90         return m_database.getXML(getDatabaseHandle());
91     }
92
93     public int hashCode()
94     {
95         return getDatabaseHandle().hashCode();
96     }
97
98     public boolean equals(Object JavaDoc obj)
99     {
100         if (this == obj)
101         {
102             return true;
103         }
104         else if (obj instanceof MyOodbProxy)
105         {
106             return getDatabaseHandle().equals(((MyOodbProxy) obj).getDatabaseHandle());
107         }
108         else if (obj instanceof org.myoodb.core.Identifier)
109         {
110             return getDatabaseHandle().equals(obj);
111         }
112         else
113         {
114             return false;
115         }
116     }
117
118     public int compareTo(Object JavaDoc obj)
119     {
120         if (obj instanceof MyOodbProxy)
121         {
122             return getDatabaseHandle().compareTo(((MyOodbProxy) obj).getDatabaseHandle());
123         }
124         else if (obj instanceof org.myoodb.core.Identifier)
125         {
126             return getDatabaseHandle().compareTo(obj);
127         }
128         else
129         {
130             return -1;
131         }
132     }
133
134     public void writeExternal(java.io.ObjectOutput JavaDoc out) throws java.io.IOException JavaDoc
135     {
136         out.writeObject(m_objectId);
137     }
138
139     public void readExternal(java.io.ObjectInput JavaDoc in) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc
140     {
141         m_objectId = (org.myoodb.core.Identifier) in.readObject();
142
143         if (in instanceof org.myoodb.util.FastObjectInputStream)
144         {
145             Object JavaDoc db = ((org.myoodb.util.FastObjectInputStream) in).getUserContext();
146
147             if (db != null)
148             {
149                 m_database = (org.myoodb.core.AbstractDatabase) db;
150             }
151         }
152     }
153
154     public String JavaDoc toString()
155     {
156         return "Proxy Handle: " + getDatabaseHandle();
157     }
158 }
159
Popular Tags