1 22 package org.jboss.system.metadata; 23 24 import java.beans.PropertyEditor ; 25 import java.beans.PropertyEditorManager ; 26 27 import javax.management.MBeanAttributeInfo ; 28 29 import org.jboss.deployment.DeploymentException; 30 import org.jboss.util.Classes; 31 import org.jboss.util.propertyeditor.PropertyEditors; 32 33 46 public class ServiceTextValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData 47 { 48 static 49 { 50 try 51 { 52 PropertyEditors.init(); 53 } 54 catch (Exception ignored) 55 { 56 } 57 } 58 59 60 private String text; 61 62 67 public ServiceTextValueMetaData(String text) 68 { 69 setText(text); 70 } 71 72 77 public String getText() 78 { 79 return text; 80 } 81 82 87 public void setText(String text) 88 { 89 if (text == null) 90 throw new IllegalArgumentException ("Null text"); 91 this.text = text; 92 } 93 94 public Object getValue(ServiceValueContext valueContext) throws Exception 95 { 96 MBeanAttributeInfo attributeInfo = valueContext.getAttributeInfo(); 97 ClassLoader cl = valueContext.getClassloader(); 98 99 String typeName = attributeInfo.getType(); 100 if (typeName == null) 101 throw new DeploymentException("AttributeInfo for " + attributeInfo.getName() + " has no type"); 102 103 Class typeClass = Classes.getPrimitiveTypeForName(typeName); 105 if (typeClass == null) 106 { 107 try 109 { 110 typeClass = cl.loadClass(typeName); 111 } 112 catch (ClassNotFoundException e) 113 { 114 throw new DeploymentException("Class not found for attribute: " + attributeInfo.getName(), e); 115 } 116 } 117 118 PropertyEditor editor = PropertyEditorManager.findEditor(typeClass); 119 if (editor == null) 120 throw new DeploymentException("No property editor for attribute: " + attributeInfo.getName() + "; type=" + typeClass.getName()); 121 122 ClassLoader tcl = Thread.currentThread().getContextClassLoader(); 125 Thread.currentThread().setContextClassLoader(cl); 126 try 127 { 128 editor.setAsText(text); 129 return editor.getValue(); 130 } 131 finally 132 { 133 Thread.currentThread().setContextClassLoader(tcl); 134 } 135 } 136 } 137 | Popular Tags |