1 /*
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
41 import org.omg.CosNaming.NamingContextPackage.*;
42 import org.omg.CORBA.*;
43
44 import com.sun.jndi.toolkit.corba.CorbaUtils;
45
46 // Needed for creating default ORB
47 import java.applet.Applet;
48
49 /**
50 * Provides a bridge to the CosNaming server provided by
51 * JavaIDL. This class provides the InitialContext from CosNaming.
52 *
53 * @author Raj Krishnamurthy
54 * @author Rosanna Lee
55 */
56
57 public class CNCtx implements javax.naming.Context {
58
59 private final static boolean debug = false;
60
61 ORB _orb; // used by ExceptionMapper and RMI/IIOP factory
62 public NamingContext _nc; // public for accessing underlying NamingContext
63 private NameComponent[] _name = null;
64
65 Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
66 static final CNNameParser parser = new CNNameParser();
67
68 private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
69 boolean federation = false;
70
71 // Reference counter for tracking _orb references
72 OrbReuseTracker orbTracker = null;
73 int enumCount;
74 boolean isCloseCalled = false;
75
76 /**
77 * Create a CNCtx object. Gets the initial naming
78 * reference for the COS Naming Service from the ORB.
79 * The ORB can be passed in via the java.naming.corba.orb property
80 * or be created using properties in the environment properties.
81 * @param env Environment properties for initializing name service.
82 * @exception NamingException Cannot initialize ORB or naming context.
97 /**
98 * This method is used by the iiop and iiopname URL Context factories.
99 */
100 @SuppressWarnings("unchecked")
101 public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
102 throws NamingException {
103 CNCtx ctx = new CNCtx();
104 if (env != null) {
105 env = (Hashtable<?,?>) env.clone();
106 }
107 ctx._env = (Hashtable<String, java.lang.Object>)env;
108 String rest = ctx.initUsingUrl(
109 env != null ?
110 (org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
111 : null,
112 url, env);
113
114 // rest is the INS name
115 // Return the parsed form to prevent subsequent lookup
116 // from parsing the string as a composite name
117 // The caller should be aware that a toString() of the name
118 // will yield its INS syntax, rather than a composite syntax
119 return new ResolveResult(ctx, parser.parse(rest));
120 }
121
122 /**
123 * Creates a CNCtx object which supports the javax.naming
124 * apis given a COS Naming Context object.
125 * @param orb The ORB used by this context
126 * @param tracker The ORB reuse tracker for tracking references to the
127 * orb object
128 * @param nctx The COS NamingContext object associated with this context
129 * @param name The name of this context relative to the root
130 */
131
132 CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx,
133 Hashtable<String, java.lang.Object> env, NameComponent[]name)
134 throws NamingException {
135 if (orb == null || nctx == null)
136 throw new ConfigurationException(
137 "Must supply ORB or NamingContext");
138 _orb = orb;
139 orbTracker = tracker;
140 if (orbTracker != null) {
141 orbTracker.incRefCount();
142 }
143 _nc = nctx;
144 _env = env;
145 _name = name;
146 federation = "true".equals(env != null ? env.get(FED_PROP) : null);
147 }
148
149 NameComponent[] makeFullName(NameComponent[] child) {
150 if (_name == null || _name.length == 0) {
151 return child;
152 }
153 NameComponent[] answer = new NameComponent[_name.length+child.length];
154
155 // parent
156 System.arraycopy(_name, 0, answer, 0, _name.length);
157
158 // child
159 System.arraycopy(child, 0, answer, _name.length, child.length);
160 return answer;
161 }
195 *<p>
196 * _nc is obtained from the IOR stored in PROVIDER_URL if it has been
197 * set and does not contain an "iiop" or "iiopname" URL. It can be
198 * a stringified IOR, "corbaloc" URL, "corbaname" URL,
199 * or a URL (such as file/http/ftp) to a location
200 * containing a stringified IOR. If PROVIDER_URL has not been
201 * set in this way, it is obtained from the result of
202 * ORB.resolve_initial_reference("NameService");
203 *<p>
204 * _name is obtained from the "iiop", "iiopname", or "corbaname" URL.
205 * It is the empty name by default.
206 *
207 * @param env Environment The possibly null environment.
208 * @exception NamingException When an error occurs while initializing the
209 * ORB or the naming context.
210 */
211 private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException {
212 org.omg.CORBA.ORB inOrb = null;
213 String ncIor = null;
214
215 if (env != null) {
216 inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb");
217 }
218
219 // Extract PROVIDER_URL from environment
220 String provUrl = null;
221 if (env != null) {
222 provUrl = (String)env.get(javax.naming.Context.PROVIDER_URL);
223 }
224
225 if (provUrl != null && !isCorbaUrl(provUrl)) {
226 // Initialize the root naming context by using the IOR supplied
227 // in the PROVIDER_URL
228 ncIor = getStringifiedIor(provUrl);
229
230 if (inOrb == null) {
231
232 // no ORB instance specified; create one using env and defaults
233 inOrb = CorbaUtils.getOrb(null, -1, env);
234 orbTracker = new OrbReuseTracker(inOrb);
235 }
236 setOrbAndRootContext(inOrb, ncIor);
237 } else if (provUrl != null) {
238 // Initialize the root naming context by using the URL supplied
239 // in the PROVIDER_URL
240 String insName = initUsingUrl(inOrb, provUrl, env);
241
242 // If name supplied in URL, resolve it to a NamingContext
243 if (insName.length() > 0) {
244 _name = CNNameParser.nameToCosName(parser.parse(insName));
245 try {
246 org.omg.CORBA.Object obj = _nc.resolve(_name);
247 _nc = NamingContextHelper.narrow(obj);
248 if (_nc == null) {
249 throw new ConfigurationException(insName +
250 " does not name a NamingContext");
251 }
252 } catch (org.omg.CORBA.BAD_PARAM e) {
253 throw new ConfigurationException(insName +
254 " does not name a NamingContext");
255 } catch (Exception e) {
256 throw ExceptionMapper.mapException(e, this, _name);
257 }
258 }
259 } else {
260 // No PROVIDER_URL supplied; initialize using defaults
261 if (inOrb == null) {
262
263 // No ORB instance specified; create one using env and defaults
264 inOrb = CorbaUtils.getOrb(null, -1, env);
265 orbTracker = new OrbReuseTracker(inOrb);
266 if (debug) {
267 System.err.println("Getting default ORB: " + inOrb + env);
268 }
269 }
270 setOrbAndRootContext(inOrb, (String)null);
271 }
272 }
273
274
275 private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env)
276 throws NamingException {
277 if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
278 return initUsingIiopUrl(orb, url, env);
279 } else {
280 return initUsingCorbanameUrl(orb, url, env);
281 }
282 }
283
284 /**
285 * Handles "iiop" and "iiopname" URLs (INS 98-10-11)
286 */
287 private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
288 throws NamingException {
289 try {
290 IiopUrl parsedUrl = new IiopUrl(url);
291
292 NamingException savedException = null;
293
294 for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
295
296 try {
297 if (defOrb != null) {
298 try {
299 String tmpUrl = "corbaloc:iiop:" + addr.host
300 + ":" + addr.port + "/NameService";
301 if (debug) {
302 System.err.println("Using url: " + tmpUrl);
303 }
304 org.omg.CORBA.Object rootCtx =
305 defOrb.string_to_object(tmpUrl);
306 setOrbAndRootContext(defOrb, rootCtx);
307 return parsedUrl.getStringName();
308 } catch (Exception e) {} // keep going
309 }
310
311 // Get ORB
312 if (debug) {
313 System.err.println("Getting ORB for " + addr.host
314 + " and port " + addr.port);
315 }
316
317 // Get ORB
318 ORB orb = CorbaUtils.getOrb(addr.host, addr.port, env);
319 orbTracker = new OrbReuseTracker(orb);
320
321 // Assign to fields
322 setOrbAndRootContext(orb, (String)null);
323 return parsedUrl.getStringName();
324
325 } catch (NamingException ne) {
326 savedException = ne;
327 }
328 }
329 if (savedException != null) {
330 throw savedException;
331 } else {
332 throw new ConfigurationException("Problem with URL: " + url);
333 }
334 } catch (MalformedURLException e) {
335 throw new ConfigurationException(e.getMessage());
336 }
337 }
338
339 /**
340 * Initializes using "corbaname" URL (INS 99-12-03)
341 */
342 private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
343 throws NamingException {
344 try {
345 CorbanameUrl parsedUrl = new CorbanameUrl(url);
346
347 String corbaloc = parsedUrl.getLocation();
348 String cosName = parsedUrl.getStringName();
349
350 if (orb == null) {
351
352 // No ORB instance specified; create one using env and defaults
353 orb = CorbaUtils.getOrb(null, -1, env);
354 orbTracker = new OrbReuseTracker(orb);
355 }
356 setOrbAndRootContext(orb, corbaloc);
357
358 return parsedUrl.getStringName();
359 } catch (MalformedURLException e) {
360 throw new ConfigurationException(e.getMessage());
361 }
362 }
363
364 private void setOrbAndRootContext(ORB orb, String ncIor)
365 throws NamingException {
366 _orb = orb;
367 try {
368 org.omg.CORBA.Object ncRef;
369 if (ncIor != null) {
370 if (debug) {
371 System.err.println("Passing to string_to_object: " + ncIor);
372 }
373 ncRef = _orb.string_to_object(ncIor);
374 } else {
375 ncRef = _orb.resolve_initial_references("NameService");
1100 // copy-on-write
1101 _env = (Hashtable<String, java.lang.Object>)_env.clone();
1102 }
1103
1104 return _env.put(propName, propValue);
1105 }
1106
1107 // Record change but do not reinitialize ORB
1108 @SuppressWarnings("unchecked")
1109 public java.lang.Object removeFromEnvironment(String propName)
1110 throws NamingException {
1111 if (_env != null && _env.get(propName) != null) {
1112 // copy-on-write
1113 _env = (Hashtable<String, java.lang.Object>)_env.clone();
1114 return _env.remove(propName);
1115 }
1116 return null;
1117 }
1118
1119 synchronized public void incEnumCount() {
1120 if (orbTracker == null) {
1121 return;
1122 }
1123 enumCount++;
1124 if (debug) {
1125 System.out.println("incEnumCount, new count:" + enumCount);
1126 }
1127 }
1128
1129 synchronized public void decEnumCount()
1130 throws NamingException {
1131 if (orbTracker == null) {
1132 return;
1133 }
1134 enumCount--;
1135 if (debug) {
1136 System.out.println("decEnumCount, new count:" + enumCount +
1137 " isCloseCalled:" + isCloseCalled);
1138 }
1139 if ((enumCount == 0) && isCloseCalled) {
1140 close();
1141 }
1142 }
1143
1144 synchronized public void close() throws NamingException {
1145 if (orbTracker == null) {
1146 return;
1147 }
1148 if (enumCount > 0) {
1149 isCloseCalled = true;
1150 return;
1151 }
1152 orbTracker.decRefCount();
1153 }
1154
1155 protected void finalize() {
1156 try {
1157 close();
1158 } catch (NamingException e) {
1159 // ignore failures
1160 }
1161 }
1162 }
|
1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
41 import org.omg.CosNaming.NamingContextPackage.*;
42 import org.omg.CORBA.*;
43
44 import com.sun.jndi.toolkit.corba.CorbaUtils;
45
46 // Needed for creating default ORB
47 import java.applet.Applet;
48
49 /**
50 * Provides a bridge to the CosNaming server provided by
51 * JavaIDL. This class provides the InitialContext from CosNaming.
52 *
53 * @author Raj Krishnamurthy
54 * @author Rosanna Lee
55 */
56
57 public class CNCtx implements javax.naming.Context {
58
59 private final static boolean debug = false;
60
61 /*
62 * Implement one shared ORB among all CNCtx. However, there is a public constructor
63 * accepting an ORB, so we need the option of using a given ORB.
64 */
65 private static ORB _defaultOrb;
66 ORB _orb; // used by ExceptionMapper and RMI/IIOP factory
67 public NamingContext _nc; // public for accessing underlying NamingContext
68
69 private synchronized static ORB getDefaultOrb() {
70 if (_defaultOrb == null) {
71 _defaultOrb = CorbaUtils.getOrb(null, -1,
72 new Hashtable<String, java.lang.Object>());
73 }
74 return _defaultOrb;
75 }
76
77 private NameComponent[] _name = null;
78
79 Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
80 static final CNNameParser parser = new CNNameParser();
81
82 private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
83 boolean federation = false;
84
85 // Reference counter for tracking _orb references
86 OrbReuseTracker orbTracker = null;
87 int enumCount;
88 boolean isCloseCalled = false;
89
90 /**
91 * Create a CNCtx object. Gets the initial naming
92 * reference for the COS Naming Service from the ORB.
93 * The ORB can be passed in via the java.naming.corba.orb property
94 * or be created using properties in the environment properties.
95 * @param env Environment properties for initializing name service.
96 * @exception NamingException Cannot initialize ORB or naming context.
111 /**
112 * This method is used by the iiop and iiopname URL Context factories.
113 */
114 @SuppressWarnings("unchecked")
115 public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
116 throws NamingException {
117 CNCtx ctx = new CNCtx();
118 if (env != null) {
119 env = (Hashtable<?,?>) env.clone();
120 }
121 ctx._env = (Hashtable<String, java.lang.Object>)env;
122 String rest = ctx.initUsingUrl(
123 env != null ?
124 (org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
125 : null,
126 url, env);
127
128 // rest is the INS name
129 // Return the parsed form to prevent subsequent lookup
130 // from parsing the string as a composite name
131 // The caller should be aware that a toString() of the name,
132 // which came from the environment will yield its INS syntax,
133 // rather than a composite syntax
134 return new ResolveResult(ctx, parser.parse(rest));
135 }
136
137 /**
138 * Creates a CNCtx object which supports the javax.naming
139 * apis given a COS Naming Context object.
140 * @param orb The ORB used by this context
141 * @param tracker The ORB reuse tracker for tracking references to the
142 * orb object
143 * @param nctx The COS NamingContext object associated with this context
144 * @param name The name of this context relative to the root
145 */
146
147 CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx,
148 Hashtable<String, java.lang.Object> env, NameComponent[]name)
149 throws NamingException {
150 if (orb == null || nctx == null)
151 throw new ConfigurationException(
152 "Must supply ORB or NamingContext");
153 if (orb != null) {
154 _orb = orb;
155 } else {
156 _orb = getDefaultOrb();
157 }
158 _nc = nctx;
159 _env = env;
160 _name = name;
161 federation = "true".equals(env != null ? env.get(FED_PROP) : null);
162 }
163
164 NameComponent[] makeFullName(NameComponent[] child) {
165 if (_name == null || _name.length == 0) {
166 return child;
167 }
168 NameComponent[] answer = new NameComponent[_name.length+child.length];
169
170 // parent
171 System.arraycopy(_name, 0, answer, 0, _name.length);
172
173 // child
174 System.arraycopy(child, 0, answer, _name.length, child.length);
175 return answer;
176 }
210 *<p>
211 * _nc is obtained from the IOR stored in PROVIDER_URL if it has been
212 * set and does not contain an "iiop" or "iiopname" URL. It can be
213 * a stringified IOR, "corbaloc" URL, "corbaname" URL,
214 * or a URL (such as file/http/ftp) to a location
215 * containing a stringified IOR. If PROVIDER_URL has not been
216 * set in this way, it is obtained from the result of
217 * ORB.resolve_initial_reference("NameService");
218 *<p>
219 * _name is obtained from the "iiop", "iiopname", or "corbaname" URL.
220 * It is the empty name by default.
221 *
222 * @param env Environment The possibly null environment.
223 * @exception NamingException When an error occurs while initializing the
224 * ORB or the naming context.
225 */
226 private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException {
227 org.omg.CORBA.ORB inOrb = null;
228 String ncIor = null;
229
230 if (inOrb == null && env != null) {
231 inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb");
232 }
233
234 if (inOrb == null)
235 inOrb = getDefaultOrb(); // will create a default ORB if none exists
236
237 // Extract PROVIDER_URL from environment
238 String provUrl = null;
239 if (env != null) {
240 provUrl = (String)env.get(javax.naming.Context.PROVIDER_URL);
241 }
242
243 if (provUrl != null && !isCorbaUrl(provUrl)) {
244 // Initialize the root naming context by using the IOR supplied
245 // in the PROVIDER_URL
246 ncIor = getStringifiedIor(provUrl);
247 setOrbAndRootContext(inOrb, ncIor);
248 } else if (provUrl != null) {
249 // Initialize the root naming context by using the URL supplied
250 // in the PROVIDER_URL
251 String insName = initUsingUrl(inOrb, provUrl, env);
252
253 // If name supplied in URL, resolve it to a NamingContext
254 if (insName.length() > 0) {
255 _name = CNNameParser.nameToCosName(parser.parse(insName));
256 try {
257 org.omg.CORBA.Object obj = _nc.resolve(_name);
258 _nc = NamingContextHelper.narrow(obj);
259 if (_nc == null) {
260 throw new ConfigurationException(insName +
261 " does not name a NamingContext");
262 }
263 } catch (org.omg.CORBA.BAD_PARAM e) {
264 throw new ConfigurationException(insName +
265 " does not name a NamingContext");
266 } catch (Exception e) {
267 throw ExceptionMapper.mapException(e, this, _name);
268 }
269 }
270 } else {
271 // No PROVIDER_URL supplied; initialize using defaults
272 if (debug) {
273 System.err.println("Getting default ORB: " + inOrb + env);
274 }
275 setOrbAndRootContext(inOrb, (String)null);
276 }
277 }
278
279
280 private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env)
281 throws NamingException {
282 if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
283 return initUsingIiopUrl(orb, url, env);
284 } else {
285 return initUsingCorbanameUrl(orb, url, env);
286 }
287 }
288
289 /**
290 * Handles "iiop" and "iiopname" URLs (INS 98-10-11)
291 */
292 private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
293 throws NamingException {
294
295 if (defOrb == null)
296 defOrb = getDefaultOrb();
297
298 try {
299 IiopUrl parsedUrl = new IiopUrl(url);
300
301 NamingException savedException = null;
302
303 for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
304
305 try {
306 try {
307 String tmpUrl = "corbaloc:iiop:" + addr.host
308 + ":" + addr.port + "/NameService";
309 if (debug) {
310 System.err.println("Using url: " + tmpUrl);
311 }
312 org.omg.CORBA.Object rootCtx =
313 defOrb.string_to_object(tmpUrl);
314 setOrbAndRootContext(defOrb, rootCtx);
315 return parsedUrl.getStringName();
316 } catch (Exception e) {} // keep going
317
318 // Get ORB
319 if (debug) {
320 System.err.println("Getting ORB for " + addr.host
321 + " and port " + addr.port);
322 }
323
324 // Assign to fields
325 setOrbAndRootContext(defOrb, (String)null);
326 return parsedUrl.getStringName();
327
328 } catch (NamingException ne) {
329 savedException = ne;
330 }
331 }
332 if (savedException != null) {
333 throw savedException;
334 } else {
335 throw new ConfigurationException("Problem with URL: " + url);
336 }
337 } catch (MalformedURLException e) {
338 throw new ConfigurationException(e.getMessage());
339 }
340 }
341
342 /**
343 * Initializes using "corbaname" URL (INS 99-12-03)
344 */
345 private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
346 throws NamingException {
347
348 if (orb == null)
349 orb = getDefaultOrb();
350
351 try {
352 CorbanameUrl parsedUrl = new CorbanameUrl(url);
353
354 String corbaloc = parsedUrl.getLocation();
355 String cosName = parsedUrl.getStringName();
356
357 setOrbAndRootContext(orb, corbaloc);
358
359 return parsedUrl.getStringName();
360 } catch (MalformedURLException e) {
361 throw new ConfigurationException(e.getMessage());
362 }
363 }
364
365 private void setOrbAndRootContext(ORB orb, String ncIor)
366 throws NamingException {
367 _orb = orb;
368 try {
369 org.omg.CORBA.Object ncRef;
370 if (ncIor != null) {
371 if (debug) {
372 System.err.println("Passing to string_to_object: " + ncIor);
373 }
374 ncRef = _orb.string_to_object(ncIor);
375 } else {
376 ncRef = _orb.resolve_initial_references("NameService");
1101 // copy-on-write
1102 _env = (Hashtable<String, java.lang.Object>)_env.clone();
1103 }
1104
1105 return _env.put(propName, propValue);
1106 }
1107
1108 // Record change but do not reinitialize ORB
1109 @SuppressWarnings("unchecked")
1110 public java.lang.Object removeFromEnvironment(String propName)
1111 throws NamingException {
1112 if (_env != null && _env.get(propName) != null) {
1113 // copy-on-write
1114 _env = (Hashtable<String, java.lang.Object>)_env.clone();
1115 return _env.remove(propName);
1116 }
1117 return null;
1118 }
1119
1120 synchronized public void incEnumCount() {
1121 enumCount++;
1122 if (debug) {
1123 System.out.println("incEnumCount, new count:" + enumCount);
1124 }
1125 }
1126
1127 synchronized public void decEnumCount()
1128 throws NamingException {
1129 enumCount--;
1130 if (debug) {
1131 System.out.println("decEnumCount, new count:" + enumCount +
1132 " isCloseCalled:" + isCloseCalled);
1133 }
1134 if ((enumCount == 0) && isCloseCalled) {
1135 close();
1136 }
1137 }
1138
1139 synchronized public void close() throws NamingException {
1140
1141 if (enumCount > 0) {
1142 isCloseCalled = true;
1143 return;
1144 }
1145
1146 // Never destroy an orb in CNCtx.
1147 // The orb we have is either the shared/default orb, or one passed in to a constructor
1148 // from elsewhere, so that orb is somebody else's reponsibility.
1149 }
1150
1151 protected void finalize() {
1152 try {
1153 close();
1154 } catch (NamingException e) {
1155 // ignore failures
1156 }
1157 }
1158 }
|