KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 package com.caucho.ejb.protocol;
28
29 import com.caucho.ejb.AbstractEJBObject;
30 import com.caucho.ejb.AbstractServer;
31
32 import javax.ejb.EJBHome JavaDoc;
33 import javax.ejb.EJBMetaData JavaDoc;
34 import javax.ejb.Handle JavaDoc;
35 import javax.ejb.HomeHandle JavaDoc;
36 import javax.ejb.RemoveException JavaDoc;
37 import java.rmi.RemoteException JavaDoc;
38
39 /**
40  * Interface for stubs inside the same JVM.
41  */

42 public abstract class JVMHome extends AbstractEJBObject implements EJBHome JavaDoc {
43   protected AbstractServer _server;
44   protected Object JavaDoc _object;
45
46   /**
47    * Initialization code.
48    */

49   void _init(AbstractServer server)
50   {
51     _server = server;
52   }
53   
54   /**
55    * Returns the implemented class.
56    */

57   public Class JavaDoc getAPIClass()
58   {
59     return getServer().getRemoteHomeClass();
60   }
61
62   /**
63    * Returns the URL
64    */

65   public String JavaDoc getURL(String JavaDoc protocol)
66   {
67     return getServer().getHandleEncoder(protocol).getServerId();
68   }
69   
70   /**
71    * Returns the serializable handle for the remote object
72    */

73   public HomeHandle JavaDoc getHomeHandle()
74     throws RemoteException JavaDoc
75   {
76     return getServer().getHomeHandle();
77   }
78
79   /**
80    * Returns the remote view of the object
81    */

82   protected Object JavaDoc _caucho_getObject()
83     throws RemoteException JavaDoc
84   {
85     if (_server == null || _server.isDead()) {
86       _object = null;
87       _server = getServer();
88     }
89
90     if (_object == null) {
91       _object = _server.getHomeObject();
92
93       if (_object == null)
94         throw new RemoteException JavaDoc("missing home object");
95
96       _caucho_init_methods(_object.getClass());
97     }
98
99     return _object;
100   }
101
102   protected void _caucho_init_methods(Class JavaDoc cl)
103   {
104   }
105
106   /**
107    * Returns the server's class loader
108    */

109   protected ClassLoader JavaDoc _caucho_getClassLoader()
110     throws RemoteException JavaDoc
111   {
112     return getServer().getClassLoader();
113   }
114
115   public EJBMetaData JavaDoc getEJBMetaData()
116   {
117     return getServer().getEJBMetaData();
118   }
119
120   /**
121    * Returns the currently active server. The server can change over time
122    * because of class reloading.
123    */

124   private AbstractServer getServer()
125   {
126     if (_server.isDead()) {
127       String JavaDoc serverId = _server.getHandleServerId();
128       
129       _object = null;
130       _server = EjbProtocolManager.getJVMServer(serverId);
131     }
132
133     return _server;
134   }
135
136   public void remove(Object JavaDoc o)
137     throws RemoveException JavaDoc, RemoteException JavaDoc
138   {
139   }
140
141   public void remove(Handle JavaDoc handle)
142     throws RemoveException JavaDoc, RemoteException JavaDoc
143   {
144   }
145 }
146
Popular Tags