286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001,2002,2004,2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl.dv.xs;
286N/A
286N/Aimport java.util.AbstractList;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.ValidationContext;
286N/Aimport com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList;
286N/A
286N/A/**
286N/A * Represent the schema list types
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Neeraj Bajaj, Sun Microsystems, inc.
286N/A * @author Sandy Gao, IBM
286N/A *
286N/A * @version $Id: ListDV.java,v 1.7 2010-11-01 04:39:47 joehw Exp $
286N/A */
286N/Apublic class ListDV extends TypeValidator{
286N/A
286N/A public short getAllowedFacets(){
286N/A return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE );
286N/A }
286N/A
286N/A // this method should never be called: XSSimpleTypeDecl is responsible for
286N/A // calling the item type for the convertion
286N/A public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
286N/A return content;
286N/A }
286N/A
286N/A // length of a list type is the number of items in the list
286N/A public int getDataLength(Object value) {
286N/A return ((ListData)value).getLength();
286N/A }
286N/A
286N/A final static class ListData extends AbstractList implements ObjectList {
286N/A final Object[] data;
286N/A private String canonical;
286N/A public ListData(Object[] data) {
286N/A this.data = data;
286N/A }
286N/A public synchronized String toString() {
286N/A if (canonical == null) {
286N/A int len = data.length;
286N/A StringBuffer buf = new StringBuffer();
286N/A if (len > 0) {
286N/A buf.append(data[0].toString());
286N/A }
286N/A for (int i = 1; i < len; i++) {
286N/A buf.append(' ');
286N/A buf.append(data[i].toString());
286N/A }
286N/A canonical = buf.toString();
286N/A }
286N/A return canonical;
286N/A }
286N/A public int getLength() {
286N/A return data.length;
286N/A }
286N/A public boolean equals(Object obj) {
286N/A if (!(obj instanceof ListData))
286N/A return false;
286N/A Object[] odata = ((ListData)obj).data;
286N/A
286N/A int count = data.length;
286N/A if (count != odata.length)
286N/A return false;
286N/A
286N/A for (int i = 0 ; i < count ; i++) {
286N/A if (!data[i].equals(odata[i]))
286N/A return false;
286N/A }//end of loop
286N/A
286N/A //everything went fine.
286N/A return true;
286N/A }
286N/A
286N/A public int hashCode() {
286N/A int hash = 0;
286N/A for (int i = 0; i < data.length; ++i) {
286N/A hash ^= data[i].hashCode();
286N/A }
286N/A return hash;
286N/A }
286N/A
286N/A public boolean contains(Object item) {
286N/A for (int i = 0;i < data.length; i++) {
286N/A if (item == data[i]) {
286N/A return true;
286N/A }
286N/A }
286N/A return false;
286N/A }
286N/A
286N/A public Object item(int index) {
286N/A if (index < 0 || index >= data.length) {
286N/A return null;
286N/A }
286N/A return data[index];
286N/A }
286N/A
286N/A /*
286N/A * List methods
286N/A */
286N/A
286N/A public Object get(int index) {
286N/A if (index >= 0 && index < data.length) {
286N/A return data[index];
286N/A }
286N/A throw new IndexOutOfBoundsException("Index: " + index);
286N/A }
286N/A
286N/A public int size() {
286N/A return getLength();
286N/A }
286N/A }
286N/A} // class ListDV