1 22 package org.jboss.system.metadata; 23 24 import javax.management.MBeanAttributeInfo ; 25 import javax.management.MBeanServer ; 26 import javax.management.MalformedObjectNameException ; 27 import javax.management.ObjectName ; 28 29 import org.jboss.dependency.spi.ControllerState; 30 import org.jboss.deployment.DeploymentException; 31 import org.jboss.mx.util.MBeanProxyExt; 32 import org.jboss.system.microcontainer.LifecycleDependencyItem; 33 import org.jboss.system.microcontainer.ServiceControllerContext; 34 35 48 public class ServiceDependencyValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData 49 { 50 51 private String dependency; 52 53 54 private ObjectName objectName; 55 56 57 private String proxyType; 58 59 62 public ServiceDependencyValueMetaData() 63 { 64 } 65 66 71 public ServiceDependencyValueMetaData(String dependency) 72 { 73 setDependency(dependency); 74 } 75 76 82 public ServiceDependencyValueMetaData(String dependency, String proxyType) 83 { 84 setDependency(dependency); 85 setProxyType(proxyType); 86 } 87 88 93 public String getDependency() 94 { 95 if (dependency == null) 96 return objectName.getCanonicalName(); 97 return dependency; 98 } 99 100 105 public void setDependency(String dependency) 106 { 107 if (dependency == null) 108 throw new IllegalArgumentException ("Null dependency"); 109 this.dependency = dependency; 110 this.objectName = null; 111 } 112 113 119 public ObjectName getObjectName() throws MalformedObjectNameException 120 { 121 if (objectName == null) 122 { 123 if (dependency.trim().length() == 0) 124 throw new MalformedObjectNameException ("Missing object name in depends"); 125 ObjectName name = new ObjectName (dependency); 126 if (name.isPattern()) 127 throw new MalformedObjectNameException ("ObjectName patterns are not allowed in depends: " + objectName); 128 objectName = new ObjectName (dependency); 129 dependency = null; 130 } 131 return objectName; 132 } 133 134 139 public void setObjectName(ObjectName objectName) 140 { 141 if (objectName == null) 142 throw new IllegalArgumentException ("Null objectName"); 143 this.objectName = objectName; 144 } 145 146 151 public String getProxyType() 152 { 153 return proxyType; 154 } 155 156 161 public void setProxyType(String proxyType) 162 { 163 this.proxyType = proxyType; 164 } 165 166 public Object getValue(ServiceValueContext valueContext) throws Exception 167 { 168 MBeanAttributeInfo attributeInfo = valueContext.getAttributeInfo(); 169 ClassLoader cl = valueContext.getClassloader(); 170 MBeanServer server = valueContext.getServer(); 171 172 ObjectName objectName = getObjectName(); 173 174 if (proxyType != null) 175 { 176 if (proxyType.equals("attribute")) 177 { 178 proxyType = attributeInfo.getType(); 179 if (proxyType == null) 180 throw new DeploymentException("AttributeInfo for " + attributeInfo.getName() + " has no type"); 181 } 182 183 Class proxyClass = cl.loadClass(proxyType); 184 return MBeanProxyExt.create(proxyClass, objectName, server, true); 185 } 186 187 return objectName; 188 } 189 190 public void visit(ServiceMetaDataVisitor visitor) 191 { 192 ServiceControllerContext context = visitor.getControllerContext(); 193 Object name = context.getName(); 194 Object other = dependency; 195 try 196 { 197 other = getObjectName().getCanonicalName(); 198 } 199 catch (MalformedObjectNameException ignored) 200 { 201 } 202 visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.CREATE)); 204 visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.START)); 205 visitor.visit(this); 206 } 207 } 208 | Popular Tags |