1 package ejava.util.ejb;
2
3 /**
4 * This class provides utiltity functions for working with an EJB in the JNDI
5 * tree.
6 */
7 public class EJBClient {
8 /**
9 * This method provides a convenience wrapper around the alternate
10 * getEJBLookupName() helper method. This can be used by EJB clients
11 * trying to locate EJBs that are part of a deployment that did not
12 * turn off maven version numbers in the deployment. This method assumes
13 * the EAR and EJB versions are the same value and will appropriately
14 * append the version to the EAR and EJB names when forming the
15 * jboss-ejb-client JNDI name.
16 * @param earName
17 * @param ejbModuleName
18 * @param distinctName
19 * @param ejbClassName
20 * @param remoteInterface
21 * @param version
22 * @return String jndi name that can be used for lookup
23 */
24 public static String getEJBClientLookupName(
25 String earName,
26 String ejbModuleName,
27 String distinctName,
28 String ejbClassName,
29 String remoteInterface,
30 boolean stateful,
31 String version) {
32 return getEJBClientLookupName(
33 String.format("%s-%s",earName,version),
34 String.format("%s-%s", ejbModuleName, version),
35 distinctName,
36 ejbClassName,
37 remoteInterface,
38 stateful);
39 }
40
41 /**
42 * This method returns an remote JNDI name that is usable by the
43 * jboss-ejb-client org.jboss.ejb.client.naming.ejb.ejbURLContextFactory
44 * context factory. To use this, list "org.jboss.ejb.client.naming"
45 * as one of your java.naming.factory.url.pkgs and be sure to have
46 * org.jboss:jboss-ejb-client listed as a dependency. The physical
47 * name will look like the following in JBoss:<p/>
48 <pre>
49 java:jboss/exported/(ear)/(module)/(ejbClass)!(remoteInterface)
50 </pre>
51 * <p/>
52 * JNDI names returned will be in the following form:<p/>
53 <pre>
54 ejb:(ear)/(module)/(distinctName)/(ejbClass)!(remoteInterface)
55 ejb:(ear)/(module)/(distinctName)/(ejbClass)!(remoteInterface)?stateful
56 </pre><p/>
57 * Where the distinct name is commonly an empty string.<p/>
58 * @param earNameVersion
59 * @param ejbModuleNameVersion
60 * @param distinctName
61 * @param ejbClassName
62 * @param remoteInterface
63 * @return String jndi name that can be used for lookup
64 */
65 public static String getEJBClientLookupName(
66 String earNameVersion,
67 String ejbModuleNameVersion,
68 String distinctName,
69 String ejbClassName,
70 String remoteInterface,
71 boolean stateful) {
72
73 return new StringBuilder("ejb:")
74 .append(earNameVersion).append("/")
75 .append(ejbModuleNameVersion).append("/")
76 .append(distinctName==null?"":distinctName).append("/")
77 .append(ejbClassName).append("!")
78 .append(remoteInterface)
79 .append(stateful?"?stateful" : "")
80 .toString();
81 }
82
83 /**
84 * This method returns a JNDI name usable with JBoss remote-naming
85 * for EJBs deployed within an EAR.<p/>
86 * org.jboss.naming.remote.client.InitialContextFactory<p/>
87 * The physical JNDI name will be listed as:<p/>
88 * <pre>
89 java:jboss/exported/(ear)/(module)/(ejbClass)!(remoteInterface)
90 </pre></p>
91 * The name returned will have the following form:<p/>
92 * <pre>
93 (ear)/(module)/(ejbClass)!(remoteInterface)
94 * </pre>
95 * @param earNameVersion
96 * @param ejbModuleNameVersion
97 * @param ejbClassName
98 * @param remoteInterface
99 * @return String jndi name that can be used for lookup
100 */
101 public static String getRemoteLookupName(
102 String earNameVersion,
103 String ejbModuleNameVersion,
104 String ejbClassName,
105 String remoteInterface) {
106
107 return new StringBuilder()
108 .append(earNameVersion).append("/")
109 .append(ejbModuleNameVersion).append("/")
110 .append(ejbClassName).append("!")
111 .append(remoteInterface)
112 .toString();
113 }
114
115 /**
116 * This method returns a JNDI name usable with JBoss remote-naming for
117 * EJBs deployed within a WAR (i.e., no EAR).<p/>
118 * The physical JNDI name will be listed as:<p/>
119 * <pre>
120 java:jboss/exported/(war)/(ejbClass)!(remoteInterface)
121 </pre>
122 * The name returned will have the following form:<p/>
123 * <pre>
124 (war)/(ejbClass)!(remoteInterface)
125 * </pre>
126 * @param moduleNameVersion
127 * @param ejbClassName
128 * @param remoteInterface
129 * @return String jndi name that can be used for lookup
130 */
131 public static String getRemoteLookupName(
132 String moduleNameVersion,
133 String ejbClassName,
134 String remoteInterface) {
135
136 return new StringBuilder()
137 .append(moduleNameVersion).append("/")
138 .append(ejbClassName).append("!")
139 .append(remoteInterface)
140 .toString();
141 }
142 }