01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.client;
17:
18: import java.io.Externalizable;
19: import java.io.IOException;
20: import java.io.ObjectInput;
21: import java.io.ObjectOutput;
22: import java.io.ObjectStreamException;
23:
24: public class EJBHomeProxyHandle implements Externalizable {
25:
26: public static ThreadLocal<Resolver> resolver = new DefaultedThreadLocal<Resolver>(
27: new ClientSideResovler());
28:
29: EJBHomeHandler handler;
30:
31: public EJBHomeProxyHandle() {
32: }
33:
34: public EJBHomeProxyHandle(EJBHomeHandler handler) {
35: this .handler = handler;
36: }
37:
38: public void writeExternal(ObjectOutput out) throws IOException {
39: // write out the version of the serialized data for future use
40: out.writeByte(1);
41:
42: handler.client.writeExternal(out);
43:
44: EJBMetaDataImpl ejb = handler.ejb;
45: out.writeObject(ejb.homeClass);
46: out.writeObject(ejb.remoteClass);
47: out.writeObject(ejb.keyClass);
48: out.writeByte(ejb.type);
49: out.writeUTF(ejb.deploymentID);
50: out.writeShort(ejb.deploymentCode);
51: handler.server.writeExternal(out);
52: /// out.writeObject( handler.primaryKey );
53: }
54:
55: public void readExternal(ObjectInput in) throws IOException,
56: ClassNotFoundException {
57: byte version = in.readByte(); // future use
58:
59: ClientMetaData client = new ClientMetaData();
60: EJBMetaDataImpl ejb = new EJBMetaDataImpl();
61: ServerMetaData server = new ServerMetaData();
62:
63: client.readExternal(in);
64:
65: ejb.homeClass = (Class) in.readObject();
66: ejb.remoteClass = (Class) in.readObject();
67: ejb.keyClass = (Class) in.readObject();
68: ejb.type = in.readByte();
69: ejb.deploymentID = in.readUTF();
70: ejb.deploymentCode = in.readShort();
71:
72: server.readExternal(in);
73: handler = EJBHomeHandler.createEJBHomeHandler(ejb, server,
74: client);
75: }
76:
77: private Object readResolve() throws ObjectStreamException {
78: return resolver.get().resolve(handler);
79: }
80:
81: public static interface Resolver {
82: Object resolve(EJBHomeHandler handler);
83: }
84:
85: public static class ClientSideResovler implements Resolver {
86: public Object resolve(EJBHomeHandler handler) {
87: handler.ejb.ejbHomeProxy = handler.createEJBHomeProxy();
88: return handler.ejb.ejbHomeProxy;
89: }
90: }
91: }
|