001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.dv.xs;
019:
020: import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
021: import org.apache.xerces.impl.dv.ValidationContext;
022: import org.apache.xerces.xs.datatypes.ObjectList;
023:
024: /**
025: * Represent the schema list types
026: *
027: * @xerces.internal
028: *
029: * @author Neeraj Bajaj, Sun Microsystems, inc.
030: * @author Sandy Gao, IBM
031: *
032: * @version $Id: ListDV.java 446745 2006-09-15 21:43:58Z mrglavas $
033: */
034: public class ListDV extends TypeValidator {
035:
036: public short getAllowedFacets() {
037: return (XSSimpleTypeDecl.FACET_LENGTH
038: | XSSimpleTypeDecl.FACET_MINLENGTH
039: | XSSimpleTypeDecl.FACET_MAXLENGTH
040: | XSSimpleTypeDecl.FACET_PATTERN
041: | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE);
042: }
043:
044: // this method should never be called: XSSimpleTypeDecl is responsible for
045: // calling the item type for the convertion
046: public Object getActualValue(String content,
047: ValidationContext context)
048: throws InvalidDatatypeValueException {
049: return content;
050: }
051:
052: // length of a list type is the number of items in the list
053: public int getDataLength(Object value) {
054: return ((ListData) value).getLength();
055: }
056:
057: final static class ListData implements ObjectList {
058: final Object[] data;
059: private String canonical;
060:
061: public ListData(Object[] data) {
062: this .data = data;
063: }
064:
065: public synchronized String toString() {
066: if (canonical == null) {
067: int len = data.length;
068: StringBuffer buf = new StringBuffer();
069: if (len > 0) {
070: buf.append(data[0].toString());
071: }
072: for (int i = 1; i < len; i++) {
073: buf.append(' ');
074: buf.append(data[i].toString());
075: }
076: canonical = buf.toString();
077: }
078: return canonical;
079: }
080:
081: public int getLength() {
082: return data.length;
083: }
084:
085: public boolean equals(Object obj) {
086: if (!(obj instanceof ListData))
087: return false;
088: Object[] odata = ((ListData) obj).data;
089:
090: int count = data.length;
091: if (count != odata.length)
092: return false;
093:
094: for (int i = 0; i < count; i++) {
095: if (!data[i].equals(odata[i]))
096: return false;
097: }//end of loop
098:
099: //everything went fine.
100: return true;
101: }
102:
103: public int hashCode() {
104: int hash = 0;
105: for (int i = 0; i < data.length; ++i) {
106: hash ^= data[i].hashCode();
107: }
108: return hash;
109: }
110:
111: public boolean contains(Object item) {
112: for (int i = 0; i < data.length; i++) {
113: if (item == data[i]) {
114: return true;
115: }
116: }
117: return false;
118: }
119:
120: public Object item(int index) {
121: if (index < 0 || index >= data.length) {
122: return null;
123: }
124: return data[index];
125: }
126: }
127: } // class ListDV
|