KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > naming > interceptors > EZBENCInterceptor


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EZBENCInterceptor.java 839 2006-07-12 09:01:24Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.naming.interceptors;
27
28 import javax.naming.Context JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30
31 import org.objectweb.easybeans.api.EasyBeansInterceptor;
32 import org.objectweb.easybeans.api.EasyBeansInvocationContext;
33 import org.objectweb.easybeans.log.JLog;
34 import org.objectweb.easybeans.log.JLogFactory;
35 import org.objectweb.easybeans.naming.NamingManager;
36
37 /**
38  * This interceptor sets the ENC context before calling method.
39  * @author Florent Benoit
40  */

41 public class EZBENCInterceptor implements EasyBeansInterceptor {
42
43     /**
44      * Logger.
45      */

46     private static JLog logger = JLogFactory.getLog(EZBENCInterceptor.class);
47
48     /**
49      * Reference on the naming manager.
50      */

51     private static NamingManager namingManager = null;
52
53     /**
54      * Default constructor.
55      * Gets a reference on the naming manager.
56      */

57     public EZBENCInterceptor() {
58         if (namingManager == null) {
59             try {
60                 namingManager = NamingManager.getInstance();
61             } catch (NamingException JavaDoc e) {
62                 throw new IllegalStateException JavaDoc("Cannot get the naming manager", e);
63             }
64         }
65     }
66
67     /**
68      * Sets ENC context.
69      * @param invocationContext context with useful attributes on the current
70      * invocation.
71      * @return result of the next invocation (to chain interceptors).
72      * @throws Exception needs for signature of interceptor.
73      */

74     public Object JavaDoc intercept(final EasyBeansInvocationContext invocationContext) throws Exception JavaDoc {
75         Context JavaDoc oldContext = namingManager.setComponentContext(invocationContext.getFactory().getJavaContext());
76         try {
77             return invocationContext.proceed();
78         } finally {
79             logger.debug("Unset ENC environment");
80             namingManager.resetComponentContext(oldContext);
81         }
82     }
83 }
84
Popular Tags