FileDocCategorySizeDatePackage
JndiMBeanHelper.javaAPI DocGlassfish v2 API5609Fri May 04 22:24:20 BST 2007com.sun.enterprise.admin.monitor.jndi

JndiMBeanHelper

public class JndiMBeanHelper extends Object
The JndiMBeanHelper serves as a delegator object for the JndiMBeanImpl for interacting with the application server's naming service. The client of the JndiMBean will call the getNames method which in turn calls this object's getJndiEntriesByContextPath to retrieve all those names bound in that naming service's subcontext.
author
Rob Ruyak

Fields Summary
private InitialContext
context
private static final Logger
logger
private static final com.sun.enterprise.util.i18n.StringManager
sm
private final String
SYSTEM_SUBCONTEXT
Constructors Summary
public JndiMBeanHelper()
Creates a new instance of JndiMBeanHelper

    
           
      
        initialize();
    
Methods Summary
java.util.ArrayListgetJndiEntriesByContextPath(java.lang.String contextPath)
Gets the jndi entries from the application server's naming service given a particular context/subcontext.

param
contextPath The naming context or subcontext to query.
return
An {@link ArrayList} of {@link NameClassPair} objects.
throws
NamingException if an error occurs when connection with the naming service is established or retrieval fails.

        ArrayList names = new ArrayList();
        NamingEnumeration ee = null;
        if(contextPath == null) { contextPath = ""; }
        try {
            ee = context.list(contextPath);
        } catch(NameNotFoundException e) {
            String msg = sm.getString("monitor.jndi.context_notfound", 
                new Object[]{contextPath});
            logger.log(Level.WARNING, msg);
            NamingException ne = new NamingException(msg);
            //ne.initCause(e);
            System.out.println("Exception print: " + ne);
            throw ne;
        }
        names = toNameClassPairArray(ee);
        return names;
    
voidinitialize()
Initializes the JndiMBeanHelper object upon creation. It specifically creates an InitialContext instance for querying the naming service during certain method invocations.

        try {
            context = new InitialContext(); 
        } catch(javax.naming.NamingException e) {
            logger.log(Level.WARNING, e.getMessage(), e);
        }
    
java.util.ArrayListtoNameClassPairArray(javax.naming.NamingEnumeration ee)
Changes a NamingEnumeration object into an ArrayList of NameClassPair objects.

param
ee An {@link NamingEnumeration} object to be transformed.
return
An {@link ArrayList} of {@link NameClassPair} objects.
throws
Exception if an error occurs when iterating over the enum.

        ArrayList names = new ArrayList();
        while(ee.hasMore()) {
            // don't add the __SYSTEM subcontext - Fix for 6041360
            Object o = ee.next();
            if(o.toString().indexOf(SYSTEM_SUBCONTEXT) == -1) {
                names.add(o);
            }
        }
        return names;