⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shippingcallbackmessagebean.java

📁 jbpm-bpel-1.1.Beta3 JBoss jBPM Starters Kit  是一个综合包
💻 JAVA
字号:
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.jbpm.bpel.tutorial.purchase.ejb;

import java.util.Calendar;

import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.rpc.ServiceException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.jbpm.bpel.tutorial.purchase.PurchaseOrderProcessService;
import org.jbpm.bpel.tutorial.purchase.ScheduleInfo;
import org.jbpm.bpel.tutorial.purchase.ShippingCallbackPT;

/**
 * Asynchronous shipping callback bean.
 * @author Jeff DeLong
 * @author Alejandro Guizar
 * @version $Revision: 1.2 $ $Date: 2006/10/29 06:27:49 $
 */
public class ShippingCallbackMessageBean implements MessageDrivenBean,
    MessageListener {

  protected MessageDrivenContext messageContext;
  protected ShippingCallbackPT shippingRequester;

  private static final Log log = LogFactory.getLog(ShippingCallbackMessageBean.class);
  private static final long serialVersionUID = 1L;

  /**
   * Process the shipping message.
   */
  public void onMessage(Message msg) {
    try {
      // for now we don't care what is in the message
      ScheduleInfo schedule = new ScheduleInfo();
      schedule.setShipDate(Calendar.getInstance());
      shippingRequester.sendSchedule(schedule);
    }
    catch (Exception e) {
      messageContext.setRollbackOnly();
      log.error("could not send schedule", e);
    }
  }

  public void setMessageDrivenContext(MessageDrivenContext messageContext) {
    this.messageContext = messageContext;
  }

  public void ejbCreate() {
    try {
      PurchaseOrderProcessService service = lookupPurchaseService();
      shippingRequester = service.getShippingRequesterPort();
    }
    catch (NamingException e) {
      log.error("could not retrieve purchase order service", e);
    }
    catch (ServiceException e) {
      log.error("could not get shipping requester endpoint", e);
    }
  }

  public void ejbRemove() {
    messageContext = null;
    shippingRequester = null;
  }

  protected PurchaseOrderProcessService lookupPurchaseService()
      throws NamingException {
    Context initialContext = new InitialContext();
    try {
      return (PurchaseOrderProcessService) initialContext.lookup("java:comp/env/service/PurchaseOrder");
    }
    finally {
      initialContext.close();
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -