Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JndiContextHelper |
|
| 1.5;1.5 |
1 | /* | |
2 | * $Id: JndiContextHelper.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.util; | |
12 | ||
13 | import java.util.Hashtable; | |
14 | import java.util.Map; | |
15 | ||
16 | import javax.naming.Context; | |
17 | import javax.naming.InitialContext; | |
18 | import javax.naming.NamingException; | |
19 | ||
20 | /** | |
21 | * Common code for initialising the JNDI context. | |
22 | */ | |
23 | public final class JndiContextHelper | |
24 | { | |
25 | /** Do not instanciate. */ | |
26 | private JndiContextHelper () | |
27 | 0 | { |
28 | // no-op | |
29 | 0 | } |
30 | ||
31 | /** | |
32 | * Create a new initial context. | |
33 | * | |
34 | * @param environment JNDI properties or <code>null</code>. In the latter case | |
35 | * a default constructor of <code>InitialContext</code> will be | |
36 | * called with standard JNDI lookup properties semantics. | |
37 | * @return jndi context | |
38 | * @throws NamingException if there was a JNDI error | |
39 | */ | |
40 | public static Context initialise(final Map environment) throws NamingException | |
41 | { | |
42 | Context context; | |
43 | 0 | if (environment != null && environment.size() > 0) |
44 | { | |
45 | 0 | context = new InitialContext(new Hashtable(environment)); |
46 | } | |
47 | else | |
48 | { | |
49 | 0 | context = new InitialContext(); |
50 | } | |
51 | ||
52 | 0 | return context; |
53 | } | |
54 | } |