01: package org.enhydra.shark.xpdl;
02:
03: import java.util.ArrayList;
04: import java.util.Arrays;
05: import java.util.Iterator;
06:
07: /**
08: * Represents attribute element from XML schema.
09: *
10: * @author Sasa Bojanic
11: */
12: public class XMLAttribute extends XMLElement {
13:
14: /** The possible choices. */
15: protected ArrayList choices;
16:
17: public XMLAttribute(XMLElement parent, String name,
18: boolean isRequired) {
19: super (parent, name, isRequired);
20: }
21:
22: public XMLAttribute(XMLElement parent, String name,
23: boolean isRequired, String[] choices, int choosenIndex) {
24: super (parent, name, isRequired);
25: this .choices = new ArrayList(Arrays.asList(choices));
26: this .value = choices[choosenIndex];
27: }
28:
29: public void setValue(String v) {
30: if (choices != null) {
31: if (!choices.contains(v)) {
32: throw new RuntimeException("Incorrect value " + v
33: + "! Possible values are: " + choices);
34: }
35: }
36: super .setValue(v);
37: }
38:
39: /**
40: * The possible String choices.
41: *
42: * @return the possible choices for this element.
43: */
44: public ArrayList getChoices() {
45: return choices;
46: }
47:
48: public Object clone() {
49: XMLAttribute d = (XMLAttribute) super .clone();
50:
51: if (choices != null) {
52: d.choices = new ArrayList();
53: Iterator it = choices.iterator();
54: while (it.hasNext()) {
55: d.choices.add(new String(it.next().toString()));
56: }
57: }
58: return d;
59: }
60:
61: public boolean equals(Object e) {
62: boolean equals = super .equals(e);
63: if (equals) {
64: XMLAttribute el = (XMLAttribute) e;
65: equals = (this .choices == null ? el.choices == null
66: : this .choices.equals(el.choices));
67: // System.out.println(" XMLAttribute choices equal - "+equals);
68: }
69: return equals;
70: }
71:
72: }
|