01: package com.tagtraum.jo.util;
02:
03: import javax.naming.Context;
04: import javax.naming.Name;
05: import javax.naming.NameNotFoundException;
06: import javax.naming.NamingException;
07:
08: /**
09: * Utility class for naming services.
10: *
11: * Date: Nov 21, 2001
12: * Time: 6:20:38 PM
13: * @version 1.1beta1 $Id: Naming.java,v 1.2 2003/07/10 00:52:34 hendriks73 Exp $
14: */
15: public class Naming {
16:
17: /** Source-Version: <code>$Id: Naming.java,v 1.2 2003/07/10 00:52:34 hendriks73 Exp $</code> */
18: public static String vcid = "$Id: Naming.java,v 1.2 2003/07/10 00:52:34 hendriks73 Exp $";
19:
20: public static void bind(Context context, String stringName,
21: Object value) throws NamingException {
22: Name name = context.getNameParser("").parse(stringName);
23: Context parentContext = createSubcontext(context, name
24: .getPrefix(name.size() - 1));
25: parentContext.bind(name.get(name.size() - 1), value);
26: }
27:
28: public static Context createSubcontext(Context context, Name name)
29: throws NamingException {
30: Context subContext = context;
31: for (int position = 0; position < name.size(); position++) {
32: String contextName = name.get(position);
33: try {
34: subContext = (Context) context.lookup(contextName);
35: } catch (NameNotFoundException e) {
36: subContext = context.createSubcontext(contextName);
37: }
38: context = subContext;
39: }
40: return subContext;
41: }
42:
43: public static Context createSubcontext(Context context,
44: String stringName) throws NamingException {
45: return createSubcontext(context, context.getNameParser("")
46: .parse(stringName));
47: }
48:
49: }
|