KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.Descriptor JavaDoc;
26 import javax.management.NotCompliantMBeanException JavaDoc;
27 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
28 import javax.management.modelmbean.DescriptorSupport JavaDoc;
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.jboss.xb.binding.GenericValueContainer;
32 import org.jboss.xb.binding.JBossXBRuntimeException;
33 import org.jboss.logging.Logger;
34 import org.jboss.mx.modelmbean.ModelMBeanConstants;
35
36 /**
37  * The ModelMBeanAttributeInfo JBossXB container
38  * @author Scott.Stark@jboss.org
39  * @version $Revision: 42809 $
40  */

41 public class ModelMBeanAttributeInfoContainer
42    implements GenericValueContainer
43 {
44    private static final Logger log = Logger.getLogger(ModelMBeanAttributeInfoContainer.class);
45    private String JavaDoc name;
46    private String JavaDoc type;
47    private String JavaDoc access;
48    private String JavaDoc getMethod;
49    private String JavaDoc setMethod;
50    private String JavaDoc description;
51    private Object JavaDoc value;
52    private Object JavaDoc defaultValue;
53    private Descriptor JavaDoc descriptor;
54
55    public Object JavaDoc getValue()
56    {
57       return value;
58    }
59
60    public void setValue(Object JavaDoc value)
61    {
62       this.value = value;
63    }
64
65    public Object JavaDoc getDefaultValue()
66    {
67       return defaultValue;
68    }
69
70    public void setDefaultValue(Object JavaDoc defaultValue)
71    {
72       this.defaultValue = defaultValue;
73    }
74
75    public String JavaDoc getType()
76    {
77       return type;
78    }
79
80    public void setType(String JavaDoc type)
81    {
82       this.type = type;
83    }
84
85    public String JavaDoc getAccess()
86    {
87       return access;
88    }
89
90    public void setAccess(String JavaDoc access)
91    {
92       this.access = access;
93    }
94
95    public String JavaDoc getGetMethod()
96    {
97       return getMethod;
98    }
99
100    public void setGetMethod(String JavaDoc getMethod)
101    {
102       this.getMethod = getMethod;
103    }
104
105    public String JavaDoc getSetMethod()
106    {
107       return setMethod;
108    }
109
110    public void setSetMethod(String JavaDoc setMethod)
111    {
112       this.setMethod = setMethod;
113    }
114
115    public Descriptor JavaDoc getDescriptors()
116    {
117       return descriptor;
118    }
119    public void setDescriptors(Descriptor JavaDoc descriptor)
120    {
121       this.descriptor = descriptor;
122    }
123
124    public Object JavaDoc instantiate()
125    {
126       try
127       {
128          ModelMBeanAttributeInfo JavaDoc info = buildAttributeInfo();
129          return info;
130       }
131       catch(NotCompliantMBeanException JavaDoc e)
132       {
133          throw new JBossXBRuntimeException(e);
134       }
135    }
136
137    public void addChild(QName JavaDoc name, Object JavaDoc value)
138    {
139       log.debug("addChild, " + name + "," + value);
140       String JavaDoc localName = name.getLocalPart();
141       if("name".equals(localName))
142       {
143          this.name = (String JavaDoc) value;
144       }
145       if("type".equals(localName))
146       {
147          this.type = (String JavaDoc) value;
148       }
149       if("access".equals(localName))
150       {
151          this.access = (String JavaDoc) value;
152       }
153       if("getMethod".equals(localName))
154       {
155          this.getMethod = (String JavaDoc) value;
156       }
157       if("setMethod".equals(localName))
158       {
159          this.setMethod = (String JavaDoc) value;
160       }
161       if("value".equals(localName))
162       {
163          this.value = value;
164       }
165       if("default".equals(localName))
166       {
167          this.defaultValue = value;
168       }
169       if("description".equals(localName))
170       {
171          this.description = (String JavaDoc) value;
172       }
173    }
174    public Class JavaDoc getTargetClass()
175    {
176       return ModelMBeanAttributeInfo JavaDoc.class;
177    }
178
179    protected ModelMBeanAttributeInfo JavaDoc buildAttributeInfo()
180       throws NotCompliantMBeanException JavaDoc
181    {
182       if (descriptor == null)
183       {
184          descriptor = new DescriptorSupport JavaDoc();
185       }
186       if (descriptor.getFieldValue(ModelMBeanConstants.NAME) == null)
187       {
188          descriptor.setField(ModelMBeanConstants.NAME, name);
189       }
190       if (descriptor.getFieldValue(ModelMBeanConstants.DESCRIPTOR_TYPE) == null)
191       {
192          descriptor.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, ModelMBeanConstants.ATTRIBUTE_DESCRIPTOR);
193       }
194
195       if (value != null)
196       {
197          descriptor.setField(ModelMBeanConstants.CACHED_VALUE, value);
198       }
199       if (defaultValue != null)
200       {
201          descriptor.setField(ModelMBeanConstants.DEFAULT, defaultValue);
202       }
203       
204       if (getMethod != null)
205       {
206          descriptor.setField(ModelMBeanConstants.GET_METHOD, getMethod);
207       }
208       if (setMethod != null)
209       {
210          descriptor.setField(ModelMBeanConstants.SET_METHOD, setMethod);
211       }
212
213       // defaults read-write
214
boolean isReadable = true;
215       boolean isWritable = true;
216       if (access.equalsIgnoreCase("read-only"))
217       {
218          isWritable = false;
219       }
220       else if (access.equalsIgnoreCase("write-only"))
221       {
222          isReadable = false;
223       }
224
225       ModelMBeanAttributeInfo JavaDoc info = new ModelMBeanAttributeInfo JavaDoc(
226          name, type, description, isReadable, isWritable, false, descriptor
227       );
228       return info;
229    }
230
231 }
232
Popular Tags