1 package org.enhydra.shark.xpdl; 2 3 import java.util.ArrayList ; 4 import java.util.Arrays ; 5 import java.util.Iterator ; 6 7 12 public class XMLAttribute extends XMLElement { 13 14 15 protected ArrayList choices; 16 17 public XMLAttribute(XMLElement parent, String name, boolean isRequired) { 18 super(parent, name, isRequired); 19 } 20 21 public XMLAttribute(XMLElement parent, String name, boolean isRequired, String [] choices, int choosenIndex) { 22 super(parent, name, isRequired); 23 this.choices = new ArrayList (Arrays.asList(choices)); 24 this.value = choices[choosenIndex]; 25 } 26 27 public void setValue (String v) { 28 if (choices != null) { 29 if (!choices.contains(v)) { 30 throw new RuntimeException ("Incorrect value! Possible values are: " + choices); 31 } 32 } 33 super.setValue(v); 34 } 35 36 41 public ArrayList getChoices() { 42 return choices; 43 } 44 45 public Object clone() { 46 XMLAttribute d = (XMLAttribute) super.clone(); 47 48 if (choices != null) { 49 d.choices = new ArrayList (); 50 Iterator it=choices.iterator(); 51 while (it.hasNext()) { 52 d.choices.add(new String (it.next().toString())); 53 } 54 } 55 return d; 56 } 57 58 public boolean equals (Object e) { 59 boolean equals=super.equals(e); 60 if (equals) { 61 XMLAttribute el=(XMLAttribute)e; 62 return (this.choices == null ? el.choices == null : this.choices.equals(el.choices)); 63 } 64 return false; 65 } 66 67 68 } 69 70 | Popular Tags |