Package info.walnutstreet.vs.ps03.dbserver

Source Code of info.walnutstreet.vs.ps03.dbserver.GoodModel

/**
*
*/
package info.walnutstreet.vs.ps03.dbserver;

import info.walnutstreet.vs.ps03.dbserver.interfaces.GoodModelInterface;
import info.walnutstreet.vs.ps03.exceptions.InvalidAvaiableNumberException;
import info.walnutstreet.vs.ps03.exceptions.InvalidPriceException;
import info.walnutstreet.vs.ps03.exceptions.InvalidUniqueIdException;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
* @author Christoph Gostner
* @author Christian Bitschnau
* @version 0.2
*
*/
public class GoodModel extends UnicastRemoteObject implements GoodModelInterface {

  /**
   *
   */
  private static final long serialVersionUID = -8774730336326170760L;
  private Integer id;
  private String name;
  private Double price;
  private Integer available;
  private String description;
 
  /**
   * Default constructor.
   * @throws InvalidUniqueIdException
   * @throws RemoteException
   */
  public GoodModel() throws InvalidUniqueIdException, RemoteException {
    this(1, null);
  }
 
  /**
   * Constructor.
   *
   * @param id Unique id of the good
   * @param name The name of the good
   * @throws InvalidUniqueIdException
   * @throws RemoteException
   */
  public GoodModel(Integer id, String name) throws InvalidUniqueIdException, RemoteException {
    super();
    if (id <= 0)
      throw new InvalidUniqueIdException();
   
    this.id = id;
    this.name = name;
    this.price = 0.0;
    this.available = 0;
    this.description = new String();
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#getId()
   */
  public synchronized Integer getId() throws RemoteException {
    return id;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#setId(java.lang.Integer)
   */
  public synchronized void setId(Integer id) throws InvalidUniqueIdException, RemoteException {
    if (id <= 0)
      throw new InvalidUniqueIdException();
    this.id = id;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#getName()
   */
  public synchronized String getName() throws RemoteException {
    return name;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#setName(java.lang.String)
   */
  public synchronized void setName(String name) throws RemoteException {
    this.name = name;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#getPrice()
   */
  public synchronized Double getPrice() throws RemoteException {
    return price;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#setPrice(java.lang.Float)
   */
  public synchronized void setPrice(Double price) throws InvalidPriceException, RemoteException {
    if (price < 0.0)
      throw new InvalidPriceException();
    this.price = price;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#getAvailable()
   */
  public synchronized Integer getAvailable() throws RemoteException {
    return available;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#setAvailable(java.lang.Integer)
   */
  public synchronized void setAvailable(Integer available) throws InvalidAvaiableNumberException, RemoteException {
    if (available < 0)
      throw new InvalidAvaiableNumberException();
    this.available = available;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#getDescription()
   */
  public synchronized String getDescription() throws RemoteException {
    return description;
  }

  /* (non-Javadoc)
   * @see info.walnutstreet.vs.ps03.model.interfaces.GoodModelInterface#setDescription(java.lang.String)
   */
  public synchronized void setDescription(String description) throws RemoteException {
    this.description = description;
  }
 
  /* (non-Javadoc)
   * @see java.rmi.server.RemoteObject#toString()
   */
  @Override
  public String toString() {
    StringBuffer buffer = new StringBuffer();
   
    try {
      buffer.append(" [id:");
      buffer.append(this.getId());
      buffer.append("] ");
      buffer.append(this.getName());
      buffer.append(" ");
      buffer.append(this.getAvailable());
    } catch (RemoteException e) {}

    return buffer.toString();
  }
}
TOP

Related Classes of info.walnutstreet.vs.ps03.dbserver.GoodModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.