package ordering.custom;

 

import javax.naming.*;

import java.util.Collection;

import ordering.common.model.OrderingModel;

import ordering.ejb.OrderingServiceEJB;

import ordering.ejb.OrderingServiceEJBHome;

import ordering.common.vo.PurchaseOrderVO;

import ordering.common.exceptions.ModelAccessException;

import ordering.common.exceptions.IntegrityException;

import ordering.common.exceptions.NotFoundException;

import ordering.common.vo.InvoiceVO;

import java.rmi.RemoteException;

import java.util.Properties;

 

public class OrderingModelEJBImpl implements OrderingModel

{

  private OrderingServiceEJB service = null;

 

  public OrderingModelEJBImpl()

  {

      try

      {

          Context ctxt = getInitialContext ();

          OrderingServiceEJBHome home =

                  (OrderingServiceEJBHome) ctxt.lookup("OrderingServiceEJB");

          service = home.create();

      }

      catch (Exception e) {

          System.out.println(e.getMessage());

      }

  }

 

 

  public static Context getInitialContext ()

       throws javax.naming.NamingException

    {

      Properties p = new Properties();

      p.put(Context.INITIAL_CONTEXT_FACTORY,

                "org.jnp.interfaces.NamingContextFactory");

      p.put(Context.PROVIDER_URL, "127.0.0.1:1099");

      p.put(Context.SECURITY_PRINCIPAL, "admin");

      p.put(Context.SECURITY_CREDENTIALS, "secret");

 

      return new InitialContext(p);

   }

 

  public void addPurchaseOrder(PurchaseOrderVO po)

      throws ModelAccessException, IntegrityException

  {

      service.addPurchaseOrder(po);

  }

 

 

  public Collection getPODescriptors(int partnerId, String status)

         throws ModelAccessException, NotFoundException

  {

      return service.getPODescriptors(partnerId, status);

  }

 

 

  public PurchaseOrderVO getPurchaseOrder(int id) throws ModelAccessException, NotFoundException

  {

      return service.getPurchaseOrder(id);

  }

 

 public void acceptPurchaseOrder(int id) throws ModelAccessException, NotFoundException

 {

     service.acceptPurchaseOrder(id);

 }

 

 public void rejectPurchaseOrder(int id) throws ModelAccessException, NotFoundException

  {

    service.rejectPurchaseOrder(id);

  }

 

  public Collection getInvoiceDescriptors(int partnerId,String status)

          throws ModelAccessException,NotFoundException

  {

      return service.getInvoiceDescriptors(partnerId,status);

  }

 

  public InvoiceVO getInvoice(int id) throws ModelAccessException,NotFoundException

  {

      return service.getInvoice(id);

  }

 

  public void saveInvoice(InvoiceVO invoice) throws ModelAccessException, IntegrityException

  {

      service.saveInvoice(invoice);

  }

 

  public void sendInvoice(int id) throws ModelAccessException

  {

      service.sendInvoice(id);

  }

 

  public int newId(String sequence_name) throws ModelAccessException

  {

      return service.newId(sequence_name);

  }

}