package com.symcor.od.common.soap.message;

import java.util.*;

/**
 * <p>Title: </p>
 * <p>Description: this class represents a search criteria where its name is the
 * criterion value where its search value will be given by an application user. </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */

public final class Criterion implements java.lang.Cloneable, java.io.Serializable {



     public final static int OPEQUAL = 1;
     public final static int OPBETWEEN = OPEQUAL + 1;

     public final static int TYPE_LIST = OPBETWEEN + 1;
     public final static int TYPE_NON_LIST = TYPE_LIST + 1;
     public final static String VALUE_LIST_ALL = "** All **";


     // Fields
      private String name;
      private int searchOp;

      /** currently unused. If used, they need to be converted to Criterion operand constants. */
      // private int[] validOps;
      private int type;  // seems that char type is not supported by BeanSerializer
                         // perhaps that char type is not supported by XML schema.
      private String[] fixedValues;
      private String[] defaultValues; // default values set by the administrator, equal to ODCriterion.getValues().
      private String[] searchValues;

      // Constructors
      public Criterion(String name)
      {
        this.name = name;
      };

      public Criterion()
      {
      };

      // Methods
      public String getName() { return name; };
      public void setName (String name) { this.name = name; };

      public int getOperand() { return searchOp; };
      public void setOperand(int searchOp)  { this.searchOp = searchOp; };

      public int getType() {return type; };
      public void setType(int type) {this.type = type;};


      public String[] getFixedValues() {return fixedValues; };
      public void setFixedValues(String[] fixedValues) {this.fixedValues = fixedValues; };

      //search values.
      public String[] getSearchValues() {return this.searchValues; };
      public void setSearchValues(String[] searchValues) {this.searchValues = searchValues; };



      // default values;
      public String[] getDefaultValues() { return defaultValues; };
      public void setDefaultValues(String[] defaultValues) {this.defaultValues = defaultValues;};


      public String toString() {
         StringBuffer sb = new StringBuffer("\nCriterion: ");
         sb.append("\nname: " + name);
         sb.append("\ntype: " + type);
         sb.append("\noperand: " + this.searchOp);
         if (searchValues != null) {
             if (searchValues.length>0) {
                 sb.append("\nsearchValues[0] " + searchValues[0]);
             }
             if (searchValues.length>1) {
                 sb.append("\nsearchValues[1] " + searchValues[1]);
             }
         } else {
            sb.append("\nsearchValues[]: null");
         }

         if (defaultValues != null) {
             if (defaultValues.length>0) {
                 sb.append("\ndefaultValues[0] " + defaultValues[0]);
             }
             if (defaultValues.length>1) {
                 sb.append("\ndefaultValues[1] " + defaultValues[1]);
             }
         } else {
            sb.append("\ndefaultValues[]: null");
         }

         if (fixedValues != null) {
             for (int i=0; i<fixedValues.length; i++) {
                 sb.append("\nfixedValues[" + i + "] " + fixedValues[i]);
             }
         } else {
            sb.append("\nfixedValues[]: null");
         }

         /*
         if (validOps != null) {
             for (int i =0; i<validOps.length; i++) {
                sb.append("\nvalidOps[" + i + "]: " + validOps[i]);
             }
         } else {
            sb.append("\nvalidOps[]: null");
         }
         */

         return sb.toString();
     }

     public Object clone () {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new java.lang.Error ("JVM error, check up your JVM version." );
        }
     }

     public static void main (String[] args) {
        Criterion c1 = new Criterion("c one");
        c1.setDefaultValues(new String[] {"default 000", "default 111"});
        c1.setFixedValues(new String[] {"fixed 000", "fixed 111"});
        c1.setSearchValues(new String[] {"search 000"});
        Vector v = new Vector();
        Criterion c2 = (Criterion)c1.clone();
        c2.setName("c two");
        v.add(c2);
        System.out.println(v);

     }
}