1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.factory;
24
25 import java.util.Properties;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29
30 /**
31 * JNDI <code>Context</code> factory implementation of <code>Factory</code> interface.<br>
32 * <br>
33 * Creates a <code>Context</code> object from given parameters.<br>
34 * <br>
35 * Parameters given to create <code>Context</code> are:
36 * <ul>
37 * <li>initialContextFactory - initial context factory to use.</li>
38 * <li>providerUrl - configuration information for the service provider to use.</li>
39 * <li>securityPrincipal - identity of the principal for authenticating the caller to
40 * the service.</li>
41 * <li>securityCredentials - credentials of the principal for authenticating the
42 * caller to the service.</li>
43 * <li>applet - an applet for the initial context constructor to use when searching
44 * for other properties.</li>
45 * <li>authoritative - authoritativeness of the service requested.</li>
46 * <li>batchsize - batch size to use when returning data via the service's
47 * protocol.</li>
48 * <li>dnsUrl - DNS host and domain names to use for the JNDI URL context.</li>
49 * <li>language - preferred language to use with the service.</li>
50 * <li>objectFactories - list of object factories to use.</li>
51 * <li>referral - how referrals encountered by the service provider are to be
52 * processed.</li>
53 * <li>securityAuthentication - security level to use.</li>
54 * <li>securityProtocol - security protocol to use.</li>
55 * <li>stateFactories - list of state factories to use.</li>
56 * <li>urlPkgPrefixes - list of package prefixes to use when loading in URL context
57 * factories.</li>
58 * </ul>
59 *
60 * @author Jose M. Palomar
61 * @version $Revision: 269 $
62 * @see javax.naming.Context
63 */
64 public final class JndiContextFactory extends FactoryService {
65
66
67
68
69 /**
70 * JNDI context init properties.
71 */
72 private Properties env = new Properties();
73
74
75 /**
76 * Creates a new <code>JndiContextFactory</code> object.
77 */
78 public JndiContextFactory() {
79 }
80
81
82 /**
83 * Sets initialContextFactory parameter.
84 *
85 * @param initialContextFactory String initial context factory to use.
86 */
87 public void setInitialContextFactory(String initialContextFactory) {
88 this.env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
89 }
90
91 /**
92 * Sets providerUrl parameter.
93 *
94 * @param providerUrl String configuration information for the service provider
95 * to use.
96 */
97 public void setProviderUrl(String providerUrl) {
98 this.env.put(Context.PROVIDER_URL, providerUrl);
99 }
100
101 /**
102 * Sets securityPrincipal parameter.
103 *
104 * @param securityPrincipal String identity of the principal for authenticating
105 * the caller to the service.
106 */
107 public void setSecurityPrincipal(String securityPrincipal) {
108 this.env.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
109 }
110
111 /**
112 * Sets securityCredentials parameter.
113 *
114 * @param securityCredentials String credentials of the principal for
115 * authenticating the caller to the service.
116 */
117 public void setSecurityCredentials(String securityCredentials) {
118 this.env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
119 }
120
121 /**
122 * Sets applet parameter.
123 *
124 * @param applet String an applet for the initial context constructor to use when
125 * searching for other properties.
126 */
127 public void setApplet(String applet) {
128 this.env.put(Context.APPLET, applet);
129 }
130
131 /**
132 * Sets authoritative parameter.
133 *
134 * @param authoritative String authoritativeness of the service requested.
135 */
136 public void setAuthoritative(String authoritative) {
137 this.env.put(Context.AUTHORITATIVE, authoritative);
138 }
139
140 /**
141 * Sets batchsize parameter.
142 *
143 * @param batchsize String batch size to use when returning data via the
144 * service's protocol.
145 */
146 public void setBatchsize(String batchsize) {
147 this.env.put(Context.BATCHSIZE, batchsize);
148 }
149
150 /**
151 * Sets dnsUrl parameter.
152 *
153 * @param dnsUrl String DNS host and domain names to use for the JNDI URL
154 * context.
155 */
156 public void setDnsUrl(String dnsUrl) {
157 this.env.put(Context.DNS_URL, dnsUrl);
158 }
159
160 /**
161 * Sets language parameter.
162 *
163 * @param language String preferred language to use with the service.
164 */
165 public void setLanguage(String language) {
166 this.env.put(Context.LANGUAGE, language);
167 }
168
169 /**
170 * Sets objectFactories parameter.
171 *
172 * @param objectFactories String list of object factories to use.
173 */
174 public void setObjectFactories(String objectFactories) {
175 this.env.put(Context.OBJECT_FACTORIES, objectFactories);
176 }
177
178 /**
179 * Sets referral parameter.
180 *
181 * @param referral String how referrals encountered by the service provider are
182 * to be processed.
183 */
184 public void setReferral(String referral) {
185 this.env.put(Context.REFERRAL, referral);
186 }
187
188 /**
189 * Sets securityAuthentication parameter.
190 *
191 * @param securityAuthentication String
192 */
193 public void setSecurityAuthentication(String securityAuthentication) {
194 this.env.put(Context.SECURITY_AUTHENTICATION, securityAuthentication);
195 }
196
197 /**
198 * Sets securityProtocol parameter.
199 *
200 * @param securityProtocol String security protocol to use.
201 */
202 public void setSecurityProtocol(String securityProtocol) {
203 this.env.put(Context.SECURITY_PROTOCOL, securityProtocol);
204 }
205
206 /**
207 * Sets stateFactories parameter.
208 *
209 * @param stateFactories String list of state factories to use.
210 */
211 public void setStateFactories(String stateFactories) {
212 this.env.put(Context.STATE_FACTORIES, stateFactories);
213 }
214
215 /**
216 * Sets urlPkgPrefixes parameter.
217 *
218 * @param urlPkgPrefixes String list of package prefixes to use when loading in
219 * URL context factories.
220 */
221 public void setUrlPkgPrefixes(String urlPkgPrefixes) {
222 this.env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
223 }
224
225 /**
226 * Returns name of service.
227 *
228 * @return String name of service.
229 * @see org.talika.tarsis.service.Service#getName()
230 */
231 public String getName() {
232 return "JndiContextFactory";
233 }
234
235 /**
236 * Returns a new <code>Context</code> instance created by this factory.
237 *
238 * @return Object a new <code>Context</code> instance created by this factory.
239 * @see org.talika.tarsis.factory.Factory#getInstance()
240 */
241 public Object getInstance() {
242 return getJndiContext();
243 }
244
245 /**
246 * Returns a new <code>Context</code> instance created by this factory.
247 *
248 * @return Context a new <code>Context</code> instance created by this factory.
249 */
250 public Context getJndiContext() {
251
252 Context jndiContext = null;
253 try {
254 jndiContext = new InitialContext(this.env);
255 }
256 catch (NamingException ne) {
257 if (getLogger().isWarningEnabled()) {
258 getLogger().logWarning("Error creating Jndi Context (" + ne.getMessage() + ")");
259 }
260 }
261
262 return jndiContext;
263 }
264
265 }