KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > AbstractJndiConnector


1 /*
2  * $Id: AbstractJndiConnector.java 3798 2006-11-04 04:07:14Z 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.providers;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.umo.lifecycle.InitialisationException;
16
17 import javax.naming.Context JavaDoc;
18 import javax.naming.InitialContext JavaDoc;
19 import javax.naming.NamingException JavaDoc;
20
21 import java.util.Hashtable JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Code by (c) 2005 P.Oikari. <p/> This class acts as common baseclass for both Rmi &
26  * EjbConnector Resolves Jndi root for connector usage
27  *
28  * @author <a HREF="mailto:tsuppari@yahoo.co.uk">P.Oikari</a>
29  * @version $Revision: 3798 $
30  */

31
32 public abstract class AbstractJndiConnector extends AbstractServiceEnabledConnector
33 {
34     protected String JavaDoc jndiInitialFactory;
35
36     protected String JavaDoc jndiUrlPkgPrefixes;
37
38     protected String JavaDoc jndiProviderUrl;
39
40     protected Context JavaDoc jndiContext;
41
42     protected Map JavaDoc jndiProviderProperties = null;
43
44     protected void initJndiContext() throws InitialisationException
45     {
46         if (null == jndiContext)
47         {
48             Hashtable JavaDoc props = new Hashtable JavaDoc();
49
50             if (null != jndiInitialFactory)
51             {
52                 props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory);
53             }
54
55             if (jndiProviderUrl != null)
56             {
57                 props.put(Context.PROVIDER_URL, jndiProviderUrl);
58             }
59
60             if (jndiUrlPkgPrefixes != null)
61             {
62                 props.put(Context.URL_PKG_PREFIXES, jndiUrlPkgPrefixes);
63             }
64
65             if (jndiProviderProperties != null)
66             {
67                 props.putAll(jndiProviderProperties);
68             }
69             try
70             {
71                 jndiContext = new InitialContext JavaDoc(props);
72             }
73             catch (NamingException JavaDoc e)
74             {
75                 throw new InitialisationException(e, this);
76             }
77         }
78     }
79
80     public Context JavaDoc getJndiContext(String JavaDoc jndiProviderUrl) throws InitialisationException
81     {
82         try
83         {
84             setJndiProviderUrl(jndiProviderUrl);
85
86             initJndiContext();
87         }
88         catch (Exception JavaDoc e)
89         {
90             throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X,
91                 "AbstractJndiConnector"), e, this);
92         }
93
94         return jndiContext;
95     }
96
97     public Context JavaDoc getJndiContext()
98     {
99
100         return jndiContext;
101     }
102
103     public void setJndiContext(Context JavaDoc jndiContext)
104     {
105         this.jndiContext = jndiContext;
106     }
107
108     public void setJndiInitialFactory(String JavaDoc jndiInitialFactory)
109     {
110         this.jndiInitialFactory = jndiInitialFactory;
111     }
112
113     public String JavaDoc getJndiInitialFactory()
114     {
115         return jndiInitialFactory;
116     }
117
118     public void setJndiUrlPkgPrefixes(String JavaDoc jndiUrlPkgPrefixes)
119     {
120         this.jndiUrlPkgPrefixes = jndiUrlPkgPrefixes;
121     }
122
123     public String JavaDoc getJndiUrlPkgPrefixes()
124     {
125         return jndiUrlPkgPrefixes;
126     }
127
128     public String JavaDoc getJndiProviderUrl()
129     {
130         return jndiProviderUrl;
131     }
132
133     public void setJndiProviderUrl(String JavaDoc jndiProviderUrl)
134     {
135         this.jndiProviderUrl = jndiProviderUrl;
136     }
137
138     public Map JavaDoc getJndiProviderProperties()
139     {
140         return jndiProviderProperties;
141     }
142
143     public void setJndiProviderProperties(Map JavaDoc jndiProviderProperties)
144     {
145         this.jndiProviderProperties = jndiProviderProperties;
146     }
147 }
148
Popular Tags