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: AllLifeCallbackResourceManagerAccess00.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.ResourceTester;
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. Every
041: * method try to access a ResourceManager.
042: * @author Eduardo Studzinski Estima de Castro
043: * @author Gisele Pinheiro Souza
044: */
045: public class AllLifeCallbackResourceManagerAccess00 extends
046: ResourceTester {
047:
048: /**
049: * Logger.
050: */
051: private Log logger = LogFactory
052: .getLog(AllLifeCallbackResourceManagerAccess00.class);
053:
054: /**
055: * SessionFacade Callback Logger.
056: */
057: @EJB(beanName="SLSBCallbackLoggerAccess")
058: private ItfCallbackLoggerAccess beanLogger;
059:
060: /**
061: * PostActivate that access a resource.
062: * @param ic contains attributes of invocation
063: */
064: @PostActivate
065: public void postActivate(final InvocationContext ic) {
066: this .intercept(ic, CallbackType.POST_ACTIVATE);
067: }
068:
069: /**
070: * PostConstruct that access a resource.
071: * @param ic contains attributes of invocation
072: */
073: @PostConstruct
074: public void postConstruct(final InvocationContext ic) {
075: this .intercept(ic, CallbackType.POST_CONSTRUCT);
076: }
077:
078: /**
079: * PreDestroy that access a resource.
080: * @param ic contains attributes of invocation
081: */
082: @PreDestroy
083: public void preDestroy(final InvocationContext ic) {
084: this .intercept(ic, CallbackType.PRE_DESTROY);
085: }
086:
087: /**
088: * PrePassivate that access a resource.
089: * @param ic contains attributes of invocation
090: */
091: @PrePassivate
092: public void prePassivate(final InvocationContext ic) {
093: this .intercept(ic, CallbackType.PRE_PASSIVATE);
094: }
095:
096: /**
097: * Does the access.
098: * @param ic context
099: * @param type lifecycle interceptor type
100: */
101: protected void intercept(final InvocationContext ic,
102: final CallbackType type) {
103: try {
104: String beanClassName = ic.getTarget().getClass().getName();
105:
106: logger.debug("{0} - Testing access - Instance: {1}.", type
107: .name(), beanClassName);
108: super .access00();
109: beanLogger.insertCallbackLogger(beanClassName, type,
110: AllLifeCallbackResourceManagerAccess00.class
111: .getName());
112: logger.debug("{0} - Access is ok - Instance: {1}.", type
113: .name(), beanClassName);
114:
115: ic.proceed();
116: } catch (Exception e) {
117: throw new IllegalStateException(type.name()
118: + " Exception. ", e);
119: }
120: }
121: }
|