1 22 package org.jboss.system.metadata; 23 24 import java.util.Properties ; 25 26 import javax.management.MBeanAttributeInfo ; 27 28 import org.jboss.deployment.DeploymentException; 29 import org.jboss.util.propertyeditor.PropertyEditors; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.Node ; 32 import org.w3c.dom.NodeList ; 33 34 47 public class ServiceJavaBeanValueMetaData extends ServiceElementValueMetaData 48 { 49 52 public ServiceJavaBeanValueMetaData() 53 { 54 super(); 55 } 56 57 62 public ServiceJavaBeanValueMetaData(Element element) 63 { 64 super(element); 65 } 66 67 public Object getValue(ServiceValueContext valueContext) throws Exception 68 { 69 MBeanAttributeInfo attributeInfo = valueContext.getAttributeInfo(); 70 ClassLoader cl = valueContext.getClassloader(); 71 boolean trim = valueContext.isTrim(); 72 boolean replace = valueContext.isReplace(); 73 74 Element element = getElement(); 76 String attributeClassName = element.getAttribute("attributeClass"); 77 if( attributeClassName == null || attributeClassName.length() == 0 ) 78 attributeClassName = attributeInfo.getType(); 79 if (attributeClassName == null) 80 throw new DeploymentException("AttributeInfo for " + attributeInfo.getName() + " has no type"); 81 Class attributeClass = cl.loadClass(attributeClassName); 82 Object bean = attributeClass.newInstance(); 84 NodeList properties = element.getElementsByTagName("property"); 86 Properties beanProps = new Properties (); 87 for(int n = 0; n < properties.getLength(); n ++) 88 { 89 Node node = properties.item(n); 91 if (node.getNodeType() != Node.ELEMENT_NODE) 92 { 93 continue; 94 } 95 Element property = (Element ) node; 96 String name = property.getAttribute("name"); 97 String value = ServiceMetaDataParser.getElementTextContent(property, trim, replace); 98 beanProps.setProperty(name, value); 99 } 100 101 PropertyEditors.mapJavaBeanProperties(bean, beanProps); 103 return bean; 104 } 105 } 106 | Popular Tags |