1 19 20 package org.netbeans.modules.xml.schema.model.impl; 21 22 import java.util.Collection ; 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 ; 34 35 39 public class ChoiceImpl extends SchemaComponentImpl implements Choice, 40 Cardinality { 41 42 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 56 public void addChoice(Choice choice) { 57 appendChild(CHOICE_PROPERTY, choice); 58 } 59 60 63 public void removeChoice(Choice choice) { 64 removeChild(CHOICE_PROPERTY, choice); 65 } 66 67 70 public void removeGroupReference(GroupReference ref) { 71 removeChild(GROUP_REF_PROPERTY, ref); 72 } 73 74 77 public void addGroupReference(GroupReference ref) { 78 appendChild(GROUP_REF_PROPERTY, ref); 79 } 80 81 84 public void removeSequence(Sequence seq) { 85 removeChild(SEQUENCE_PROPERTY, seq); 86 } 87 88 91 public void addSequence(Sequence seq) { 92 appendChild(SEQUENCE_PROPERTY, seq); 93 } 94 95 98 public void addAny(AnyElement any) { 99 appendChild(ANY_PROPERTY, any); 100 } 101 102 105 public void removeAny(AnyElement any) { 106 removeChild(ANY_PROPERTY, any); 107 } 108 109 112 public void removeLocalElement(LocalElement element) { 113 removeChild(LOCAL_ELEMENT_PROPERTY, element); 114 } 115 116 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 130 public void addElementReference(ElementReference element) { 131 appendChild(ELEMENT_REFERENCE_PROPERTY, element); 132 } 133 134 137 public Collection <GroupReference> getGroupReferences() { 138 return getChildren(GroupReference.class); 139 } 140 141 144 public Collection <Sequence> getSequences() { 145 return getChildren(Sequence.class); 146 } 147 148 151 public Collection <AnyElement> getAnys() { 152 return getChildren(AnyElement.class); 153 } 154 155 158 public Collection <LocalElement> getLocalElements() { 159 return getChildren(LocalElement.class); 160 } 161 162 public Collection <ElementReference> getElementReferences() { 163 return getChildren(ElementReference.class); 164 } 165 166 169 public Collection <Choice> getChoices() { 170 return getChildren(Choice.class); 171 } 172 173 177 public Class <? extends SchemaComponent> getComponentType() { 178 return Choice.class; 179 } 180 181 public void setMaxOccurs(String max) { 182 setAttribute(MAX_OCCURS_PROPERTY, SchemaAttributes.MAX_OCCURS, max); 183 } 184 185 public void setMinOccurs(Integer 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 getMaxOccurs() { 194 return getAttribute(SchemaAttributes.MAX_OCCURS); 195 } 196 197 public Integer getMinOccurs() { 198 String 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 s = getAttribute(SchemaAttributes.MIN_OCCURS); 208 return s == null ? getMinOccursDefault() : Integer.valueOf(s).intValue(); 209 } 210 211 public String getMaxOccursDefault() { 212 return String.valueOf(1); 213 } 214 215 public String getMaxOccursEffective() { 216 String 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 |