package ejbdemo;
import java.util.*;import java.rmi.RemoteException;
import javax.ejb.*;

/** This Entity bean is over-simplified, because it is used only to show
    how EJB tags are used. Primary Key type is Integer. The bean creates
    instances on the fly. It does not use persistence.
  */
public class DemoEntityEJB implements EntityBean, DemoEntity
{

  protected EntityContext context;
  public int id; // Integer primary key 
  private String name = null;
	
  public DemoEntityEJB() {
  }

  public java.lang.Integer ejbCreate(Integer id) throws CreateException
  {		
    return id; 
  }

  public void ejbPostCreate(Integer id)
  {		
    this.id=id.intValue();
  }

  public Integer ejbFindByPrimaryKey(Integer pk)
    throws FinderException, RemoteException
  {
    return pk;
  }

  public Collection ejbFindAll() throws FinderException, RemoteException
  {
    Vector beans = new Vector();
    beans.add(new Integer(1));
    beans.add(new Integer(2));
    beans.add(new Integer(3));
    beans.add(new Integer(4));
    return beans;
  }
  public String getName() throws RemoteException {
    return "Demo Entity Bean";
  }

  public int getId() throws RemoteException {

    Integer pk = (Integer)context.getPrimaryKey();
    return pk.intValue();
  }


	public void ejbLoad()
	{
	}

	public void ejbStore()
	{
	}

	public void ejbActivate()
	{
	}

	public void ejbPassivate()
	{
	}

	public void ejbRemove()
	{
	}

	public void setEntityContext(EntityContext context)
	{
		this.context = context;
	}

	public void unsetEntityContext()
	{
		this.context = null;
	}

  public EJBHome getEJBHome()
  {
    return context.getEJBHome();
  }

  public Handle getHandle() throws RemoteException
  {
    return context.getEJBObject().getHandle();
  }

  public Object getPrimaryKey() throws RemoteException
  {
    return context.getEJBObject().getPrimaryKey();
  }

  public boolean isIdentical(EJBObject remote) throws RemoteException
  {
    return context.getEJBObject().isIdentical(remote);
  }

  public void remove() throws RemoveException, RemoteException {
    context.getEJBObject().remove();
  }


}
