KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > RemoteBusinessWrapperBase


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.ejb.containers;
25
26 import java.rmi.Remote JavaDoc;
27
28 import java.io.ObjectInputStream JavaDoc;
29 import java.io.WriteAbortedException JavaDoc;
30 import java.io.ObjectStreamException JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 import com.sun.ejb.EJBUtils;
34
35 public class RemoteBusinessWrapperBase
36     implements java.io.Serializable JavaDoc {
37
38     // This is the name of the developer-written business interface.
39
private String JavaDoc businessInterface_;
40
41     private Remote JavaDoc stub_;
42     
43     private transient int hashCode_;
44
45     public RemoteBusinessWrapperBase(Remote JavaDoc stub, String JavaDoc busIntf) {
46         stub_ = stub;
47         businessInterface_ = busIntf;
48         this.hashCode_ = busIntf.hashCode();
49     }
50
51     public Remote JavaDoc getStub() {
52         return stub_;
53     }
54     
55     public int hashCode() {
56         return hashCode_;
57     }
58
59     public boolean equals(Object JavaDoc obj) {
60         
61         boolean result = (obj == this); //Most efficient
62
if ((result == false) && (obj != null)) { //Do elaborate checks
63
if (obj instanceof RemoteBusinessWrapperBase) {
64                 RemoteBusinessWrapperBase remoteBWB =
65                         (RemoteBusinessWrapperBase) obj;
66                 boolean hasSameBusinessInterface =
67                         (remoteBWB.hashCode_ == hashCode_) &&
68                         remoteBWB.businessInterface_.equals(businessInterface_);
69                 if (hasSameBusinessInterface) {
70                     org.omg.CORBA.Object JavaDoc other = (org.omg.CORBA.Object JavaDoc) remoteBWB.stub_;
71                     org.omg.CORBA.Object JavaDoc me = (org.omg.CORBA.Object JavaDoc) stub_;
72                     result = me._is_equivalent(other);
73                 }
74             }
75         }
76         
77         return result;
78     }
79     
80     public String JavaDoc getBusinessInterfaceName() {
81         return businessInterface_;
82     }
83
84     public Object JavaDoc writeReplace() throws ObjectStreamException JavaDoc {
85         return new RemoteBusinessWrapperBase(stub_, businessInterface_);
86     }
87
88     private void writeObject(java.io.ObjectOutputStream JavaDoc oos)
89         throws java.io.IOException JavaDoc
90     {
91
92         oos.writeObject(businessInterface_);
93         oos.writeObject(stub_);
94
95     }
96
97     private void readObject(ObjectInputStream JavaDoc ois)
98         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
99
100         try {
101
102             businessInterface_ = (String JavaDoc) ois.readObject();
103             hashCode_ = businessInterface_.hashCode();
104
105             EJBUtils.loadGeneratedRemoteBusinessClasses(businessInterface_);
106
107             stub_ = (Remote JavaDoc) ois.readObject();
108
109         } catch(Exception JavaDoc e) {
110             IOException JavaDoc ioe = new IOException JavaDoc("RemoteBusinessWrapper.readObj "
111                                               + " error");
112             ioe.initCause(e);
113             throw ioe;
114         }
115     }
116                  
117     public Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
118
119         try {
120
121             return EJBUtils.createRemoteBusinessObject(businessInterface_,
122                                                        stub_);
123         } catch(Exception JavaDoc e) {
124             WriteAbortedException JavaDoc wae = new WriteAbortedException JavaDoc
125                 ("RemoteBusinessWrapper.readResolve error", e);
126             wae.initCause(e);
127             throw wae;
128         }
129
130     }
131                 
132
133
134
135 }
136
137
Popular Tags