KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > deployers > DeployersMonitor


1 /*
2 * JBoss, Home of Professional Open Source.
3 * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4 * as indicated by the @author tags. See the copyright.txt file in the
5 * distribution for a full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.aop.deployers;
23
24 import java.util.Map JavaDoc;
25 import java.util.TreeMap JavaDoc;
26
27 import org.jboss.aop.AspectManager;
28 import org.jboss.aop.advice.AdviceBinding;
29 import org.jboss.aop.advice.AspectDefinition;
30 import org.jboss.aop.advice.AspectFactory;
31 import org.jboss.aop.advice.GenericAspectFactory;
32
33 /**
34  *
35  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
36  * @version $Revision: 1.1 $
37  */

38 public class DeployersMonitor implements DeployersMonitorMBean
39 {
40    AspectManager manager = AspectManager.instance();
41
42    public Map JavaDoc<String JavaDoc, String JavaDoc> getCurrentBindings()
43    {
44       Map JavaDoc<String JavaDoc, String JavaDoc> result = new TreeMap JavaDoc<String JavaDoc, String JavaDoc>();
45       Map JavaDoc bindings = manager.getBindings();
46       for (Object JavaDoc binding : bindings.values())
47       {
48          String JavaDoc key = ((AdviceBinding)binding).getName();
49          String JavaDoc poincut = ((AdviceBinding)binding).getPointcut().getExpr();
50          result.put(key, poincut);
51       }
52       
53       return result;
54    }
55
56    public Map JavaDoc<String JavaDoc, String JavaDoc> getCurrentAspectDefinitions()
57    {
58       Map JavaDoc<String JavaDoc, String JavaDoc> result = new TreeMap JavaDoc();
59       Map JavaDoc definitions = manager.getAspectDefinitions();
60       for (Object JavaDoc def : definitions.values())
61       {
62          AspectFactory factory = ((AspectDefinition)def).getFactory();
63          
64          if (factory instanceof GenericAspectFactory)
65          {
66             String JavaDoc key = ((AspectDefinition)def).getName();
67             String JavaDoc clazz = ((GenericAspectFactory)factory).getClassname();
68             result.put(key, clazz);
69          }
70       }
71       
72       return result;
73    }
74
75    public void invokeXmlPOJO() throws Exception JavaDoc
76    {
77       org.jboss.test.aop.deployers.xml.POJO pojo = new org.jboss.test.aop.deployers.xml.POJO();
78       org.jboss.test.aop.deployers.xml.POJO.invoked = false;
79       org.jboss.test.aop.deployers.xml.SomeInterceptor.invoked = 0;
80       org.jboss.test.aop.deployers.xml.SomeAspect.invoked = 0;
81       
82       pojo.someMethod();
83       
84       if (org.jboss.test.aop.deployers.xml.SomeInterceptor.invoked != 2) throw new RuntimeException JavaDoc("SomeInterceptor should have intercepted 2 times not " + org.jboss.test.aop.deployers.xml.SomeInterceptor.invoked);
85       if (org.jboss.test.aop.deployers.xml.SomeAspect.invoked != 2) throw new RuntimeException JavaDoc("SomeAspect should have intercepted 2 times not " + org.jboss.test.aop.deployers.xml.SomeAspect.invoked);
86       if (!org.jboss.test.aop.deployers.xml.POJO.invoked) throw new RuntimeException JavaDoc("POJO was not called");
87    }
88    
89    public void invokeAnnotationPOJO() throws Exception JavaDoc
90    {
91       org.jboss.test.aop.deployers.annotations.POJO pojo = new org.jboss.test.aop.deployers.annotations.POJO();
92       org.jboss.test.aop.deployers.annotations.POJO.invoked = false;
93       org.jboss.test.aop.deployers.annotations.SomeInterceptor.invoked = 0;
94       org.jboss.test.aop.deployers.annotations.SomeAspect.invoked = 0;
95       
96       pojo.someMethod();
97       
98       if (org.jboss.test.aop.deployers.annotations.SomeInterceptor.invoked != 1) throw new RuntimeException JavaDoc("SomeInterceptor should have intercepted 1 times not " + org.jboss.test.aop.deployers.annotations.SomeInterceptor.invoked);
99       if (org.jboss.test.aop.deployers.annotations.SomeAspect.invoked != 1) throw new RuntimeException JavaDoc("SomeAspect should have intercepted 1 times not " + org.jboss.test.aop.deployers.annotations.SomeAspect.invoked);
100       if (!org.jboss.test.aop.deployers.annotations.POJO.invoked) throw new RuntimeException JavaDoc("POJO was not called");
101    }
102 }
103
Popular Tags