📄 ozoneproxy.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: OzoneProxy.java,v 1.5 2003/09/24 12:42:23 leomekenkamp Exp $package org.ozoneDB;import java.io.*;import org.ozoneDB.DxLib.DxHashMap;import org.ozoneDB.DxLib.DxMap;import org.ozoneDB.core.Env;import org.ozoneDB.core.ObjectID;import org.ozoneDB.core.GarbageCollector;import org.ozoneDB.core.xml.Consts;import org.xml.sax.helpers.AttributesImpl;/** * Proxy of an OzoneRemote object. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @author <a href="http://www.medium.net/">Medium.net</a> * @version $Revision: 1.5 $Date: 2003/09/24 12:42:23 $ */public class OzoneProxy implements OzoneRemote, Externalizable { private final static long serialVersionUID = 3L; /** * Table of stream to OzoneInterface pairs. The method {@link #readExternal(ObjectInput)} checks this * table to find corresponding database link. */ public static DxMap linkTable = new DxHashMap(); public transient OzoneInterface link = null; public ObjectID remoteID; /** * This constructor will only be called, when the object is constructed * from a stream. */ public OzoneProxy() { //we assume that we are inside the kernel Env env = Env.currentEnv(); if (env != null) { link = env.database; } } /** * This constructor is only be called, when this object is constructed * inside the database. However, it may be the result of a RMI call. */ public OzoneProxy(ObjectID id, OzoneInterface link) { this.link = link; remoteID = (ObjectID) id.clone(); } public OzoneProxy(OzoneProxy rhs) { link = rhs.link; remoteID = (ObjectID) rhs.remoteID.clone(); } public boolean isSame(OzoneProxy proxy) { return remoteID.equals(proxy.remoteID); } /** * Base implementation of equals(). May be overwritten by an implementation * of the actual database object. In that case the method is handled, as all * remote methods, on the server side. */ public boolean equals(Object obj) { if (obj instanceof OzoneProxy && obj != null) { return isSame((OzoneProxy) obj); } else { return false; } } /** * Base implementation of hashCode(). May be overwritten by an implementation * of the actual database object. In that case the method is handled, as all * remote methods, on the server side. */ public int hashCode() { return remoteID.hashCode(); } /** * Base implementation of toString() that runs client side only. * When you want to override this method with one that runs on the server * side, as all remote methods, you need to define <code>public String toString()</code> * in your <code>OzoneRemote</code> extending interface so that OPP will * generate a remote call. For instance: <code> * * public interface Foo extends OzoneRemote { * * // ensure OPP will create a remote call * public String toString(); * * // other methods * } * * </code> * Providing an implementation for <code>toString()</code> in your * <code>OzoneObject</code> extending class is optional; if you do not, then * the implementation of <code>toString()</code> in <code>OzoneObject</code> * will be used server-side conform normal java method override rules. * * @return String string representation of this proxy, containing a string * representation of the ozone id of the object this proxy represents */ public String toString() { return getClass().toString() + " remoteID:" + remoteID.toString(); } public ObjectID remoteID() { return remoteID; } /** Returns the ObjectID of the represented ozone object. ObjectIDs are equal for equal ozone objects and different for different ozone objects. They are comparable, so that ozone objects may use {@link org.ozoneDB.core.ObjectID#compareTo(Object)} in comparison functions. <p> Currently, ObjectID exposes other methods than {@link org.ozoneDB.core.ObjectID#equals(Object)} and {@link org.ozoneDB.core.ObjectID#compareTo(Object)}. However, they should not be used, as ObjectIDs should be, apart from this method, opaque. </p> @return the ObjectID of the represented ozone object */ public ObjectID getObjectID() { return remoteID(); } /** * Retrieves a handle to a specific instance of an OzoneObject. <br> * A handle is * the externalizeable equivalent of OzoneProxy. The purpose of handles is to enable * detached systems (such as web interfaces) that are not able to use OzoneProxy * objects directly a means to access specific objects where object naming is not * practical or convenient. A handle is valid for the lifetime of * the OzoneObject it references. Unlike OzoneProxy, retrieving a handle on an * object does nothing to guarantee its existence. While the handle is valid * for the lifetime of the object it refers to, that object's lifetime may * be shorter than the handle's. * <br><br> * The resultant string representation will be composed * entirely of alphanumeric characters [A-Z], [a-z], and [0-9]; as such, * it can safely and reliably be used in URLs without need for escaping. * */ public String getHandle() { return remoteID.toString(); } /** * @deprecated use getHandle() */ public String handle() { return getHandle(); } /** * <p>Adds the required attributes for a simple XLink which points to this * proxy to an attribute list.</p> * * @param atts The SAX attribute list to which the attributes will be added. */ public void createProxyLinkAttributes(AttributesImpl atts) { atts.addAttribute(Consts.ATTR_XLINK_NAMESPACE, Consts.ATTR_XLINK_TYPE_LOCAL, Consts.ATTR_XLINK_TYPE_RAW, "PCDATA", "simple"); atts.addAttribute(Consts.ATTR_XLINK_NAMESPACE, Consts.ATTR_XLINK_HREF_LOCAL, Consts.ATTR_XLINK_HREF_RAW, "PCDATA", String.valueOf(remoteID)); } /** * Method to use the proxy without a generated stub. The method signature * will be generated from the actual argument types. This may be in * some cases! */ public Object invoke(String methodName, int lockLevel) throws Exception { Object[] args = {}; return link.invoke(this, methodName, null, args, lockLevel); } /** * Method to use the proxy without a generated stub. */ public Object invoke(String methodName, Object arg1, int lockLevel) throws Exception { Object[] args = {arg1}; return link.invoke(this, methodName, null, args, lockLevel); } /** * Method to use the proxy without a generated stub. */ public Object invoke(String methodName, Object arg1, Object arg2, int lockLevel) throws Exception { Object[] args = {arg1, arg2}; return link.invoke(this, methodName, null, args, lockLevel); } /** * Method to use the proxy without a generated stub. */ public Object invoke(String methodName, Object arg1, Object arg2, Object arg3, int lockLevel) throws Exception { Object[] args = {arg1, arg2, arg3}; return link.invoke(this, methodName, null, args, lockLevel); } /** Notify the database link that this reference dies. */ public void finalize() { if (link!=null) { try { link.notifyProxyDeath(this); } finally { link = null; // We notify the proxy death only once. } } } public void writeExternal(ObjectOutput out) throws IOException { if (out instanceof GarbageCollector.GarbageCollectorProxyObjectIdentificationObjectOutputStream) { ((GarbageCollector.GarbageCollectorProxyObjectIdentificationObjectOutputStream) out).notifyOzoneProxyEncountered(this); } out.writeLong(remoteID.value()); // out.writeObject (remoteID); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { remoteID = new ObjectID(in.readLong()); // remoteID = (ObjectID)in.readObject(); ExternalDatabase db = (ExternalDatabase) linkTable.elementForKey(in); if (db != null) { link = db.linkForProxy(this); // System.out.println ("*** Proxy link updated."); // new Exception().fillInStackTrace().printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -