1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001,2002,2004,2005 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.dv.xs; 22 23 import java.util.AbstractList; 24 25 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 26 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 27 import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList; 28 29 /** 30 * Represent the schema list types 31 * 32 * @xerces.internal 33 * 34 * @author Neeraj Bajaj, Sun Microsystems, inc. 35 * @author Sandy Gao, IBM 36 * 37 * @version $Id: ListDV.java,v 1.7 2010-11-01 04:39:47 joehw Exp $ 38 */ 39 public class ListDV extends TypeValidator{ 40 41 public short getAllowedFacets(){ 42 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE ); 43 } 44 45 // this method should never be called: XSSimpleTypeDecl is responsible for 46 // calling the item type for the convertion 47 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ 48 return content; 49 } 50 51 // length of a list type is the number of items in the list 52 public int getDataLength(Object value) { 53 return ((ListData)value).getLength(); 54 } 55 56 final static class ListData extends AbstractList implements ObjectList { 57 final Object[] data; 58 private String canonical; 59 public ListData(Object[] data) { 60 this.data = data; 61 } 62 public synchronized String toString() { 63 if (canonical == null) { 64 int len = data.length; 65 StringBuffer buf = new StringBuffer(); 66 if (len > 0) { 67 buf.append(data[0].toString()); 68 } 69 for (int i = 1; i < len; i++) { 70 buf.append(' '); 71 buf.append(data[i].toString()); 72 } 73 canonical = buf.toString(); 74 } 75 return canonical; 76 } 77 public int getLength() { 78 return data.length; 79 } 80 public boolean equals(Object obj) { 81 if (!(obj instanceof ListData)) 82 return false; 83 Object[] odata = ((ListData)obj).data; 84 85 int count = data.length; 86 if (count != odata.length) 87 return false; 88 89 for (int i = 0 ; i < count ; i++) { 90 if (!data[i].equals(odata[i])) 91 return false; 92 }//end of loop 93 94 //everything went fine. 95 return true; 96 } 97 98 public int hashCode() { 99 int hash = 0; 100 for (int i = 0; i < data.length; ++i) { 101 hash ^= data[i].hashCode(); 102 } 103 return hash; 104 } 105 106 public boolean contains(Object item) { 107 for (int i = 0;i < data.length; i++) { 108 if (item == data[i]) { 109 return true; 110 } 111 } 112 return false; 113 } 114 115 public Object item(int index) { 116 if (index < 0 || index >= data.length) { 117 return null; 118 } 119 return data[index]; 120 } 121 122 /* 123 * List methods 124 */ 125 126 public Object get(int index) { 127 if (index >= 0 && index < data.length) { 128 return data[index]; 129 } 130 throw new IndexOutOfBoundsException("Index: " + index); 131 } 132 133 public int size() { 134 return getLength(); 135 } 136 } 137 } // class ListDV