001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.jmx.adaptor.snmp.agent;
023:
024: import java.util.ArrayList;
025:
026: import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
027: import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
028: import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
029: import org.jboss.logging.Logger;
030: import org.jboss.xb.binding.ObjectModelFactory;
031: import org.jboss.xb.binding.UnmarshallingContext;
032: import org.xml.sax.Attributes;
033:
034: /**
035: * Parse the mapping of JMX mbean attributes to SNMP OIDs
036: *
037: * @author <a href="mailto:hwr@pilhuhn.de">Heiko W. Rupp</a>
038: * @version $Revision: 57210 $
039: */
040: public class AttributeMappingsBinding implements ObjectModelFactory {
041: private static Logger log = Logger
042: .getLogger(AttributeMappingsBinding.class);
043:
044: public Object newRoot(Object root, UnmarshallingContext ctx,
045: String namespaceURI, String localName, Attributes attrs) {
046: if (!localName.equals("attribute-mappings")) {
047: throw new IllegalStateException("Unexpected root "
048: + localName + ". Expected <attribute-mappings>");
049: }
050: return new AttributeMappings();
051: }
052:
053: public Object completeRoot(Object root, UnmarshallingContext ctx,
054: String uri, String name) {
055: return root;
056: }
057:
058: public void setValue(AttributeMappings mappings,
059: UnmarshallingContext navigator, String namespaceUri,
060: String localName, String value) {
061: }
062:
063: public Object newChild(AttributeMappings mappings,
064: UnmarshallingContext navigator, String namespaceUri,
065: String localName, Attributes attrs) {
066: if ("mbean".equals(localName)) {
067: String name = attrs.getValue("name");
068: String oidPrefix = attrs.getValue("oid-prefix");
069: ManagedBean child = new ManagedBean();
070: child.setName(name);
071: child.setOidPrefix(oidPrefix);
072: if (log.isTraceEnabled())
073: log.trace("newChild: " + child.toString());
074: return child;
075: }
076: return null;
077: }
078:
079: public void addChild(AttributeMappings mappings, ManagedBean mbean,
080: UnmarshallingContext navigator, String namespaceURI,
081: String localName) {
082: mappings.addMonitoredMBean(mbean);
083: }
084:
085: public Object newChild(ManagedBean mbean,
086: UnmarshallingContext navigator, String namespaceUri,
087: String localName, Attributes attrs) {
088:
089: MappedAttribute attribute = null;
090: if ("attribute".equals(localName)) {
091: String oid = attrs.getValue("oid");
092: String name = attrs.getValue("name");
093: String mode = attrs.getValue("mode");
094: attribute = new MappedAttribute();
095: if ("rw".equalsIgnoreCase(mode))
096: attribute.setReadWrite(true);
097: attribute.setName(name);
098: attribute.setOid(oid);
099: }
100: return attribute;
101: }
102:
103: public void addChild(ManagedBean mbean, MappedAttribute attribute,
104: UnmarshallingContext navigator, String namespaceURI,
105: String localName) {
106: if (mbean.getAttributes() == null)
107: mbean.setAttributes(new ArrayList());
108:
109: mbean.getAttributes().add(attribute);
110: }
111: }
|