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.entity.interfaces;
23:
24: /**
25: * Utility class for TestEntity.
26: */
27: public class TestEntityUtil {
28:
29: // Home interface lookup methods
30:
31: /**
32: * Obtain remote home interface from default initial context
33: * @return Home interface for TestEntity. Lookup using JNDI_NAME
34: */
35: public static TestEntityHome getHome()
36: throws javax.naming.NamingException {
37: // Obtain initial context
38: javax.naming.InitialContext initialContext = new javax.naming.InitialContext();
39: try {
40: Object objRef = initialContext
41: .lookup(TestEntityHome.JNDI_NAME);
42: return (TestEntityHome) javax.rmi.PortableRemoteObject
43: .narrow(objRef, TestEntityHome.class);
44: } finally {
45: initialContext.close();
46: }
47: }
48:
49: /**
50: * Obtain remote home interface from parameterised initial context
51: * @param environment Parameters to use for creating initial context
52: * @return Home interface for TestEntity. Lookup using JNDI_NAME
53: */
54: public static TestEntityHome getHome(java.util.Hashtable environment)
55: throws javax.naming.NamingException {
56: // Obtain initial context
57: javax.naming.InitialContext initialContext = new javax.naming.InitialContext(
58: environment);
59: try {
60: Object objRef = initialContext
61: .lookup(TestEntityHome.JNDI_NAME);
62: return (TestEntityHome) javax.rmi.PortableRemoteObject
63: .narrow(objRef, TestEntityHome.class);
64: } finally {
65: initialContext.close();
66: }
67: }
68:
69: /**
70: * Obtain local home interface from default initial context
71: * @return Local home interface for TestEntity. Lookup using JNDI_NAME
72: */
73: public static TestEntityLocalHome getLocalHome()
74: throws javax.naming.NamingException {
75: // Local homes shouldn't be narrowed, as there is no RMI involved.
76: // Obtain initial context
77: javax.naming.InitialContext initialContext = new javax.naming.InitialContext();
78: try {
79: return (TestEntityLocalHome) initialContext
80: .lookup(TestEntityLocalHome.JNDI_NAME);
81: } finally {
82: initialContext.close();
83: }
84: }
85:
86: }
|