1 28 29 package com.caucho.ejb.hessian; 30 31 import com.caucho.ejb.EJBExceptionWrapper; 32 import com.caucho.ejb.RemoteExceptionWrapper; 33 import com.caucho.ejb.protocol.AbstractHandle; 34 import com.caucho.ejb.protocol.HandleEncoder; 35 36 import javax.ejb.EJBObject ; 37 import java.rmi.RemoteException ; 38 39 49 public class HessianHandle extends AbstractHandle { 50 private String url; 51 52 private transient String serverId; 53 private transient String objectId; 54 private transient Object objectKey; 55 private transient EJBObject object; 56 57 60 public HessianHandle() {} 61 62 65 public HessianHandle(String url) 66 { 67 this.url = url; 68 } 69 70 73 public HessianHandle(String url, Object key) 74 { 75 this.url = url; 76 this.objectKey = key; 77 } 78 79 82 public String getServerId() 83 { 84 if (serverId == null) { 85 int p = url.lastIndexOf('?'); 86 serverId = url.substring(0, p); 87 } 88 89 return serverId; 90 } 91 92 95 public String getObjectId() 96 { 97 if (objectId == null) { 98 int p = url.lastIndexOf('?'); 99 objectId = url.substring(p + 7); 100 } 101 102 return objectId; 103 } 104 105 void setEJBObject(EJBObject obj) 106 { 107 this.object = obj; 108 } 109 110 public EJBObject getEJBObject() 111 throws RemoteException 112 { 113 if (object == null) { 114 try { 115 HessianClientContainer client; 116 client = HessianClientContainer.find(getServerId()); 117 object = client.createObjectStub(url); 118 } catch (Exception e) { 119 throw RemoteExceptionWrapper.create(e); 120 } 121 } 122 123 return object; 124 } 125 126 129 public Object getObjectKey() 130 { 131 if (objectKey == null) { 132 try { 133 HandleEncoder encoder = HessianClientContainer.find(getServerId()).getHandleEncoder(); 134 objectKey = encoder.objectIdToKey(getObjectId()); 135 } catch (Exception e) { 136 throw new EJBExceptionWrapper(e); 137 } 138 } 139 140 return objectKey; 141 } 142 143 146 public String getURL() 147 { 148 return url; 149 } 150 151 154 public String getURL(String protocol) 155 { 156 return url; 157 } 158 159 162 public int hashCode() 163 { 164 return url.hashCode(); 165 } 166 167 170 public boolean equals(Object obj) 171 { 172 if (! (obj instanceof HessianHandle)) 173 return false; 174 175 HessianHandle handle = (HessianHandle) obj; 176 177 return url.equals(handle.url); 178 } 179 180 183 public String toString() 184 { 185 return url; 186 } 187 } 188 | Popular Tags |