KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.ejb.EJB JavaDoc;
25 import javax.annotation.Resource;
26 import javax.transaction.TransactionManager JavaDoc;
27 import javax.sql.DataSource JavaDoc;
28 import javax.persistence.PersistenceContext;
29 import javax.persistence.EntityManager;
30 import javax.persistence.PersistenceUnit;
31 import javax.persistence.EntityManagerFactory;
32 import javax.interceptor.AroundInvoke;
33 import javax.interceptor.InvocationContext;
34
35 import org.jboss.annotation.JndiInject;
36 import org.hibernate.Session;
37 import org.hibernate.SessionFactory;
38
39 /**
40  * Comment
41  *
42  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
43  * @version $Revision: 45473 $
44  */

45 public class MyInterceptor extends MyBaseInterceptor
46 {
47    @EJB JavaDoc MySession2 session2;
48    @JndiInject(jndiName="java:/TransactionManager") TransactionManager JavaDoc tm;
49    @Resource(name="DefaultDS", mappedName="java:DefaultDS") DataSource JavaDoc ds;
50    @PersistenceContext(unitName="interceptors-test") EntityManager em;
51    @PersistenceContext(unitName="interceptors-test") Session session;
52    @PersistenceUnit(unitName="interceptors-test") EntityManagerFactory factory;
53    @PersistenceUnit(unitName="interceptors-test") SessionFactory sessionFactory;
54
55    MySession2 session2Method;
56    TransactionManager JavaDoc tmMethod;
57    DataSource JavaDoc dsMethod;
58    EntityManager emMethod;
59    Session sessionMethod;
60    EntityManagerFactory factoryMethod;
61    SessionFactory sessionFactoryMethod;
62
63    @EJB JavaDoc
64    public void setSession2Method(MySession2 session2Method)
65    {
66       this.session2Method = session2Method;
67    }
68    @JndiInject(jndiName="java:/TransactionManager")
69    public void setTmMethod(TransactionManager JavaDoc tmMethod)
70    {
71       this.tmMethod = tmMethod;
72    }
73    @Resource(name="DefaultDS", mappedName="java:DefaultDS")
74    public void setDsMethod(DataSource JavaDoc dsMethod)
75    {
76       this.dsMethod = dsMethod;
77    }
78    @PersistenceContext(unitName="interceptors-test")
79    public void setEmMethod(EntityManager emMethod)
80    {
81       this.emMethod = emMethod;
82    }
83    @PersistenceContext(unitName="interceptors-test")
84    public void setSessionMethod(Session sessionMethod)
85    {
86       this.sessionMethod = sessionMethod;
87    }
88    @PersistenceUnit(unitName="interceptors-test")
89    public void setFactoryMethod(EntityManagerFactory factoryMethod)
90    {
91       this.factoryMethod = factoryMethod;
92    }
93    @PersistenceUnit(unitName="interceptors-test")
94    public void setSessionFactoryMethod(SessionFactory sessionFactoryMethod)
95    {
96       this.sessionFactoryMethod = sessionFactoryMethod;
97    }
98
99    @AroundInvoke
100    public Object JavaDoc invoke(InvocationContext ctx) throws Exception JavaDoc
101    {
102       session2.doit();
103       if (tm == null) throw new RuntimeException JavaDoc("tm was null");
104       if (ds == null) throw new RuntimeException JavaDoc("ds was null");
105       if (em == null) throw new RuntimeException JavaDoc("em was null");
106       if (session == null) throw new RuntimeException JavaDoc("session was null");
107       if (factory == null) throw new RuntimeException JavaDoc("factory was null");
108       if (sessionFactory == null) throw new RuntimeException JavaDoc("sessionFactory was null");
109
110       session2Method.doit();
111       if (tmMethod == null) throw new RuntimeException JavaDoc("tm was null");
112       if (dsMethod == null) throw new RuntimeException JavaDoc("ds was null");
113       if (emMethod == null) throw new RuntimeException JavaDoc("em was null");
114       if (sessionMethod == null) throw new RuntimeException JavaDoc("session was null");
115       if (factoryMethod == null) throw new RuntimeException JavaDoc("factory was null");
116       if (sessionFactoryMethod == null) throw new RuntimeException JavaDoc("sessionFactory was null");
117       return ctx.proceed();
118    }
119 }
120
Popular Tags