KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > HomeFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: HomeFactory.java,v 1.13 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.container;
28
29 import java.util.Hashtable JavaDoc;
30
31 import javax.naming.Context JavaDoc;
32 import javax.naming.Name JavaDoc;
33 import javax.naming.Reference JavaDoc;
34 import javax.naming.spi.ObjectFactory JavaDoc;
35
36 import org.objectweb.util.monolog.api.BasicLevel;
37
38 /**
39  * This Factory return Home or LocalHome objects to clients.
40  * No need to use it in case of RMI Remote Home because Remote References are
41  * registered directly in JNDI.
42  * This class should be used only for local Home or ServiceEndpointHome
43  * @author Guillaume Riviere (Inria)
44  */

45 public class HomeFactory implements ObjectFactory JavaDoc {
46
47     /**
48      * Used in case of local Home or ServiceEndpointHome
49      * @param refObj - The possibly null object containing location or reference
50      * information that can be used in creating an object.
51      * @param name - The name of this object relative to nameCtx, or null if no name is specified.
52      * @param nameCtx - The context relative to which the name parameter is specified,
53      * or null if name is relative to the default initial context.
54      * @param env - The possibly null environment that is used in creating the object.
55      * @return ServiceEndpointHome or LocalHome object
56      * @throws Exception - if this object factory encountered an exception while attempting
57      * to create an object, and no other object factories are to be tried.
58      */

59     public Object JavaDoc getObjectInstance(Object JavaDoc refObj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc env) throws Exception JavaDoc {
60         Reference JavaDoc ref = (Reference JavaDoc) refObj;
61         String JavaDoc clname = ref.getClassName();
62
63         if (TraceEjb.isDebugIc()) {
64             TraceEjb.interp.log(BasicLevel.DEBUG, clname);
65         }
66
67         if (clname.equals("org.objectweb.jonas_ejb.container.JLocalHome")) {
68             // Local Home
69
String JavaDoc beanName = (String JavaDoc) ref.get("bean.name").getContent();
70             JLocalHome localhome = JLocalHome.getLocalHome(beanName);
71             if (localhome == null) {
72                 TraceEjb.logger.log(BasicLevel.ERROR, "cannot get " + beanName);
73             }
74             return localhome;
75         } else if (clname.equals("org.objectweb.jonas_ejb.container.JServiceEndpointHome")) {
76             // Service Endpoint Home
77
String JavaDoc beanName = (String JavaDoc) ref.get("bean.name").getContent();
78             JServiceEndpointHome sehome = JServiceEndpointHome.getSEHome(beanName);
79             if (sehome == null) {
80                 TraceEjb.logger.log(BasicLevel.ERROR, "cannot get " + beanName);
81             }
82             return sehome;
83         } else {
84             TraceEjb.logger.log(BasicLevel.ERROR, "bad class name: " + clname);
85         }
86         // not found !
87
return null;
88     }
89 }
90
Popular Tags