本文整理汇总了Java中javax.management.ServiceNotFoundException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceNotFoundException.getCause方法的具体用法?Java ServiceNotFoundException.getCause怎么用?Java ServiceNotFoundException.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.ServiceNotFoundException
的用法示例。
在下文中一共展示了ServiceNotFoundException.getCause方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.management.ServiceNotFoundException; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
示例2: main
import javax.management.ServiceNotFoundException; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}