| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.impl; |
| 18 |
|
|
| 19 |
|
import java.util.Hashtable; |
| 20 |
|
|
| 21 |
|
import javax.naming.Context; |
| 22 |
|
import javax.naming.InitialContext; |
| 23 |
|
import javax.naming.NameNotFoundException; |
| 24 |
|
import javax.naming.NamingException; |
| 25 |
|
|
| 26 |
|
import org.apache.camel.RuntimeCamelException; |
| 27 |
|
import org.apache.camel.spi.Registry; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
public class JndiRegistry implements Registry { |
| 35 |
|
private Context context; |
| 36 |
|
|
| 37 |
0 |
public JndiRegistry() { |
| 38 |
0 |
} |
| 39 |
|
|
| 40 |
222 |
public JndiRegistry(Context context) { |
| 41 |
222 |
this.context = context; |
| 42 |
222 |
} |
| 43 |
|
|
| 44 |
|
public <T> T lookup(String name, Class<T> type) { |
| 45 |
9 |
Object value = lookup(name); |
| 46 |
9 |
return type.cast(value); |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
public Object lookup(String name) { |
| 50 |
|
try { |
| 51 |
27 |
return getContext().lookup(name); |
| 52 |
15 |
} catch (NameNotFoundException e) { |
| 53 |
15 |
return null; |
| 54 |
0 |
} catch (NamingException e) { |
| 55 |
0 |
throw new RuntimeCamelException(e); |
| 56 |
|
} |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
public void bind(String s, Object o) { |
| 60 |
|
try { |
| 61 |
3 |
getContext().bind(s, o); |
| 62 |
0 |
} catch (NamingException e) { |
| 63 |
0 |
throw new RuntimeCamelException(e); |
| 64 |
3 |
} |
| 65 |
3 |
} |
| 66 |
|
|
| 67 |
|
public void close() throws NamingException { |
| 68 |
0 |
getContext().close(); |
| 69 |
0 |
} |
| 70 |
|
|
| 71 |
|
public Context getContext() throws NamingException { |
| 72 |
30 |
if (context == null) { |
| 73 |
0 |
context = createContext(); |
| 74 |
|
} |
| 75 |
30 |
return context; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
public void setContext(Context context) { |
| 79 |
0 |
this.context = context; |
| 80 |
0 |
} |
| 81 |
|
|
| 82 |
|
protected Context createContext() throws NamingException { |
| 83 |
0 |
Hashtable properties = new Hashtable(System.getProperties()); |
| 84 |
0 |
return new InitialContext(properties); |
| 85 |
|
} |
| 86 |
|
} |