package configuration;
/**
 * A class representing events related to ComponentConfigurators.
 * @author  Fabio Kon
 * @version 0.2
 * @see     ComponentEvent
 * @see     ComponentConfigurator
*/
public class SimpleEvent implements ComponentEvent {

/**
 * A message that describes the event in more detail.
 */
    String description;
/**
 * The event type.
 */
    int type;

/**
  * Creates a new SimpleEvent object.
  *
  * @param     description a String describing the event 
  * @param     type the event type
  * @see       java.lang.Object
  */
    public SimpleEvent (String description, int type)
    {
        this.description = description;
	this.type = type;
    }

/**
 * Converts the event into a String.
 * @return a string describing the event.
 */
    public String toString()
    {
        String typeString;
        
        switch (type) {
          case STARTED:
              typeString = "STARTED"; break;
          case FINISHED:
              typeString = "FINISHED"; break;
          case SHUTDOWN:
              typeString = "SHUTDOWN"; break;
          case RECONFIGURED:
              typeString = "RECONFIGURED"; break;
          case REPLACED:
              typeString = "REPLACED"; break;
          case MIGRATED:
              typeString = "MIGRATED"; break;
          case DELETED:
              typeString = "DELETED"; break;
          case FAILED:
              typeString = "FAILED"; break;
          case APP_SPECIFIC:
              typeString = "APP_SPECIFIC"; break;
          default:    
              return UNKNOWN;
        }

        if (description != null)
            return "type = " + typeString + " description = " + description;
        else
            return "type = " + typeString;
    }
    // Note that subclasses of this class can test for different kinds of
    // events that were not defined in the ComponentEvent interface. So,
    // subclasses can define their own application-specific events.

/**
 * Accessor for the event type.
 * @return the type of the event.
 */
    public int getType()
    {
        return this.type;
    }
    

}

