1 19 package org.netbeans.modules.xml.axi.impl; 20 21 import java.util.List ; 22 import org.netbeans.modules.xml.axi.AXIComponent; 23 import org.netbeans.modules.xml.axi.AXIDocument; 24 import org.netbeans.modules.xml.axi.ContentModel; 25 import org.netbeans.modules.xml.schema.model.*; 26 import org.netbeans.modules.xml.schema.model.visitor.DeepSchemaVisitor; 27 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 28 29 39 public class AXIModelBuilder extends AbstractModelBuilder { 40 41 44 public AXIModelBuilder(AXIComponent parent) { 45 super((AXIModelImpl)parent.getModel()); 46 this.parent = parent; 47 } 48 49 58 public void populateChildren(SchemaComponent schemaComponent, 59 boolean visitChildren, List <AXIComponent> children) { 60 this.children = children; 61 62 if(!visitChildren) { 65 schemaComponent.accept(this); 66 return; 67 } 68 69 for(SchemaComponent child : schemaComponent.getChildren()) { 71 child.accept(this); 72 } 73 } 74 75 78 public void visit(Schema schema) { 79 } 80 81 84 public void visit(org.netbeans.modules.xml.schema.model.AnyElement schemaComponent) { 85 AXIComponent child = getAXIComponent(schemaComponent, false); 86 addChild(child); 87 } 88 89 92 public void visit(AnyAttribute schemaComponent) { 93 AXIComponent child = getAXIComponent(schemaComponent, false); 94 addChild(child); 95 } 96 97 100 public void visit(GlobalElement component) { 101 AXIComponent child = getAXIComponent(component, true); 102 addChild(child); 103 } 104 105 108 public void visit(LocalElement component) { 109 AXIComponent child = getAXIComponent(component, false); 110 addChild(child); 111 } 112 113 116 public void visit(ElementReference component) { 117 AXIComponent child = getAXIComponent(component, false); 118 addChild(child); 119 } 120 121 124 public void visit(GlobalAttribute component) { 125 AXIComponent child = getAXIComponent(component, true); 126 addChild(child); 127 } 128 129 132 public void visit(LocalAttribute component) { 133 AXIComponent child = getAXIComponent(component, false); 134 addChild(child); 135 } 136 137 140 public void visit(AttributeReference component) { 141 AXIComponent child = getAXIComponent(component, false); 142 addChild(child); 143 } 144 145 148 public void visit(Sequence component) { 149 AXIComponent child = getAXIComponent(component, false); 150 addChild(child); 151 } 152 153 156 public void visit(Choice component) { 157 AXIComponent child = getAXIComponent(component, false); 158 addChild(child); 159 } 160 161 164 public void visit(All component) { 165 AXIComponent child = getAXIComponent(component, false); 166 addChild(child); 167 } 168 169 172 public void visit(GlobalGroup component) { 173 AXIComponent child = getAXIComponent(component, true); 174 addChild(child); 175 } 176 177 180 public void visit(GroupReference component) { 181 NamedComponentReference ref = component.getRef(); 182 if(ref == null) 183 return; 184 SchemaComponent sc = model.getReferenceableSchemaComponent(ref); 185 if(sc == null) 186 return; 187 AXIComponent child = getAXIComponent(sc, true); 188 addChild(child); 189 } 190 191 194 public void visit(GlobalAttributeGroup component) { 195 AXIComponent child = getAXIComponent(component, true); 196 addChild(child); 197 } 198 199 202 public void visit(AttributeGroupReference component) { 203 NamedComponentReference ref = component.getGroup(); 204 if(ref == null) 205 return; 206 SchemaComponent sc = model.getReferenceableSchemaComponent(ref); 207 if(sc == null) 208 return; 209 AXIComponent child = getAXIComponent(sc, true); 210 addChild(child); 211 } 212 213 216 public void visit(GlobalComplexType component) { 217 AXIComponent child = getAXIComponent(component, true); 218 addChild(child); 219 } 220 221 224 public void visit(LocalComplexType component) { 225 visitChildren(component); 226 } 227 228 231 public void visit(ComplexContent component) { 232 visitChildren(component); 233 } 234 235 238 public void visit(SimpleContent component) { 239 visitChildren(component); 240 } 241 242 245 public void visit(SimpleExtension component) { 246 NamedComponentReference ref = component.getBase(); 247 if(ref != null) { 248 SchemaComponent type = model.getReferenceableSchemaComponent(ref); 249 if(type != null) { 250 AXIComponent child = getAXIComponent(type, true); 251 addChild(child); 252 } 253 } 254 visitChildren(component); 255 } 256 257 260 public void visit(ComplexExtension component) { 261 NamedComponentReference ref = component.getBase(); 262 if(ref != null) { 263 SchemaComponent type = model.getReferenceableSchemaComponent(ref); 264 if(type != null) { 265 AXIComponent child = getAXIComponent(type, true); 266 addChild(child); 267 } 268 } 269 visitChildren(component); 270 } 271 272 280 private AXIComponent getAXIComponent(final SchemaComponent schemaComponent, boolean isGlobal) { 281 if(parent instanceof AXIDocument || !isGlobal) { 284 return new AXIComponentCreator(getModel()). 285 createNew(schemaComponent); 286 } 287 288 if(!getModel().fromSameSchemaModel(schemaComponent)) { 289 return getModel().lookupFromOtherModel(schemaComponent); 290 } 291 292 return getModel().lookup(schemaComponent); 293 } 294 295 298 private void addChild(AXIComponent child) { 299 if(child == null) 300 return; 301 302 if(parent instanceof AXIDocument) { 303 children.add(child); 304 ((AXIDocumentImpl)parent).addToCache(child); 305 return; 306 } 307 308 if(child instanceof ContentModel) { 309 Util.addProxyChildren(parent, child, children); 310 return; 311 } 312 children.add(child); 313 } 314 315 321 private AXIComponent parent; 322 323 326 private List <AXIComponent> children; 327 } 328 329 330 | Popular Tags |