1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 20 import org.apache.xerces.impl.dv.ValidationContext; 21 import org.apache.xerces.xs.datatypes.ObjectList; 22 23 33 public class ListDV extends TypeValidator{ 34 35 public short getAllowedFacets(){ 36 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE ); 37 } 38 39 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ 42 return content; 43 } 44 45 public int getDataLength(Object value) { 47 return ((ListData)value).getLength(); 48 } 49 50 final static class ListData implements ObjectList { 51 final Object [] data; 52 private String canonical; 53 public ListData(Object [] data) { 54 this.data = data; 55 } 56 public synchronized String toString() { 57 if (canonical == null) { 58 int len = data.length; 59 StringBuffer buf = new StringBuffer (); 60 if (len > 0) { 61 buf.append(data[0].toString()); 62 } 63 for (int i = 1; i < len; i++) { 64 buf.append(' '); 65 buf.append(data[i].toString()); 66 } 67 canonical = buf.toString(); 68 } 69 return canonical; 70 } 71 public int getLength() { 72 return data.length; 73 } 74 public boolean equals(Object obj) { 75 if (!(obj instanceof ListData)) 76 return false; 77 Object [] odata = ((ListData)obj).data; 78 79 int count = data.length; 80 if (count != odata.length) 81 return false; 82 83 for (int i = 0 ; i < count ; i++) { 84 if (!data[i].equals(odata[i])) 85 return false; 86 } 88 return true; 90 } 91 92 public boolean contains(Object item) { 93 for (int i = 0;i < data.length; i++) { 94 if (item == data[i]) { 95 return true; 96 } 97 } 98 return false; 99 } 100 101 public Object item(int index) { 102 if (index < 0 || index >= data.length) { 103 return null; 104 } 105 return data[index]; 106 } 107 } 108 } 110 | Popular Tags |