KickJava   Java API By Example, From Geeks To Geeks.

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


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.XSSimpleType;
21 import org.apache.ws.jaxme.xs.XSType;
22 import org.apache.ws.jaxme.xs.xml.XsEEnumeration;
23 import org.apache.ws.jaxme.xs.xml.XsEPattern;
24 import org.apache.ws.jaxme.xs.xml.XsGSimpleRestrictionModel;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
29  */

30 public abstract class XSSimpleTypeRestrictionImpl extends XSSimpleTypeImpl {
31   private final XSSimpleType baseType;
32   private final XSType restrictedType;
33   private final XsGSimpleRestrictionModel restriction;
34   private final XSEnumeration[] enumerations;
35
36   protected XSSimpleTypeRestrictionImpl(XSType pParent,
37                                          XSType pRestrictedType,
38                                          XsGSimpleRestrictionModel pRestriction)
39       throws SAXException JavaDoc {
40     restrictedType = pRestrictedType;
41     baseType = pRestrictedType.getSimpleType();
42     restriction = pRestriction;
43
44     XsEEnumeration[] enums = restriction.getEnumerations();
45     if (enums.length == 0) {
46       enumerations = getBaseType().getEnumerations();
47     } else {
48       enumerations = new XSEnumeration[enums.length];
49       for (int i = 0; i < enums.length; i++) {
50         enumerations[i] = pParent.getXSSchema().getXSObjectFactory().newXSEnumeration(pParent, enums[i]);
51       }
52     }
53   }
54
55   protected XSSimpleType getBaseType() {
56     return baseType;
57   }
58
59   public boolean isRestriction() { return true; }
60   public XSType getRestrictedType() { return restrictedType; }
61
62   protected XsGSimpleRestrictionModel getRestriction() {
63     return restriction;
64   }
65
66   public String JavaDoc[][] getPattern() {
67     XsEPattern[] patterns = restriction.getPatterns();
68     String JavaDoc[][] base = getBaseType().getPattern();
69     if (patterns.length == 0) {
70       return base;
71     } else {
72       String JavaDoc[][] result;
73       if (base == null) {
74           result = new String JavaDoc[1][];
75       } else {
76           result = new String JavaDoc[base.length+1][];
77           for (int i = 0; i < base.length; i++) {
78             result[i+1] = base[i];
79           }
80       }
81       String JavaDoc[] thisStepsPatterns = new String JavaDoc[patterns.length];
82       for (int i = 0; i < patterns.length; i++) {
83         thisStepsPatterns[i] = patterns[i].getValue();
84       }
85       result[0] = thisStepsPatterns;
86       return result;
87     }
88   }
89
90   public XSEnumeration[] getEnumerations() {
91     return enumerations;
92   }
93 }
94
Popular Tags