001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JavaEEVerifierMBeanInstaller.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package test;
030:
031: import com.sun.appserv.server.LifecycleEvent;
032: import com.sun.appserv.server.LifecycleEventContext;
033: import com.sun.appserv.server.LifecycleListener;
034: import com.sun.appserv.server.ServerLifecycleException;
035:
036: import java.util.Properties;
037: import java.util.logging.Logger;
038: import javax.management.openmbean.OpenDataException;
039: import javax.management.ObjectName;
040: import javax.management.StandardMBean;
041: import javax.management.MBeanServer;
042: import java.lang.management.ManagementFactory;
043:
044: /**
045: *
046: * This class is used to add the JavaEEVerifierMBean in the MBean Server.
047: * This class is used to test the contract between JBI application verifier
048: * and JavaEEVerifier.
049: *
050: * @author Sun Microsystems, Inc.
051: */
052: public class JavaEEVerifierMBeanInstaller implements LifecycleListener {
053:
054: /**
055: * Provide the processing for AppServer lifecycle events. For each
056: * event, a corresponding method is called to perform the processing
057: * for that event.
058: * @param anEvent LifecycleEvent from AppServer
059: * @throws ServerLifecycleException if any error occurs processing
060: * an event.
061: */
062: public void handleEvent(LifecycleEvent anEvent)
063: throws ServerLifecycleException {
064: // This entire method must be enclosed in a try-catch block to
065: // prevent any exception other than ServerLifecycleException from
066: // being thrown. Any other exception causes the AppServer startup
067: // to fail.
068:
069: try {
070: LifecycleEventContext eventContext = anEvent
071: .getLifecycleEventContext();
072:
073: if (LifecycleEvent.STARTUP_EVENT == anEvent.getEventType()) {
074: addJavaEEVerifierMBean(eventContext);
075: }
076: } catch (Throwable ex) {
077: throw new ServerLifecycleException(ex);
078: }
079:
080: return;
081: }
082:
083: /**
084: * This method is used to add the JavaEEVerifier MBean
085: * @param LifecycleEventContext event context
086: */
087: public void addJavaEEVerifierMBean(
088: LifecycleEventContext eventContext) {
089: try {
090: ObjectName mBeanObjName = new ObjectName(
091: "com.sun.jbi:ServiceName=JavaEEVerifier,ComponentType=System");
092: StandardMBean mbean = new StandardMBean(
093: new TestJavaEEVerifierMBeanImpl(),
094: test.TestJavaEEVerifierMBean.class);
095: ManagementFactory.getPlatformMBeanServer().registerMBean(
096: mbean, mBeanObjName);
097: } catch (javax.management.MalformedObjectNameException ex) {
098: System.out.println("JavaEEVerifierMBean could not be added"
099: + ex.getMessage());
100: } catch (javax.management.NotCompliantMBeanException ex) {
101: System.out.println("JavaEEVerifierMBean could not be added"
102: + ex.getMessage());
103: } catch (javax.management.InstanceAlreadyExistsException ex) {
104: System.out.println("JavaEEVerifierMBean could not be added"
105: + ex.getMessage());
106: } catch (javax.management.MBeanRegistrationException ex) {
107: System.out.println("JavaEEVerifierMBean could not be added"
108: + ex.getMessage());
109: }
110:
111: }
112: }
|