KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > adventnet > jmx > DefaultDynamicMBean


1 /**
2 * The XMOJO Project 5
3 * Copyright © 2003 XMOJO.org. All rights reserved.
4
5 * NO WARRANTY
6
7 * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
8 * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
9 * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
10 * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
11 * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
13 * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
14 * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
15 * REPAIR OR CORRECTION.
16
17 * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
18 * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
19 * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
20 * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
21 * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
22 * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
23 * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
24 * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGES.
26 **/

27
28 package com.adventnet.jmx;
29
30 import java.lang.reflect.Constructor JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32 import java.lang.reflect.InvocationTargetException JavaDoc;
33 import java.util.Arrays JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import javax.management.Attribute JavaDoc;
38 import javax.management.AttributeList JavaDoc;
39 import javax.management.DynamicMBean JavaDoc;
40 import javax.management.ObjectName JavaDoc;
41 import javax.management.MBeanServer JavaDoc;
42 import javax.management.MBeanServerFactory JavaDoc;
43 import javax.management.MBeanRegistration JavaDoc;
44 import javax.management.MBeanInfo JavaDoc;
45 import javax.management.MBeanAttributeInfo JavaDoc;
46 import javax.management.MBeanConstructorInfo JavaDoc;
47 import javax.management.MBeanOperationInfo JavaDoc;
48 import javax.management.MBeanParameterInfo JavaDoc;
49 import javax.management.MBeanNotificationInfo JavaDoc;
50 import javax.management.Notification JavaDoc;
51 import javax.management.NotificationListener JavaDoc;
52 import javax.management.NotificationFilter JavaDoc;
53 import javax.management.NotificationBroadcaster JavaDoc;
54 import javax.management.AttributeNotFoundException JavaDoc;
55 import javax.management.ListenerNotFoundException JavaDoc;
56 import javax.management.MBeanException JavaDoc;
57 import javax.management.NotCompliantMBeanException JavaDoc;
58 import javax.management.ReflectionException JavaDoc;
59 import javax.management.RuntimeErrorException JavaDoc;
60 import javax.management.RuntimeMBeanException JavaDoc;
61 import javax.management.RuntimeOperationsException JavaDoc;
62 import javax.management.InvalidAttributeValueException JavaDoc;
63
64 /**
65  * This class acts as the wrapper dynamic mbean for standard mbeans
66  * that intends to register with the MBeanServer. This class gets
67  * instantiated from the server's registerMBean method, whenever the
68  * incoming object is a standard mbean.
69  */

70 public class DefaultDynamicMBean implements DynamicMBean JavaDoc,
71                                             NotificationBroadcaster JavaDoc,
72                                             NotificationListener JavaDoc,
73                                             NotificationFilter JavaDoc,
74                                             MBeanRegistration JavaDoc
75 {
76     public MBeanInfo JavaDoc mbeanInfo = null;
77     public Object JavaDoc object = null;
78     public Class JavaDoc clazz = null;
79     public Class JavaDoc iclazz = null;
80     public Method JavaDoc[] superInterfaceMeths = null;
81     public Vector JavaDoc readMeths = null;
82     public Vector JavaDoc writeMeths = null;
83     public Vector JavaDoc isIsMeths = null;
84
85     public DefaultDynamicMBean(Object JavaDoc object) throws Exception JavaDoc
86     {
87         this.object = object;
88         clazz = object.getClass();
89
90         Class JavaDoc[] interfaces = clazz.getInterfaces();
91
92         boolean flag = false;
93
94         if(interfaces == null)
95         {
96             clazz = clazz.getSuperclass();
97             if(clazz == null)
98                 throw new Exception JavaDoc("NonJmxMBeanRegistrationException");
99             if((interfaces = clazz.getInterfaces()) == null)
100                 throw new Exception JavaDoc("NonJmxMBeanRegistrationException");
101         }
102         else
103         {
104             for(int i = 0;i<interfaces.length;i++)
105             {
106                 if(interfaces[i].getName().equals(clazz.getName() + "MBean") )
107                 {
108                     iclazz = interfaces[i];
109                     flag = true;
110                     /** This will be used for Attribute's get, set and is methods overloading */
111                     Class JavaDoc[] interClass = interfaces[i].getInterfaces();
112                     if(interClass != null)
113                     {
114                         if(interClass.length >0)
115                         {
116                             superInterfaceMeths = interClass[0].getMethods();
117                         }
118                     }
119                     break;
120                 }
121             }
122
123             if(!flag)
124             {
125                 clazz = clazz.getSuperclass();
126                 if(clazz == null)
127                     throw new Exception JavaDoc("NonJmxMBeanRegistrationException");
128                 if((interfaces = clazz.getInterfaces()) == null)
129                     throw new Exception JavaDoc("NonJmxMBeanRegistrationException");
130             }
131         }
132
133         if(!flag)
134         {
135             for(int i = 0;i<interfaces.length;i++)
136             {
137                 if(interfaces[i].getName().equals(clazz.getName() + "MBean") )
138                     {
139                         iclazz = interfaces[i];
140                         flag = true;
141                         break;
142                     }
143             }
144
145             while(!flag)
146             {
147                 flag = getFlagValue(clazz,flag);
148                 if(clazz==null)
149                     break;
150             }
151         }
152
153         if(!flag)
154             throw new Exception JavaDoc("NonJmxMBeanRegistrationException");
155
156         clazz = object.getClass();
157         makeMBeanInfo();
158     }
159
160     public Object JavaDoc getStandardMBeanObject()
161     {
162         return object;
163     }
164
165     protected void makeMBeanInfo() throws Exception JavaDoc
166     {
167         String JavaDoc className = clazz.getName();
168         String JavaDoc description = className + " MBean";
169
170         mbeanInfo = new MBeanInfo JavaDoc(className,
171                                   description,
172                                   getAttributes(),
173                                   getConstructors(),
174                                   getOperations(),
175                                   getNotifications());
176     }
177
178     private MBeanAttributeInfo JavaDoc[] getAttributes() throws Exception JavaDoc
179     {
180         int length = 0;
181         int size = 0;
182         int pos = 0;
183         //Method[] meths = iclazz.getDeclaredMethods();
184
//Method[] meths = iclazz.getDeclaredMethods();
185
Method JavaDoc[] meths = iclazz.getMethods();
186         readMeths = new Vector JavaDoc();
187         writeMeths = new Vector JavaDoc();
188         isIsMeths = new Vector JavaDoc();
189         Vector JavaDoc readableVec= new Vector JavaDoc();
190         Vector JavaDoc writableVec= new Vector JavaDoc();
191         Vector JavaDoc isWriteStatus = new Vector JavaDoc();
192         String JavaDoc[] types = null;
193         String JavaDoc[] names = null;
194
195         /** The Changes have been done for making standard MBean TCK compliance.
196             However the restrictions are
197             1. Overlaoaded methods are not handled.
198             2.If set method with multiple parameter comes it is treated as Attribute
199             ----> The restictions are to be fixed.
200         */

201
202         /** This loop is used to identify the attribute. Seperates "get", "set" and "is" **/
203
204
205         for(int i=0; i<meths.length; i++){
206             ///test
207
String JavaDoc methName = meths[i].getName();
208                         ////////
209
/** This is to avoid the method by named "get" "set" and "is" getting added in
210                 attribute list. */

211             if(methName.equals("get") || methName.equals("set") || methName.equals("is")){
212                 continue;
213             }
214             if((methName.startsWith("get") && meths[i].getParameterTypes().length == 0 ) && !(meths[i].getReturnType().getName().equals("void"))|| (methName.startsWith("is") && (meths[i].getReturnType().getName().equals("boolean") || meths[i].getReturnType().getName().equals("java.lang.Boolean")) &&
215                                                                                                                                                     meths[i].getParameterTypes().length == 0 )){
216                                 //System.out.println(" READ METH IS "+meths[i].getName());
217
if(methName.startsWith("get")){
218                     /*if(isAttributeMethodOverloaded(meths[i])){
219                       throw new NotCompliantMBeanException();
220                       }*/

221                     readMeths.add(meths[i]);
222                 }
223                 else{
224                     isIsMeths.add(meths[i]);
225                     /*if(isAttributeMethodOverloaded(meths[i])){
226                       throw new NotCompliantMBeanException();
227                       }*/

228                 }
229             }
230             if(methName.startsWith("set") && meths[i].getParameterTypes().length ==1 && meths[i].getReturnType().getName().equals("void")){
231                 writeMeths.add(meths[i]);
232                                 /*if(isAttributeMethodOverloaded(meths[i])){
233                                   throw new NotCompliantMBeanException();
234                                   }*/

235             }
236
237         }
238
239         /** Comparison is done between get and set attribute to fine read-write access */
240         for(int i=0; i<readMeths.size(); i++){
241             boolean isMatched = false;
242             Method JavaDoc read = (Method JavaDoc)readMeths.get(i);
243             /** This remove and add is done to avoid checking the same method */
244                         readMeths.remove(i);
245             if(isAttributeMethodOverloaded(read)){
246                 throw new NotCompliantMBeanException JavaDoc();
247             }
248             readMeths.add(i,read);
249             for(int j=0;j<writeMeths.size(); j++){
250                 Method JavaDoc write = (Method JavaDoc)writeMeths.get(j);
251                 writeMeths.remove(j);
252                 if(isAttributeMethodOverloaded(write)){
253                     throw new NotCompliantMBeanException JavaDoc();
254                 }
255                 writeMeths.add(j,write);
256                 if(((Method JavaDoc)readMeths.get(i)).getName().substring(3).equals(((Method JavaDoc)writeMeths.get(j)).getName().substring(3))){
257                     if(!(read.getReturnType().getName().equals(write.getParameterTypes()[0].getName()))){
258                         throw new NotCompliantMBeanException JavaDoc();
259                     }
260                     readableVec.add(new Boolean JavaDoc(true));
261                     writableVec.add(new Boolean JavaDoc(true));
262                     writeMeths.remove(j);
263                     isMatched = true;
264                     break;
265                 }
266             }
267             if(!isMatched){
268                 readableVec.add(new Boolean JavaDoc(true));
269                 writableVec.add(new Boolean JavaDoc(false));
270             }
271         }
272         /** Comparison is done between is and set attribute to find read-write access */
273         for(int i=0;i<isIsMeths.size();i++){
274             boolean isMatched = false;
275             Method JavaDoc is = (Method JavaDoc)isIsMeths.get(i);
276             isIsMeths.remove(i);
277             if(isAttributeMethodOverloaded(is)){
278                 throw new NotCompliantMBeanException JavaDoc();
279             }
280             isIsMeths.add(i,is);
281             for(int j=0;j<writeMeths.size(); j++){
282                 Method JavaDoc write = (Method JavaDoc)writeMeths.get(j);
283                 if(is.getName().substring(2).equals(write.getName().substring(3))){
284                     if(!(is.getReturnType().getName().equals(write.getParameterTypes()[0].getName()))){
285                         throw new NotCompliantMBeanException JavaDoc();
286                     }
287                     /*readableVec.add(new Boolean(true));
288                       writableVec.add(new Boolean(true));
289                       writeMeths.remove(j);*/

290                     isWriteStatus.add(new Boolean JavaDoc(true));
291                     isMatched = true;
292                     writeMeths.remove(j);
293                     break;
294                 }
295             }
296             if(!isMatched){
297                 //readableVec.add(new Boolean(true));
298
//writableVec.add(new Boolean(false));
299
isWriteStatus.add(new Boolean JavaDoc(false));
300             }
301         }
302
303         /** Only the write access attribute */
304         for(int i=0; i<writeMeths.size();i++){
305             Method JavaDoc meth = (Method JavaDoc)writeMeths.get(i);
306             writeMeths.remove(i);
307             if(isAttributeMethodOverloaded(meth)){
308                 throw new NotCompliantMBeanException JavaDoc();
309             }
310             writeMeths.add(i,meth);
311             readableVec.add(new Boolean JavaDoc(false));
312             writableVec.add(new Boolean JavaDoc(true));
313                                 //System.out.println("222222222222222222222 readable is "+readableVec);
314
//System.out.println("333333333333333333333 writable is "+writableVec);
315
}
316         size = readMeths.size()+writeMeths.size();
317         types = new String JavaDoc[size];
318         names = new String JavaDoc[readMeths.size()+writeMeths.size()+isIsMeths.size()];
319         pos = 0;
320
321         /** Find the types of attribute and split the attributes name */
322         for(int i=0; i< readMeths.size(); i++){
323             names[i] = ((Method JavaDoc)readMeths.get(i)).getName().substring(3);
324             //types[i] = convertToJmxArrayType(((Method)readMeths.get(i)).getReturnType().getName());
325
types[i] = (((Method JavaDoc)readMeths.get(i)).getReturnType().getName());
326         }
327         for(int i=readMeths.size(); i<size; i++){
328             //types[i] = convertToJmxArrayType(((Method)writeMeths.get(pos)).getParameterTypes()[0].getName());
329
types[i] = (((Method JavaDoc)writeMeths.get(pos)).getParameterTypes()[0].getName());
330             names[i] = ((Method JavaDoc)writeMeths.get(pos)).getName().substring(3);
331             pos++;
332         }
333
334         MBeanAttributeInfo JavaDoc[] toRet = new MBeanAttributeInfo JavaDoc[names.length];
335         String JavaDoc des = "This attribute is present in a Standard MBean";
336         for(int i = 0; i<size;i++)
337             {
338
339                 if(clazz.getName().equals("javax.management.MBeanServerDelegate"))
340                     {
341                         if(names[i].equals("MBeanServerId"))
342                             des = "Specifies the ID of this JMX MBean Server";
343                         else if(names[i].equals("ImplementationName"))
344                             des = "Specifies the JMX implementation name (the name of this product).";
345                         else if(names[i].equals("ImplementationVendor"))
346                             des = "Specifies the JMX implementation vendor (the vendor of this product)";
347                         else if(names[i].equals("ImplementationVersion"))
348                             des = "Specifies the JMX implementation version (the version of this product). ";
349                         else if(names[i].equals("SpecificationName"))
350                             des = "Specifies the full name of the JMX specification implemented by this product.";
351                         else if(names[i].equals("SpecificationVendor"))
352                             des = "Specifies the vendor of the JMX specification implemented by this product.";
353                         else if(names[i].equals("SpecificationVersion"))
354                             des = "Specifies the version of the JMX specification implemented by this product.";
355                     }
356                 else if(clazz.getName().equals("javax.management.loading.MLet"))
357                     {
358                         if(names[i].equals("URLs"))
359                             des = "specifies the search path of URLs for loading classes and resources.";
360                     }
361
362                 toRet[i] = new MBeanAttributeInfo JavaDoc(names[i],types[i],des,((Boolean JavaDoc)readableVec.get(i)).booleanValue(),((Boolean JavaDoc)writableVec.get(i)).booleanValue(),false);
363             }
364         /** isIs artributes are handled here */
365         pos =0;
366                                 //int writePos = size;
367
for(int i=size; i<toRet.length; i++){
368             Method JavaDoc meth = (Method JavaDoc)isIsMeths.get(pos);
369             //toRet[i] = new MBeanAttributeInfo(meth.getName().substring(2),meth.getReturnType().getName(),des,true,((Boolean)writableVec.get(writePos)).booleanValue(),true);
370
toRet[i] = new MBeanAttributeInfo JavaDoc(meth.getName().substring(2),meth.getReturnType().getName(),des,true,((Boolean JavaDoc)isWriteStatus.get(pos)).booleanValue(),true);
371             pos++;
372             //writePos++;
373
}
374
375         return toRet;
376     }
377
378     private boolean isAttributeMethodOverloaded(Method JavaDoc toCheckMeth){
379         String JavaDoc toCheckStr = toCheckMeth.getName();
380         String JavaDoc methStr = null;
381         if(toCheckStr.startsWith("is")){
382             toCheckStr = toCheckStr.substring(2);
383         }
384         else if(toCheckStr.startsWith("get")){
385             toCheckStr = toCheckStr.substring(3);
386         }
387         if(toCheckMeth.getName().startsWith("is") || toCheckMeth.getName().startsWith("get")){
388             for(int i=0; i<readMeths.size(); i++){
389                 Method JavaDoc meth = (Method JavaDoc)readMeths.get(i);
390                 methStr = meth.getName();
391                 if(toCheckStr.equals(methStr.substring(3))){
392                     if(!(toCheckMeth.getReturnType().getName().equals(meth.getReturnType().getName()))
393                                                 || (toCheckMeth.getDeclaringClass().getName().equals(meth.getDeclaringClass().getName()))){
394                         //readMeths.remove(i);
395
return true;
396                      }
397                     readMeths.remove(i);
398                                         //return true;
399
}
400             }
401             for(int i=0; i<isIsMeths.size(); i++){
402                 Method JavaDoc meth = (Method JavaDoc)isIsMeths.get(i);
403                 methStr = meth.getName();
404                 if(toCheckStr.equals(methStr.substring(2))){
405                     if(!(toCheckMeth.getReturnType().getName().equals(meth.getReturnType().getName()))
406                                         || (toCheckMeth.getDeclaringClass().getName().equals(meth.getDeclaringClass().getName())))
407 {
408                       //isIsMeths.remove(i);
409
return true;
410                     }
411                     isIsMeths.remove(i);
412                                         //return true;
413
}
414             }
415         }
416         else if(toCheckMeth.getName().startsWith("set")){
417             toCheckStr = toCheckStr.substring(3);
418             for(int i=0; i<writeMeths.size();i++){
419                 Method JavaDoc meth = (Method JavaDoc)writeMeths.get(i);
420                 methStr = ((Method JavaDoc)writeMeths.get(i)).getName();
421                 if(toCheckStr.equals(methStr.substring(3))){
422                     if(!(toCheckMeth.getParameterTypes()[0].getName().equals(meth.getParameterTypes()[0].getName()))||(toCheckMeth.getDeclaringClass().getName().equals(meth.getDeclaringClass().getName()))){
423                       //writeMeths.remove(i);
424
return true;
425                     }
426                     writeMeths.remove(i);
427                                         //return true;
428
}
429             }
430         }
431         return false;
432     }
433
434     public MBeanConstructorInfo JavaDoc[] getConstructors()
435     {
436         Constructor JavaDoc[] constrs = clazz.getConstructors();
437         MBeanConstructorInfo JavaDoc[] toRet = new MBeanConstructorInfo JavaDoc[constrs.length];
438
439         for(int i=0;i<toRet.length;i++)
440         {
441             Class JavaDoc[] cparams = constrs[i].getParameterTypes();
442             MBeanParameterInfo JavaDoc[] params = new MBeanParameterInfo JavaDoc[cparams.length];
443
444             for(int j=0;j<params.length;j++)
445             {
446                 params[j] = new MBeanParameterInfo JavaDoc( ("param" + j ),
447                                                     cparams[j].getName(),
448                                                     "param to constructor");
449             }
450
451             toRet[i] = new MBeanConstructorInfo JavaDoc(constrs[i].getName(),
452                                                 constrs[i].toString(),
453                                                 params);
454         }
455
456         return toRet;
457     }
458
459     public MBeanOperationInfo JavaDoc[] getOperations()
460     {
461         int length = 0;
462         int pos = 0;
463
464         Method JavaDoc[] meths = iclazz.getMethods();
465
466         //MBeanOperationInfo[] toRet = new MBeanOperationInfo[length];
467
Vector JavaDoc operInfo = new Vector JavaDoc();
468         MBeanOperationInfo JavaDoc mbOperInfo = null;
469
470         for(int i=0;i<meths.length; i++)
471         {
472             String JavaDoc methName = meths[i].getName();
473             String JavaDoc returnType = meths[i].getReturnType().getName();
474             Class JavaDoc[] mparams = meths[i].getParameterTypes();
475             if(methName.startsWith("get") && !methName.equals("get")&&
476                (mparams.length ==0) &&!(returnType.equals("void"))){
477                 continue;
478             }
479             if(methName.startsWith("is") && !methName.equals("is")&&
480                (mparams.length ==0) &&(returnType.equals("boolean")|| returnType.equals("java.lang.Boolean"))){
481                 continue;
482             }
483             if(methName.startsWith("set") && !methName.equals("set")&&
484                (mparams.length == 1) && returnType.equals("void")){
485                 continue;
486             }
487
488             MBeanParameterInfo JavaDoc[] params = new MBeanParameterInfo JavaDoc[mparams.length];
489                             //commentSystem.out.println("\n\n** DEFAULT DYNAMIC MBEAN = "+meths[i].getName());
490
for(int j=0;j<params.length;j++)
491                 {
492                     //commentSystem.out.println("** PARAMETER = "+mparams[j].getName());
493
//params[j] = new MBeanParameterInfo( ("param" + j ), convertToJmxArrayType(mparams[j].getName()),"param to method");
494
params[j] = new MBeanParameterInfo JavaDoc(("param"+j),mparams[j].getName(),"param to method");
495                 }
496             String JavaDoc des = "Operation exposed for management";
497             if(clazz.getName().equals("javax.management.loading.MLet"))
498                 {
499                     if(meths[i].getName().equals("addURL"))
500                         des = "Appends the specified URL to the list of URLs to search for classes and resources.";
501                     else if(meths[i].getName().equals("getMBeansFromURL"))
502                         des = "Loads a text file containing MLET tags that define the MBeans to be added to the agent.";
503                 }
504
505             mbOperInfo = new MBeanOperationInfo JavaDoc(meths[i].getName(),des,params,meths[i].getReturnType().getName(),MBeanOperationInfo.ACTION);
506             operInfo.add(mbOperInfo);
507         }
508
509         int size = operInfo.size();
510         MBeanOperationInfo JavaDoc[] toRet = new MBeanOperationInfo JavaDoc[size];
511         for(int i=0; i<size; i++){
512             toRet[i] = (MBeanOperationInfo JavaDoc)operInfo.get(i);
513         }
514         return toRet;
515     }
516
517     public MBeanNotificationInfo JavaDoc[] getNotifications()
518     {
519         //currently not supported
520
return null;
521     }
522
523     public MBeanInfo JavaDoc getMBeanInfo()
524     {
525         return mbeanInfo;
526     }
527
528     public Object JavaDoc getAttribute(String JavaDoc attribute) //throws Exception
529
throws javax.management.AttributeNotFoundException JavaDoc,
530                javax.management.MBeanException JavaDoc,
531                javax.management.ReflectionException JavaDoc
532     {
533         try{
534
535             Class JavaDoc e = null;
536             e = object.getClass();
537             Method JavaDoc attrMethod = null;
538             Object JavaDoc[] arguments = new Object JavaDoc[0];
539
540             try{
541                 //String[] attributes = getAttributes();
542
MBeanAttributeInfo JavaDoc[] attrInfo = getMBeanInfo().getAttributes();
543                 boolean isAttributeFound = false;
544                 for(int i=0; i<attrInfo.length; i++){
545                         if(attribute.equals(attrInfo[i].getName())){
546                                 isAttributeFound = true;
547                         }
548                 }
549                 if(!isAttributeFound){
550                         throw new AttributeNotFoundException JavaDoc();
551                 }
552
553                 attrMethod = e.getMethod("get"+attribute,null);
554                 /*if(attrMethod == null){
555                         throw new AttributeNotFoundException();
556                 }*/

557                 return attrMethod.invoke(object,arguments);
558             }catch(Exception JavaDoc ee){
559                                 /** For TCK */
560                 if(ee instanceof NoSuchMethodException JavaDoc){
561                     attrMethod = e.getMethod("is"+attribute,null);
562                     return attrMethod.invoke(object,arguments);
563                 }
564                 throw ee;
565             }
566         }catch(Exception JavaDoc e){
567                         if(e instanceof AttributeNotFoundException JavaDoc){
568                                 throw (AttributeNotFoundException JavaDoc)e;
569                         }
570             if(e instanceof NoSuchMethodException JavaDoc)
571                 throw new AttributeNotFoundException JavaDoc();
572
573             if(e instanceof InvocationTargetException JavaDoc)
574                 {
575                                 /** For TCK */
576                     InvocationTargetException JavaDoc ite = (InvocationTargetException JavaDoc)e;
577                     Throwable JavaDoc th = ite.getTargetException();
578                     if(th instanceof Error JavaDoc){
579                         Error JavaDoc er = (Error JavaDoc)th;
580                         RuntimeErrorException JavaDoc ree = new RuntimeErrorException JavaDoc(er);
581                         throw ree;
582                     }
583                     Exception JavaDoc e1 = (Exception JavaDoc)((InvocationTargetException JavaDoc)e).getTargetException();
584                     throw new ReflectionException JavaDoc(e1);
585                 }
586             throw new ReflectionException JavaDoc(e);
587         }
588     }
589
590     public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
591     //throws Exception
592
{
593         AttributeList JavaDoc toRet = null;
594         if(attributes == null)
595             return toRet;
596
597         toRet = new AttributeList JavaDoc();
598         for(int i = 0; i<attributes.length;i++)
599         {
600             Attribute JavaDoc attr = null;
601
602             try{
603                 attr = new Attribute JavaDoc(attributes[i], getAttribute(attributes[i]));
604             }catch(Exception JavaDoc e){
605                 attr = new Attribute JavaDoc(attributes[i], e);
606             }
607             toRet.add(attr);
608         }
609
610         return toRet;
611     }
612
613     public Object JavaDoc invoke(String JavaDoc actionName, Object JavaDoc[] params, String JavaDoc[] signature)
614         throws javax.management.MBeanException JavaDoc,
615                javax.management.ReflectionException JavaDoc
616     {
617         Class JavaDoc e = null;
618         try
619         {
620             e = object.getClass();
621
622             MBeanOperationInfo JavaDoc[] opers = mbeanInfo.getOperations();
623
624             MBeanOperationInfo JavaDoc oper = null;
625             for(int i=0;i<opers.length;i++)
626             {
627                 if(opers[i].getName().equals(actionName))
628                 {
629                     MBeanParameterInfo JavaDoc[] pars = opers[i].getSignature();
630                     if(pars == null)
631                         break;
632
633                     if(params != null)
634                     {
635                          if( !(pars.length == params.length) )
636                          {
637                             if(i != (opers.length-1)){
638                                 continue;
639                             }
640                             else{
641                                 throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc());
642                             }
643                         }
644                     }
645
646                     if(params != null && signature != null)
647                     {
648                         if(params.length != signature.length)
649                         {
650                             throw new ReflectionException JavaDoc(new IllegalArgumentException JavaDoc());
651                         }
652                     }
653
654                     int j=0;
655                     for(;j<pars.length;j++)
656                         {
657                             if(params[j] != null){
658                                 String JavaDoc jmxParam = convertToJmxArrayType(signature[j]);
659
660                                 if(!pars[j].getType().equals(jmxParam))
661                                     {
662                                         String JavaDoc temp = convertToWrapperType(pars[j].getType());
663
664                                         if((temp == null) || (!(temp.equals(jmxParam))))
665                                             continue;
666                                     }
667                             }
668
669
670
671                         }
672                     if(j < pars.length)
673                         continue;
674
675                     oper = opers[i];
676                     break;
677                 }
678             }
679
680             if(oper == null){
681                 /* Provision for handling Attribute */
682                 /*if(actionName.startsWith("get") || actionName.startsWith("set")){
683                   actionName = actionName.substring(3);
684                   }
685                   else if(actionName.startsWith("is")){
686                   actionName = actionName.substring(2);
687                   }
688                   Object attribute = getAttribute(actionName);
689                   if(attribute == null){
690                   throw new MBeanException(new Exception());
691                   }*/

692                 /** This is to execute Attributes .Setter will have only one parameters*/
693                 Class JavaDoc[] paramClass = null;
694                 if(params != null){
695                     if(params.length == 0 || params.length == 1){
696                         paramClass = new Class JavaDoc[params.length];
697                         for(int i=0; i<params.length;i++){
698                             paramClass[i] = params[i].getClass();
699                         }
700                     }
701                     else{
702                         //throw new MBeanException(new Exception());
703
throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc());
704                     }
705                 }
706                 Method JavaDoc attrMethod = null;
707                 try{
708                     attrMethod = e.getMethod(actionName,paramClass);
709                 }catch(NoSuchMethodException JavaDoc ne){
710                     if(paramClass.length == 1){
711                         Method JavaDoc[] meths = e.getMethods();
712                         for(int i=0;i< meths.length; i++){
713                             if(meths[i].getName().equals(actionName)){
714                                 Class JavaDoc[] parameters = meths[i].getParameterTypes();
715                                 if(parameters[0].isAssignableFrom(paramClass[0])){
716                                     attrMethod = meths[i];
717                                     return attrMethod.invoke(object,params);
718                                 }
719                             }
720                         }
721                         if(attrMethod == null){
722                             paramClass[0] = getPrimitiveClass(paramClass[0].getName());
723                             attrMethod = e.getMethod(actionName,paramClass);
724                         }
725                     }
726                     else{
727                         throw new MBeanException JavaDoc(new Exception JavaDoc());
728                     }
729                 }
730                 if(attrMethod == null){
731                     throw new MBeanException JavaDoc(new Exception JavaDoc());
732                 }
733                 return attrMethod.invoke(object,params);
734                 //throw new MBeanException(new Exception());
735
}
736             MBeanParameterInfo JavaDoc[] pars = oper.getSignature();
737             Class JavaDoc parameterTypes[]=null;
738             if(params != null){
739                 parameterTypes = new Class JavaDoc[params.length];
740                 for(int i=0; i<params.length; i++)
741                 {
742                     Class JavaDoc clazz = getProperClass(pars[i].getType());
743                     if(clazz == null)
744                         clazz = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
745
746                     parameterTypes[i] = clazz;
747                 }
748             }
749
750             Method JavaDoc attrMethod = e.getMethod(actionName,parameterTypes);
751             return attrMethod.invoke(object,params);
752         }
753         catch(ReflectionException JavaDoc re)
754         {
755             throw re;
756         }
757         catch(Exception JavaDoc ex)
758         {
759             if(ex instanceof InvocationTargetException JavaDoc)
760                 {
761                     /** For TCK */
762                     Exception JavaDoc ee = null;
763                     InvocationTargetException JavaDoc ite = (InvocationTargetException JavaDoc)ex;
764                     Throwable JavaDoc th = ite.getTargetException();
765                     if(th instanceof Error JavaDoc){
766                         Error JavaDoc er = (Error JavaDoc)th;
767                         RuntimeErrorException JavaDoc ree = new RuntimeErrorException JavaDoc(er);
768                         throw ree;
769                     }
770                     else{
771                         //ee = (Exception)th;
772
if(th instanceof RuntimeException JavaDoc){
773                                                         throw new RuntimeMBeanException JavaDoc((RuntimeException JavaDoc)th);
774                         }
775                         if(th instanceof ReflectionException JavaDoc){
776                                                         throw new MBeanException JavaDoc((ReflectionException JavaDoc)th);
777                                                 }
778                                         }
779                             throw new MBeanException JavaDoc((Exception JavaDoc)th);
780                 }
781             if(ex instanceof RuntimeOperationsException JavaDoc){
782                                 throw (RuntimeOperationsException JavaDoc)ex;
783             }
784             if(ex instanceof RuntimeException JavaDoc){
785                 throw new RuntimeMBeanException JavaDoc((RuntimeException JavaDoc)ex);
786             }
787
788             if(ex instanceof ClassNotFoundException JavaDoc)
789                 {
790
791                     try{
792                         Class JavaDoc[] classParams = new Class JavaDoc[params.length];
793                         for(int i=0; i<params.length; i++){
794                             if(isPrimitiveDataType(signature[i]))
795                                 classParams[i] = getProperClass(signature[i]);
796                             else
797                                 classParams[i] = params[i].getClass();
798                         }
799                         //try{
800
Method JavaDoc meth = e.getMethod(actionName,classParams);
801                         return meth.invoke(object,params);
802                         /*}catch(NoSuchMethodException cnfe){
803                           Class[] cParams = new Class[params.length];
804                           for(int i=0; i<params.length; i++){
805                           try{
806                           cParams[i] = DefaultLoaderRepositoryExt.loadClass(signature[i]);
807                           }catch(Exception exc){
808                           //when classnotfound in default loader repository, there is a chance it to be
809                           //system class like java.*
810                           if(isPrimitiveDataType(signature[i]))
811                           cParams[i] = getProperClass(signature[i]);
812                           else
813                           cParams[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
814                           }
815                           }
816                           Method meth = e.getMethod(actionName,cParams);
817                           return meth.invoke(object,params);
818                           }*/

819                     }catch(NoSuchMethodException JavaDoc ne){
820                         try
821                         {
822                             Class JavaDoc[] cParams = new Class JavaDoc[params.length];
823                               for(int i=0; i<params.length; i++){
824                               try{
825                               cParams[i] = DefaultLoaderRepositoryExt.loadClass(signature[i]);
826                               }catch(Exception JavaDoc exc){
827                               //when classnotfound in default loader repository, there is a chance it to be
828
//system class like java.*
829
if(isPrimitiveDataType(signature[i]))
830                               cParams[i] = getProperClass(signature[i]);
831                               else
832                               cParams[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
833                               }
834                               }
835                               Method JavaDoc meth = e.getMethod(actionName,cParams);
836                               return meth.invoke(object,params);
837                         }catch(NoSuchMethodException JavaDoc nee)
838                         {
839                         throw new ReflectionException JavaDoc(ne);
840                         }catch(Exception JavaDoc eee)
841                         {
842                             throw new MBeanException JavaDoc(eee);
843                         }
844                     }catch(Exception JavaDoc ene){
845                         if(ene instanceof MBeanException JavaDoc)
846                         {
847                             throw (MBeanException JavaDoc)ene;
848                         }
849
850                         throw new MBeanException JavaDoc(ene);
851                     }
852                 }
853             throw new MBeanException JavaDoc(ex);
854             //throw new ReflectionException(e);
855
}
856     }
857
858     private boolean isPrimitiveDataType(String JavaDoc type)
859     {
860         if(type.endsWith("int"))
861             return true;
862         else if(type.endsWith("long"))
863             return true;
864         else if(type.endsWith("byte"))
865             return true;
866         else if(type.endsWith("float"))
867             return true;
868         else if(type.endsWith("char"))
869             return true;
870         else if(type.endsWith("short"))
871             return true;
872         else if(type.endsWith("double"))
873             return true;
874         else if(type.endsWith("boolean"))
875             return true;
876
877         return false;
878
879     }
880
881     private boolean isPrimitiveArrayDataType(String JavaDoc type)
882     {
883         if(type.endsWith("int[]"))
884             return true;
885         else if(type.endsWith("long[]"))
886             return true;
887         else if(type.endsWith("byte[]"))
888             return true;
889         else if(type.endsWith("float[]"))
890             return true;
891         else if(type.endsWith("char[]"))
892             return true;
893         else if(type.endsWith("short[]"))
894             return true;
895         else if(type.endsWith("double[]"))
896             return true;
897         else if(type.endsWith("boolean[]"))
898             return true;
899
900         return false;
901
902     }
903
904     private String JavaDoc convertToWrapperType(String JavaDoc type)
905     {
906         if(type.endsWith("int"))
907             return "java.lang.Integer";
908         else if(type.endsWith("int[]"))
909             return "[Ljava.lang.Integer;";
910         else if(type.endsWith("long"))
911             return "java.lang.Long";
912         else if(type.endsWith("long[]"))
913             return "[Ljava.lang.Long;";
914         else if(type.endsWith("byte"))
915             return "java.lang.Byte";
916         else if(type.endsWith("byte[]"))
917             return "[Ljava.lang.Byte;";
918         else if(type.endsWith("float"))
919             return "java.lang.Float";
920         else if(type.endsWith("float[]"))
921             return "[Ljava.lang.Float;";
922         else if(type.endsWith("char"))
923             return "java.lang.Character";
924         else if(type.endsWith("char[]"))
925             return "[Ljava.lang.Character;";
926         else if(type.endsWith("short"))
927             return "java.lang.Short";
928         else if(type.endsWith("short[]"))
929             return "[Ljava.lang.Short;";
930         else if(type.endsWith("double"))
931             return "java.lang.Double";
932         else if(type.endsWith("double[]"))
933             return "[Ljava.lang.Double;";
934         else if(type.endsWith("boolean"))
935             return "java.lang.Boolean";
936         else if(type.endsWith("boolean[]"))
937             return "[Ljava.lang.Boolean;";
938
939         return null;
940
941     }
942
943     private Class JavaDoc getProperClass(String JavaDoc type)
944     {
945         if(type.endsWith("int[]"))
946             return (new int[0]).getClass();
947         else if(type.endsWith("long[]"))
948             return (new long[0]).getClass();
949         else if(type.endsWith("byte[]"))
950             return (new byte[0]).getClass();
951         else if(type.endsWith("float[]"))
952             return (new float[0]).getClass();
953         else if(type.endsWith("char[]"))
954             return (new char[0]).getClass();
955         else if(type.endsWith("short[]"))
956             return (new short[0]).getClass();
957         else if(type.endsWith("double[]"))
958             return (new double[0]).getClass();
959         else if(type.endsWith("boolean[]"))
960             return (new boolean[0]).getClass();
961         else if(type.endsWith("String[]")){
962             return (new String JavaDoc[0]).getClass();
963         }
964
965         if(type.endsWith("int"))
966             return int.class;
967         else if(type.endsWith("long"))
968             return long.class;
969         else if(type.endsWith("byte"))
970             return byte.class;
971         else if(type.endsWith("float"))
972             return float.class;
973         else if(type.endsWith("char"))
974             return char.class;
975         else if(type.endsWith("short"))
976             return short.class;
977         else if(type.endsWith("double"))
978             return double.class;
979         else if(type.endsWith("boolean"))
980             return boolean.class;
981
982         return null;
983     }
984
985     private Class JavaDoc getPrimitiveClass(String JavaDoc className){
986         if(className.equals("java.lang.Integer")){
987             return Integer.TYPE;
988         }
989         else if(className.equals("java.lang.Long")){
990             return Long.TYPE;
991         }
992         else if(className.equals("java.lang.Short")){
993             return Short.TYPE;
994         }
995         else if(className.equals("java.lang.Float")){
996             return Float.TYPE;
997         }
998         else if(className.equals("java.lang.Double")){
999             return Double.TYPE;
1000        }
1001        else if(className.equals("java.lang.Character")){
1002            return Character.TYPE;
1003        }
1004        else if(className.equals("java.lang.Boolean")){
1005            return Boolean.TYPE;
1006        }
1007
1008        return null;
1009    }
1010
1011    private String JavaDoc convertToJmxArrayType(String JavaDoc type)
1012    {
1013        if(type.equals("[I") )
1014            return "int[]";
1015        else if(type.equals("[J"))
1016            return "long[]";
1017        else if(type.equals("[B"))
1018            return "byte[]";
1019        else if(type.equals("[F"))
1020            return "float[]";
1021        else if(type.equals("[C"))
1022            return "char[]";
1023        else if(type.equals("[S"))
1024            return "short[]";
1025        else if(type.equals("[D"))
1026            return "double[]";
1027        else if(type.equals("[Z"))
1028            return "boolean[]";
1029
1030        if(type.startsWith("[L") && type.endsWith(";"))
1031            return (type.substring(2, type.length() -1) + "[]");
1032
1033        return type;
1034    }
1035
1036    public void setAttribute(Attribute JavaDoc attribute)
1037    //throws Exception
1038
throws javax.management.AttributeNotFoundException JavaDoc,
1039               javax.management.InvalidAttributeValueException JavaDoc,
1040               javax.management.MBeanException JavaDoc,
1041               javax.management.ReflectionException JavaDoc
1042    {
1043
1044        if(attribute == null)
1045            throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Null values not possible"));
1046
1047        try
1048        {
1049            Class JavaDoc e = null;
1050            try
1051            {
1052                e = Thread.currentThread().getContextClassLoader().loadClass(mbeanInfo.getClassName());
1053            }
1054            catch(ClassNotFoundException JavaDoc cce)
1055            {
1056                MBeanServerImpl server = null;
1057                ArrayList JavaDoc list = MBeanServerFactory.findMBeanServer(null);
1058                if(list != null)
1059                    server = (MBeanServerImpl)list.toArray()[0];
1060                else throw cce;
1061
1062                Object JavaDoc loader = server.getLoaderTable().get(mbeanInfo.getClassName());
1063                if(loader == null)
1064                    throw cce;
1065
1066                e = Class.forName(mbeanInfo.getClassName(), true, (ClassLoader JavaDoc)loader);
1067            }
1068
1069            MBeanAttributeInfo JavaDoc[] attrs = mbeanInfo.getAttributes();
1070            MBeanAttributeInfo JavaDoc attr = null;
1071            for(int i=0;i<attrs.length;i++)
1072            {
1073
1074                if(attrs[i].getName().equals(attribute.getName()))
1075                    {
1076                        attr = attrs[i];
1077                        break;
1078                    }
1079            }
1080
1081            if(attr == null)
1082                throw new AttributeNotFoundException JavaDoc(attribute.getName());
1083
1084            Class JavaDoc parameterTypes[]=new Class JavaDoc[1];
1085
1086            Class JavaDoc clazz = getProperClass(attr.getType());
1087            if(clazz == null){
1088                clazz = attribute.getValue().getClass();
1089            }
1090            parameterTypes[0] = clazz;
1091
1092            Method JavaDoc attrMethod = null;
1093            ArrayList JavaDoc methodList = new ArrayList JavaDoc();
1094            ArrayList JavaDoc paramList = new ArrayList JavaDoc();
1095            try
1096            {
1097                Method JavaDoc[] meths = e.getMethods();
1098                Class JavaDoc[] params = null;
1099                parameterTypes[0] = null;
1100                for(int i=0; i<meths.length; i++)
1101                {
1102                    Method JavaDoc meth = meths[i];
1103                    if(meth.getName().equals("set"+attribute.getName()))
1104                    {
1105                        params = meth.getParameterTypes();
1106                        //Attribute will have only one param
1107
if(params != null)
1108                        {
1109                            if(params[0].isAssignableFrom(clazz)){
1110                                parameterTypes[0] = params[0];
1111                                methodList.add(meth);
1112                                paramList.add(parameterTypes[0]);
1113                            }
1114                        }
1115                    }
1116
1117                    if(params != null && params.length >0 && params[0] != null)
1118                    {
1119                        if(parameterTypes[0] == null)
1120                        {
1121                            throw new InvalidAttributeValueException JavaDoc();
1122                        }
1123                    }
1124                }
1125                int size = methodList.size();
1126                if(size == 0){
1127                        throw new NoSuchMethodException JavaDoc();
1128                }
1129                else if(size == 1){
1130                        attrMethod = (Method JavaDoc)methodList.get(0);
1131                }
1132                else{
1133                    MBeanInfo JavaDoc info = getMBeanInfo();
1134                    //String className = info.getClassName()+"MBean";
1135
//Class mbeanClass = Class.forName(className);
1136
Method JavaDoc[] mbeanMeths =iclazz.getMethods();
1137                    int mbeanMethsSize = mbeanMeths.length;
1138                    boolean isFound = false;
1139                    for(int i=0;i<size;i++){
1140                        Method JavaDoc meth = (Method JavaDoc)methodList.get(i);
1141                        for(int j=0; j<mbeanMethsSize; j++){
1142                            if(meth.getName().equals(mbeanMeths[j].getName())){
1143                                if(Arrays.equals(meth.getExceptionTypes(),mbeanMeths[j].getExceptionTypes())){ attrMethod = meth;
1144                                  isFound = true;
1145                                  break;
1146                                }
1147                            }
1148                        }
1149                        if(isFound){
1150                                break;
1151                        }
1152                    }
1153                }
1154                if(attrMethod == null){
1155                        throw new NoSuchMethodException JavaDoc();
1156                }
1157            }
1158            catch(Exception JavaDoc ee){
1159                                if(ee instanceof InvalidAttributeValueException JavaDoc){
1160                                        throw (InvalidAttributeValueException JavaDoc)ee;
1161                                }
1162                                if(ee instanceof NoSuchMethodException JavaDoc){
1163                     throw new AttributeNotFoundException JavaDoc();
1164                }
1165                //ee.printStackTrace();
1166
throw new MBeanException JavaDoc(ee);
1167           }
1168
1169            try
1170            {
1171                attrMethod.invoke(object, new Object JavaDoc[]{attribute.getValue()} );
1172            }catch(Exception JavaDoc e2){
1173                                if(e2 instanceof AttributeNotFoundException JavaDoc){
1174                    throw (AttributeNotFoundException JavaDoc)e2;
1175                }
1176                if(e2 instanceof InvocationTargetException JavaDoc)
1177                {
1178                    /** For TCK */
1179                    InvocationTargetException JavaDoc ite = (InvocationTargetException JavaDoc)e2;
1180                    Throwable JavaDoc th = ite.getTargetException();
1181                    if(th instanceof Error JavaDoc){
1182                        Error JavaDoc er = (Error JavaDoc)th;
1183                        RuntimeErrorException JavaDoc ree = new RuntimeErrorException JavaDoc(er);
1184                        throw ree;
1185                    }
1186                    else{
1187                            if(th instanceof ReflectionException JavaDoc){
1188                                    throw (ReflectionException JavaDoc)th;
1189                            }
1190
1191                            if(th instanceof RuntimeException JavaDoc){
1192                                    throw new RuntimeMBeanException JavaDoc((RuntimeException JavaDoc)th);
1193                            }
1194                            else{
1195                                    throw new MBeanException JavaDoc((Exception JavaDoc)th);
1196                            }
1197                    }
1198                }
1199            }
1200        }
1201        catch(ReflectionException JavaDoc e){
1202            throw e;
1203        }
1204        catch(Exception JavaDoc e){
1205                        if(e instanceof InvalidAttributeValueException JavaDoc){
1206                                        throw (InvalidAttributeValueException JavaDoc)e;
1207                        }
1208            if(e instanceof AttributeNotFoundException JavaDoc){
1209                throw (AttributeNotFoundException JavaDoc)e;
1210            }
1211
1212            if(e instanceof InvocationTargetException JavaDoc)
1213            {
1214                            /** For TCK */
1215                InvocationTargetException JavaDoc ite = (InvocationTargetException JavaDoc)e;
1216                Throwable JavaDoc th = ite.getTargetException();
1217                if(th instanceof Error JavaDoc){
1218                    Error JavaDoc er = (Error JavaDoc)th;
1219                    RuntimeErrorException JavaDoc ree = new RuntimeErrorException JavaDoc(er);
1220                    throw ree;
1221                }
1222                                    else{
1223                                                    if(th instanceof ReflectionException JavaDoc){
1224                                                            throw (ReflectionException JavaDoc)th;
1225                                                    }
1226
1227                                                    if(th instanceof RuntimeException JavaDoc){
1228                                                            throw new RuntimeMBeanException JavaDoc((RuntimeException JavaDoc)th);
1229                                                    }
1230                                                    else{
1231                                                            throw new MBeanException JavaDoc((Exception JavaDoc)th);
1232                                                    }
1233                                    }
1234            }
1235
1236            if(e instanceof RuntimeMBeanException JavaDoc){
1237                    throw (RuntimeMBeanException JavaDoc)e;
1238            }
1239            if(e instanceof MBeanException JavaDoc){
1240                    throw (MBeanException JavaDoc)e;
1241            }
1242        }
1243    }
1244
1245    public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
1246    {
1247        if(attributes == null)
1248            throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Null values not possible"));
1249
1250        Object JavaDoc[] array = attributes.toArray();
1251
1252        if(array == null)
1253            return attributes;
1254
1255        for(int i = 0; i<array.length;i++)
1256        {
1257            Attribute JavaDoc attr = null;
1258            try
1259            {
1260                attr = (Attribute JavaDoc)array[i];
1261            }
1262            catch(ClassCastException JavaDoc ce)
1263            {
1264                continue;
1265            }
1266
1267            try
1268            {
1269                setAttribute(attr);
1270            }
1271            catch(Exception JavaDoc e)
1272            {
1273                int index = attributes.indexOf(attr);
1274                attributes.remove(index);
1275                attr = new Attribute JavaDoc(attr.getName(), e);
1276                attributes.add(index, attr);
1277            }
1278        }
1279
1280        return attributes;
1281    }
1282
1283    //Implementing NotificationBroadcaster
1284
public void addNotificationListener(NotificationListener JavaDoc listener,
1285                                        NotificationFilter JavaDoc filter,
1286                                        Object JavaDoc handback)
1287                                throws IllegalArgumentException JavaDoc
1288    {
1289        if( !(object instanceof NotificationBroadcaster JavaDoc))
1290        {
1291            throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("The MBean does not implement NotificationBroadCaster"));
1292        }
1293
1294        ((NotificationBroadcaster JavaDoc)object).addNotificationListener(listener,
1295                                                            filter, handback);
1296    }
1297
1298    public void removeNotificationListener(NotificationListener JavaDoc listener)
1299                                        throws ListenerNotFoundException JavaDoc
1300    {
1301        if( !(object instanceof NotificationBroadcaster JavaDoc))
1302        {
1303            throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("The MBean does not implement NotificationBroadCaster"));
1304        }
1305
1306       ((NotificationBroadcaster JavaDoc)object).removeNotificationListener(listener);
1307    }
1308
1309    public MBeanNotificationInfo JavaDoc[] getNotificationInfo()
1310    {
1311        if( !(object instanceof NotificationBroadcaster JavaDoc))
1312            return null;
1313
1314        return ((NotificationBroadcaster JavaDoc)object).getNotificationInfo();
1315    }
1316
1317    //Implementing for NotificationFilter
1318
public boolean isNotificationEnabled(Notification JavaDoc notification)
1319    {
1320        if( !(object instanceof NotificationFilter JavaDoc))
1321            return false;
1322
1323        return ((NotificationFilter JavaDoc)object).isNotificationEnabled(notification);
1324    }
1325
1326    //IMplementing for NotificationListener
1327
public void handleNotification(Notification JavaDoc notification, Object JavaDoc handback)
1328    {
1329        if( !(object instanceof NotificationListener JavaDoc))
1330            return;
1331
1332        ((NotificationListener JavaDoc)object).handleNotification(notification, handback);
1333    }
1334
1335    //IMplementing for MBeanRegistration
1336
public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name) throws Exception JavaDoc
1337    {
1338        if( !(object instanceof MBeanRegistration JavaDoc))
1339            return null;
1340
1341        return ((MBeanRegistration JavaDoc)object).preRegister(server, name);
1342    }
1343
1344    public void postRegister(java.lang.Boolean JavaDoc registrationDone)
1345    {
1346        if( !(object instanceof MBeanRegistration JavaDoc))
1347            return;
1348
1349        ((MBeanRegistration JavaDoc)object).postRegister(registrationDone);
1350    }
1351
1352    public void preDeregister() throws Exception JavaDoc
1353    {
1354        if( !(object instanceof MBeanRegistration JavaDoc))
1355            return;
1356        try
1357        {
1358            ((MBeanRegistration JavaDoc)object).preDeregister();
1359        }
1360        catch(Exception JavaDoc e)
1361        {
1362            throw e;
1363        }
1364    }
1365
1366    public void postDeregister()
1367    {
1368        if( !(object instanceof MBeanRegistration JavaDoc))
1369            return;
1370
1371        ((MBeanRegistration JavaDoc)object).postDeregister();
1372    }
1373
1374    private boolean getFlagValue(Class JavaDoc mainClass,boolean value)
1375    {
1376        clazz = mainClass.getSuperclass();
1377
1378        Class JavaDoc [] interfaces = clazz.getInterfaces();
1379        for(int i = 0;i<interfaces.length;i++)
1380        {
1381            if(interfaces[i].getName().equals(clazz.getName() + "MBean") )
1382            {
1383                iclazz = interfaces[i];
1384                value = true;
1385                break;
1386            }
1387
1388        }
1389
1390        return value;
1391    }
1392}
Popular Tags