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 getValue(String str, ValidationContext vc) { 14 String [] tokens = StringSplitter.split(str); 15 Object [] items = new Object [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 str) { 25 String [] 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 str, ValidationContext vc) { 33 String [] 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 obj) { 45 return ((Object [])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 obj) { 60 Object [] items = (Object [])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 obj1, Object obj2) { 68 Object [] items1 = (Object [])obj1; 69 Object [] items2 = (Object [])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 |