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