KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > proxy > ejb > handle > HomeHandleImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.proxy.ejb.handle;
23
24 import javax.ejb.HomeHandle JavaDoc;
25 import javax.ejb.EJBHome JavaDoc;
26
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import java.rmi.ServerException JavaDoc;
30 import java.rmi.RemoteException JavaDoc;
31 import java.io.ObjectStreamField JavaDoc;
32 import java.io.ObjectInputStream JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.ObjectOutputStream JavaDoc;
35 import java.util.Hashtable JavaDoc;
36 import org.jboss.naming.NamingContextFactory;
37
38
39 /**
40  * An EJB home handle implementation.
41  *
42  * @author <a HREF="mailto:marc.fleury@jboss.org">Marc Fleury</a>.
43  * @author Scott.Stark@jboss.org
44  * @version $Revision: 37459 $
45  */

46 public class HomeHandleImpl
47       implements HomeHandle JavaDoc
48 {
49    // Constants -----------------------------------------------------
50

51    /** Serial Version Identifier. */
52    static final long serialVersionUID = 208629381571948124L;
53    /** The persistent field defintions */
54    private static final ObjectStreamField JavaDoc[] serialPersistentFields =
55       new ObjectStreamField JavaDoc[]
56    {
57       new ObjectStreamField JavaDoc("jndiName", String JavaDoc.class),
58       new ObjectStreamField JavaDoc("jndiEnv", Hashtable JavaDoc.class)
59    };
60
61    /** The JNDI name of the home inteface binding */
62    private String JavaDoc jndiName;
63    /** The JNDI env in effect when the home handle was created */
64    private Hashtable JavaDoc jndiEnv;
65
66    // Static --------------------------------------------------------
67

68    // Constructors --------------------------------------------------
69

70    /**
71     * Construct a <tt>HomeHandleImpl</tt>.
72     *
73     * @param handle The initial context handle that will be used
74     * to restore the naming context or null to use
75     * a fresh InitialContext object.
76     * @param name JNDI name.
77     */

78    public HomeHandleImpl(String JavaDoc jndiName)
79    {
80       this.jndiName = jndiName;
81       this.jndiEnv = (Hashtable JavaDoc) NamingContextFactory.lastInitialContextEnv.get();
82    }
83
84    // Public --------------------------------------------------------
85

86    // Handle implementation -----------------------------------------
87

88    /**
89     * HomeHandle implementation.
90     *
91     * @return <tt>EJBHome</tt> reference.
92     *
93     * @throws ServerException Could not get EJBObject.
94     * @throws RemoteException
95     */

96    public EJBHome JavaDoc getEJBHome() throws RemoteException JavaDoc
97    {
98       try
99       {
100          InitialContext JavaDoc ic = null;
101          if( jndiEnv != null )
102             ic = new InitialContext JavaDoc(jndiEnv);
103          else
104             ic = new InitialContext JavaDoc();
105          EJBHome JavaDoc home = (EJBHome JavaDoc) ic.lookup(jndiName);
106          return home;
107       }
108       catch (NamingException JavaDoc e)
109       {
110          throw new ServerException JavaDoc("Could not get EJBHome", e);
111       }
112    }
113
114    /**
115     * @return the jndi name
116     */

117    public String JavaDoc getJNDIName()
118    {
119       return jndiName;
120    }
121
122    private void readObject(ObjectInputStream JavaDoc ois)
123       throws IOException JavaDoc, ClassNotFoundException JavaDoc
124    {
125       ObjectInputStream.GetField JavaDoc getField = ois.readFields();
126       jndiName = (String JavaDoc) getField.get("jndiName", null);
127       jndiEnv = (Hashtable JavaDoc) getField.get("jndiEnv", null);
128    }
129
130    private void writeObject(ObjectOutputStream JavaDoc oos)
131       throws IOException JavaDoc
132    {
133       ObjectOutputStream.PutField JavaDoc putField = oos.putFields();
134       putField.put("jndiName", jndiName);
135       putField.put("jndiEnv", jndiEnv);
136       oos.writeFields();
137    }
138 }
139
140
Popular Tags