KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > ejb > ReadOnlyBeanHelper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.appserv.ejb;
25
26 import java.rmi.RemoteException JavaDoc;
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import com.sun.ejb.containers.ReadOnlyEJBLocalHome;
32 import com.sun.ejb.containers.ReadOnlyEJBHome;
33
34 import com.sun.ejb.containers.ReadOnlyBeanNotifierImpl;
35
36 import java.util.logging.*;
37 import com.sun.logging.*;
38
39 /**
40  * Class that is used to obtain ReadOnlyBeanNotifier
41  * and ReadOnlyBeanLocalNotifier.
42  *
43  * @author Mahesh Kannan
44  */

45 public class ReadOnlyBeanHelper {
46
47     protected static Logger _logger;
48
49     static {
50         _logger=LogDomains.getLogger(LogDomains.EJB_LOGGER);
51     }
52
53     public static ReadOnlyBeanNotifier getReadOnlyBeanNotifier(String JavaDoc ejbName) {
54         try {
55             Context JavaDoc ctx = new InitialContext JavaDoc();
56             Object JavaDoc obj = ctx.lookup(ejbName);
57             ReadOnlyEJBHome home = (ReadOnlyEJBHome)
58                 PortableRemoteObject.narrow(obj, ReadOnlyEJBHome.class);
59             return new ReadOnlyBeanNotifierImpl(home);
60         } catch (Exception JavaDoc ex) {
61             if(_logger.isLoggable(Level.SEVERE)) {
62                 _logger.log(Level.SEVERE, "ejb.remote_exception", ex);
63             }
64         }
65         return null;
66     }
67
68     public static ReadOnlyBeanLocalNotifier getReadOnlyBeanLocalNotifier(
69             String JavaDoc ejbName)
70     {
71         try {
72             Context JavaDoc ctx = new InitialContext JavaDoc();
73             ReadOnlyEJBLocalHome home =
74                 (ReadOnlyEJBLocalHome) ctx.lookup(ejbName);
75             return home.getReadOnlyBeanLocalNotifier();
76         } catch (Exception JavaDoc ex) {
77             if(_logger.isLoggable(Level.SEVERE)) {
78                 _logger.log(Level.SEVERE, "ejb.remote_exception",ex);
79             }
80         }
81         return null;
82     }
83
84 }
85
86
Popular Tags