KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.ws.jaxme.xs.xml.*;
24
25
26 /** <p>Implementation of <code>xs:attrDecls</code>, with the
27  * following specification:
28  * <pre>
29  * &lt;xs:group name="attrDecls"&gt;
30  * &lt;xs:sequence&gt;
31  * &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
32  * &lt;xs:element name="attribute" type="xs:attribute"/&gt;
33  * &lt;xs:element name="attributeGroup" type="xs:attributeGroupRef"/&gt;
34  * &lt;/xs:choice&gt;
35  * &lt;xs:element ref="xs:anyAttribute" minOccurs="0"/&gt;
36  * &lt;/xs:sequence&gt;
37  * &lt;/xs:group&gt;
38  * </pre></p>
39  *
40  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
41  */

42 public class XsGAttrDeclsImpl implements XsGAttrDecls {
43   private final XsObject owner;
44   private List JavaDoc childs;
45   private XsTWildcard anyAttribute;
46
47   protected XsGAttrDeclsImpl(XsObject pOwner) {
48     owner = pOwner;
49   }
50
51   protected void addChild(Object JavaDoc o) {
52     if (o instanceof XsTWildcard) {
53       if (anyAttribute != null) {
54         throw new IllegalStateException JavaDoc("Multiple 'anyAttribute' child elements are forbidden.");
55       }
56       anyAttribute = (XsTWildcard) o;
57     } else {
58       if (anyAttribute != null) {
59         throw new IllegalStateException JavaDoc("An 'attribute' or 'attributeGroup' child element is invalid after an 'anyAttribute' child element.");
60       }
61     }
62     if (childs == null) {
63       childs = new ArrayList JavaDoc();
64     }
65     childs.add(o);
66   }
67
68   public XsTAttribute createAttribute() {
69     XsTAttribute attribute = owner.getObjectFactory().newXsTAttribute(owner);
70     addChild(attribute);
71     return attribute;
72   }
73
74   public XsTAttribute[] getAttributes() {
75     if (childs == null || childs.size() == 0) {
76       return new XsTAttribute[0];
77     }
78     List JavaDoc result = new ArrayList JavaDoc();
79     for (Iterator JavaDoc iter = childs.iterator(); iter.hasNext(); ) {
80       Object JavaDoc o = iter.next();
81       if (o instanceof XsTAttribute) {
82         result.add(o);
83       }
84     }
85     return (XsTAttribute[]) result.toArray(new XsTAttribute[result.size()]);
86   }
87
88   public XsTAttributeGroupRef createAttributeGroup() {
89     XsTAttributeGroupRef attributeGroupRef = owner.getObjectFactory().newXsTAttributeGroupRef(owner);
90     addChild(attributeGroupRef);
91     return attributeGroupRef;
92   }
93
94   public XsTAttributeGroupRef[] getAttributeGroups() {
95     if (childs == null || childs.size() == 0) {
96       return new XsTAttributeGroupRefImpl[0];
97     }
98     List JavaDoc result = new ArrayList JavaDoc();
99     for (Iterator JavaDoc iter = childs.iterator(); iter.hasNext(); ) {
100       Object JavaDoc o = iter.next();
101       if (o instanceof XsTAttributeGroupRef) {
102         result.add(o);
103       }
104     }
105     return (XsTAttributeGroupRef[]) result.toArray(new XsTAttributeGroupRef[result.size()]);
106   }
107
108   public XsTWildcard createAnyAttribute() {
109     XsTWildcard myAnyAttribute = owner.getObjectFactory().newXsTWildcard(owner);
110     addChild(myAnyAttribute);
111     return myAnyAttribute;
112   }
113
114   public XsTWildcard getAnyAttribute() {
115     return anyAttribute;
116   }
117
118   public Object JavaDoc[] getAllAttributes() {
119     if (childs == null) {
120       return new Object JavaDoc[0];
121     } else {
122       return childs.toArray();
123     }
124   }
125 }
126
Popular Tags