KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.ws.jaxme.xs.xml.*;
23
24
25 /** <p>Implementation of the <code>xs:keybase</code> type, with the
26  * following specification:
27  * <pre>
28  * &lt;xs:complexType name="keybase"&gt;
29  * &lt;xs:complexContent&gt;
30  * &lt;xs:extension base="xs:annotated"&gt;
31  * &lt;xs:sequence&gt;
32  * &lt;xs:element ref="xs:selector"/&gt;
33  * &lt;xs:element ref="xs:field" minOccurs="1" maxOccurs="unbounded"/&gt;
34  * &lt;/xs:sequence&gt;
35  * &lt;xs:attribute name="name" type="xs:NCName" use="required"/&gt;
36  * &lt;/xs:extension&gt;
37  * &lt;/xs:complexContent&gt;
38  * &lt;/xs:complexType&gt;
39  * </pre></p>
40  *
41  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
42  */

43 public class XsTKeybaseImpl extends XsTAnnotatedImpl implements XsTKeybase {
44   private XsESelector selector;
45   private List JavaDoc fields = new ArrayList JavaDoc();
46   private XsNCName name;
47
48   protected XsTKeybaseImpl(XsObject pParent) {
49     super(pParent);
50   }
51
52   public XsESelector createSelector() {
53     if (selector != null) {
54       throw new IllegalStateException JavaDoc("Multiple 'selector' child elements are forbidden.");
55     }
56     if (fields.size() > 0) {
57       throw new IllegalStateException JavaDoc("The 'selector' child element must precede the 'field' child elements.");
58     }
59     selector = getObjectFactory().newXsESelector(this);
60     return selector;
61   }
62
63   public XsESelector getSelector() {
64     return selector;
65   }
66
67   public XsEField createField() {
68     if (selector == null) {
69       throw new NullPointerException JavaDoc("This 'field' child element must be preceded by a 'selector' child element.");
70     }
71     XsEField field = getObjectFactory().newXsEField(this);
72     fields.add(field);
73     return field;
74   }
75
76   public XsEField[] getFields() {
77     return (XsEField[]) fields.toArray(new XsEField[fields.size()]);
78   }
79
80   public void setName(XsNCName pName) {
81     name = pName;
82   }
83
84   public XsNCName getName() {
85     return name;
86   }
87
88   public void validate() {
89     if (name == null) {
90       throw new NullPointerException JavaDoc("Missing attribute: 'name'");
91     }
92     if (selector == null) {
93       throw new NullPointerException JavaDoc("Missing child element: 'selector'");
94     }
95     if (fields.size() == 0) {
96       throw new NullPointerException JavaDoc("Missing child element: 'field'");
97     }
98   }
99 }
100
Popular Tags