01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: AbsRemoveInterceptor.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.container.session.stateful.interceptors;
25:
26: import org.ow2.easybeans.api.EasyBeansInvocationContext;
27: import org.ow2.easybeans.api.Factory;
28: import org.ow2.easybeans.api.bean.EasyBeansSB;
29: import org.ow2.easybeans.api.pool.Pool;
30: import org.ow2.easybeans.api.pool.PoolException;
31: import org.ow2.easybeans.container.session.SessionFactory;
32:
33: /**
34: * Defines a method that discard the bean found in the invocation context.
35: * @author Florent Benoit
36: */
37: public abstract class AbsRemoveInterceptor {
38:
39: /**
40: * Remove from the factory's pool the bean found in the current invocation context.
41: * @param invocationContext the context of the current invocation
42: * @throws PoolException if removal is failing
43: */
44: @SuppressWarnings("unchecked")
45: protected void remove(
46: final EasyBeansInvocationContext invocationContext)
47: throws PoolException {
48: // Gets the factory
49: Factory factory = invocationContext.getFactory();
50:
51: // factory is a session factory.
52: SessionFactory sessionFactory = (SessionFactory) factory;
53:
54: // get pool
55: Pool<EasyBeansSB, Long> pool = sessionFactory.getPool();
56:
57: // Get the bean
58: EasyBeansSB bean = (EasyBeansSB) invocationContext.getTarget();
59:
60: // discard instance
61: pool.discard(bean);
62: }
63: }
|