KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > portable > EJBMetaDataImpl


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 package com.sun.ejb.portable;
24
25 import java.io.*;
26 import javax.ejb.*;
27 import javax.rmi.PortableRemoteObject JavaDoc;
28
29 /**
30  * A portable, Serializable implementation of EJBMetaData.
31  * This class can potentially be instantiated in another vendor's container
32  * so it must not refer to any non-portable RI-specific classes.
33  *
34  */

35
36 public final class EJBMetaDataImpl implements javax.ejb.EJBMetaData JavaDoc, Serializable
37 {
38     private Class JavaDoc keyClass;
39     private Class JavaDoc homeClass;
40     private Class JavaDoc remoteClass;
41     private boolean isSessionBean;
42     private boolean isStatelessSessionBean;
43     private HomeHandle homeHandle;
44
45     // Dont serialize the EJBHome ref directly, use the HomeHandle
46
transient private EJBHome ejbHomeStub;
47
48
49     // this constructor is only called in the RI's EJB container
50
public EJBMetaDataImpl(EJBHome ejbHomeStub, Class JavaDoc homeClass,
51            Class JavaDoc remoteClass, Class JavaDoc keyClass,
52            boolean isSessionBean, boolean isStatelessSessionBean)
53     {
54     this.ejbHomeStub = ejbHomeStub;
55     this.homeHandle = new HomeHandleImpl(ejbHomeStub);
56     this.keyClass = keyClass;
57     this.homeClass = homeClass;
58     this.remoteClass = remoteClass;
59     this.isSessionBean = isSessionBean;
60     this.isStatelessSessionBean = isStatelessSessionBean;
61     }
62
63
64     /**
65      *
66      */

67     public Class JavaDoc getHomeInterfaceClass()
68     {
69     return homeClass;
70     }
71
72     /**
73      *
74      */

75     public Class JavaDoc getRemoteInterfaceClass()
76     {
77     return remoteClass;
78     }
79
80     /**
81      *
82      */

83     public EJBHome getEJBHome()
84     {
85     return ejbHomeStub;
86     }
87
88     /**
89      *
90      */

91     public Class JavaDoc getPrimaryKeyClass()
92     {
93     if ( keyClass == null ) {
94         // for SessionBeans there is no primary key
95
throw new RuntimeException JavaDoc("SessionBeans do not have a primary key");
96     }
97     return keyClass;
98     }
99
100     /**
101      *
102      */

103     public boolean isSession()
104     {
105     return isSessionBean;
106     }
107
108
109     public boolean isStatelessSession()
110     {
111     return isStatelessSessionBean;
112     }
113
114
115     private void readObject(ObjectInputStream in)
116     throws IOException, ClassNotFoundException JavaDoc
117     {
118     isSessionBean = in.readBoolean();
119     isStatelessSessionBean = in.readBoolean();
120
121     // Use thread context classloader to load home/remote/primarykey classes
122
// See EJB2.0 spec section 18.4.4
123
ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
124     remoteClass = loader.loadClass(in.readUTF());
125     homeClass = loader.loadClass(in.readUTF());
126     if ( !isSessionBean )
127         keyClass = loader.loadClass(in.readUTF());
128
129     homeHandle = (HomeHandle)in.readObject();
130     ejbHomeStub = homeHandle.getEJBHome();
131     // narrow the home so that the application doesnt have to do
132
// a narrow after EJBMetaData.getEJBHome().
133
ejbHomeStub = (EJBHome)PortableRemoteObject.narrow(ejbHomeStub, homeClass);
134     }
135
136     private void writeObject(ObjectOutputStream out)
137     throws IOException
138     {
139     out.writeBoolean(isSessionBean);
140     out.writeBoolean(isStatelessSessionBean);
141
142     // Write the String names of the Class objects,
143
// since Class objects cant be serialized unless the classes
144
// they represent are Serializable.
145
out.writeUTF(remoteClass.getName());
146     out.writeUTF(homeClass.getName());
147     if ( !isSessionBean )
148         out.writeUTF(keyClass.getName());
149
150     out.writeObject(homeHandle);
151     }
152 }
153
Popular Tags