KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > xml > impl > XsAGOccursImpl


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.xml.impl;
18
19 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
20 import org.apache.ws.jaxme.xs.xml.XsAGOccurs;
21 import org.apache.ws.jaxme.xs.xml.XsObject;
22 import org.xml.sax.SAXException JavaDoc;
23
24
25 /** <p>Implementation of the attribute group <code>xs:occurs</code>,
26  * as specified by the following:
27  * <pre>
28  * &lt;xs:attributeGroup name="occurs"&gt;
29  * &lt;xs:annotation&gt;
30  * &lt;xs:documentation&gt;
31  * for all particles
32  * &lt;/xs:documentation&gt;
33  * &lt;/xs:annotation&gt;
34  * &lt;xs:attribute name="minOccurs" type="xs:nonNegativeInteger"
35  * use="optional" default="1"/&gt;
36  * &lt;xs:attribute name="maxOccurs" type="xs:allNNI"
37  * use="optional" default="1"/&gt;
38  * &lt;/xs:attributeGroup&gt;
39  * </pre></p>
40  * <p><em>Implementation note:</em> The implementation must ensure
41  * that either 'maxOccurs' is unbounded or 'minOccurs' <= 'maxOccurs'.</p>
42  *
43  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
44  */

45 public class XsAGOccursImpl implements XsAGOccurs {
46   private final XsObject owner;
47   private int minOccurs = 1, maxOccurs = 1;
48
49   public XsAGOccursImpl(XsObject pOwner) {
50     owner = pOwner;
51   }
52
53   public void setMaxOccurs(String JavaDoc pMaxOccurs) {
54     if ("unbounded".equals(pMaxOccurs)) {
55       maxOccurs = -1;
56     } else {
57       try {
58         maxOccurs = Integer.parseInt(pMaxOccurs);
59         if (maxOccurs < 0) {
60           throw new IllegalArgumentException JavaDoc();
61         }
62       } catch (Exception JavaDoc e) {
63         throw new IllegalArgumentException JavaDoc("Invalid value for maxOccurs: " +
64                                             pMaxOccurs +
65                                             "; expected 'unbounded' or a nonnegative integer value.");
66       }
67     }
68   }
69
70   public int getMaxOccurs() {
71     return maxOccurs;
72   }
73
74   public void setMinOccurs(int pMinOccurs) {
75     if (pMinOccurs < 0) {
76       throw new IllegalArgumentException JavaDoc("Invalid value for minOccurs: " +
77                                           pMinOccurs +
78                                           "; expected a nonnegative integer value.");
79     }
80     minOccurs = pMinOccurs;
81   }
82
83   public int getMinOccurs() {
84     return minOccurs;
85   }
86
87   public void validate() throws SAXException {
88     if (maxOccurs != -1 && minOccurs > maxOccurs) {
89       throw new LocSAXException("The 'minOccurs' attribute value (" +
90                                  minOccurs +
91                                  ") is greater than the 'maxOccurs' attribute value (" +
92                                  maxOccurs + ")", owner.getLocator());
93     }
94   }
95 }
96
Popular Tags