[Mc4j-cvs] mc4j/src/org/mc4j/console/connection Oc4jConnectionNode.java,NONE,1.1
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2004-04-02 03:37:54
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/connection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16150/src/org/mc4j/console/connection Added Files: Oc4jConnectionNode.java Log Message: Initial OC4J 10.0.3 support. --- NEW FILE: Oc4jConnectionNode.java --- /* * Author: Steve Button * * The contents of this file are subject to the Sapient Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy of the * License at http://mc4j.sf.net/License-SPL.html. * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, * either express or implied. See the License for the specific language governing rights and limitations * under the License. * * The Original Code is The MC4J Management Console * The Initial Developer of the Original Code is Greg Hinkle (gh...@us...) * Copyright (C) 2004 Greg Hinkle. All Rights Reserved. * * Redistributions of code or binary files using or based on this code must reproduce the * above copyright and disclaimer. For more information see <http://mc4j.sourceforge.net>. */ package org.mc4j.console.connection; import java.lang.reflect.Field; import java.util.Hashtable; import javax.management.MBeanServer; import javax.management.j2ee.Management; import javax.management.j2ee.ManagementHome; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.mc4j.console.connection.proxy.GenericMBeanServerProxy; /** * This Node acts as a connection to an OC4J MBean Server via a MEJB. * The MEJB connection is ontained using a J2EE ApplicationClient. This * involves a workaround which requires a META-INF/application-client.xml to be * present in one of the JAR files which the client is loading. The application-client.xml * file can be completely empty, it just needs to be present. * <p/> * Accordingly, an empty application-client.xml has been added to the src/etc directory * and is included in the mc4j_core.jar file when it is created. * * @author Steve Button(sb...@us...), March 2004 * @version 1.0 */ public class Oc4jConnectionNode extends ConnectionNode { private static final boolean M_DEBUG = true; protected MBeanServer mbeanServer; /** * Connect to the OC4J ManagementEJB. This should only be used while the JSR160 * interface is not available. * * @throws Exception */ public void connect() throws Exception { log("Oc4jConnectionNode"); log(connectionSettings.toString()); logMessage("ConnectionSettings: " + connectionSettings.toString()); Context ctx = null; ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); try { //The OC4J connection type Hashtable env = new Hashtable(); env.put(Context.PROVIDER_URL, connectionSettings.getServerUrl()); env.put(Context.SECURITY_PRINCIPAL, connectionSettings.getPrinciple()); env.put(Context.SECURITY_CREDENTIALS, connectionSettings.getCredentials()); env.put(Context.INITIAL_CONTEXT_FACTORY, connectionSettings.getInitialContextName()); Context oc4jctx = new InitialContext(env); Object obj = (ManagementHome) oc4jctx.lookup(connectionSettings.getJndiName()); ManagementHome mgmtHome = (ManagementHome) PortableRemoteObject.narrow(obj, ManagementHome.class); Management oc4jmbs = mgmtHome.create(); this.mbeanServer = (MBeanServer) GenericMBeanServerProxy.buildServerProxy(oc4jmbs); super.connect(); } catch (Exception e) { e.printStackTrace(); NotifyDescriptor d = new NotifyDescriptor.Message("Unable to connect to OC4J server at [" + this.connectionSettings.getServerUrl() + "]. \nCheck to make sure the OC4J server is running on the specified host and port.", NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(d); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } } public String getConstant(Class clazz, String name) throws Exception { Field field = clazz.getField(name); return (String) field.get(null); } public void disconnect() throws Exception { super.disconnect(); //this.connector.close(); super.connected = false; } public MBeanServer getMBeanServer() { return this.mbeanServer; } private void logMessage(String msg) { if (!M_DEBUG) return; NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(d); } private void log(String msg) { if (!M_DEBUG) return; System.out.println(msg); } public String getDefaultServerUrl() { return "ormi://localhost:23791/default"; } public String getDefaultJndiName() { return "java:comp/env/ejb/mgmt/MEJB"; } public String getDefaultInitialContext() { return "com.evermind.server.ApplicationClientInitialContextFactory"; } public String getDefaultPrinciple() { return "admin"; } public String getDefaultCredentials() { return ""; } } |