package com.alodar.example.ejb;

/**
 * @author Mark Lui
 *
 * @ejb:bean
 *    type="Stateless"
 *    name="AddressBO"
 *    jndi-name="com.alodar.example.interfaces.AddressBO"
 *    view-type="local"
 *
 * @ejb:transaction type="Required"
 * @ejb:transaction-type type="Container"
 *
 * @jboss-net:web-service urn="AddressBO"
 *                        expose-all="true"
 *
 */
public class AddressBOBean implements javax.ejb.SessionBean
{

    /**
    * echo test method
    *
    * @param value - String value to return
    *
    * @ejb:interface-method view-type="local"
    */
    public String echo(String value)
    {
        return value;
    }

    /**
    * returns String value of com.alodar.example.interfaces.AddressData
    *
    * @param addressData - data object
    *
    * @ejb:interface-method view-type="local"
    */
    public String test(com.alodar.example.interfaces.AddressData addressData)
    {
        return addressData.toString();

    }

    /**
    * get Address data object
    *
    * @param key - primary key
    *
    * @ejb:interface-method view-type="local"
    */
    public com.alodar.example.interfaces.AddressData get(int key) throws AddressBOException
    {

        try
        {

            com.alodar.example.interfaces.AddressLocalHome addressHome =
                    (com.alodar.example.interfaces.AddressLocalHome)com.alodar.example.interfaces.AddressUtil.getLocalHome();
            com.alodar.example.interfaces.AddressLocal address =
                    addressHome.findByPrimaryKey(new com.alodar.example.interfaces.AddressPK(new Integer(key)));

            return address.getData();

        }
        catch(Exception e)
        {
            throw new AddressBOException(e.getMessage());
        }
    }

    /**
    * creates new Address
    *
    * @param addressData - data object
    *
    * @ejb:interface-method view-type="local"
    */
    public void create(com.alodar.example.interfaces.AddressData addressData)
            throws AddressBOException
    {

        try
        {

            com.alodar.example.interfaces.AddressLocalHome addressHome =
                    (com.alodar.example.interfaces.AddressLocalHome)com.alodar.example.interfaces.AddressUtil.getLocalHome();
            addressHome.create(addressData);

        }
        catch(Exception e)
        {
            throw new AddressBOException(e.getMessage());
        }

    }
    
    /**
    * updates Address
    *
    * @param addressData - data object
    *
    * @ejb:interface-method view-type="local"
    */
    public void update(com.alodar.example.interfaces.AddressData addressData)
            throws AddressBOException
    {

        try
        {

            com.alodar.example.interfaces.AddressLocalHome addressHome =
                    (com.alodar.example.interfaces.AddressLocalHome)com.alodar.example.interfaces.AddressUtil.getLocalHome();
            com.alodar.example.interfaces.AddressLocal address =
                    addressHome.findByPrimaryKey(new com.alodar.example.interfaces.AddressPK(addressData.getAddressId()));
            address.setData(addressData);
        }
        catch(Exception e)
        {
            throw new AddressBOException(e.getMessage());
        }

    }

    /**
    * The container invokes this method when the instance is taken out of the pool of
    * available instances to become associated with a specific EJB object.
    */
    public void ejbActivate()
    {
    }

    /**
    * The container invokes this method on an instance before the instance becomes
    * disassociated with a specific EJB object.
    */
    public void ejbPassivate()
    {
    }

    /**
    * The container invokes this method before it removes the EJB object that is
    * currently associated with the instance.
    */
    public void ejbRemove()
    {
    }

    /**
    * The container invokes setSessionContext just once - when it creates the bean instance.
    */
    public void setSessionContext(javax.ejb.SessionContext sessionContext) {}
}