KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > xpdl > XMLAttribute


1 package org.enhydra.shark.xpdl;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Arrays JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 /**
8  * Represents attribute element from XML schema.
9  *
10  * @author Sasa Bojanic
11  */

12 public class XMLAttribute extends XMLElement {
13
14    /** The possible choices. */
15    protected ArrayList JavaDoc choices;
16
17    public XMLAttribute(XMLElement parent, String JavaDoc name, boolean isRequired) {
18       super(parent, name, isRequired);
19    }
20
21    public XMLAttribute(XMLElement parent, String JavaDoc name, boolean isRequired, String JavaDoc[] choices, int choosenIndex) {
22       super(parent, name, isRequired);
23       this.choices = new ArrayList JavaDoc(Arrays.asList(choices));
24       this.value = choices[choosenIndex];
25    }
26
27    public void setValue (String JavaDoc v) {
28       if (choices != null) {
29          if (!choices.contains(v)) {
30             throw new RuntimeException JavaDoc("Incorrect value! Possible values are: " + choices);
31          }
32       }
33       super.setValue(v);
34    }
35
36    /**
37     * The possible String choices.
38     *
39     * @return the possible choices for this element.
40     */

41    public ArrayList JavaDoc getChoices() {
42       return choices;
43    }
44
45    public Object JavaDoc clone() {
46       XMLAttribute d = (XMLAttribute) super.clone();
47
48       if (choices != null) {
49          d.choices = new ArrayList JavaDoc();
50          Iterator JavaDoc it=choices.iterator();
51          while (it.hasNext()) {
52             d.choices.add(new String JavaDoc(it.next().toString()));
53          }
54       }
55       return d;
56    }
57
58    public boolean equals (Object JavaDoc 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