1 27 28 package org.objectweb.fractal.rmi.io; 29 30 import org.objectweb.fractal.api.Interface; 31 32 import org.objectweb.jonathan.apis.binding.NamingContext; 33 import org.objectweb.jonathan.apis.binding.Reference; 34 35 import java.io.IOException ; 36 import java.io.ObjectOutputStream ; 37 import java.io.OutputStream ; 38 39 43 44 public class RmiObjectOutputStream extends ObjectOutputStream { 45 46 50 51 protected NamingContext domain; 52 53 61 62 public RmiObjectOutputStream ( 63 final OutputStream os, 64 final NamingContext domain) throws IOException 65 { 66 super(os); 67 enableReplaceObject(true); 68 this.domain = domain; 69 String codeBase = System.getProperty("java.rmi.server.codebase"); 70 writeUTF(codeBase == null ? "" : codeBase); 71 } 72 73 89 90 protected Object replaceObject (final Object obj) throws IOException { 91 if (obj instanceof Interface) { 92 try { 93 Ref ref = new Ref(); 94 ref.type = obj.getClass().getInterfaces()[0].getName(); 95 if (obj instanceof Reference) { 96 ref.id = ((Reference)obj).getIdentifiers()[0].encode(); 97 } else { 98 ref.id = domain.export(obj, null).encode(); 99 } 100 return ref; 101 } catch (Exception e) { 102 throw new IOException ("Cannot export object: " + e); 103 } 104 } 105 return obj; 106 } 107 108 113 114 protected void drain () throws IOException { 115 super.drain(); 116 } 117 } 118 | Popular Tags |