01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 6673 2005-04-28 16:53:00Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.jonas_ejb.container;
25:
26: import java.util.Hashtable;
27:
28: import javax.naming.Context;
29: import javax.naming.Name;
30: import javax.naming.Reference;
31: import javax.naming.spi.ObjectFactory;
32:
33: import org.objectweb.util.monolog.api.BasicLevel;
34:
35: /**
36: * This Factory return Home or LocalHome objects to clients.
37: * No need to use it in case of RMI Remote Home because Remote References are
38: * registered directly in JNDI.
39: * This class should be used only for local Home or ServiceEndpointHome
40: * @author Guillaume Riviere (Inria)
41: */
42: public class HomeFactory implements ObjectFactory {
43:
44: /**
45: * Used in case of local Home or ServiceEndpointHome
46: * @param refObj - The possibly null object containing location or reference
47: * information that can be used in creating an object.
48: * @param name - The name of this object relative to nameCtx, or null if no name is specified.
49: * @param nameCtx - The context relative to which the name parameter is specified,
50: * or null if name is relative to the default initial context.
51: * @param env - The possibly null environment that is used in creating the object.
52: * @return ServiceEndpointHome or LocalHome object
53: * @throws Exception - if this object factory encountered an exception while attempting
54: * to create an object, and no other object factories are to be tried.
55: */
56: public Object getObjectInstance(Object refObj, Name name,
57: Context nameCtx, Hashtable env) throws Exception {
58: Reference ref = (Reference) refObj;
59: String clname = ref.getClassName();
60:
61: if (TraceEjb.isDebugIc()) {
62: TraceEjb.interp.log(BasicLevel.DEBUG, clname);
63: }
64:
65: if (clname
66: .equals("org.objectweb.jonas_ejb.container.JLocalHome")) {
67: // Local Home
68: String beanName = (String) ref.get("bean.name")
69: .getContent();
70: JLocalHome localhome = JLocalHome.getLocalHome(beanName);
71: if (localhome == null) {
72: TraceEjb.logger.log(BasicLevel.ERROR, "cannot get "
73: + beanName);
74: }
75: return localhome;
76: } else if (clname
77: .equals("org.objectweb.jonas_ejb.container.JServiceEndpointHome")) {
78: // Service Endpoint Home
79: String beanName = (String) ref.get("bean.name")
80: .getContent();
81: JServiceEndpointHome sehome = JServiceEndpointHome
82: .getSEHome(beanName);
83: if (sehome == null) {
84: TraceEjb.logger.log(BasicLevel.ERROR, "cannot get "
85: + beanName);
86: }
87: return sehome;
88: } else {
89: TraceEjb.logger.log(BasicLevel.ERROR, "bad class name: "
90: + clname);
91: }
92: // not found !
93: return null;
94: }
95: }
|