01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * Initial developer(s): ____________________________________.
22: * Contributor(s):
23: *
24: * --------------------------------------------------------------------------
25: * $Id: ContextDump.java 5039 2004-07-01 14:44:18Z sauthieg $
26: * --------------------------------------------------------------------------
27: */
28:
29: package org.objectweb.jonas.common;
30:
31: import javax.naming.NamingEnumeration;
32: import javax.naming.NameClassPair;
33: import javax.naming.Context;
34: import javax.naming.NamingException;
35: import org.objectweb.util.monolog.api.Logger;
36:
37: /**
38: * Used to print out a Naming context content
39: */
40: public class ContextDump {
41:
42: public static void print(String header, Context ctx, Logger logger,
43: int logLevel) {
44: logger.log(logLevel, header);
45: logger.log(logLevel, "=================================");
46: print(ctx, logger, logLevel, "");
47: logger.log(logLevel, "=================================");
48: }
49:
50: /**
51: * @param ctx
52: * @param logger
53: * @param logLevel
54: * @param string
55: */
56: private static void print(Context ctx, Logger logger, int logLevel,
57: String indent) {
58: String aName = null;
59: try {
60: for (NamingEnumeration pNames = ctx.list(""); pNames
61: .hasMore();) {
62: Object o = pNames.next();
63: if (o instanceof NameClassPair) {
64: aName = ((NameClassPair) o).getName();
65: Object v = ctx.lookup(aName);
66: if (v != null) {
67: if (v instanceof Context) {
68: logger.log(logLevel, indent + aName);
69: print((Context) v, logger, logLevel, indent
70: + " ");
71: } else {
72: logger.log(logLevel, indent + aName + " = "
73: + v);
74: }
75: }
76: }
77: }
78: } catch (NamingException ne) {
79: logger.log(logLevel, "Failed to dump contex: "
80: + ne.toString());
81: }
82: }
83: }
|