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: MDBLifecycle00.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.lifecallback;
025:
026: import javax.annotation.PostConstruct;
027: import javax.annotation.PreDestroy;
028: import javax.ejb.ActivationConfigProperty;
029: import javax.ejb.MessageDriven;
030: import javax.interceptor.Interceptors;
031: import javax.jms.Message;
032: import javax.jms.MessageListener;
033:
034: import org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
035: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.BaseInsertCallbackEvent;
036: import org.ow2.easybeans.tests.common.interceptors.lifecycle.predestroy.PreDestroyLogger00;
037: import org.ow2.easybeans.tests.common.jms.JMSManager;
038: import org.ow2.util.log.Log;
039: import org.ow2.util.log.LogFactory;
040:
041: /**
042: * This bean is used to test the PostConstruct and PreDestroy lifecycle event
043: * callback methods.
044: * @author Eduardo Studzinski Estima de Castro
045: * @author Gisele Pinheiro Souza
046: */
047: @MessageDriven(messageListenerInterface=MessageListener.class,activationConfig={@ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"),@ActivationConfigProperty(propertyName="destination",propertyValue=JMSManager.DEFAULT_QUEUE),@ActivationConfigProperty(propertyName="messageSelector",propertyValue="TYPE = 'org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.lifecallback.MDBLifecycle00'")})
048: @Interceptors({PostConstructMDB.class,PreDestroyLogger00.class})
049: public class MDBLifecycle00 extends BaseInsertCallbackEvent {
050:
051: /**
052: * External PostConstruct.
053: */
054: private boolean externalInvoked;
055:
056: /**
057: * Internal PostConstruct.
058: */
059: private boolean internalInvoked;
060:
061: /**
062: * Logger.
063: */
064: private static Log logger = LogFactory.getLog(MDBLifecycle00.class);
065:
066: /**
067: * Message type.
068: */
069: public static final String MESSAGE_TYPE = "org.ow2.easybeans.tests."
070: + "common.ejbs.mdb.containermanaged.lifecallback.MDBLifecycle00";
071:
072: /**
073: * PostConstruct method.
074: */
075: @SuppressWarnings("unused")
076: @PostConstruct
077: private void postConstruct00() {
078: internalInvoked = true;
079: }
080:
081: /**
082: * Sets the external postconstruct invocation result.
083: * @param b true if ok, otherwise false.
084: */
085: public void setStatusPostConstruct(final boolean b) {
086: externalInvoked = b;
087: }
088:
089: /**
090: * PreDestroy method.
091: */
092: @SuppressWarnings("unused")
093: @PreDestroy
094: private void preDestroy00() {
095: super .log(MDBLifecycle00.class, CallbackType.PRE_DESTROY,
096: MDBLifecycle00.class);
097: logger.debug("{0} was invoked.", CallbackType.PRE_DESTROY
098: .toString());
099: }
100:
101: /**
102: * Receives a message.
103: * @param message msg
104: */
105: public void onMessage(final Message message) {
106: if (externalInvoked) {
107: super
108: .log(MDBLifecycle00.class,
109: CallbackType.POST_CONSTRUCT,
110: PostConstructMDB.class);
111: logger.debug("Internal PostConstruct was invoked.");
112: }
113: if (internalInvoked) {
114: super .log(MDBLifecycle00.class,
115: CallbackType.POST_CONSTRUCT, MDBLifecycle00.class);
116: logger.debug("Internal PostConstruct was invoked.");
117: }
118: }
119:
120: }
|