KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dv > xs > ListDV


1 /*
2  * Copyright 2001,2002,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
24  * Represent the schema list types
25  *
26  * @xerces.internal
27  *
28  * @author Neeraj Bajaj, Sun Microsystems, inc.
29  * @author Sandy Gao, IBM
30  *
31  * @version $Id: ListDV.java,v 1.12 2005/01/11 13:41:58 mrglavas Exp $
32  */

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     // this method should never be called: XSSimpleTypeDecl is responsible for
40
// calling the item type for the convertion
41
public Object JavaDoc getActualValue(String JavaDoc content, ValidationContext context) throws InvalidDatatypeValueException{
42         return content;
43     }
44
45     // length of a list type is the number of items in the list
46
public int getDataLength(Object JavaDoc value) {
47         return ((ListData)value).getLength();
48     }
49
50     final static class ListData implements ObjectList {
51         final Object JavaDoc[] data;
52         private String JavaDoc canonical;
53         public ListData(Object JavaDoc[] data) {
54             this.data = data;
55         }
56         public synchronized String JavaDoc toString() {
57             if (canonical == null) {
58                 int len = data.length;
59                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc obj) {
75             if (!(obj instanceof ListData))
76                 return false;
77             Object JavaDoc[] 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             }//end of loop
87

88             //everything went fine.
89
return true;
90         }
91         
92         public boolean contains(Object JavaDoc 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 JavaDoc item(int index) {
102             if (index < 0 || index >= data.length) {
103                 return null;
104             }
105             return data[index];
106         }
107     }
108 } // class ListDV
109

110
Popular Tags