001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: OzoneObject.java,v 1.4 2002/07/12 09:25:11 mediumnet Exp $
008:
009: package org.ozoneDB;
010:
011: import org.ozoneDB.core.ObjectContainer;
012: import org.ozoneDB.core.ObjectID;
013: import org.xml.sax.ContentHandler;
014: import org.xml.sax.SAXException;
015:
016: /**
017: * This class can be extended to build actual database objects. It provides a
018: * default implementation of the {@link OzoneCompatible} interface.
019: *
020: * @author <a href="http://www.softwarebuero.de/">SMB</a>
021: * @version $Revision: 1.4 $Date: 2002/07/12 09:25:11 $
022: */
023: public class OzoneObject implements OzoneCompatible {
024:
025: final static long serialVersionUID = 3171995582505722338L;
026:
027: transient ObjectContainer container = null;
028:
029: public int hashCode() {
030: return container.id().hashCode();
031: }
032:
033: public synchronized void setContainer(ObjectContainer _container) {
034: container = _container;
035: }
036:
037: public OzoneProxy self() {
038: if (container == null) {
039: throw new RuntimeException(
040: "Object is not (yet) associated to a database container.");
041: }
042: return container.ozoneProxy();
043: }
044:
045: public ObjectContainer container() {
046: if (container == null) {
047: throw new RuntimeException(
048: "Object is not (yet) associated to a database container.");
049: }
050: return container;
051: }
052:
053: /**
054: * Retrieves a handle to a specific instance of an OzoneObject. A handle is
055: * the externalizeable equivalent of OzoneProxy. The purpose of handles is to enable
056: * detached systems (such as web interfaces) that are not able to use OzoneProxy
057: * objects directly a means to access specific objects where object naming is not
058: * practical or convenient. A handle is valid for the lifetime of
059: * the OzoneObject it references. Unlike OzoneProxy, retrieving a handle on an
060: * object does nothing to guarantee its existence. While the handle is valid
061: * for the lifetime of the object it refers to, that object's lifetime may
062: * be shorter than the handle's.
063: * <br><br>
064: * The resultant string representation will be composed
065: * entirely of alphanumeric characters [A-Z], [a-z], and [0-9]; as such,
066: * it can safely and reliably be used in URLs without need for escaping.
067: *
068: */
069: public String handle() {
070: if (container == null) {
071: throw new RuntimeException(
072: "Object is not (yet) associated to a database container.");
073: }
074: return container.id().toString();
075: }
076:
077: public OzoneInterface database() {
078: if (container == null) {
079: throw new RuntimeException(
080: "Object is not (yet) associated to a database container.");
081: }
082: return container.database();
083: }
084:
085: public String toString() {
086: return "OzoneObject, ID: "
087: + (container != null ? container.id().toString()
088: : "null");
089: }
090:
091: /**
092: * This default implementation of the onCreate() method does nothing.
093: */
094: public void onCreate() throws Exception {
095: }
096:
097: /**
098: * This default implementation of the onDelete() method does nothing.
099: */
100: public void onDelete() throws Exception {
101: }
102:
103: // This Method is not needed anymore, because it is only used in ClassicStore
104: /**
105: * This default implementation of the size() method. It returns just -1 to
106: * signal that a default value should be used.
107: *
108: public int size() throws Exception {
109: return -1;
110: }
111: */
112:
113: /**
114: * This default implementation of the toSAX() method. It returns just false
115: * to signal that a default value should be used.
116: */
117: public boolean toXML(ContentHandler ch) throws SAXException {
118: return false;
119: }
120:
121: public void deleteRecursive() {
122: throw new RuntimeException(
123: "deleteRecursive() is not implemented yet.");
124: }
125:
126: /**
127: Returns the ObjectID of the represented ozone object. ObjectIDs are equal for equal
128: ozone objects and different for different ozone objects. They are comparable, so that
129: ozone objects may use {@link ObjectID#compareTo) in comparison functions.
130: <P>
131: Currently, ObjectID exposes other methods than {@link ObjectID#equals) and
132: {@link ObjectID#compareTo). However, they should not be used, as ObjectIDs should
133: be, apart from this methods, opaque.
134: </P>
135: */
136: public ObjectID getObjectID() {
137: return container.id();
138: }
139: }
|