XMLAttribute.java :  » Workflow-Engines » JaWE » org » enhydra » shark » xpdl » Java Open Source

Java Open Source » Workflow Engines » JaWE 
JaWE » org » enhydra » shark » xpdl » XMLAttribute.java
package org.enhydra.shark.xpdl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

/**
 *  Represents attribute element from XML schema.
 * 
 *  @author Sasa Bojanic
 */
public class XMLAttribute extends XMLElement {

   /** The possible choices. */
   protected ArrayList choices;

   public XMLAttribute(XMLElement parent, String name, boolean isRequired) {
      super(parent, name, isRequired);
   }

   public XMLAttribute(XMLElement parent, String name, boolean isRequired, String[] choices, int choosenIndex) {
      super(parent, name, isRequired);
      this.choices = new ArrayList(Arrays.asList(choices));
      this.value = choices[choosenIndex];
   }

   public void setValue (String v) {
      if (choices != null) {
         if (!choices.contains(v)) {
            throw new RuntimeException("Incorrect value "+v+"! Possible values are: " + choices);
         }
      }
      super.setValue(v);
   }

   /**
    * The possible String choices.
    * 
    * @return the possible choices for this element.
    */
   public ArrayList getChoices() {
      return choices;
   }

   public Object clone() {
      XMLAttribute d = (XMLAttribute) super.clone();

      if (choices != null) {
         d.choices = new ArrayList();
         Iterator it=choices.iterator();
         while (it.hasNext()) {
            d.choices.add(new String(it.next().toString()));
         }         
      }
      return d;
   }

   public boolean equals (Object e) {
      boolean equals=super.equals(e);
      if (equals) {
         XMLAttribute el=(XMLAttribute)e;
         equals=(this.choices == null ? el.choices == null : this.choices.equals(el.choices));
//         System.out.println("          XMLAttribute choices equal - "+equals);
      }
      return equals;
   }
   

}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.