KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jmx > adaptor > snmp > agent > AttributeMappingsBinding


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.jmx.adaptor.snmp.agent;
23
24 import java.util.ArrayList JavaDoc;
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 JavaDoc;
33
34 /**
35  * Parse the mapping of JMX mbean attributes to SNMP OIDs
36  *
37  * @author <a HREF="mailto:hwr@pilhuhn.de">Heiko W. Rupp</a>
38  * @version $Revision: 44605 $
39  */

40 public class AttributeMappingsBinding implements ObjectModelFactory
41 {
42    private static Logger log = Logger.getLogger(AttributeMappingsBinding.class);
43     
44     public Object JavaDoc newRoot(Object JavaDoc root, UnmarshallingContext ctx,
45             String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
46    {
47        if (!localName.equals("attribute-mappings"))
48       {
49           throw new IllegalStateException JavaDoc("Unexpected root " + localName + ". Expected <attribute-mappings>");
50         }
51        return new AttributeMappings();
52     }
53
54     public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx, String JavaDoc uri, String JavaDoc name)
55    {
56        return root;
57     }
58
59     public void setValue(AttributeMappings mappings, UnmarshallingContext navigator,
60               String JavaDoc namespaceUri, String JavaDoc localName, String JavaDoc value)
61     {
62     }
63     
64     public Object JavaDoc newChild(AttributeMappings mappings, UnmarshallingContext navigator,
65             String JavaDoc namespaceUri, String JavaDoc localName, Attributes JavaDoc attrs)
66     {
67         if ("mbean".equals(localName))
68       {
69             String JavaDoc name = attrs.getValue("name");
70             String JavaDoc 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 JavaDoc namespaceURI, String JavaDoc localName)
83     {
84         mappings.addMonitoredMBean(mbean);
85     }
86     
87     public Object JavaDoc newChild(ManagedBean mbean, UnmarshallingContext navigator,
88             String JavaDoc namespaceUri, String JavaDoc localName, Attributes JavaDoc attrs)
89     {
90         
91         MappedAttribute attribute = null;
92         if ("attribute".equals(localName)) {
93             String JavaDoc oid = attrs.getValue("oid");
94             String JavaDoc name = attrs.getValue("name");
95             String JavaDoc 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 JavaDoc namespaceURI, String JavaDoc localName)
107     {
108         if (mbean.getAttributes() == null)
109          mbean.setAttributes(new ArrayList JavaDoc());
110         
111         mbean.getAttributes().add(attribute);
112     }
113 }
114
Popular Tags