1 22 package org.jboss.console.plugins; 23 24 import gnu.trove.TLongObjectHashMap; 25 import org.jboss.aop.AspectManager; 26 import org.jboss.aop.CallerConstructorInfo; 27 import org.jboss.aop.CallerMethodInfo; 28 import org.jboss.aop.ClassAdvisor; 29 import org.jboss.aop.MethodInfo; 30 import org.jboss.aop.advice.AdviceBinding; 31 import org.jboss.aop.advice.Interceptor; 32 import org.jboss.aop.advice.AbstractAdvice; 33 import org.jboss.aop.advice.CFlowInterceptor; 34 import org.jboss.aop.introduction.InterfaceIntroduction; 35 import org.jboss.aop.standalone.Package; 36 import org.jboss.console.manager.interfaces.ManageableResource; 37 import org.jboss.console.manager.interfaces.TreeNode; 38 import org.jboss.console.plugins.helpers.AbstractPluginWrapper; 39 40 import java.io.PrintWriter ; 41 import java.lang.reflect.Constructor ; 42 import java.lang.reflect.Field ; 43 import java.lang.reflect.Method ; 44 import java.util.ArrayList ; 45 import java.util.HashMap ; 46 import java.util.HashSet ; 47 import java.util.Iterator ; 48 import java.util.Map ; 49 50 import javax.servlet.ServletConfig ; 51 52 66 public class AOPLister 67 extends AbstractPluginWrapper 68 { 69 Thread refreshPoller; 70 71 72 public AOPLister() 73 { 74 super(); 75 } 76 77 TreeNode[] createMetaDataTree(org.jboss.aop.metadata.SimpleMetaData metaData, String description, String baseUrl) throws Exception 78 { 79 HashSet groups = metaData.tags(); 80 if (groups.size() == 0) 81 { 82 return null; 83 } 84 85 TreeNode[] nodes = new TreeNode[groups.size()]; 86 Iterator it = groups.iterator(); 87 for (int i = 0; it.hasNext(); i++) 88 { 89 String group = (String ) it.next(); 90 nodes[i] = createTreeNode( 91 group, description, 93 "images/database.gif", baseUrl + "&group=" + group, 95 null, null, null ); 99 } 100 return nodes; 101 } 102 103 TreeNode[] loadDefaultMetaData(ClassAdvisor advisor, String classname) throws Exception 104 { 105 org.jboss.aop.metadata.SimpleMetaData metaData = advisor.getDefaultMetaData(); 106 return createMetaDataTree(metaData, 107 "Default metadata for " + classname, 108 "AOPDefaultMetaData.jsp?classname=" + classname); 109 } 110 111 TreeNode[] loadClassMetaData(ClassAdvisor advisor, String classname) throws Exception 112 { 113 org.jboss.aop.metadata.SimpleMetaData metaData = advisor.getClassMetaData(); 114 return createMetaDataTree(metaData, 115 "Class metadata for " + classname, 116 "AOPClassMetaData.jsp?classname=" + classname); 117 } 118 119 TreeNode[] loadMethodMetaData(ClassAdvisor advisor, String classname) throws Exception 120 { 121 org.jboss.aop.metadata.MethodMetaData metaData = advisor.getMethodMetaData(); 122 123 Iterator it = metaData.getMethods(); 124 if (!it.hasNext()) return null; 125 ArrayList methods = new ArrayList (); 126 while (it.hasNext()) 127 { 128 String method = (String ) it.next(); 129 org.jboss.aop.metadata.SimpleMetaData methodData = metaData.getMethodMetaData(method); 130 TreeNode[] methodNodes = createMetaDataTree(methodData, 131 "Metadata for method " + method, 132 "AOPMethodMetaData.jsp?classname=" + classname + "&method=" + java.net.URLEncoder.encode(method)); 133 methods.add(createTreeNode( 134 method, "Metadata for method " + method, 136 "images/starfolder.gif", null, 138 null, methodNodes, null )); 142 143 } 144 return (TreeNode[]) methods.toArray(new TreeNode[methods.size()]); 145 } 146 147 TreeNode[] loadFieldMetaData(ClassAdvisor advisor, String classname) throws Exception 148 { 149 org.jboss.aop.metadata.FieldMetaData metaData = advisor.getFieldMetaData(); 150 151 Iterator it = metaData.getFields(); 152 if (!it.hasNext()) return null; 153 ArrayList fields = new ArrayList (); 154 while (it.hasNext()) 155 { 156 String field = (String ) it.next(); 157 org.jboss.aop.metadata.SimpleMetaData fieldData = metaData.getFieldMetaData(field); 158 TreeNode[] fieldNodes = createMetaDataTree(fieldData, 159 "Metadata for field " + field, 160 "AOPFieldMetaData.jsp?classname=" + classname + "&field=" + field); 161 fields.add(createTreeNode( 162 field, "Metadata for field " + field, 164 "images/starfolder.gif", null, 166 null, fieldNodes, null )); 170 171 } 172 return (TreeNode[]) fields.toArray(new TreeNode[fields.size()]); 173 } 174 175 TreeNode[] loadConstructorMetaData(ClassAdvisor advisor, String classname) throws Exception 176 { 177 org.jboss.aop.metadata.ConstructorMetaData metaData = advisor.getConstructorMetaData(); 178 179 Iterator it = metaData.getConstructors(); 180 if (!it.hasNext()) return null; 181 ArrayList constructors = new ArrayList (); 182 while (it.hasNext()) 183 { 184 String signature = (String )it.next(); 185 org.jboss.aop.metadata.SimpleMetaData constructorData = metaData.getConstructorMetaData(signature); 186 TreeNode[] constructorNodes = createMetaDataTree(constructorData, 187 "Metadata for constructor", 188 "AOPConstructorMetaData.jsp?classname=" + classname + "&constructor=" + java.net.URLEncoder.encode(signature)); 189 constructors.add(createTreeNode( 190 signature, "Metaata for constructor " + signature, 192 "images/starfolder.gif", null, 194 null, constructorNodes, null )); 198 199 } 200 return (TreeNode[]) constructors.toArray(new TreeNode[constructors.size()]); 201 } 202 203 TreeNode getMetaData(ClassAdvisor advisor) throws Exception 204 { 205 ArrayList nodes = new ArrayList (); 206 207 String classname = advisor.getClazz().getName(); 208 209 TreeNode[] defaultMetaData = loadDefaultMetaData(advisor, classname); 210 if (defaultMetaData != null) 211 { 212 nodes.add(createTreeNode( 213 "Default", 214 "Default metadata for for " + classname, "images/starfolder.gif", null, 217 null, defaultMetaData, null )); 221 } 222 223 TreeNode[] classMetaData = loadClassMetaData(advisor, classname); 224 if (classMetaData != null) 225 { 226 nodes.add(createTreeNode( 227 "Class", 228 "Class metadata for for " + classname, "images/starfolder.gif", null, 231 null, classMetaData, null )); 235 } 236 237 TreeNode[] methodMetaData = loadMethodMetaData(advisor, classname); 238 if (methodMetaData != null) 239 { 240 nodes.add(createTreeNode( 241 "Methods", 242 "Method metadata for for " + classname, "images/starfolder.gif", null, 245 null, methodMetaData, null )); 249 } 250 251 TreeNode[] fieldMetaData = loadFieldMetaData(advisor, classname); 252 if (fieldMetaData != null) 253 { 254 nodes.add(createTreeNode( 255 "Fields", 256 "Field metadata for for " + classname, "images/starfolder.gif", null, 259 null, fieldMetaData, null )); 263 } 264 265 TreeNode[] constructorMetaData = loadConstructorMetaData(advisor, classname); 266 if (constructorMetaData != null) 267 { 268 nodes.add(createTreeNode( 269 "Constructors", 270 "Constructor metadata for for " + classname, "images/starfolder.gif", null, 273 null, constructorMetaData, null )); 277 } 278 279 280 if (nodes.size() == 0) return null; 281 TreeNode[] subnodes = (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 282 283 return createTreeNode( 284 "Metadata", "Metadata for " + classname, "images/starfolder.gif", null, 288 null, subnodes, null ); 292 } 293 294 TreeNode[] getIntroductions(ClassAdvisor advisor) throws Exception 295 { 296 ArrayList introductions = advisor.getInterfaceIntroductions(); 297 if (introductions == null || introductions.size() == 0) return null; 298 299 TreeNode[] nodes = new TreeNode[introductions.size()]; 300 for (int i = 0; i < introductions.size(); i++) 301 { 302 InterfaceIntroduction introduction = (InterfaceIntroduction) introductions.get(i); 303 nodes[i] = createTreeNode( 304 "Introduction " + i, "Introduction for " + advisor.getName(), "images/service.gif", "AOPIntroductionPointcut.jsp?pointcut=" + java.net.URLEncoder.encode(introduction.getName()), null, null, null ); 312 } 313 314 return nodes; 315 } 316 317 public static String shortenMethod(String classname, Method method) 318 { 319 return method.toString().replaceAll(classname + "." + method.getName(), method.getName()); 320 } 321 322 public static String shortenConstructor(String classname, Constructor constructor) 323 { 324 String base = classname.substring(classname.lastIndexOf('.') + 1); 325 return constructor.toString().replaceAll(classname, base); 326 } 327 328 public static String shortenField(String classname, Field field) 329 { 330 return field.toString().replaceAll(classname + "." + field.getName(), field.getName()); 331 } 332 333 public TreeNode[] createAdvisorNodes(ClassAdvisor advisor) throws Exception 334 { 335 ArrayList nodes = new ArrayList (); 336 populateIntroductions(advisor, nodes); 337 338 populateConstructors(advisor, nodes); 339 populateMethods(advisor, nodes); 340 341 populateFields(advisor, nodes); 342 TreeNode metadata = getMetaData(advisor); 343 if (metadata != null) nodes.add(metadata); 344 345 return (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 346 } 347 348 private void populateFields(ClassAdvisor advisor, ArrayList nodes) throws Exception 349 { 350 if (advisor.getAdvisedFields() == null) return; 351 ArrayList fieldWriteNodes = new ArrayList (); 352 ArrayList fieldReadNodes = new ArrayList (); 353 for (int i = 0; i < advisor.getAdvisedFields().length; i++) 354 { 355 Field f = advisor.getAdvisedFields()[i]; 356 Interceptor[] chain = advisor.getFieldWriteInterceptors()[i]; 357 if (chain != null && chain.length > 0) 358 { 359 fieldWriteNodes.add(createTreeNode( 360 shortenField(advisor.getName(), f), 361 "Field write interceptor chain", 362 "images/service.gif", "AOPFieldChain.jsp?classname=" + java.net.URLEncoder.encode(advisor.getName()) 364 + "&field=" + i 365 + "&mode=write", 366 null, null, null )); 370 } 371 chain = advisor.getFieldReadInterceptors()[i]; 372 if (chain != null && chain.length > 0) 373 { 374 fieldReadNodes.add(createTreeNode( 375 shortenField(advisor.getName(), f), 376 "Field read interceptor chain", 377 "images/service.gif", "AOPFieldChain.jsp?classname=" + java.net.URLEncoder.encode(advisor.getName()) 379 + "&field=" + i 380 + "&mode=read", 381 null, null, null )); 385 } 386 } 387 388 if (fieldWriteNodes.size() > 0 && fieldWriteNodes.size() > 0) 389 { 390 ArrayList fieldReadWriteNodes = new ArrayList (); 391 if (fieldWriteNodes.size() > 0) 392 { 393 TreeNode[] cnodes = (TreeNode[]) fieldWriteNodes.toArray(new TreeNode[fieldWriteNodes.size()]); 394 fieldReadWriteNodes.add(createTreeNode( 395 "write interceptors", "field write info", "images/starfolder.gif", null, 399 null, cnodes, null )); 403 } 404 405 if (fieldReadNodes.size() > 0) 406 { 407 TreeNode[] cnodes = (TreeNode[]) fieldReadNodes.toArray(new TreeNode[fieldReadNodes.size()]); 408 fieldReadWriteNodes.add(createTreeNode( 409 "read interceptors", "field read info", "images/starfolder.gif", null, 413 null, cnodes, null )); 417 } 418 419 TreeNode[] fieldRwNodes = (TreeNode[]) fieldReadWriteNodes.toArray(new TreeNode[fieldReadWriteNodes.size()]); 420 nodes.add(createTreeNode( 421 "Fields", "field info", "images/starfolder.gif", null, 425 null, fieldRwNodes, null )); 429 430 } 431 } 432 433 private void populateConstructors(ClassAdvisor advisor, ArrayList nodes) throws Exception 434 { 435 if (advisor.getConstructors() == null) return; 436 if (advisor.getConstructorInterceptors() == null) return; 437 if (advisor.getMethodCalledByConInterceptors() == null) return; 438 ArrayList constructorNodes = new ArrayList (); 439 for (int i = 0; i < advisor.getConstructors().length; i++) 440 { 441 Constructor con = advisor.getConstructors()[i]; 442 Interceptor[] chain = advisor.getConstructorInterceptors()[i]; 443 HashMap methodCallers = advisor.getMethodCalledByConInterceptors()[i]; 444 HashMap conCallers = advisor.getConCalledByConInterceptors()[i]; 445 if ((chain != null && chain.length > 0) || methodCallers != null || conCallers != null) 446 { 447 ArrayList conNodes = new ArrayList (); 448 if (chain != null && chain.length > 0) 449 { 450 conNodes.add(createTreeNode( 451 "Interceptors", 452 "Execution Interceptors", 453 "images/service.gif", "AOPConstructorChain.jsp?classname=" + java.net.URLEncoder.encode(con.getDeclaringClass().getName()) 455 + "&constructor=" + i, 456 null, null, null )); 460 } 461 if (conCallers != null) 462 { 463 conNodes.add(createTreeNode( 464 "constructor callers", 465 "constructor caller interceptions", 466 "images/starfolder.gif", null, 468 null, createConstructorConstructorCallers(i, advisor, conCallers), null )); 472 } 473 if (methodCallers != null) 474 { 475 conNodes.add(createTreeNode( 476 "method callers", 477 "method caller interceptions", 478 "images/starfolder.gif", null, 480 null, createConstructorMethodCallers(i, advisor, methodCallers), null )); 484 } 485 TreeNode[] cnodes = (TreeNode[]) conNodes.toArray(new TreeNode[conNodes.size()]); 486 constructorNodes.add(createTreeNode( 487 shortenConstructor(advisor.getName(), con), "constructor info", "images/starfolder.gif", null, 491 null, cnodes, null )); 495 } 496 } 497 if (constructorNodes.size() > 0) 498 { 499 TreeNode[] cnodes = (TreeNode[]) constructorNodes.toArray(new TreeNode[constructorNodes.size()]); 500 nodes.add(createTreeNode( 501 "Constructors", "constructor info", "images/starfolder.gif", null, 505 null, cnodes, null )); 509 } 510 } 511 512 private void populateMethods(ClassAdvisor advisor, ArrayList nodes) throws Exception 513 { 514 if (advisor.getMethodInterceptors() == null) return; 515 ArrayList methodNodes = new ArrayList (); 516 long[] keys = advisor.getMethodInterceptors().keys(); 517 for (int i = 0; i < keys.length; i++) 518 { 519 long key = keys[i]; 520 MethodInfo method = (MethodInfo) advisor.getMethodInterceptors().get(key); 521 HashMap methodCallers = (HashMap) advisor.getMethodCalledByMethodInterceptors().get(key); 522 HashMap conCallers = (HashMap) advisor.getConCalledByMethodInterceptors().get(key); 523 if (method == null && methodCallers == null) continue; 524 if (method != null && methodCallers == null && (method.getInterceptors() == null || method.getInterceptors().length < 1)) continue; 525 ArrayList mNodes = new ArrayList (); 526 if (method.getInterceptors() != null && method.getInterceptors().length > 0 || methodCallers != null || conCallers != null) 527 { 528 mNodes.add(createTreeNode( 529 "Interceptors", 530 "Execution Interceptors", 531 "images/service.gif", "AOPMethodChain.jsp?classname=" + java.net.URLEncoder.encode(advisor.getName()) 533 + "&method=" + keys[i], 534 null, null, null )); 538 } 539 if (conCallers != null) 540 { 541 mNodes.add(createTreeNode( 542 "constructor callers", 543 "constructor caller interceptions", 544 "images/starfolder.gif", null, 546 null, createMethodConstructorCallers(key, advisor, conCallers), null )); 550 } 551 if (methodCallers != null) 552 { 553 mNodes.add(createTreeNode( 554 "method callers", 555 "method caller interceptions", 556 "images/starfolder.gif", null, 558 null, createMethodMethodCallers(key, advisor, methodCallers), null )); 562 } 563 TreeNode[] mnodes = (TreeNode[]) mNodes.toArray(new TreeNode[mNodes.size()]); 564 methodNodes.add(createTreeNode( 565 shortenMethod(advisor.getName(), method.getAdvisedMethod()), "method info", "images/starfolder.gif", null, 569 null, mnodes, null )); 573 } 574 if (methodNodes.size() > 0) 575 { 576 TreeNode[] cnodes = (TreeNode[]) methodNodes.toArray(new TreeNode[methodNodes.size()]); 577 nodes.add(createTreeNode( 578 "Methods", "method info", "images/starfolder.gif", null, 582 null, cnodes, null )); 586 } 587 } 588 589 private void populateIntroductions(ClassAdvisor advisor, ArrayList nodes) throws Exception 590 { 591 ArrayList introductions = advisor.getInterfaceIntroductions(); 592 if (introductions != null && introductions.size() > 0) 593 { 594 TreeNode[] introductionNodes = getIntroductions(advisor); 595 TreeNode introductionsNode = createTreeNode( 596 "Introductions", "Introductions for " + advisor.getName(), "images/starfolder.gif", null, 600 null, introductionNodes, null ); 604 nodes.add(introductionsNode); 605 } 606 } 607 608 public TreeNode[] createConstructorMethodCallers(int index, ClassAdvisor advisor, HashMap called) throws Exception 609 { 610 ArrayList nodes = new ArrayList (); 611 Iterator it = called.keySet().iterator(); 612 while (it.hasNext()) 613 { 614 String calledClass = (String ) it.next(); 615 TLongObjectHashMap map = (TLongObjectHashMap) called.get(calledClass); 616 Object [] values = map.getValues(); 617 long[] keys = map.keys(); 618 for (int i = 0; i < values.length; i++) 619 { 620 CallerMethodInfo caller = (CallerMethodInfo) values[i]; 621 nodes.add(createTreeNode( 622 caller.getMethod().toString(), 623 "caller interceptions", 624 "images/service.gif", "AOPConstructorMethodCallerChain.jsp?index=" + index + "&hash=" + java.net.URLEncoder.encode(Long.toString(keys[i])) + "&classname=" + java.net.URLEncoder.encode(advisor.getName()) + "&calledclassname=" + java.net.URLEncoder.encode(calledClass), 626 null, null, null )); 630 } 631 } 632 return (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 633 } 634 635 public TreeNode[] createConstructorConstructorCallers(int index, ClassAdvisor advisor, HashMap called) throws Exception 636 { 637 ArrayList nodes = new ArrayList (); 638 Iterator it = called.keySet().iterator(); 639 while (it.hasNext()) 640 { 641 String calledClass = (String ) it.next(); 642 TLongObjectHashMap map = (TLongObjectHashMap) called.get(calledClass); 643 Object [] values = map.getValues(); 644 long[] keys = map.keys(); 645 for (int i = 0; i < values.length; i++) 646 { 647 CallerConstructorInfo caller = (CallerConstructorInfo) values[i]; 648 nodes.add(createTreeNode( 649 caller.getConstructor().toString(), 650 "caller interceptions", 651 "images/service.gif", "AOPConstructorConstructorCallerChain.jsp?index=" + index + "&hash=" + java.net.URLEncoder.encode(Long.toString(keys[i])) + "&classname=" + java.net.URLEncoder.encode(advisor.getName()) + "&calledclassname=" + java.net.URLEncoder.encode(calledClass), 653 null, null, null )); 657 } 658 } 659 return (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 660 } 661 662 public TreeNode[] createMethodMethodCallers(long callingHash, ClassAdvisor advisor, HashMap called) throws Exception 663 { 664 ArrayList nodes = new ArrayList (); 665 Iterator it = called.keySet().iterator(); 666 while (it.hasNext()) 667 { 668 String calledClass = (String ) it.next(); 669 TLongObjectHashMap map = (TLongObjectHashMap) called.get(calledClass); 670 Object [] values = map.getValues(); 671 long[] keys = map.keys(); 672 for (int i = 0; i < values.length; i++) 673 { 674 CallerMethodInfo caller = (CallerMethodInfo) values[i]; 675 nodes.add(createTreeNode( 676 caller.getMethod().toString(), 677 "caller interceptions", 678 "images/service.gif", "AOPMethodMethodCallerChain.jsp?callinghash=" + callingHash + "&hash=" + java.net.URLEncoder.encode(Long.toString(keys[i])) + "&classname=" + java.net.URLEncoder.encode(advisor.getName()) + "&calledclassname=" + java.net.URLEncoder.encode(calledClass), 680 null, null, null )); 684 } 685 } 686 return (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 687 } 688 689 public TreeNode[] createMethodConstructorCallers(long callingHash, ClassAdvisor advisor, HashMap called) throws Exception 690 { 691 ArrayList nodes = new ArrayList (); 692 Iterator it = called.keySet().iterator(); 693 while (it.hasNext()) 694 { 695 String calledClass = (String ) it.next(); 696 TLongObjectHashMap map = (TLongObjectHashMap) called.get(calledClass); 697 Object [] values = map.getValues(); 698 long[] keys = map.keys(); 699 for (int i = 0; i < values.length; i++) 700 { 701 CallerConstructorInfo caller = (CallerConstructorInfo) values[i]; 702 nodes.add(createTreeNode( 703 caller.getConstructor().toString(), 704 "caller interceptions", 705 "images/service.gif", "AOPMethodConstructorCallerChain.jsp?callinghash=" + callingHash + "&hash=" + java.net.URLEncoder.encode(Long.toString(keys[i])) + "&classname=" + java.net.URLEncoder.encode(advisor.getName()) + "&calledclassname=" + java.net.URLEncoder.encode(calledClass), 707 null, null, null )); 711 } 712 } 713 return (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 714 } 715 716 public TreeNode[] getUnboundBindings() throws Exception 717 { 718 ArrayList unbounded = new ArrayList (); 719 Iterator it = AspectManager.instance().getBindings().values().iterator(); 720 while (it.hasNext()) 721 { 722 AdviceBinding binding = (AdviceBinding) it.next(); 723 if (!binding.hasAdvisors()) 724 { 725 unbounded.add(createTreeNode( 726 binding.getName(), 727 "Unbounded Binding", 728 "images/service.gif", "AOPBinding.jsp?binding=" + java.net.URLEncoder.encode(binding.getName()), 730 null, null, null )); 734 } 735 } 736 if (unbounded.size() == 0) return null; 737 return (TreeNode[])unbounded.toArray(new TreeNode[unbounded.size()]); 738 } 739 740 741 TreeNode[] createAOPNodes(Package root) throws Exception 742 { 743 ArrayList nodes = new ArrayList (); 744 Iterator it = root.packages.entrySet().iterator(); 745 while (it.hasNext()) 746 { 747 Map.Entry entry = (Map.Entry) it.next(); 748 String pkgName = (String ) entry.getKey(); 749 Package p = (Package ) entry.getValue(); 750 nodes.add(createTreeNode( 751 pkgName, "Package " + pkgName, "images/starfolder.gif", null, null, createAOPNodes(p), null )); 759 } 760 it = root.advisors.entrySet().iterator(); 761 while (it.hasNext()) 762 { 763 Map.Entry entry = (Map.Entry) it.next(); 764 String classname = (String ) entry.getKey(); 765 ClassAdvisor advisor = (ClassAdvisor) entry.getValue(); 766 nodes.add(createTreeNode( 767 classname, "Class " + classname, "images/serviceset.gif", null, 771 null, createAdvisorNodes(advisor), null ) 775 ); 776 } 777 TreeNode[] result; 778 if (nodes.size() == 0) 779 { 780 result = null; 781 } 782 else 783 { 784 result = (TreeNode[]) nodes.toArray(new TreeNode[nodes.size()]); 785 } 786 787 return result; 788 } 789 790 protected TreeNode getTreeForResource(String profile, ManageableResource resource) 791 { 792 try 793 { 794 TreeNode[] unbounded = getUnboundBindings(); 795 TreeNode[] children = new TreeNode[2]; 796 children[0] = createTreeNode( 797 "Classes", "Display all Classes", "images/serviceset.gif", null, null, 802 createAOPNodes(Package.aopClassMap()), null ); 805 children[1] = createTreeNode( 806 "Unbound Bindings", "Unbound Bindings", "images/serviceset.gif", null, null, 811 unbounded, null ); 814 return createTreeNode ( 815 "AOP", "AOP Management", "images/spirale32.gif", null, null, 820 children, 821 null); 822 } 823 catch (Exception e) 824 { 825 e.printStackTrace(); 826 return null; 827 } 828 } 829 830 831 public static String outputChain(Interceptor[] chain) 832 { 833 String output = ""; 834 for (int i = 0; i < chain.length; i++) 835 { 836 output += "<tr>"; 837 if (chain[i] instanceof AbstractAdvice) 838 { 839 output +="<td><font size=\"1\">advice</font></td><td><font size=\"1\">" + chain[i].getName() + "</font></td>"; 840 } 841 else if (chain[i] instanceof CFlowInterceptor) 842 { 843 output +="<td><font size=\"1\">cflow</font></td><td><font size=\"1\">" + ((CFlowInterceptor) chain[i]).getCFlowString() + "</font></td>"; 844 } 845 else 846 { 847 output +="<td><font size=\"1\">interceptor</font></td><td><font size=\"1\">" + chain[i].getClass().getName() + "</font></td>"; 848 } 849 output += "</tr>"; 850 } 851 return output; 852 } 853 854 856 public void init(ServletConfig servletConfig) throws Exception 857 { 858 super.init(servletConfig); 859 refreshPoller = new RefreshPoller(); 860 refreshPoller.start(); 861 } 862 863 class RefreshPoller extends Thread 864 { 865 866 final static int REFRESH_RATE = 20 * 1000; 867 868 RefreshPoller() 869 { 870 setName("AOPListner"); 871 setDaemon(true); 872 } 873 874 public void run() 875 { 876 try 877 { 878 int advisorCount = 0; 879 while (!isInterrupted()) 880 { 881 int count = AspectManager.instance().getAdvisors().size(); 882 if (count != advisorCount) 883 { 884 pm.regenerateAdminTree(); 885 } 886 advisorCount = count; 887 888 Thread.sleep(REFRESH_RATE); 889 } 890 } 891 catch (InterruptedException e) 892 { 893 return; 894 } 895 } 896 } 897 898 public void destroy() 899 { 900 super.destroy(); 901 try 902 { 903 refreshPoller.interrupt(); 904 refreshPoller.join(); 905 } 906 catch (Exception e) 907 { 908 } 909 } 910 911 920 public static ClassAdvisor findAdvisor(String classname) 921 { 922 return AdvisorFinder.getAdvisor(classname); 923 } 924 928 static class AdvisorFinder 929 { 930 public static ClassAdvisor getAdvisor(String classname) 931 { 932 String [] name = classname.split("\\."); 933 Package root = Package.aopClassMap(); 934 935 if (!root.name.equals("classes"))throw new RuntimeException ("Did not get expected root 'classes'"); 936 937 for (Iterator it = root.packages.entrySet().iterator() ; it.hasNext() ; ) 938 { 939 Map.Entry entry = (Map.Entry) it.next(); 940 Package pkg = (Package ) entry.getValue(); 941 ClassAdvisor advisor = findAdvisor(pkg, classname, name, 0); 942 if (advisor != null) 943 { 944 return advisor; 945 } 946 } 947 return null; 948 } 949 950 private static ClassAdvisor findAdvisor(Package pkg, String classname, String [] name, int depth) 951 { 952 if (depth >= name.length || !pkg.name.equals(name[depth])) 953 { 954 return null; 955 } 956 957 for (Iterator it = pkg.packages.entrySet().iterator() ; it.hasNext() ; ) 958 { 959 Map.Entry entry = (Map.Entry) it.next(); 960 Package p = (Package ) entry.getValue(); 961 ClassAdvisor advisor = findAdvisor(p, classname, name, depth + 1); 962 if (advisor != null) 963 { 964 return advisor; 965 } 966 } 967 968 for (Iterator it = pkg.advisors.entrySet().iterator(); it.hasNext() ; ) 969 { 970 Map.Entry entry = (Map.Entry) it.next(); 971 ClassAdvisor advisor = (ClassAdvisor) entry.getValue(); 972 if (advisor.getClazz().getName().equals(classname)) 973 { 974 return advisor; 975 } 976 } 977 978 return null; 979 } 980 } 981 982 983 984 } 985 | Popular Tags |