KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > interceptors > MyBaseInterceptor


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.test.interceptors;
23
24 import java.util.ArrayList JavaDoc;
25
26 import javax.ejb.EJB JavaDoc;
27 import javax.annotation.Resource;
28 import javax.interceptor.AroundInvoke;
29 import javax.interceptor.InvocationContext;
30 import javax.persistence.EntityManager;
31 import javax.persistence.EntityManagerFactory;
32 import javax.persistence.PersistenceContext;
33 import javax.persistence.PersistenceUnit;
34 import javax.sql.DataSource JavaDoc;
35 import javax.transaction.TransactionManager JavaDoc;
36
37 import org.hibernate.Session;
38 import org.hibernate.SessionFactory;
39 import org.jboss.annotation.JndiInject;
40
41 /**
42  *
43  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
44  * @version $Revision: 45473 $
45  */

46 public class MyBaseInterceptor
47 {
48    @EJB JavaDoc MySession2 baseSession2;
49    @JndiInject(jndiName="java:/TransactionManager") TransactionManager JavaDoc baseTm;
50    @Resource(name="DefaultDS", mappedName="java:DefaultDS") DataSource JavaDoc baseDs;
51    @PersistenceContext(unitName="interceptors-test") EntityManager baseEm;
52    @PersistenceContext(unitName="interceptors-test") Session baseSession;
53    @PersistenceUnit(unitName="interceptors-test") EntityManagerFactory baseFactory;
54    @PersistenceUnit(unitName="interceptors-test") SessionFactory baseSessionFactory;
55
56    MySession2 baseSession2Method;
57    TransactionManager JavaDoc baseTmMethod;
58    DataSource JavaDoc baseDsMethod;
59    EntityManager baseEmMethod;
60    Session baseSessionMethod;
61    EntityManagerFactory baseFactoryMethod;
62    SessionFactory baseSessionFactoryMethod;
63
64    @EJB JavaDoc
65    public void setBaseSession2Method(MySession2 session2Method)
66    {
67       this.baseSession2Method = session2Method;
68    }
69    @JndiInject(jndiName="java:/TransactionManager")
70    public void setBaseTmMethod(TransactionManager JavaDoc tmMethod)
71    {
72       this.baseTmMethod = tmMethod;
73    }
74    @Resource(name="DefaultDS", mappedName="java:DefaultDS")
75    public void setBaseDsMethod(DataSource JavaDoc dsMethod)
76    {
77       this.baseDsMethod = dsMethod;
78    }
79    @PersistenceContext(unitName="interceptors-test")
80    public void setBaseEmMethod(EntityManager emMethod)
81    {
82       this.baseEmMethod = emMethod;
83    }
84    @PersistenceContext(unitName="interceptors-test")
85    public void setBaseSessionMethod(Session sessionMethod)
86    {
87       this.baseSessionMethod = sessionMethod;
88    }
89    @PersistenceUnit(unitName="interceptors-test")
90    public void setBaseFactoryMethod(EntityManagerFactory factoryMethod)
91    {
92       this.baseFactoryMethod = factoryMethod;
93    }
94    @PersistenceUnit(unitName="interceptors-test")
95    public void setBaseSessionFactoryMethod(SessionFactory sessionFactoryMethod)
96    {
97       this.baseSessionFactoryMethod = sessionFactoryMethod;
98    }
99
100    @AroundInvoke
101    public Object JavaDoc baseInvoke(InvocationContext ctx) throws Exception JavaDoc
102    {
103       baseSession2.doit();
104       if (baseTm == null) throw new RuntimeException JavaDoc("tm was null");
105       if (baseDs == null) throw new RuntimeException JavaDoc("ds was null");
106       if (baseEm == null) throw new RuntimeException JavaDoc("em was null");
107       if (baseSession == null) throw new RuntimeException JavaDoc("session was null");
108       if (baseFactory == null) throw new RuntimeException JavaDoc("factory was null");
109       if (baseSessionFactory == null) throw new RuntimeException JavaDoc("sessionFactory was null");
110
111       baseSession2Method.doit();
112       if (baseTmMethod == null) throw new RuntimeException JavaDoc("tm was null");
113       if (baseDsMethod == null) throw new RuntimeException JavaDoc("ds was null");
114       if (baseEmMethod == null) throw new RuntimeException JavaDoc("em was null");
115       if (baseSessionMethod == null) throw new RuntimeException JavaDoc("session was null");
116       if (baseFactoryMethod == null) throw new RuntimeException JavaDoc("factory was null");
117       if (baseSessionFactoryMethod == null) throw new RuntimeException JavaDoc("sessionFactory was null");
118       ArrayList JavaDoc list = (ArrayList JavaDoc)ctx.proceed();
119       list.add(0, "MyBaseInterceptor");
120       return list;
121    }
122    
123 }
124
Popular Tags