KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > protocol > HomeHandleImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.protocol;
30
31 import javax.ejb.EJBHome JavaDoc;
32 import java.rmi.RemoteException JavaDoc;
33
34 /**
35  * Implementation for a home handle.
36  */

37 public class HomeHandleImpl extends AbstractHomeHandle {
38   protected String JavaDoc serverId;
39   protected transient EJBHome JavaDoc home;
40
41   /**
42    * Null arg constructor for serialization.
43    */

44   public HomeHandleImpl() {}
45
46   /**
47    * Creates a new HomeHandle.
48    *
49    * @param url the url for the bean
50    */

51   public HomeHandleImpl(String JavaDoc url)
52   {
53     if (url.endsWith("/"))
54       url = url.substring(url.length() - 1);
55
56     this.serverId = url;
57   }
58
59   /**
60    * Creates a new HomeHandle.
61    *
62    * @param url the url for the bean
63    */

64   public HomeHandleImpl(EJBHome JavaDoc home, String JavaDoc url)
65   {
66     this(url);
67
68     this.home = home;
69   }
70
71   public EJBHome JavaDoc getEJBHome()
72     throws RemoteException JavaDoc
73   {
74     if (home == null)
75       home = SameJVMClientContainer.find(serverId).getEJBHome();
76
77     return home;
78   }
79
80   /**
81    * Return the bean's server id.
82    */

83   public String JavaDoc getServerId()
84   {
85     return serverId;
86   }
87
88   public String JavaDoc getURL(String JavaDoc protocol)
89   {
90     return serverId;
91   }
92
93   /**
94    * Returns the hash code for the container.
95    */

96   public int hashCode()
97   {
98     return serverId.hashCode();
99   }
100
101   /**
102    * Returns true if the handle equals the object.
103    */

104   public boolean equals(Object JavaDoc o)
105   {
106     if (o == null || ! o.getClass().equals(getClass()))
107       return false;
108
109     HomeHandleImpl handle = (HomeHandleImpl) o;
110
111     return serverId.equals(handle.serverId);
112   }
113 }
114
Popular Tags