package com.sun.solarisinstall.core;

//
// Copyright (c) 1999 Sun Microsystems, Inc., all rights reserved.
//
//
// a very simple Error class - adapted from Genie

import com.sun.wizards.core.*;
import com.sun.solarisinstall.*;
import com.sun.solarisinstall.panels.*;
import java.util.Vector;


public class DependError {

  public static final int SUCCESS		    = 0;
  public static final int OS_NOT_VALID		    = 1;
  public static final int OS_NOT_VALID_UPGRADE	    = 2;


  private Vector v;
  private int errorCode;


  public DependError() {
      reset();
  }

  public Vector getInfoVector() {
    return (v);
  }

  public int getErrorCode() {
    return (errorCode);
  }

  public void setErrorCode(int newValue) {
    errorCode = newValue;
  }

  public void reset() {
      errorCode = SUCCESS;
      v = new Vector();
  }

  public void appendInfo (Object o) {
      v.addElement(o);
  }

  public void setInfoAt (Object o, int index) {
      v.setElementAt(o, index);
  }

  public int getInfoSize() {
      return v.size();
  }

  public boolean hasError() {
    boolean result = false;

    if (errorCode != SUCCESS) {
      result = true;
    }
    return (result);
  }


  public String setDisplayMsg() {
    String message = null;
    String requiredOS = null;
    String selectedOS = null;


    switch (errorCode) {

      case OS_NOT_VALID:
          if (Def.DEBUG) System.out.println ("DependError: OS_NOT_VALID");

	  requiredOS = (String) v.elementAt(0);
	  selectedOS = (String) v.elementAt(1);
          Object[] clusterArg = { selectedOS };
          message = MsgCat.getString("com.sun.solarisinstall.SolarisInstall",
               SolarisInstallResources.MSG_DEP_COPACK_NEEDS_DIFF_CLUSTER,
               clusterArg); 

              /*
               * Show all the products which require
               * different cluster
               */
	      for (int i = 2; i < v.size(); i++) {
                  message += "\n   " + (String) v.elementAt(i);
              }
	  break;

      case OS_NOT_VALID_UPGRADE:
          if (Def.DEBUG)System.out.println("DependError: OS_NOT_VALID_UPGRADE");

	  requiredOS = (String) v.elementAt(0);
	  selectedOS = (String) v.elementAt(1);
          Object[] upgradeArg = { selectedOS };
          message = MsgCat.getString("com.sun.solarisinstall.SolarisInstall",
               SolarisInstallResources.MSG_DEP_COPACK_RECOMMENDS_DIFF_CLUSTER,
               upgradeArg); 

              /*
               * Show all the products which require
               * different cluster
               */
	      for (int i = 2; i < v.size(); i++) {
                  message += "\n   " + (String) v.elementAt(i);
              }
	  break;


    }
    return (message);
  }

}

