KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > common > ContextDump


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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,v 1.2 2004/07/01 14:44:18 sauthieg Exp $
26  * --------------------------------------------------------------------------
27  */

28
29 package org.objectweb.jonas.common;
30
31 import javax.naming.NamingEnumeration JavaDoc;
32 import javax.naming.NameClassPair JavaDoc;
33 import javax.naming.Context JavaDoc;
34 import javax.naming.NamingException JavaDoc;
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 JavaDoc header, Context JavaDoc ctx, Logger logger, int logLevel) {
43         logger.log(logLevel, header);
44         logger.log(logLevel, "=================================");
45         print(ctx, logger, logLevel, "");
46         logger.log(logLevel, "=================================");
47     }
48
49     /**
50      * @param ctx
51      * @param logger
52      * @param logLevel
53      * @param string
54      */

55     private static void print(Context JavaDoc ctx, Logger logger, int logLevel, String JavaDoc indent) {
56         String JavaDoc aName = null;
57         try {
58             for (NamingEnumeration JavaDoc pNames = ctx.list(""); pNames.hasMore();) {
59                 Object JavaDoc o = pNames.next();
60                 if (o instanceof NameClassPair JavaDoc) {
61                     aName = ((NameClassPair JavaDoc) o).getName();
62                     Object JavaDoc v = ctx.lookup(aName);
63                     if (v != null) {
64                         if (v instanceof Context JavaDoc) {
65                             logger.log(logLevel, indent + aName);
66                             print((Context JavaDoc) v, logger, logLevel, indent + " ");
67                         } else {
68                             logger.log(logLevel, indent + aName + " = " + v);
69                         }
70                     }
71                 }
72             }
73         } catch (NamingException JavaDoc ne) {
74             logger.log(logLevel, "Failed to dump contex: " + ne.toString());
75         }
76     }
77 }
Popular Tags