1 28 29 package com.caucho.ejb.hessian; 30 31 import com.caucho.java.WorkDir; 32 import com.caucho.hessian.io.AbstractHessianInput; 33 import com.caucho.hessian.io.HessianOutput; 34 import com.caucho.hessian.io.HessianRemoteResolver; 35 import com.caucho.hessian.io.HessianSerializerInput; 36 import com.caucho.server.util.CauchoSystem; 37 import com.caucho.vfs.Path; 38 import com.caucho.vfs.Vfs; 39 40 import java.io.IOException ; 41 import java.io.InputStream ; 42 import java.io.OutputStream ; 43 44 57 58 public class HessianStubFactory implements HessianRemoteResolver { 59 private HessianRemoteResolver _resolver; 60 private Path _workPath; 61 62 public HessianStubFactory() 63 { 64 _resolver = this; 65 } 66 67 70 public HessianRemoteResolver getRemoteResolver() 71 { 72 return _resolver; 73 } 74 75 public void setWorkPath(Path path) 76 { 77 _workPath = path; 78 } 79 80 public Path getWorkPath() 81 { 82 if (_workPath != null) 83 return _workPath; 84 else 85 return WorkDir.getLocalWorkDir(); 86 } 87 88 102 public Object create(Class api, String url) 103 throws Exception 104 { 105 StubGenerator gen = new StubGenerator(); 106 gen.setClassDir(getWorkPath().lookup("ejb")); 107 108 Class cl = gen.createStub(api); 109 110 HessianStub stub = (HessianStub) cl.newInstance(); 111 112 stub._hessian_setURLPath(Vfs.lookup(url)); 113 stub._hessian_setClientContainer(this); 114 115 return stub; 116 } 117 118 public AbstractHessianInput getHessianInput(InputStream is) 119 { 120 AbstractHessianInput in = new HessianSerializerInput(is); 121 in.setRemoteResolver(_resolver); 122 123 return in; 124 } 125 126 public HessianOutput getHessianOutput(OutputStream os) 127 { 128 return new HessianWriter(os); 129 } 130 131 134 public Object lookup(String type, String url) 135 throws IOException 136 { 137 try { 138 Class api = CauchoSystem.loadClass(type); 139 140 return create(api, url); 141 } catch (Exception e) { 142 throw new IOException (String.valueOf(e)); 143 } 144 } 145 } 146 | Popular Tags |