001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.client;
017:
018: import java.io.IOException;
019: import java.io.ObjectInput;
020: import java.io.ObjectOutput;
021: import java.rmi.RemoteException;
022:
023: import javax.ejb.EJBHome;
024:
025: public class EJBHomeHandle implements java.io.Externalizable,
026: javax.ejb.HomeHandle {
027:
028: protected transient EJBHomeProxy ejbHomeProxy;
029: protected transient EJBHomeHandler handler;
030:
031: public EJBHomeHandle() {
032: }
033:
034: public EJBHomeHandle(EJBHomeProxy proxy) {
035: this .ejbHomeProxy = proxy;
036: this .handler = ejbHomeProxy.getEJBHomeHandler();
037: }
038:
039: protected void setEJBHomeProxy(EJBHomeProxy ejbHomeProxy) {
040: this .ejbHomeProxy = ejbHomeProxy;
041: this .handler = ejbHomeProxy.getEJBHomeHandler();
042: }
043:
044: public EJBHome getEJBHome() throws RemoteException {
045: return ejbHomeProxy;
046: }
047:
048: public void writeExternal(ObjectOutput out) throws IOException {
049: // write out the version of the serialized data for future use
050: out.writeByte(1);
051:
052: handler.client.writeExternal(out);
053:
054: EJBMetaDataImpl ejb = handler.ejb;
055: out.writeObject(getClassName(ejb.homeClass));
056: out.writeObject(getClassName(ejb.remoteClass));
057: out.writeObject(getClassName(ejb.keyClass));
058: out.writeByte(ejb.type);
059: out.writeUTF(ejb.deploymentID);
060: out.writeShort(ejb.deploymentCode);
061: handler.server.writeExternal(out);
062: }
063:
064: public void readExternal(ObjectInput in) throws IOException,
065: ClassNotFoundException {
066: byte version = in.readByte(); // future use
067:
068: ClientMetaData client = new ClientMetaData();
069: EJBMetaDataImpl ejb = new EJBMetaDataImpl();
070: ServerMetaData server = new ServerMetaData();
071:
072: client.readExternal(in);
073:
074: ClassLoader classLoader = Thread.currentThread()
075: .getContextClassLoader();
076: if (classLoader == null) {
077: classLoader = this .getClass().getClassLoader();
078: }
079:
080: ejb.homeClass = loadClass(classLoader, (String) in.readObject());
081: ejb.remoteClass = loadClass(classLoader, (String) in
082: .readObject());
083: ejb.keyClass = loadClass(classLoader, (String) in.readObject());
084: ejb.type = in.readByte();
085: ejb.deploymentID = in.readUTF();
086: ejb.deploymentCode = in.readShort();
087:
088: server.readExternal(in);
089:
090: handler = EJBHomeHandler.createEJBHomeHandler(ejb, server,
091: client);
092: ejbHomeProxy = handler.createEJBHomeProxy();
093: }
094:
095: private static String getClassName(Class clazz) {
096: return (clazz == null) ? null : clazz.getName();
097: }
098:
099: private static Class loadClass(ClassLoader classLoader,
100: String homeClassName) throws ClassNotFoundException {
101: return (homeClassName == null) ? null : Class.forName(
102: homeClassName, true, classLoader);
103: }
104: }
|