KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > burlap > BurlapHomeHandle


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.burlap;
30
31 import com.caucho.ejb.RemoteExceptionWrapper;
32 import com.caucho.ejb.protocol.AbstractHomeHandle;
33
34 import javax.ejb.EJBHome JavaDoc;
35 import java.rmi.RemoteException JavaDoc;
36
37 /**
38  * Implementation for a home handle.
39  */

40 public class BurlapHomeHandle extends AbstractHomeHandle {
41   private String JavaDoc _url;
42   private transient EJBHome JavaDoc _home;
43
44   /**
45    * Null arg constructor for serialization.
46    */

47   public BurlapHomeHandle() {}
48
49   /**
50    * Creates a new HomeHandle.
51    *
52    * @param url the url for the bean
53    */

54   public BurlapHomeHandle(String JavaDoc url)
55   {
56     _url = url;
57   }
58
59   /**
60    * Creates a new HomeHandle.
61    *
62    * @param url the url for the bean
63    */

64   public BurlapHomeHandle(EJBHome JavaDoc home, String JavaDoc url)
65   {
66     _url = url;
67
68     _home = home;
69   }
70
71   /**
72    * Returns the handle's server id.
73    */

74   public String JavaDoc getServerId()
75   {
76     return _url;
77   }
78   
79   /**
80    * Returns the EJBHome object associated with the handle.
81    */

82   public EJBHome JavaDoc getEJBHome()
83     throws RemoteException JavaDoc
84   {
85     if (_home == null) {
86       try {
87         _home = BurlapClientContainer.find(_url).getHomeStub();
88       } catch (Exception JavaDoc e) {
89         throw RemoteExceptionWrapper.create(e);
90       }
91     }
92     
93     return _home;
94   }
95
96   /**
97    * Returns the URL for a particular protocol.
98    */

99   public String JavaDoc getURL(String JavaDoc protocol)
100   {
101     return _url;
102   }
103
104   /**
105    * Returns the full URL
106    */

107   public String JavaDoc getURL()
108   {
109     return _url;
110   }
111
112   /**
113    * Returns true if the test handle refers to the same object.
114    * In this implementation, the handles are identical iff the urls
115    * are identical.
116    */

117   public boolean equals(Object JavaDoc b)
118   {
119     if (! (b instanceof BurlapHomeHandle))
120       return false;
121
122     BurlapHomeHandle handle = (BurlapHomeHandle) b;
123
124     return _url.equals(handle._url);
125   }
126
127   /**
128    * The handle's hashcode is the same as the url's hashcode
129    */

130   public int hashCode()
131   {
132     return _url.hashCode();
133   }
134
135   /**
136    * The printed representation of the handle is the url.
137    */

138   public String JavaDoc toString()
139   {
140     return _url;
141   }
142 }
143
Popular Tags