KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > impl > XSListTypeImpl


1 /*
2  * Copyright 2003, 2004 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.ws.jaxme.xs.impl;
18
19 import org.apache.ws.jaxme.xs.XSEnumeration;
20 import org.apache.ws.jaxme.xs.XSListType;
21 import org.apache.ws.jaxme.xs.XSType;
22 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
23 import org.apache.ws.jaxme.xs.xml.XsEList;
24 import org.apache.ws.jaxme.xs.xml.XsQName;
25 import org.apache.ws.jaxme.xs.xml.XsTLocalSimpleType;
26 import org.xml.sax.SAXException JavaDoc;
27
28 /**
29  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
30  */

31 public class XSListTypeImpl extends XSSimpleTypeImpl implements XSListType {
32   private static final String JavaDoc[][] ZERO_PATTERNS = new String JavaDoc[0][];
33   private static final XSEnumeration[] ZERO_ENUMERATIONS = new XSEnumeration[0];
34   private final XSType itemType;
35
36   public boolean isRestriction() { return false; }
37   public XSType getRestrictedType() {
38     throw new IllegalStateException JavaDoc("This is a basic list type and not a restriction of another simple type.");
39   }
40
41   public XSListTypeImpl(XSType pOwner, XsEList pBaseList) throws SAXException {
42     XsQName itemTypeName = pBaseList.getItemType();
43     if (itemTypeName == null) {
44       XsTLocalSimpleType simpleType = pBaseList.getSimpleType();
45       if (simpleType == null) {
46         throw new LocSAXException("You must either set the 'itemType' attribute or add a 'simpleType' element.",
47                                    pBaseList.getLocator());
48       }
49       XSType type = pOwner.getXSSchema().getXSObjectFactory().newXSType(pOwner, simpleType);
50       type.validate();
51       itemType = type;
52     } else {
53       XSType type = pOwner.getXSSchema().getType(itemTypeName);
54       if (type == null) {
55         throw new LocSAXException("Unknown item type: " + itemTypeName, pBaseList.getLocator());
56       }
57       type.validate();
58       if (!type.isSimple()) {
59         throw new LocSAXException("The item type " + itemTypeName + " is complex.",
60                                      pBaseList.getLocator());
61       }
62       itemType = type;
63     }
64   }
65
66   public boolean isList() { return true; }
67   public XSListType getListType() { return this; }
68   public String JavaDoc[][] getPattern() { return ZERO_PATTERNS; }
69   public XSEnumeration[] getEnumerations() { return ZERO_ENUMERATIONS; }
70   public Long JavaDoc getLength() { return null; }
71   public Long JavaDoc getMinLength() { return null; }
72   public Long JavaDoc getMaxLength() { return null; }
73   public XSType getItemType() { return itemType; }
74 }
75
Popular Tags