KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > metadata > xb > ModelMBeanInfoSupportWrapper


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
23 package org.jboss.mx.metadata.xb;
24
25 import java.util.ArrayList JavaDoc;
26 import javax.management.modelmbean.ModelMBeanOperationInfo JavaDoc;
27 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
28 import javax.management.modelmbean.ModelMBeanConstructorInfo JavaDoc;
29 import javax.management.modelmbean.ModelMBeanNotificationInfo JavaDoc;
30 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
31 import javax.management.modelmbean.ModelMBeanInfoSupport JavaDoc;
32 import javax.management.Descriptor JavaDoc;
33
34 import org.jboss.logging.Logger;
35 import org.jboss.mx.modelmbean.ModelMBeanConstants;
36
37 /**
38  * A javabean wrapper used to construct a ModelMBeanInfoSupport
39  * @author Scott.Stark@jboss.org
40  * @version $Revision: 42797 $
41  */

42 public class ModelMBeanInfoSupportWrapper
43 {
44    private static final Logger log = Logger.getLogger(ModelMBeanInfoSupportWrapper.class);
45    private String JavaDoc mmbClassName = "org.jboss.mx.modelmbean.XMBean";
46
47    private String JavaDoc description;
48    private ArrayList JavaDoc operInfo = new ArrayList JavaDoc();
49    private ArrayList JavaDoc attrInfo = new ArrayList JavaDoc();
50    private ArrayList JavaDoc constrInfo = new ArrayList JavaDoc();
51    private ArrayList JavaDoc notifInfo = new ArrayList JavaDoc();
52    private Descriptor JavaDoc descriptor;
53
54    public String JavaDoc getClassName()
55    {
56       return mmbClassName;
57    }
58
59    public void setClassName(String JavaDoc mmbClassName)
60    {
61       this.mmbClassName = mmbClassName;
62    }
63
64    public String JavaDoc getDescription()
65    {
66       return description;
67    }
68    public void setDescription(String JavaDoc description)
69    {
70       this.description = description;
71    }
72    public Descriptor JavaDoc getDescriptors()
73    {
74       return descriptor;
75    }
76    public void setDescriptors(Descriptor JavaDoc descriptor)
77    {
78       this.descriptor = descriptor;
79    }
80
81    public void addConstructor(ModelMBeanConstructorInfo JavaDoc info)
82    {
83       this.constrInfo.add(info);
84    }
85    public void addAttribute(ModelMBeanAttributeInfo JavaDoc info)
86    {
87       this.attrInfo.add(info);
88    }
89    public void addOperation(ModelMBeanOperationInfo JavaDoc info)
90    {
91       this.operInfo.add(info);
92    }
93    public void addNotification(ModelMBeanNotificationInfo JavaDoc info)
94    {
95       this.notifInfo.add(info);
96    }
97
98    public Object JavaDoc instantiate()
99    {
100       ModelMBeanOperationInfo JavaDoc[] ops = new ModelMBeanOperationInfo JavaDoc[operInfo.size()];
101       operInfo.toArray(ops);
102       ModelMBeanAttributeInfo JavaDoc[] attrs = new ModelMBeanAttributeInfo JavaDoc[attrInfo.size()];
103       attrInfo.toArray(attrs);
104       ModelMBeanConstructorInfo JavaDoc[] ctors = new ModelMBeanConstructorInfo JavaDoc[constrInfo.size()];
105       constrInfo.toArray(ctors);
106       ModelMBeanNotificationInfo JavaDoc[] msgs = new ModelMBeanNotificationInfo JavaDoc[notifInfo.size()];
107       notifInfo.toArray(msgs);
108       // Validate the required descriptor fields
109
if( descriptor != null )
110       {
111          if( descriptor.getFieldValue(ModelMBeanConstants.NAME) == null )
112             descriptor.setField(ModelMBeanConstants.NAME, getClassName());
113          if( descriptor.getFieldValue(ModelMBeanConstants.DESCRIPTOR_TYPE) == null )
114             descriptor.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, ModelMBeanConstants.MBEAN_DESCRIPTOR);
115       }
116       ModelMBeanInfo JavaDoc info = new ModelMBeanInfoSupport JavaDoc(
117          mmbClassName, description, attrs, ctors,
118          ops, msgs, descriptor);
119       return info;
120    }
121
122    public ModelMBeanInfo JavaDoc getMBeanInfo()
123    {
124       return (ModelMBeanInfo JavaDoc) instantiate();
125    }
126 }
127
Popular Tags