1 package org.apache.tools.ant.taskdefs.optional.jmx; 2 3 52 53 54 import org.apache.tools.ant.BuildException; 55 56 57 67 public class CreateMBeanTask extends ConfigureMBeanTask { 68 69 private String ifExists = IfExists.FAIL; 70 private String type = null; 71 72 public void setType(String type) { 73 this.type = type; 74 } 75 76 private String getType() { 77 if (type == null) { 80 try { 81 type = getObjectName().getKeyProperty("Type"); 82 } catch (Exception eatMe) { 83 } 85 } 86 87 return type; 88 } 89 90 98 public void setIfExists(IfExists ifExists) { 99 this.ifExists = ifExists.getValue(); 100 } 101 102 108 protected void execute(javax.management.MBeanServer mbserver) throws BuildException { 109 110 try { 111 javax.management.ObjectName mbeanName = getObjectName(); 112 113 removeMBeanIfExists(mbserver,mbeanName,ifExists); 114 115 if (!mbserver.isRegistered(mbeanName)) { 116 try { 117 mbeanName = getJMXServer().createMBean(getType(),getObjectName(),mbserver); 118 if (!mbserver.isRegistered(mbeanName)) { 119 throw new BuildException("Cannot create MBean. [" + toString() + "]"); 120 } 121 } catch (Exception ex) { 122 throw new BuildException("Cannot create MBean. [" + toString() + "]",ex); 123 } 124 } else { 125 throw new BuildException("Cannot create MBean. [" + toString() + "]"); 126 } 127 } catch (javax.management.MalformedObjectNameException x) { 128 throw new BuildException(x); 129 } 130 131 super.execute(mbserver); 134 } 135 136 137 } 138 139 149 | Popular Tags |