1 23 24 29 30 package com.sun.enterprise.admin.monitor.jndi; 31 32 import com.sun.enterprise.admin.common.constant.AdminConstants; 33 import com.sun.enterprise.util.i18n.StringManager; 34 import java.util.ArrayList ; 35 import java.util.logging.Level ; 36 import java.util.logging.Logger ; 37 import javax.naming.InitialContext ; 38 import javax.naming.NameNotFoundException ; 39 import javax.naming.NamingEnumeration ; 40 import javax.naming.NamingException ; 41 42 51 public class JndiMBeanHelper { 52 53 private InitialContext context; 54 private static final Logger logger = 55 Logger.getLogger(AdminConstants.kLoggerName); 56 private static final StringManager sm = 57 StringManager.getManager(JndiMBeanHelper.class); 58 private final String SYSTEM_SUBCONTEXT = "__SYSTEM"; 59 60 61 public JndiMBeanHelper() { 62 initialize(); 63 } 64 65 70 void initialize() { 71 try { 72 context = new InitialContext (); 73 } catch(javax.naming.NamingException e) { 74 logger.log(Level.WARNING, e.getMessage(), e); 75 } 76 } 77 78 87 ArrayList getJndiEntriesByContextPath(String contextPath) 88 throws NamingException { 89 ArrayList names = new ArrayList (); 90 NamingEnumeration ee = null; 91 if(contextPath == null) { contextPath = ""; } 92 try { 93 ee = context.list(contextPath); 94 } catch(NameNotFoundException e) { 95 String msg = sm.getString("monitor.jndi.context_notfound", 96 new Object []{contextPath}); 97 logger.log(Level.WARNING, msg); 98 NamingException ne = new NamingException (msg); 99 System.out.println("Exception print: " + ne); 101 throw ne; 102 } 103 names = toNameClassPairArray(ee); 104 return names; 105 } 106 107 115 ArrayList toNameClassPairArray(NamingEnumeration ee) 116 throws javax.naming.NamingException { 117 ArrayList names = new ArrayList (); 118 while(ee.hasMore()) { 119 Object o = ee.next(); 121 if(o.toString().indexOf(SYSTEM_SUBCONTEXT) == -1) { 122 names.add(o); 123 } 124 } 125 return names; 126 } 127 } 128 | Popular Tags |