1 22 package org.jboss.jmx.adaptor.snmp.agent; 23 24 import java.util.ArrayList ; 25 26 import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings; 27 import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean; 28 import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute; 29 import org.jboss.logging.Logger; 30 import org.jboss.xb.binding.ObjectModelFactory; 31 import org.jboss.xb.binding.UnmarshallingContext; 32 import org.xml.sax.Attributes ; 33 34 40 public class AttributeMappingsBinding implements ObjectModelFactory 41 { 42 private static Logger log = Logger.getLogger(AttributeMappingsBinding.class); 43 44 public Object newRoot(Object root, UnmarshallingContext ctx, 45 String namespaceURI, String localName, Attributes attrs) 46 { 47 if (!localName.equals("attribute-mappings")) 48 { 49 throw new IllegalStateException ("Unexpected root " + localName + ". Expected <attribute-mappings>"); 50 } 51 return new AttributeMappings(); 52 } 53 54 public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name) 55 { 56 return root; 57 } 58 59 public void setValue(AttributeMappings mappings, UnmarshallingContext navigator, 60 String namespaceUri, String localName, String value) 61 { 62 } 63 64 public Object newChild(AttributeMappings mappings, UnmarshallingContext navigator, 65 String namespaceUri, String localName, Attributes attrs) 66 { 67 if ("mbean".equals(localName)) 68 { 69 String name = attrs.getValue("name"); 70 String oidPrefix = attrs.getValue("oid-prefix"); 71 ManagedBean child = new ManagedBean(); 72 child.setName(name); 73 child.setOidPrefix(oidPrefix); 74 if (log.isTraceEnabled()) 75 log.trace("newChild: " + child.toString()); 76 return child; 77 } 78 return null; 79 } 80 81 public void addChild(AttributeMappings mappings, ManagedBean mbean, 82 UnmarshallingContext navigator, String namespaceURI, String localName) 83 { 84 mappings.addMonitoredMBean(mbean); 85 } 86 87 public Object newChild(ManagedBean mbean, UnmarshallingContext navigator, 88 String namespaceUri, String localName, Attributes attrs) 89 { 90 91 MappedAttribute attribute = null; 92 if ("attribute".equals(localName)) { 93 String oid = attrs.getValue("oid"); 94 String name = attrs.getValue("name"); 95 String mode = attrs.getValue("mode"); 96 attribute = new MappedAttribute(); 97 if ("rw".equalsIgnoreCase(mode)) 98 attribute.setReadWrite(true); 99 attribute.setName(name); 100 attribute.setOid(oid); 101 } 102 return attribute; 103 } 104 105 public void addChild(ManagedBean mbean, MappedAttribute attribute, 106 UnmarshallingContext navigator, String namespaceURI, String localName) 107 { 108 if (mbean.getAttributes() == null) 109 mbean.setAttributes(new ArrayList ()); 110 111 mbean.getAttributes().add(attribute); 112 } 113 } 114 | Popular Tags |