KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > mdb > CurrentMessageInjectorInterceptorFactory


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

22 package org.jboss.ejb3.mdb;
23
24 import java.lang.reflect.Field JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import org.jboss.aop.advice.AspectFactory;
28 import org.jboss.aop.Advisor;
29 import org.jboss.aop.InstanceAdvisor;
30 import org.jboss.aop.joinpoint.Joinpoint;
31 import org.jboss.annotation.ejb.CurrentMessage;
32
33 import org.jboss.ejb3.Container;
34
35 /**
36  * Comment
37  *
38  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
39  * @version $Revision: 37459 $
40  */

41 public class CurrentMessageInjectorInterceptorFactory implements AspectFactory
42 {
43    public Object JavaDoc createPerVM()
44    {
45       return null;
46    }
47
48    public Object JavaDoc createPerClass(Advisor advisor)
49    {
50       Class JavaDoc clazz = advisor.getClazz();
51       ArrayList JavaDoc<Field JavaDoc> fs = new ArrayList JavaDoc<Field JavaDoc>();
52       ArrayList JavaDoc<Method JavaDoc> ms = new ArrayList JavaDoc<Method JavaDoc>();
53
54       search(advisor,clazz, fs, ms);
55
56       Method JavaDoc[] methods = ms.toArray(new Method JavaDoc[ms.size()]);
57       Field JavaDoc[] fields = fs.toArray(new Field JavaDoc[fs.size()]);
58       if (methods.length == 0) methods = null;
59       if (fields.length == 0) fields = null;
60       return new CurrentMessageInjectorInterceptor(fields, methods);
61    }
62
63    protected void search(Advisor advisor, Class JavaDoc clazz, ArrayList JavaDoc<Field JavaDoc> fs, ArrayList JavaDoc<Method JavaDoc> ms)
64    {
65       Method JavaDoc[] methods = clazz.getDeclaredMethods();
66       Field JavaDoc[] fields = clazz.getDeclaredFields();
67       for (Field JavaDoc field : fields)
68       {
69          if (advisor.resolveAnnotation(field, CurrentMessage.class) != null)
70             fs.add(field);
71       }
72       for (Method JavaDoc method : methods)
73       {
74          if (advisor.resolveAnnotation(method, CurrentMessage.class) != null)
75             ms.add(method);
76       }
77       if (clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object JavaDoc.class))
78       {
79          search(advisor, clazz.getSuperclass(), fs, ms);
80       }
81    }
82
83    public Object JavaDoc createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
84    {
85       throw new IllegalArgumentException JavaDoc("NOT LEGAL");
86    }
87
88    public Object JavaDoc createPerJoinpoint(Advisor advisor, Joinpoint jp)
89    {
90       throw new IllegalArgumentException JavaDoc("NOT LEGAL");
91    }
92
93    public Object JavaDoc createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)
94    {
95       throw new IllegalArgumentException JavaDoc("NOT LEGAL");
96    }
97
98    public String JavaDoc getName()
99    {
100       return CurrentMessageInjectorInterceptor.class.getName();
101    }
102 }
103
Popular Tags