01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.cmp2.cmrstress.interfaces;
23:
24: import javax.naming.InitialContext;
25: import javax.naming.NamingException;
26: import javax.rmi.PortableRemoteObject;
27:
28: /**
29: * Utility class for Parent.
30: */
31: public class ParentUtil {
32: /** Cached remote home (EJBHome). Uses lazy loading to obtain its value (loaded by getHome() methods). */
33: private static ParentHome cachedRemoteHome = null;
34:
35: /** Cached local home (EJBLocalHome). Uses lazy loading to obtain its value (loaded by getLocalHome() methods). */
36: private static ParentLocalHome cachedLocalHome = null;
37:
38: // Home interface lookup methods
39:
40: /**
41: * Obtain remote home interface from default initial context
42: * @return Home interface for Parent. Lookup using JNDI_NAME
43: */
44: public static ParentHome getHome() throws NamingException {
45: if (cachedRemoteHome == null) {
46: // Obtain initial context
47: InitialContext initialContext = new InitialContext();
48: try {
49: java.lang.Object objRef = initialContext
50: .lookup(ParentHome.JNDI_NAME);
51: cachedRemoteHome = (ParentHome) PortableRemoteObject
52: .narrow(objRef, ParentHome.class);
53: } finally {
54: initialContext.close();
55: }
56: }
57: return cachedRemoteHome;
58: }
59:
60: /**
61: * Obtain remote home interface from parameterised initial context
62: * @param environment Parameters to use for creating initial context
63: * @return Home interface for Parent. Lookup using JNDI_NAME
64: */
65: public static ParentHome getHome(java.util.Hashtable environment)
66: throws NamingException {
67: // Obtain initial context
68: InitialContext initialContext = new InitialContext(environment);
69: try {
70: java.lang.Object objRef = initialContext
71: .lookup(ParentHome.JNDI_NAME);
72: return (ParentHome) PortableRemoteObject.narrow(objRef,
73: ParentHome.class);
74: } finally {
75: initialContext.close();
76: }
77: }
78:
79: /**
80: * Obtain local home interface from default initial context
81: * @return Local home interface for Parent. Lookup using JNDI_NAME
82: */
83: public static ParentLocalHome getLocalHome() throws NamingException {
84: // Local homes shouldn't be narrowed, as there is no RMI involved.
85: if (cachedLocalHome == null) {
86: // Obtain initial context
87: InitialContext initialContext = new InitialContext();
88: try {
89: cachedLocalHome = (ParentLocalHome) initialContext
90: .lookup(ParentLocalHome.JNDI_NAME);
91: } finally {
92: initialContext.close();
93: }
94: }
95: return cachedLocalHome;
96: }
97:
98: }
|