01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: /*
06: * Generated file - Do not edit!
07: */
08: package com.opensymphony.workflow.ejb;
09:
10: /**
11: * Utility class for Workflow.
12: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
13: * @author <a href="mailto:hani@formicary.net">Hani Suleiman</a>
14: * @version $Revision: 1.7 $
15: */
16: public class WorkflowHomeFactory {
17: //~ Static fields/initializers /////////////////////////////////////////////
18:
19: public static final String COMP_NAME = "java:comp/env/ejb/Workflow";
20: public static final String JNDI_NAME = "Workflow";
21:
22: /** Cached remote home (EJBHome). Uses lazy loading to obtain its value (loaded by getHome() methods). */
23: private static com.opensymphony.workflow.ejb.WorkflowHome cachedRemoteHome = null;
24:
25: //~ Methods ////////////////////////////////////////////////////////////////
26:
27: // Home interface lookup methods
28:
29: /**
30: * Obtain remote home interface from default initial context
31: * @return Home interface for Workflow. Lookup using COMP_NAME
32: */
33: public static com.opensymphony.workflow.ejb.WorkflowHome getHome()
34: throws javax.naming.NamingException {
35: if (cachedRemoteHome == null) {
36: cachedRemoteHome = (com.opensymphony.workflow.ejb.WorkflowHome) lookupHome(
37: null, COMP_NAME,
38: com.opensymphony.workflow.ejb.WorkflowHome.class);
39: }
40:
41: return cachedRemoteHome;
42: }
43:
44: /**
45: * Obtain remote home interface from parameterised initial context
46: * @param environment Parameters to use for creating initial context
47: * @return Home interface for Workflow. Lookup using COMP_NAME
48: */
49: public static com.opensymphony.workflow.ejb.WorkflowHome getHome(
50: java.util.Hashtable environment)
51: throws javax.naming.NamingException {
52: return (com.opensymphony.workflow.ejb.WorkflowHome) lookupHome(
53: environment, COMP_NAME,
54: com.opensymphony.workflow.ejb.WorkflowHome.class);
55: }
56:
57: private static Object lookupHome(java.util.Hashtable environment,
58: String jndiName, Class narrowTo)
59: throws javax.naming.NamingException {
60: // Obtain initial context
61: javax.naming.InitialContext initialContext = new javax.naming.InitialContext(
62: environment);
63:
64: try {
65: Object objRef = initialContext.lookup(jndiName);
66:
67: // only narrow if necessary
68: if (java.rmi.Remote.class.isAssignableFrom(narrowTo)) {
69: return javax.rmi.PortableRemoteObject.narrow(objRef,
70: narrowTo);
71: } else {
72: return objRef;
73: }
74: } finally {
75: initialContext.close();
76: }
77: }
78: }
|