001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb;
025:
026: public class MyOodbProxy implements MyOodbRemote,
027: java.io.Externalizable {
028: private org.myoodb.core.Identifier m_objectId = null;
029:
030: protected transient int m_timeout = -1;
031: protected transient int m_readMode = org.myoodb.MyOodbAccess.READ;
032: protected transient int m_writeMode = org.myoodb.MyOodbAccess.WRITE;
033:
034: protected transient org.myoodb.core.AbstractDatabase m_database = null;
035:
036: public MyOodbProxy() {
037: }
038:
039: public MyOodbProxy(org.myoodb.core.Identifier id,
040: org.myoodb.core.AbstractDatabase db) {
041: m_objectId = id;
042: m_database = db;
043: }
044:
045: public final MyOodbProxy getSelf() {
046: return this ;
047: }
048:
049: public final org.myoodb.core.AbstractDatabase getDatabase() {
050: return m_database;
051: }
052:
053: public final org.myoodb.core.Identifier getDatabaseHandle() {
054: return m_objectId;
055: }
056:
057: public final void setTimeout(int timeout) {
058: m_timeout = timeout;
059: }
060:
061: public final int getTimeout() {
062: return m_timeout;
063: }
064:
065: public final void setReadMode(int readMode) {
066: m_readMode = readMode;
067: }
068:
069: public final int getReadMode() {
070: return m_readMode;
071: }
072:
073: public final void setWriteMode(int writeMode) {
074: m_writeMode = writeMode;
075: }
076:
077: public final int getWriteMode() {
078: return m_writeMode;
079: }
080:
081: public final void setBean(MyOodbBean bean) {
082: m_database.setBean(getDatabaseHandle(), bean);
083: }
084:
085: public final MyOodbBean getBean() {
086: return m_database.getBean(getDatabaseHandle());
087: }
088:
089: public final void setXML(String xml) {
090: m_database.setXML(getDatabaseHandle(), xml);
091: }
092:
093: public final String getXML() {
094: return m_database.getXML(getDatabaseHandle());
095: }
096:
097: public int hashCode() {
098: return getDatabaseHandle().hashCode();
099: }
100:
101: public boolean equals(Object obj) {
102: if (this == obj) {
103: return true;
104: } else if (obj instanceof MyOodbProxy) {
105: return getDatabaseHandle().equals(
106: ((MyOodbProxy) obj).getDatabaseHandle());
107: } else if (obj instanceof org.myoodb.core.Identifier) {
108: return getDatabaseHandle().equals(obj);
109: } else {
110: return false;
111: }
112: }
113:
114: public int compareTo(Object obj) {
115: if (obj instanceof MyOodbProxy) {
116: return getDatabaseHandle().compareTo(
117: ((MyOodbProxy) obj).getDatabaseHandle());
118: } else if (obj instanceof org.myoodb.core.Identifier) {
119: return getDatabaseHandle().compareTo(obj);
120: } else {
121: return -1;
122: }
123: }
124:
125: public void writeExternal(java.io.ObjectOutput out)
126: throws java.io.IOException {
127: out.writeObject(m_objectId);
128: }
129:
130: public void readExternal(java.io.ObjectInput in)
131: throws java.io.IOException, ClassNotFoundException {
132: m_objectId = (org.myoodb.core.Identifier) in.readObject();
133:
134: if (in instanceof org.myoodb.util.FastObjectInputStream) {
135: m_database = (org.myoodb.core.AbstractDatabase) ((org.myoodb.util.FastObjectInputStream) in)
136: .getContext();
137: }
138: /*
139: else if (in instanceof org.myoodb.util.XStreamInputStream)
140: {
141: m_database = (org.myoodb.core.AbstractDatabase) ((org.myoodb.util.XStreamInputStream) in).getContext();
142: }
143: */
144: else if (org.myoodb.core.MyOodbManager.getTheManager() != null) {
145: m_database = org.myoodb.core.MyOodbManager.getTheManager()
146: .getDatabase();
147: }
148: }
149:
150: public String toString() {
151: return "Proxy Handle: " + getDatabaseHandle();
152: }
153: }
|