/* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. */ import com.sun.appserv.security.ProgrammaticLogin; import java.util.Set; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import javax.management.ObjectName; import javax.management.j2ee.Management; import javax.management.j2ee.ManagementHome; import java.util.Iterator; import java.util.Properties; import javax.management.MBeanAttributeInfo; import javax.management.MBeanInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanParameterInfo; import javax.naming.NamingException; public class MEJBStandaloneClient { public static void main(String[] args) { String jndiName = null; if (args.length == 1 ) { jndiName = args[0]; } else { System.out.println("usage: MEJBStandaloneClient jndiName"); System.exit(1); } try { Context ctx = new InitialContext(); Object objref = ctx.lookup(jndiName); ManagementHome home = (ManagementHome)PortableRemoteObject.narrow(objref, javax.management.j2ee.ManagementHome.class); // Authentication ProgrammaticLogin pl = new ProgrammaticLogin(); System.out.println("Login success = " + pl.login("j2ee","j2ee","default", true)); // Use the MEJB Management mejb = home.create(); ObjectName sp = new ObjectName("*:*"); Set mbeanNames = mejb.queryNames(null, null); System.out.println("Found " + mbeanNames.size() + " Managed Objects."); Iterator it = mbeanNames.iterator(); while ( it.hasNext() ) { ObjectName name = (ObjectName)it.next(); System.out.println("ObjectName = "+name); // Construct list of attr names MBeanInfo info = mejb.getMBeanInfo(name); System.out.println("MBean class = " + info.getClassName()); System.out.println(""); MBeanAttributeInfo[] attrInfo = info.getAttributes(); for ( int i=0; i