1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package net.sf.webphotos.locator; |
17 | |
|
18 | |
import java.util.Hashtable; |
19 | |
import javax.naming.Context; |
20 | |
import javax.naming.InitialContext; |
21 | |
import javax.naming.NamingException; |
22 | |
import org.apache.log4j.Logger; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class BasicEJBLocator { |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | protected InitialContext cachedContext = null; |
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public static String EJB_URL_PREFIXES = "org.jboss.naming"; |
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public static String EJB_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory"; |
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public static String EJB_SERVER = "127.0.0.1:1099"; |
46 | |
|
47 | 0 | private static Logger logger = Logger.getLogger(BasicEJBLocator.class); |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public void initEJBContext() { |
53 | |
try { |
54 | 0 | cachedContext = (InitialContext) getRemoteEJBsInitialContext(); |
55 | 0 | } catch (NamingException e) { |
56 | 0 | logger.error("Erro fatal com context de EJBs", e); |
57 | 0 | } |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public InitialContext getEJBContext() { |
65 | 0 | if (cachedContext == null) { |
66 | 0 | initEJBContext(); |
67 | |
} |
68 | 0 | return cachedContext; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public Context getRemoteEJBsInitialContext() throws NamingException { |
77 | 0 | Hashtable<String, String> props = new Hashtable<String, String>(); |
78 | 0 | props.put(Context.INITIAL_CONTEXT_FACTORY, EJB_CONTEXT_FACTORY); |
79 | 0 | props.put(Context.PROVIDER_URL, EJB_SERVER); |
80 | 0 | props.put(Context.URL_PKG_PREFIXES, EJB_URL_PREFIXES); |
81 | 0 | return new InitialContext(props); |
82 | |
} |
83 | |
|
84 | |
} |