ContextDump.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): ____________________________________.
00022  * Contributor(s):
00023  *
00024  * --------------------------------------------------------------------------
00025  * $Id: ContextDump.java,v 1.2 2004/07/01 14:44:18 sauthieg Exp $
00026  * --------------------------------------------------------------------------
00027  */
00028 
00029 package org.objectweb.jonas.common;
00030 
00031 import javax.naming.NamingEnumeration;
00032 import javax.naming.NameClassPair;
00033 import javax.naming.Context;
00034 import javax.naming.NamingException;
00035 import org.objectweb.util.monolog.api.Logger;
00036 
00040 public class ContextDump {
00041 
00042     public static void print(String header, Context ctx, Logger logger, int logLevel) {
00043         logger.log(logLevel, header);
00044         logger.log(logLevel, "=================================");
00045         print(ctx, logger, logLevel, "");
00046         logger.log(logLevel, "=================================");
00047     }
00048 
00055     private static void print(Context ctx, Logger logger, int logLevel, String indent) {
00056         String aName = null;
00057         try {
00058             for (NamingEnumeration pNames = ctx.list(""); pNames.hasMore();) {
00059                 Object o = pNames.next();
00060                 if (o instanceof NameClassPair) {
00061                     aName = ((NameClassPair) o).getName();
00062                     Object v = ctx.lookup(aName);
00063                     if (v != null) {
00064                         if (v instanceof Context) {
00065                             logger.log(logLevel, indent + aName);
00066                             print((Context) v, logger, logLevel, indent + "  ");
00067                         } else {
00068                             logger.log(logLevel, indent + aName + " = " + v);
00069                         }
00070                     }
00071                 }
00072             }
00073         } catch (NamingException ne) {
00074             logger.log(logLevel, "Failed to dump contex: " + ne.toString());
00075         }
00076     }
00077 }

Generated on Tue Feb 15 15:05:14 2005 for JOnAS by  doxygen 1.3.9.1