KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > meta > MBeanRegistryEntry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: MBeanRegistryEntry.java,v 1.6 2006/03/12 01:26:57 jluehe Exp $
26  * @author: alexkrav
27  *
28  * $Log: MBeanRegistryEntry.java,v $
29  * Revision 1.6 2006/03/12 01:26:57 jluehe
30  * Renamed AS's org.apache.commons.* to com.sun.org.apache.commons.*, to avoid collisions with org.apache.commons.* packages bundled by webapps.
31  *
32  * Tests run: QL, Servlet TCK
33  *
34  * Revision 1.5 2005/12/25 03:47:37 tcfujii
35  * Updated copyright text and year.
36  *
37  * Revision 1.4 2005/10/06 21:44:07 kravtch
38  * Bug #6331466
39  * create-ssl for iiop-service procedure has been changed.
40  * First, ssl-client-config is created with ssl subelement in it then it added to condig context.
41  * + ManagedConfigBean swithed from enclosing associated MBean to MBeanInfo.
42  * Submitted by: kravtch
43  * Reviewed by: Sreeni
44  * Affected modules admin/mbeans; admin-core/admin
45  * Tests passed: QLT/EE + devtests
46  *
47  * Revision 1.3 2005/08/16 22:19:31 kravtch
48  * M3: 1. ConfigMBeans: Support for generic getXXXNamesList() operation (request from management-rules).
49  * 2. MBeanRegistry: support for getElementPrintName() to provide readable element's description for validator's messages
50  * Submitted by: kravtch
51  * Reviewed by: Shreedhar
52  * Affected modules admin-core/admin
53  * Tests passed: QLT/EE + devtests
54  *
55  * Revision 1.2 2005/06/27 21:19:44 tcfujii
56  * Issue number: CDDL header updates.
57  *
58  * Revision 1.1.1.1 2005/05/27 22:52:02 dpatil
59  * GlassFish first drop
60  *
61  * Revision 1.21 2005/05/07 04:35:27 ruyakr
62  * Engineer: Rob Ruyak
63  *
64  * Fixed warning messages displayed from jdk1.5 because of introduction of varargs in certain apis such as ja
65  * va.lang.Class.
66  *
67  *
68  * This is my last checkin here at Sun! Thanks for all the good times!
69  *
70  * Revision 1.20 2004/11/14 07:04:21 tcfujii
71  * Updated copyright text and/or year.
72  *
73  * Revision 1.19 2004/06/26 02:03:41 sv96363
74  * Part of restart required bug checkin.
75  *
76  * Reviewed By: Alex Kr.
77  *
78  * Revision 1.18 2004/06/05 02:33:35 kravtch
79  * Reviewer: Nazrul
80  * New operations are added to infrastructure:
81  * isAttributeDynamicallyReconfigurable(attr)
82  * isChangesDynamicallyReconfigurable(changeList)
83  * Test: qlt
84  *
85  * Revision 1.17 2004/06/04 19:13:59 kravtch
86  * Reviewer: Nazrul
87  * Support for "dynamicallyReconfigurable" MBean descriptor field is added to infrastructure.
88  * Tests passed: QLT PE/EE
89  *
90  * Revision 1.16 2004/03/02 18:26:32 kravtch
91  * MBean's Descriptor field ElementChangeEvent support added (Constant, get method).
92  * MBeanRegistryFactory.setAdminMBeanRegistry() added for tester
93  *
94  * Revision 1.14 2003/12/13 16:52:52 qouyang
95  *
96  * Revision 1.13.4.1 2003/12/01 21:52:39 kravtch
97  * Bug #4939964
98  * Reviewer: Sridatta
99  * admin.config.ManagedConfigBean.createChildByType() now analyzes registryEntries.AttributeInfo for each "empty" valued attribute (similar to setAttribute(), but could not use MBeanAttributeInfo because MBean is not exists yet). If "emptyValueAllowed" field in registrEntry.AttributeInfo is not "true", then "empty" attribute will be ignored.
100  *
101  * Revision 1.13 2003/09/10 00:24:23 kravtch
102  * Reviewer: Sridatta
103  * New operation in DomainMBean is returning list of default attribute values according to mbean type. This operation will return DTD defined default values if custom mbean does not implement its own static operation overriding(extending) standard ones.
104  *
105  * Revision 1.12 2003/08/30 06:25:57 kravtch
106  * Bug #4914348
107  * Reviwer: Sridatta
108  *
109  * Commons-modeler managedBean.createMBeanInfo() preserves one copy of ModelMBeanInfo for all mbeans of the same type. S1AS Mbeans instantiation process sets some instance-cpecific field values into MBeanInfo descriptor. It means that our MBeans can not share MBeanInfo.
110  * MBeanRegistryEntry.createMBeanInfo modified to force managedBean to refresh MBeanInfo.
111  *
112  * Revision 1.11 2003/08/29 02:16:41 kravtch
113  * Bug #4910964 (and similar others)
114  * Reviewer: Sridatta
115  *
116  * Exception handling and logging enchancements:
117  * - extraction target exception for MBeanException and TargetInvocationException:
118  * - switch to localStrings usage;
119  * - throwing exception for config MBeans if error in creation of ConfigBean;
120  * - exceptions for null-results in configbean operations,like getXXbyYYY() [changes commented because of crashing of quick test]
121  *
122  * Revision 1.10 2003/08/21 21:45:26 kravtch
123  * instantiateMBean() is modified for runtime MBeans to provide ConfigBean as one of managed resources along with JSR77ModelBean.
124  *
125  * Revision 1.9 2003/08/07 00:41:06 kravtch
126  * - new DTD related changes;
127  * - properties support added;
128  * - getDefaultAttributeValue() implemented for config MBeans;
129  * - merge Jsr77 and config activity in runtime mbeans;
130  *
131  * Revision 1.8 2003/07/29 18:59:35 kravtch
132  * MBeanRegistryEntry:
133  * - support for toFormatString();
134  * - instantiateMBean() method modified to instantiate runtime MBeans as well;
135  * MBeanRegistryFactory:
136  * - fixed bug in getRuntimeRegistry();
137  * MBeanNamingInfo:
138  * - less strict requirements for parm_list_array size in constructor (can be more then needed);
139  * BaseRuntimeMBean:
140  * - exception ClassCastException("Managed resource is not a Jsr77ModelBean") handling;
141  * ManagedJsr77MdlBean:
142  * - call managed bean bug fixed ( getDeclaredMethod()->getMethod())
143  * admin/dtds/runtime-mbeans-descriptors.xml - modified to represent new runtime mbeans;
144  *
145  * Revision 1.7 2003/07/18 20:14:44 kravtch
146  * 1. ALL config mbeans are now covered by descriptors.xml
147  * 2. new infrastructure for runtime mbeans is added
148  * 3. generic constructors added to jsr77Mdl beans (String[])
149  * 4. new test cases are added to admintest
150  * 5. MBeanRegistryFactory has now different methods to obtain admin/runtime registries
151  * 6. runtime-descriptors xml-file is added to build
152  *
153  * Revision 1.6 2003/06/25 20:03:40 kravtch
154  * 1. java file headers modified
155  * 2. properties handling api is added
156  * 3. fixed bug for xpathes containing special symbols;
157  * 4. new testcases added for jdbc-resource
158  * 5. introspector modified by not including base classes operations;
159  *
160  *
161 */

162
163 package com.sun.enterprise.admin.meta;
164
165 //import javax.management.Descriptor;
166
import javax.management.DynamicMBean JavaDoc;
167 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
168 import com.sun.org.apache.commons.modeler.ManagedBean;
169 import com.sun.org.apache.commons.modeler.FeatureInfo;
170 import com.sun.org.apache.commons.modeler.AttributeInfo;
171 import com.sun.org.apache.commons.modeler.OperationInfo;
172 import com.sun.org.apache.commons.modeler.ParameterInfo;
173 import com.sun.org.apache.commons.modeler.FieldInfo;
174
175 import java.util.Iterator JavaDoc;
176 import java.util.List JavaDoc;
177 import java.util.HashMap JavaDoc;
178 import java.util.Hashtable JavaDoc;
179 import java.util.HashSet JavaDoc;
180 import java.util.Set JavaDoc;
181 import java.util.StringTokenizer JavaDoc;
182
183 import java.lang.reflect.Constructor JavaDoc;
184
185 import com.sun.enterprise.admin.meta.naming.MBeanNamingDescriptor;
186 import com.sun.enterprise.admin.meta.naming.MBeansNaming;
187 import com.sun.enterprise.admin.meta.naming.MBeanNamingInfo;
188 import com.sun.enterprise.admin.meta.naming.MBeanNamingException;
189
190 import com.sun.enterprise.admin.BaseAdminMBean;
191 import com.sun.enterprise.admin.config.BaseConfigMBean;
192
193 import com.sun.enterprise.config.ConfigException;
194 import com.sun.enterprise.config.ConfigContext;
195 import com.sun.enterprise.config.ConfigBeansFactory;
196
197 import javax.management.Descriptor JavaDoc;
198 import javax.management.ObjectName JavaDoc;
199 import javax.management.MBeanException JavaDoc;
200 import javax.management.InstanceNotFoundException JavaDoc;
201 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
202
203
204 /**
205  *
206  */

207 public class MBeanRegistryEntry implements MBeanMetaConstants
208 {
209     MBeanNamingDescriptor namingDescriptor = null;
210
211     //FIXME: should be removed or protected
212
private ManagedBean managedBean = null;
213     private HashMap JavaDoc fields = null;
214     
215
216     public MBeanRegistryEntry(ManagedBean mb) throws MBeanNamingException,ClassNotFoundException JavaDoc
217     {
218         managedBean = mb;
219         fields = convertListOfFieldsToHashMap(mb.getFields());
220
221         // convert dynamically changeable list to map
222
String JavaDoc dynList = (String JavaDoc)fields.get(DYNAMICALLY_RECONFIGURABLE_LIST_FIELD_NAME);
223         if(dynList!=null)
224         {
225             //replace it by set
226
fields.put(DYNAMICALLY_RECONFIGURABLE_LIST_FIELD_NAME, convertDelimListToSet(dynList));
227         }
228
229         //modify class info
230
String JavaDoc clazz = managedBean.getClassName();
231         if(clazz.startsWith("com.sun.org.apache"))
232             clazz = null;
233         String JavaDoc group = managedBean.getGroup();
234         if("config".equals(group))
235         {
236             if(clazz==null)
237             {
238                 clazz = "com.sun.enterprise.admin.config.BaseConfigMBean";
239                 managedBean.setClassName(clazz);
240             }
241             else
242             {
243                 if(clazz.indexOf('.')<0)
244                     clazz = "com.sun.enterprise.admin.config.mbeans."+clazz;
245             }
246             MBeanMetaHelper.mergeWithConfigBean(managedBean,
247                               MBeanMetaHelper.getConfigBeanClass((String JavaDoc)fields.get(XPATH_FIELD_NAME)),
248                               EXPOSE_ALL);
249             MBeanMetaHelper.mergeWithDynamicMBean(managedBean, Class.forName(clazz));
250         }
251         else if("runtime".equals(group))
252         {
253             if(clazz==null)
254             {
255                 clazz = "com.sun.enterprise.admin.runtime.BaseRuntimeMBean";
256                 managedBean.setClassName(clazz);
257             }
258             else
259             {
260                 if(clazz.indexOf('.')<0)
261                     clazz = "com.sun.enterprise.admin.runtime.mbeans"+clazz;
262             }
263             Class JavaDoc modelBeanClass = MBeanMetaHelper.getRuntimeModelBeanClass(mb.getName());
264             if(modelBeanClass!=null)
265                MBeanMetaHelper.mergeWithRuntimeModelBean(managedBean, modelBeanClass);
266             Class JavaDoc configBeanClass = MBeanMetaHelper.getConfigBeanClass((String JavaDoc)fields.get(XPATH_FIELD_NAME));
267             if(configBeanClass!=null)
268             {
269                 int mode;
270                 if(modelBeanClass!=null)
271                     mode = EXPOSE_RUNTIME_WITH_MODEL;
272                 else
273                     mode = EXPOSE_RUNTIME_WITHOUT_MODEL;
274                     
275                 MBeanMetaHelper.mergeWithConfigBean(managedBean, configBeanClass, mode);
276             }
277             MBeanMetaHelper.mergeWithDynamicMBean(managedBean, Class.forName(clazz));
278         }
279             
280         namingDescriptor = new MBeanNamingDescriptor( mb.getName(),
281                 new Integer JavaDoc(MBeansNaming.MODE_CONFIG),
282                 (String JavaDoc)fields.get(CLINAME_FIELD_NAME),
283                 (String JavaDoc)fields.get(OBJECTNAME_FIELD_NAME),
284                 MBeanNamingDescriptor.XPATH_TO_MASK((String JavaDoc)fields.get(XPATH_FIELD_NAME)),
285                 (String JavaDoc)clazz); // fields.get("Class")));*/
286

287 /* AttributeInfo[] attrs = managedBean.getAttributes();
288         if(attrs!=null && attrs.length>0 && "modelerType".equals(attrs[0].getName()))
289         {
290             AttributeInfo[] attrsNew = new AttributeInfo[attrs.length-1];
291             for(int i=1; i<attrs.lenght; i++)
292                 attrsNew[i-1] = attrs[i];
293             managedBean.setAttributes(attrsNew);
294         }
295 */

296     }
297
298     public String JavaDoc toString()
299     {
300         String JavaDoc str = "\n--- MBeanRegistryEntry:\n ";
301         if(managedBean!=null)
302         {
303             str = str + managedBean.toString() + "\n " +
304             MBeanMetaHelper.descriptorToString(managedBean.getFields());
305         }
306         AttributeInfo[] attrs = managedBean.getAttributes();
307         str = str + "\n\n --- Attributes:";
308         if(attrs!=null)
309             for(int i=0; i<attrs.length; i++)
310             {
311                 if("modelerType".equals(attrs[i].getName()))
312                     continue;
313                 str = str + "\n " + attrs[i].toString();
314                 if(attrs[i].getFields().size()>0)
315                    str = str + "\n " + MBeanMetaHelper.descriptorToString(attrs[i].getFields());
316             }
317
318         OperationInfo[] opers = managedBean.getOperations();
319         if(opers!=null && opers.length>0)
320         {
321             str = str + "\n\n --- Operations:";
322             for(int i=0; i<opers.length; i++)
323             {
324                 str = str + "\n " + opers[i].toString();
325                 if(opers[i].getFields().size()>0)
326                    str = str + "\n " + MBeanMetaHelper.descriptorToString(opers[i].getFields());
327                 ParameterInfo[] params = opers[i].getSignature();
328                 if(params!=null && params.length>0)
329                 {
330                     str = str + "\n --- Parameters:";
331                     for(int j=0; j<params.length; j++)
332                     {
333                         str = str + "\n " + params[j].toString();
334                         if(params[j].getFields().size()>0)
335                            str = str + "\n " + MBeanMetaHelper.descriptorToString(params[j].getFields());
336                     }
337                 }
338             }
339         }
340         return str;
341     }
342
343     final static String JavaDoc filler=" ";
344     private String JavaDoc fillStr(String JavaDoc name, int minSize)
345     {
346         if(name.length()>=minSize)
347             return name;
348         return name+filler.substring(0, minSize-name.length());
349     }
350     
351     private String JavaDoc formatClassName(String JavaDoc className, int minSize)
352     {
353         if(className==null || className.length()==0)
354             className = "void";
355         else
356         {
357            int iLast = className.lastIndexOf('.');
358            boolean bArray = className.startsWith("[");
359            if(iLast>=0)
360                className = className.substring(iLast+1);
361            if(bArray)
362                className = className.substring(0, className.length()-1)+"[]";
363         }
364         return fillStr(className, minSize);
365     }
366
367     public String JavaDoc toFormatString()
368     {
369         String JavaDoc str = "\n\n*************** mbean type:"+managedBean.getName()+" ***************";
370         String JavaDoc wrk;
371         str += "\n--- ObjectName ="+ fields.get(OBJECTNAME_FIELD_NAME);
372         str += "\n--- XPath ="+ fields.get(XPATH_FIELD_NAME);
373         AttributeInfo[] attrs = managedBean.getAttributes();
374         str = str + "\n--- Attributes:";
375         if(attrs!=null)
376             for(int i=0; i<attrs.length; i++)
377             {
378                 if("modelerType".equals(attrs[i].getName()))
379                     continue;
380                 str = str + "\n " + formatClassName(attrs[i].getType(), 12)+" "+attrs[i].getName()+",";
381                 if(attrs[i].getDescription()!=null)
382                    str = str + str + " // "+ attrs[i].getDescription();
383             }
384
385         OperationInfo[] opers = managedBean.getOperations();
386         if(opers!=null && opers.length>0)
387         {
388             str = str + "\n--- Operations:";
389             for(int i=0; i<opers.length; i++)
390             {
391                 wrk = formatClassName(opers[i].getReturnType(), 14) + " " + opers[i].getName() + "(";
392                 str = str + "\n"+wrk;
393                 //convert wrk to indent
394
wrk = fillStr("\n", wrk.length()+1);
395                 ParameterInfo[] params = opers[i].getSignature();
396                 if(params!=null && params.length>0)
397                 {
398                     for(int j=0; j<params.length; j++)
399                     {
400                         if(j!=0)
401                             str += wrk;
402                         str = str + formatClassName(params[j].getType(), 0) + " " + params[j].getName();
403                     }
404 // str = str + "[, Target target]";
405
}
406 // else
407
// str = str + "[Target target]";
408

409                 str = str + ");";
410                 if(opers[i].getDescription()!=null)
411                    str = str + str + " // "+ opers[i].getDescription();
412             }
413         }
414         return str;
415     }
416
417     //******************************************************************************************
418
static private HashMap JavaDoc convertListOfFieldsToHashMap(List JavaDoc fields)
419     {
420         Iterator JavaDoc iter = fields.iterator();
421         HashMap JavaDoc fldsMap = new HashMap JavaDoc();
422         while(iter.hasNext())
423         {
424             FieldInfo field = (FieldInfo)iter.next();
425             fldsMap.put(field.getName(), field.getValue());
426         }
427         return fldsMap;
428     }
429     
430     //******************************************************************************************
431
static private Set JavaDoc convertDelimListToSet(String JavaDoc list)
432     {
433         HashSet JavaDoc set = new HashSet JavaDoc();
434         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(list, ", ");
435         while(tokenizer.hasMoreTokens())
436         {
437             String JavaDoc token = tokenizer.nextToken();
438             if(token.length()>0) //?
439
set.add(token);
440         }
441         return set;
442     }
443     
444     //******************************************************************************************
445
public String JavaDoc getName()
446     {
447         if(managedBean!=null)
448             return managedBean.getName();
449         return null;
450     }
451     //******************************************************************************************
452
public MBeanNamingDescriptor getNamingDescriptor()
453     {
454         return namingDescriptor;
455     }
456     //******************************************************************************************
457
public boolean isObjectNamePatternMatch(Hashtable JavaDoc ht)
458     {
459         if(namingDescriptor!=null)
460             return namingDescriptor.isObjectNamePatternMatch(ht);
461         return false;
462     }
463
464     //******************************************************************************************
465
public boolean isObjectNamePatternMatch(ObjectName JavaDoc objectName)
466     {
467         if(namingDescriptor!=null)
468             return namingDescriptor.isObjectNamePatternMatch(objectName);
469         return false;
470     }
471
472     //******************************************************************************************
473
public String JavaDoc[] getAttributeNames()
474     {
475         AttributeInfo[] infos = managedBean.getAttributes();
476         if(infos==null)
477             return (new String JavaDoc[0]);
478         String JavaDoc[] names = new String JavaDoc[infos.length];
479         for(int i=0; i<infos.length; i++)
480             names[i] = infos[i].getName();
481         return names;
482     }
483     //******************************************************************************************
484
public void mergeAttribute( String JavaDoc attrName, String JavaDoc attrType,
485                                 String JavaDoc attrGetMethod, String JavaDoc attrSetMethod,
486                                 boolean attrReadable, boolean attrWriteable)
487     {
488         AttributeInfo ai = findAttributeInfo(attrName);
489         if(ai==null)
490         {
491             String JavaDoc str[] = new String JavaDoc[2];
492             ai = new AttributeInfo();
493             ai.setName(attrName);
494             ai.setType(attrType);
495             managedBean.addAttribute(ai);
496         }
497         if(ai.isReadable() && !attrReadable)
498             ai.setReadable(false);
499         if(ai.isWriteable() && !attrWriteable)
500             ai.setWriteable(false);
501         if(attrGetMethod!=null)
502             ai.setGetMethod(attrGetMethod);
503         if(attrSetMethod!=null)
504             ai.setSetMethod(attrSetMethod);
505     }
506
507    
508     //******************************************************************************************
509
private FeatureInfo findFeatureInfo(String JavaDoc attrName, FeatureInfo[] features)
510     {
511         if(attrName==null)
512             return null;
513         for(int i=0; i<features.length; i++)
514         {
515             if(attrName.equals(features[i].getName()))
516                 return features[i];
517         }
518         return null;
519     }
520     
521     //******************************************************************************************
522
private AttributeInfo findAttributeInfo(String JavaDoc attrName)
523     {
524         return (AttributeInfo)findFeatureInfo(attrName, (FeatureInfo[]) managedBean.getAttributes());
525     }
526
527     //******************************************************************************************
528
// returns name for ElementChangeEvent assigned to entry
529
// it analyses the "ElementChangeEvent"-atrribute value for given MBean descriptor
530
// in mbean-descriptor file.
531
public String JavaDoc getElementChangeEventName()
532     {
533         return (String JavaDoc)this.fields.get(ELEMENTCHANGEEVENT_FIELD_NAME);
534     }
535
536     //******************************************************************************************
537
// returns set represnting list of dynamically reconfigurable attributes
538
// it analyses the "dynamicallyReconfigurable"-atrribute value for given MBean descriptor
539
// in mbean-descriptor file (converted to set from comma-separated list).
540
public Set JavaDoc getDynamicallyReconfigurableAttributes()
541     {
542         return (Set JavaDoc)this.fields.get(DYNAMICALLY_RECONFIGURABLE_LIST_FIELD_NAME);
543     }
544
545     //******************************************************************************************
546
private boolean checkItemsInReconfigurableSet(String JavaDoc name1, String JavaDoc name2)
547     {
548         Set JavaDoc set = getDynamicallyReconfigurableAttributes();
549         if(set==null || set.size()<1)
550             return false;
551         if(set.contains("**") ||
552            set.contains(name1) ||
553            (name2!=null && set.contains(name2)))
554             return true;
555         return false;
556     }
557     //******************************************************************************************
558
public boolean isAttributeDynamicallyReconfigurable(String JavaDoc attr)
559     {
560         return checkItemsInReconfigurableSet(attr, "*");
561     }
562     //******************************************************************************************
563
public boolean isPropertyDynamicallyReconfigurable(String JavaDoc attr)
564     {
565         return checkItemsInReconfigurableSet("property."+attr, "property.*");
566     }
567     //******************************************************************************************
568
public boolean isElementCreationDynamicallyReconfigurable()
569     {
570         return checkItemsInReconfigurableSet("+", null);
571     }
572     //******************************************************************************************
573
public boolean isElementDeletionDynamicallyReconfigurable()
574     {
575         return checkItemsInReconfigurableSet("-", null);
576     }
577     //******************************************************************************************
578
public boolean isElementDynamicallyReconfigurable()
579     {
580         return checkItemsInReconfigurableSet("**", null);
581     }
582
583     //******************************************************************************************
584
// returns boolean indicating whether empty value allowed or not for given MBean attribute
585
// it analyzes the "emptyValueAllowed"-atrribute value for given MBean attribute descriptor
586
// in mbean-descriptor file.
587
// returns true, if only it is has "true" or "yes" value
588
public boolean isAttributeEmptyValueAllowed(String JavaDoc attrName) throws MBeanMetaException
589     {
590         AttributeInfo ai = findAttributeInfo(attrName);
591         if(ai==null)
592             throw new MBeanMetaException("Attribute info is not founmd for attribute "+attrName);
593         //get attribute's descriptor fields
594
List JavaDoc fields = ai.getFields();
595         if(fields!=null)
596             for(int i=0; i<fields.size(); i++) //enum fields
597
{
598                 if(EMPTYVALUEALLOWED_FIELD_NAME.equals(((FieldInfo)fields.get(i)).getName()))
599                 {
600                     //get "emptyValueAllowed" field value and compare it with "true"
601
Object JavaDoc value = ((FieldInfo)fields.get(i)).getValue();
602                     if(value!=null && (value instanceof String JavaDoc) &&
603                        ("true".equalsIgnoreCase((String JavaDoc)value)|| "yes".equalsIgnoreCase((String JavaDoc)value)))
604                         return true; //empty value is allowed
605
}
606             }
607         return false; //empty value is not allowed
608
}
609
610     //******************************************************************************************
611
public ModelMBeanInfo JavaDoc createMBeanInfo(MBeanNamingInfo namingInfo, String JavaDoc domainName) throws Exception JavaDoc
612     {
613         //force managedBean to reset MBeanInfo
614
managedBean.setDescription(managedBean.getDescription());
615         
616         ModelMBeanInfo JavaDoc info = managedBean.createMBeanInfo();
617         Descriptor descr = info.getMBeanDescriptor();
618         if(domainName!=null)
619             descr.setField(DOMAIN_FIELD_NAME, domainName);
620         if(namingInfo!=null)
621         {
622             descr.setField(NMTYPE_FIELD_NAME, namingInfo.getType());
623             descr.setField(NMLOCATION_FIELD_NAME, namingInfo.getLocationParams());
624         }
625         info.setMBeanDescriptor(descr);
626         return info;
627     }
628     
629     //******************************************************************************************
630
public BaseAdminMBean instantiateMBean(ObjectName JavaDoc objectName, Object JavaDoc managedResource, ConfigContext ctx)
631                                    throws Exception JavaDoc
632     {
633         String JavaDoc domainName = objectName.getDomain();
634         return instantiateMBean(new MBeanNamingInfo(namingDescriptor, objectName), managedResource, domainName, ctx);
635     }
636     
637     //******************************************************************************************
638
public BaseAdminMBean instantiateMBean(String JavaDoc type, String JavaDoc[] location, Object JavaDoc managedResource, String JavaDoc domainName, ConfigContext ctx)
639                                    throws Exception JavaDoc
640     {
641         return instantiateMBean(new MBeanNamingInfo(namingDescriptor, type, location), managedResource, domainName, ctx);
642     }
643
644     //******************************************************************************************
645
private BaseAdminMBean instantiateMBean(MBeanNamingInfo namingInfo, Object JavaDoc managedResource, String JavaDoc domainName, ConfigContext ctx)
646                                    throws Exception JavaDoc
647     {
648         if(managedBean==null)
649             return null;
650         ModelMBeanInfo JavaDoc mbi = createMBeanInfo(namingInfo, domainName);
651         //FIXME set fields xpath&object_name here
652
String JavaDoc clazz = managedBean.getClassName();
653         String JavaDoc group = managedBean.getGroup();
654         
655         Constructor JavaDoc constructor = Class.forName(clazz).getConstructor();
656         BaseAdminMBean mbean = (BaseAdminMBean)constructor.newInstance();
657         mbean.setModelMBeanInfo(mbi);
658
659         //BaseConfigMBean mbean = new BaseConfigMBean(mbi);
660
String JavaDoc xpath = namingInfo.getXPath();
661         if("config".equals(group))
662         {
663             if(xpath!=null && xpath.length()>0)
664             {
665                 Object JavaDoc configBean = (Object JavaDoc)ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath);
666                 if(configBean!=null)
667                     mbean.setManagedResource(configBean, CONFIG_BEAN_REF);
668                 else
669                     throw new MBeanMetaException("instantiateMBean(): config mbean does not exist for xpath - " + xpath );
670             }
671             return mbean;
672         }
673         if( "runtime".equals(group))
674         {
675             //CONFIG BEAN
676
if(xpath!=null && xpath.length()>0)
677             {
678                 Object JavaDoc configBean = (Object JavaDoc)ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath);
679                 if(configBean!=null)
680                     mbean.setManagedResource(configBean, CONFIG_BEAN_REF);
681             }
682
683  
684             //JSR77BEAN
685
//construct JSR77Beanname
686
String JavaDoc beanClassName = (String JavaDoc)fields.get(JSR77BEAN_FIELD_NAME);
687             if(beanClassName==null || beanClassName.length()==0)
688                 beanClassName = "com.sun.enterprise.management.model."+namingInfo.getType()+"Mdl";
689             
690             if(managedResource==null)
691             {
692                 Class JavaDoc cl = Class.forName(beanClassName);
693                 if(cl!=null)
694                 {
695                     String JavaDoc[] location = namingInfo.getLocationParams();
696                     if(location!=null)
697                     {
698                         Constructor JavaDoc ctr = cl.getConstructor(new Class JavaDoc[]{location.getClass()});
699                         if(ctr!=null)
700                            managedResource = ctr.newInstance(new Object JavaDoc[]{location});
701
702                     }
703                 }
704             }
705             if(managedResource!=null)
706                 mbean.setManagedResource(managedResource, JSR77_MODEL_BEAN_REF);
707             return mbean;
708
709         }
710         return null;
711     }
712     public String JavaDoc getElementPrintName()
713     {
714        return (String JavaDoc)fields.get(PRINTNAME_FIELD_NAME);
715     }
716 }
717
718
Popular Tags