KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > container > JndiContainerContext


1 /*
2  * $Id: JndiContainerContext.java 4259 2006-12-14 03:12:07Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl.container;
12
13 import java.io.Reader JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import javax.naming.Context JavaDoc;
17 import javax.naming.InitialContext JavaDoc;
18 import javax.naming.Name JavaDoc;
19 import javax.naming.NamingException JavaDoc;
20
21 import org.apache.commons.lang.ObjectUtils;
22 import org.mule.config.i18n.Message;
23 import org.mule.config.i18n.Messages;
24 import org.mule.umo.lifecycle.InitialisationException;
25 import org.mule.umo.manager.ContainerException;
26 import org.mule.umo.manager.ObjectNotFoundException;
27
28 /**
29  * <code>JndiContainerContext</code> is a container implementaiton that exposes a
30  * jndi context. Whatever properties are set on the container in configuration will
31  * be passed to the initial context.
32  */

33 public class JndiContainerContext extends AbstractContainerContext
34 {
35     protected volatile Context JavaDoc context;
36     private volatile Map JavaDoc environment;
37
38     public JndiContainerContext()
39     {
40         super("jndi");
41     }
42
43     protected JndiContainerContext(String JavaDoc name)
44     {
45         super(name);
46     }
47
48     public Map JavaDoc getEnvironment()
49     {
50         return environment;
51     }
52
53     public void setEnvironment(Map JavaDoc environment)
54     {
55         this.environment = environment;
56     }
57
58     public Context JavaDoc getContext()
59     {
60         return context;
61     }
62
63     public void setContext(InitialContext JavaDoc context)
64     {
65         this.context = context;
66     }
67
68     public Object JavaDoc getComponent(Object JavaDoc key) throws ObjectNotFoundException
69     {
70         try
71         {
72             if (key == null)
73             {
74                 throw new ObjectNotFoundException("null");
75             }
76             if (key instanceof Name JavaDoc)
77             {
78                 return context.lookup((Name JavaDoc)key);
79             }
80             else if (key instanceof Class JavaDoc)
81             {
82                 return context.lookup(((Class JavaDoc)key).getName());
83             }
84             else
85             {
86                 return context.lookup(key.toString());
87             }
88         }
89         catch (NamingException JavaDoc e)
90         {
91             throw new ObjectNotFoundException(ObjectUtils.toString(key, "null"), e);
92         }
93     }
94
95     public void configure(Reader JavaDoc configuration) throws ContainerException
96     {
97         throw new UnsupportedOperationException JavaDoc("configure(Reader)");
98     }
99
100     public void initialise() throws InitialisationException
101     {
102         try
103         {
104             if (context == null)
105             {
106                 context = JndiContextHelper.initialise(getEnvironment());
107             }
108         }
109         catch (NamingException JavaDoc e)
110         {
111             throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X, "Jndi context"), e,
112                 this);
113         }
114     }
115 }
116
Popular Tags