001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: AllLifeCallbackEntityManagerAccess00.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.interceptors.lifecycle.misc;
025:
026: import javax.annotation.PostConstruct;
027: import javax.annotation.PreDestroy;
028: import javax.ejb.EJB;
029: import javax.ejb.PostActivate;
030: import javax.ejb.PrePassivate;
031: import javax.interceptor.InvocationContext;
032:
033: import org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
034: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
035: import org.ow2.easybeans.tests.common.resources.EntityManagerTester;
036: import org.ow2.util.log.Log;
037: import org.ow2.util.log.LogFactory;
038:
039: /**
040: * This interceptor contains methods to the four lifecycle callbacks.
041: * Every method tries to access an EntityManager.
042: * @author Eduardo Studzinski Estima de Castro
043: * @author Gisele Pinheiro Souza
044: *
045: */
046: public class AllLifeCallbackEntityManagerAccess00 extends
047: EntityManagerTester {
048:
049: /**
050: * Logger.
051: */
052: private Log logger = LogFactory
053: .getLog(AllLifeCallbackEntityManagerAccess00.class);
054:
055: /**
056: * SessionFacade Callback Logger.
057: */
058: @EJB(beanName="SLSBCallbackLoggerAccess")
059: private ItfCallbackLoggerAccess beanLogger;
060:
061: /**
062: * PostActivate that accesses the EntityManager.
063: * @param ic contains attributes of invocation
064: */
065: @PostActivate
066: public void postActivate(final InvocationContext ic) {
067: this .intercept(ic, CallbackType.POST_ACTIVATE);
068: }
069:
070: /**
071: * PostConstruct that accesses the EntityManager.
072: * @param ic contains attributes of invocation
073: */
074: @PostConstruct
075: public void postConstruct(final InvocationContext ic) {
076: this .intercept(ic, CallbackType.POST_CONSTRUCT);
077: }
078:
079: /**
080: * PreDestroy that accesses the EntityManager.
081: * @param ic contains attributes of invocation
082: */
083: @PreDestroy
084: public void preDestroy(final InvocationContext ic) {
085: this .intercept(ic, CallbackType.PRE_DESTROY);
086: }
087:
088: /**
089: * PrePassivate that accesses the EntityManager.
090: * @param ic contains attributes of invocation
091: */
092: @PrePassivate
093: public void prePassivate(final InvocationContext ic) {
094: this .intercept(ic, CallbackType.PRE_PASSIVATE);
095: }
096:
097: /**
098: * Does the access.
099: * @param ic context
100: * @param type lifecycle interceptor type
101: */
102: protected void intercept(final InvocationContext ic,
103: final CallbackType type) {
104: try {
105: String beanClassName = ic.getTarget().getClass().getName();
106:
107: logger.debug("{0} - Testing access - Instance: {1}.", type
108: .name(), beanClassName);
109: super .access00();
110: beanLogger.insertCallbackLogger(beanClassName, type,
111: AllLifeCallbackEntityManagerAccess00.class
112: .getName());
113: logger.debug("{0} - Access is ok - Instance: {1}.", type
114: .name(), beanClassName);
115:
116: ic.proceed();
117: } catch (Exception e) {
118: throw new IllegalStateException(type.name()
119: + " Exception. ", e);
120: }
121: }
122: }
|