KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > jmx > config > Attributes


1 package org.sapia.soto.jmx.config;
2
3 import org.sapia.soto.ConfigurationException;
4 import org.sapia.soto.jmx.AttributeDescriptor;
5 import org.sapia.soto.jmx.MBeanDescriptor;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9
10 import javax.management.IntrospectionException JavaDoc;
11
12
13 /**
14  * @author Yanick Duchesne
15  * 18-Aug-2003
16  * <dl>
17  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
18  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
19  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
20  * </dl>
21  */

22 public class Attributes {
23   private List JavaDoc _includes = new ArrayList JavaDoc();
24   private List JavaDoc _excludes = new ArrayList JavaDoc();
25
26   /**
27    * Constructor for Attributes.
28    */

29   public Attributes() {
30     super();
31   }
32
33   public void init(MBeanDescriptor mbean)
34     throws IntrospectionException JavaDoc, ConfigurationException {
35     Attribute attr;
36     AttributeDescriptor desc;
37     List JavaDoc includes = new ArrayList JavaDoc();
38     List JavaDoc descs;
39
40     for (int i = 0; i < _includes.size(); i++) {
41       attr = (Attribute) _includes.get(i);
42
43       if (attr.getName() == null) {
44         throw new ConfigurationException(
45           "'name' attribute not specified on 'include' element");
46       }
47
48       includes.addAll(descs = mbean.getAttributeDescriptorsFor(attr.getName(),
49             attr.getType()));
50
51       for (int j = 0; j < descs.size(); j++) {
52         desc = (AttributeDescriptor) descs.get(j);
53         desc.setDescription(attr.getDescription());
54
55         if (desc.getWriteMethod() != null) {
56           desc.setWritable(attr.isWritable());
57         }
58       }
59     }
60
61     for (int i = 0; i < _excludes.size(); i++) {
62       attr = (Attribute) _excludes.get(i);
63
64       if (attr.getName() == null) {
65         throw new ConfigurationException(
66           "'name' attribute not specified on 'exclude' element");
67       }
68
69       mbean.removeAttributeDescriptorsFor(attr.getName(), attr.getType());
70     }
71
72     for (int i = 0; i < includes.size(); i++) {
73       mbean.addAttributeDescriptor((AttributeDescriptor) includes.get(i));
74     }
75   }
76
77   public Attribute createInclude() {
78     Attribute attr = new Attribute();
79     _includes.add(attr);
80
81     return attr;
82   }
83
84   public Attribute createExclude() {
85     Attribute attr = new Attribute();
86     _excludes.add(attr);
87
88     return attr;
89   }
90 }
91
Popular Tags