KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > impl > ChoiceImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.model.impl;
21
22 import java.util.Collection JavaDoc;
23 import org.netbeans.modules.xml.schema.model.AnyElement;
24 import org.netbeans.modules.xml.schema.model.Cardinality;
25 import org.netbeans.modules.xml.schema.model.Choice;
26 import org.netbeans.modules.xml.schema.model.ElementReference;
27 import org.netbeans.modules.xml.schema.model.GlobalGroup;
28 import org.netbeans.modules.xml.schema.model.GroupReference;
29 import org.netbeans.modules.xml.schema.model.LocalElement;
30 import org.netbeans.modules.xml.schema.model.SchemaComponent;
31 import org.netbeans.modules.xml.schema.model.Sequence;
32 import org.netbeans.modules.xml.schema.model.visitor.SchemaVisitor;
33 import org.w3c.dom.Element JavaDoc;
34
35 /**
36  *
37  * @author Vidhya Narayanan
38  */

39 public class ChoiceImpl extends SchemaComponentImpl implements Choice,
40     Cardinality {
41     
42     /**
43      *
44      */

45     public ChoiceImpl(SchemaModelImpl model, Element el) {
46     super(model, el);
47     }
48     
49     public ChoiceImpl(SchemaModelImpl model) {
50         this(model, createNewComponent(SchemaElements.CHOICE,model));
51     }
52     
53     /**
54      *
55      */

56     public void addChoice(Choice choice) {
57     appendChild(CHOICE_PROPERTY, choice);
58     }
59     
60     /**
61      *
62      */

63     public void removeChoice(Choice choice) {
64     removeChild(CHOICE_PROPERTY, choice);
65     }
66     
67     /**
68      *
69      */

70     public void removeGroupReference(GroupReference ref) {
71     removeChild(GROUP_REF_PROPERTY, ref);
72     }
73     
74     /**
75      *
76      */

77     public void addGroupReference(GroupReference ref) {
78     appendChild(GROUP_REF_PROPERTY, ref);
79     }
80     
81     /**
82      *
83      */

84     public void removeSequence(Sequence seq) {
85     removeChild(SEQUENCE_PROPERTY, seq);
86     }
87     
88     /**
89      *
90      */

91     public void addSequence(Sequence seq) {
92     appendChild(SEQUENCE_PROPERTY, seq);
93     }
94     
95     /**
96      *
97      */

98     public void addAny(AnyElement any) {
99     appendChild(ANY_PROPERTY, any);
100     }
101     
102     /**
103      *
104      */

105     public void removeAny(AnyElement any) {
106     removeChild(ANY_PROPERTY, any);
107     }
108     
109     /**
110      *
111      */

112     public void removeLocalElement(LocalElement element) {
113     removeChild(LOCAL_ELEMENT_PROPERTY, element);
114     }
115     
116     /**
117      *
118      */

119     public void addLocalElement(LocalElement element) {
120     appendChild(LOCAL_ELEMENT_PROPERTY, element);
121     }
122     
123     public void removeElementReference(ElementReference element) {
124     removeChild(ELEMENT_REFERENCE_PROPERTY, element);
125     }
126     
127     /**
128      *
129      */

130     public void addElementReference(ElementReference element) {
131     appendChild(ELEMENT_REFERENCE_PROPERTY, element);
132     }
133     
134     /**
135      *
136      */

137     public Collection JavaDoc<GroupReference> getGroupReferences() {
138     return getChildren(GroupReference.class);
139     }
140     
141     /**
142      *
143      */

144     public Collection JavaDoc<Sequence> getSequences() {
145     return getChildren(Sequence.class);
146     }
147     
148     /**
149      *
150      */

151     public Collection JavaDoc<AnyElement> getAnys() {
152     return getChildren(AnyElement.class);
153     }
154     
155     /**
156      *
157      */

158     public Collection JavaDoc<LocalElement> getLocalElements() {
159     return getChildren(LocalElement.class);
160     }
161     
162     public Collection JavaDoc<ElementReference> getElementReferences() {
163     return getChildren(ElementReference.class);
164     }
165     
166     /**
167      *
168      */

169     public Collection JavaDoc<Choice> getChoices() {
170     return getChildren(Choice.class);
171     }
172     
173     /**
174      *
175      *
176      */

177     public Class JavaDoc<? extends SchemaComponent> getComponentType() {
178     return Choice.class;
179     }
180     
181     public void setMaxOccurs(String JavaDoc max) {
182     setAttribute(MAX_OCCURS_PROPERTY, SchemaAttributes.MAX_OCCURS, max);
183     }
184     
185     public void setMinOccurs(Integer JavaDoc min) {
186     setAttribute(MIN_OCCURS_PROPERTY, SchemaAttributes.MIN_OCCURS, min);
187     }
188     
189     public void accept(SchemaVisitor v) {
190     v.visit(this);
191     }
192     
193     public String JavaDoc getMaxOccurs() {
194     return getAttribute(SchemaAttributes.MAX_OCCURS);
195     }
196     
197     public Integer JavaDoc getMinOccurs() {
198     String JavaDoc s = getAttribute(SchemaAttributes.MIN_OCCURS);
199     return s == null ? null : Integer.valueOf(s);
200     }
201     
202     public int getMinOccursDefault() {
203     return 1;
204     }
205     
206     public int getMinOccursEffective() {
207     String JavaDoc s = getAttribute(SchemaAttributes.MIN_OCCURS);
208     return s == null ? getMinOccursDefault() : Integer.valueOf(s).intValue();
209     }
210     
211     public String JavaDoc getMaxOccursDefault() {
212     return String.valueOf(1);
213     }
214     
215     public String JavaDoc getMaxOccursEffective() {
216     String JavaDoc s = getAttribute(SchemaAttributes.MAX_OCCURS);
217     return s == null ? getMaxOccursDefault() : s;
218     }
219     
220     public Cardinality getCardinality() {
221     return getParent() instanceof GlobalGroup?null:this;
222     }
223 }
224
Popular Tags