KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > lib > impl > AbstractEJBProxy


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.lib.impl;
16
17 import java.rmi.RemoteException JavaDoc;
18
19 import org.apache.hivemind.lib.NameLookup;
20 import org.apache.hivemind.lib.RemoteExceptionCoordinator;
21
22 /**
23  * Generic EJB proxy for stateless session beans. Acts as an InvocationHandler
24  * for a dynamic proxy.
25  *
26  * @author Howard Lewis Ship
27  */

28 public abstract class AbstractEJBProxy
29 {
30     private NameLookup _nameLookup;
31     private RemoteExceptionCoordinator _coordinator;
32
33     protected AbstractEJBProxy(NameLookup nameLookup, RemoteExceptionCoordinator coordinator)
34     {
35         _nameLookup = nameLookup;
36         _coordinator = coordinator;
37     }
38
39     protected Object JavaDoc _lookup(String JavaDoc name)
40     {
41         return _nameLookup.lookup(name, Object JavaDoc.class);
42     }
43
44     /**
45      * Clears the home and remote objects after any remote exception.
46      */

47
48     protected abstract void _clearCachedReferences();
49     
50     /**
51      * Invoked by the fabricated subclass when a remote exception occurs.
52      * This notifies the {@link RemoteExceptionCoordinator} (which, indirectly,
53      * allows the {@link NameLookup} service to release its JNDI context).
54      * In addition, {@link #_clearCachedReferences()} is invoked.
55      */

56     protected void _handleRemoteException(RemoteException JavaDoc ex)
57     {
58         _clearCachedReferences();
59         _coordinator.fireRemoteExceptionDidOccur(this, ex);
60     }
61 }
62
Popular Tags