001: /*
002: * @(#)IxcOutputStream.java 1.6 06/08/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.jumpimpl.ixc;
028:
029: import java.io.IOException;
030: import java.io.ObjectOutputStream;
031: import java.io.ObjectStreamClass;
032: import java.io.OutputStream;
033: import java.lang.reflect.Array;
034: import java.rmi.Remote;
035: import java.security.AccessController;
036: import java.security.PrivilegedAction;
037:
038: import javax.microedition.xlet.XletContext;
039:
040: public class IxcOutputStream extends ObjectOutputStream {
041:
042: private XletContext context;
043:
044: static private NullObject nullObject = new NullObject();
045:
046: IxcOutputStream(OutputStream out, XletContext context,
047: boolean isExecutiveVM) throws IOException {
048: super (out);
049: this .context = context;
050:
051: /***
052: * isExecutiveVM value indicates that this IxcOutputStream is used
053: * for the central JUMPExecIxcRegistry's output stream.
054: * In the JUMPExecIxcRegistry, we don't want to be converting
055: * Remote object to a RemoteRef, but just write out outgoing
056: * RemoteRef objects.
057: **/
058: if (!isExecutiveVM) {
059: AccessController.doPrivileged(new PrivilegedAction() {
060: public Object run() {
061: enableReplaceObject(true);
062: return null;
063: }
064: });
065: }
066: }
067:
068: protected Object replaceObject(Object obj) throws IOException {
069:
070: Object nextObject = obj;
071:
072: if (nextObject instanceof Remote) {
073: /*
074: * If this is a Remote object, need to replace it
075: * with a corresponding RemoteRef instance to be sent
076: * over the pipe. IxcInputStream will convert the
077: * incoming RemoteRef instance to the stub.
078: *
079: * If this object is already a stub, just send
080: * the RemoteRef used to create that stub.
081: * Else, record this Remote instance in
082: * the ExportedObject table, and send out the
083: * RemoteRef given from the ExportedObject.
084: **/
085: if (nextObject instanceof StubObject) { // is it a stub?
086: nextObject = ((StubObject) nextObject).remoteRef;
087: } else {
088: //System.out.println("@@implicit export at marshallObject");
089: ExportedObject eo = ExportedObject
090: .registerExportedObject((Remote) nextObject,
091: context);
092:
093: nextObject = eo.getRemoteRef();
094: }
095: } else if (nextObject == null) {
096: nextObject = nullObject;
097: }
098:
099: return nextObject;
100: }
101: }
|