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 MyOodbObject implements MyOodbLocal {
027: private transient boolean m_convertFlag = true;
028: private transient org.myoodb.core.AbstractObjectContainer m_container = null;
029:
030: public MyOodbObject() {
031: }
032:
033: public void onCreate() {
034: }
035:
036: public void onDelete() {
037: }
038:
039: public final void setConvertFlag(boolean convertFlag) {
040: m_convertFlag = convertFlag;
041: }
042:
043: public final boolean getConvertFlag() {
044: return m_convertFlag;
045: }
046:
047: public final void setContainer(
048: org.myoodb.core.AbstractObjectContainer container) {
049: m_container = container;
050: }
051:
052: public final org.myoodb.core.AbstractObjectContainer getContainer() {
053: if (m_container == null) {
054: throw new org.myoodb.exception.PermissionException(
055: "Invalid access (" + this .getClass()
056: + " is not (yet) associated to a database");
057: }
058:
059: return m_container;
060: }
061:
062: public final MyOodbProxy getSelf() {
063: return getContainer().getProxy();
064: }
065:
066: public final org.myoodb.core.Identifier getDatabaseHandle() {
067: return getContainer().getObjectIdentifier();
068: }
069:
070: public final org.myoodb.core.AbstractDatabase getDatabase() {
071: return org.myoodb.core.MyOodbManager.getTheManager()
072: .getDatabase();
073: }
074:
075: public final Object writeReplace()
076: throws java.io.ObjectStreamException {
077: if (m_convertFlag == false) {
078: m_convertFlag = true;
079:
080: return this ;
081: } else {
082: return getSelf();
083: }
084: }
085:
086: public final void setBean(MyOodbBean bean) {
087: getDatabase().setBean(getDatabaseHandle(), bean);
088: }
089:
090: public final MyOodbBean getBean() {
091: return getDatabase().getBean(getDatabaseHandle());
092: }
093:
094: public final void setXML(String xml) {
095: getDatabase().setXML(getDatabaseHandle(), xml);
096: }
097:
098: public final String getXML() {
099: return getDatabase().getXML(getDatabaseHandle());
100: }
101:
102: public int hashCode() {
103: return getDatabaseHandle().hashCode();
104: }
105:
106: public boolean equals(Object obj) {
107: if (obj == this ) {
108: return true;
109: } else if (obj instanceof MyOodbObject) {
110: return getDatabaseHandle().equals(
111: ((MyOodbObject) obj).getDatabaseHandle());
112: } else if (obj instanceof MyOodbProxy) {
113: return getDatabaseHandle().equals(
114: ((MyOodbProxy) obj).getDatabaseHandle());
115: } else if (obj instanceof org.myoodb.core.Identifier) {
116: return getDatabaseHandle().equals(obj);
117: } else {
118: return false;
119: }
120: }
121:
122: public int compareTo(Object obj) {
123: if (obj instanceof MyOodbObject) {
124: return getDatabaseHandle().compareTo(
125: ((MyOodbObject) obj).getDatabaseHandle());
126: } else if (obj instanceof MyOodbProxy) {
127: return getDatabaseHandle().compareTo(
128: ((MyOodbProxy) obj).getDatabaseHandle());
129: } else if (obj instanceof org.myoodb.core.Identifier) {
130: return getDatabaseHandle().compareTo(obj);
131: } else {
132: return -1;
133: }
134: }
135:
136: public String toString() {
137: return "Object Handle: " + getDatabaseHandle();
138: }
139: }
|