KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > datatype > xsd > ListDatatype


1 package com.thaiopensource.datatype.xsd;
2
3 import org.relaxng.datatype.ValidationContext;
4 import com.thaiopensource.xml.util.StringSplitter;
5
6 class ListDatatype extends DatatypeBase implements Measure {
7   private final DatatypeBase itemType;
8   
9   ListDatatype(DatatypeBase itemType) {
10     this.itemType = itemType;
11   }
12
13   Object JavaDoc getValue(String JavaDoc str, ValidationContext vc) {
14     String JavaDoc[] tokens = StringSplitter.split(str);
15     Object JavaDoc[] items = new Object JavaDoc[tokens.length];
16     for (int i = 0; i < items.length; i++) {
17       items[i] = itemType.getValue(tokens[i], vc);
18       if (items[i] == null)
19     return null;
20     }
21     return items;
22   }
23
24   boolean lexicallyAllows(String JavaDoc str) {
25     String JavaDoc[] tokens = StringSplitter.split(str);
26     for (int i = 0; i < tokens.length; i++)
27       if (!itemType.lexicallyAllows(tokens[i]))
28     return false;
29     return true;
30   }
31
32   boolean allowsValue(String JavaDoc str, ValidationContext vc) {
33     String JavaDoc[] tokens = StringSplitter.split(str);
34     for (int i = 0; i < tokens.length; i++)
35       if (!itemType.allowsValue(tokens[i], vc))
36     return false;
37     return true;
38   }
39
40   Measure getMeasure() {
41     return this;
42   }
43
44   public int getLength(Object JavaDoc obj) {
45     return ((Object JavaDoc[])obj).length;
46   }
47
48   public boolean isContextDependent() {
49     return itemType.isContextDependent();
50   }
51
52   public int getIdType() {
53     if (itemType.getIdType() == ID_TYPE_IDREF)
54       return ID_TYPE_IDREFS;
55     else
56       return ID_TYPE_NULL;
57   }
58
59   public int valueHashCode(Object JavaDoc obj) {
60     Object JavaDoc[] items = (Object JavaDoc[])obj;
61     int hc = 0;
62     for (int i = 0; i < items.length; i++)
63       hc ^= itemType.valueHashCode(items[i]);
64     return hc;
65   }
66
67   public boolean sameValue(Object JavaDoc obj1, Object JavaDoc obj2) {
68     Object JavaDoc[] items1 = (Object JavaDoc[])obj1;
69     Object JavaDoc[] items2 = (Object JavaDoc[])obj2;
70     if (items1.length != items2.length)
71       return false;
72     for (int i = 0; i < items1.length; i++)
73       if (!itemType.sameValue(items1[i], items2[i]))
74     return false;
75     return true;
76   }
77 }
78
Popular Tags