1 19 package org.netbeans.modules.xml.axi.impl; 20 21 import org.netbeans.modules.xml.axi.AXIComponent; 22 import org.netbeans.modules.xml.axi.AXIComponentFactory; 23 import org.netbeans.modules.xml.axi.Attribute; 24 import org.netbeans.modules.xml.axi.Compositor; 25 import org.netbeans.modules.xml.axi.ContentModel; 26 import org.netbeans.modules.xml.axi.Element; 27 import org.netbeans.modules.xml.schema.model.*; 28 29 38 public class AXIComponentCreator extends AbstractModelBuilder { 39 40 43 public AXIComponentCreator(AXIModelImpl model) { 44 super(model); 45 factory = model.getComponentFactory(); 46 } 47 48 51 AXIComponent createNew(SchemaComponent schemaComponent) { 52 schemaComponent.accept(this); 53 54 return newAXIComponent; 55 } 56 57 60 public void visit(Schema schema) { 61 newAXIComponent = new AXIDocumentImpl(model, schema); 62 } 63 64 67 public void visit(AnyElement schemaComponent) { 68 org.netbeans.modules.xml.axi.AnyElement element = factory. 69 createAnyElement(schemaComponent); 70 Util.updateAnyElement(element); 71 newAXIComponent = element; 72 } 73 74 77 public void visit(AnyAttribute schemaComponent) { 78 org.netbeans.modules.xml.axi.AnyAttribute attribute = factory. 79 createAnyAttribute(schemaComponent); 80 Util.updateAnyAttribute(attribute); 81 newAXIComponent = attribute; 82 } 83 84 87 public void visit(GlobalElement schemaComponent) { 88 if(!model.fromSameSchemaModel(schemaComponent)) { 89 newAXIComponent = model.lookupFromOtherModel(schemaComponent); 90 return; 91 } 92 93 Element element = factory.createElement(schemaComponent); 94 Util.updateGlobalElement(element); 95 newAXIComponent = element; 96 } 97 98 101 public void visit(LocalElement component) { 102 Element element = factory.createElement(component); 103 Util.updateLocalElement(element); 104 newAXIComponent = element; 105 } 106 107 110 public void visit(ElementReference component) { 111 SchemaComponent originalElement = component.getRef().get(); 112 if(originalElement == null) 113 return; 114 AXIComponent referent = null; 115 if(!model.fromSameSchemaModel(originalElement)) { 116 referent = model.lookupFromOtherModel(originalElement); 117 } else { 118 referent = model.lookup(originalElement); 119 } 120 assert (referent != null); 121 Element element = factory.createElementReference(component, (Element)referent); 122 Util.updateElementReference(element); 123 newAXIComponent = element; 124 } 125 126 129 public void visit(GlobalAttribute schemaComponent) { 130 if(!model.fromSameSchemaModel(schemaComponent)) { 131 newAXIComponent = model.lookupFromOtherModel(schemaComponent); 132 return; 133 } 134 Attribute attribute = factory.createAttribute(schemaComponent); 135 Util.updateGlobalAttribute(attribute); 136 newAXIComponent = attribute; 137 } 138 139 142 public void visit(LocalAttribute component) { 143 Attribute attribute = factory.createAttribute(component); 144 Util.updateLocalAttribute(attribute); 145 newAXIComponent = attribute; 146 } 147 148 151 public void visit(AttributeReference component) { 152 SchemaComponent originalElement = component.getRef().get(); 153 if(originalElement == null) 154 return; 155 AXIComponent referent = null; 156 if(!model.fromSameSchemaModel(originalElement)) { 157 referent = model.lookupFromOtherModel(originalElement); 158 } else { 159 referent = model.lookup(originalElement); 160 } 161 assert(referent != null); 162 Attribute attribute = factory.createAttributeReference(component, 163 (Attribute)referent); 164 Util.updateAttributeReference(attribute); 165 newAXIComponent = attribute; 166 } 167 168 171 public void visit(Sequence component) { 172 Compositor compositor = factory.createSequence(component); 173 Util.updateCompositor(compositor); 174 newAXIComponent = compositor; 175 } 176 177 180 public void visit(Choice component) { 181 Compositor compositor = factory.createChoice(component); 182 Util.updateCompositor(compositor); 183 newAXIComponent = compositor; 184 } 185 186 189 public void visit(All component) { 190 Compositor compositor = factory.createAll(component); 191 Util.updateCompositor(compositor); 192 newAXIComponent = compositor; 193 } 194 195 198 public void visit(GlobalGroup schemaComponent) { 199 if(!model.fromSameSchemaModel(schemaComponent)) { 200 newAXIComponent = model.lookupFromOtherModel(schemaComponent); 201 return; 202 } 203 ContentModel cm = factory.createContentModel(schemaComponent); 204 Util.updateContentModel(cm); 205 newAXIComponent = cm; 206 } 207 208 211 public void visit(GroupReference component) { 212 SchemaComponent sc = component.getRef().get(); 213 if(sc == null) 214 return; 215 AXIComponent referent = new AXIComponentCreator(model). 216 createNew(sc); 217 newAXIComponent = referent; 218 } 219 220 223 public void visit(GlobalAttributeGroup schemaComponent) { 224 if(!model.fromSameSchemaModel(schemaComponent)) { 225 newAXIComponent = model.lookupFromOtherModel(schemaComponent); 226 return; 227 } 228 ContentModel cm = factory.createContentModel(schemaComponent); 229 Util.updateContentModel(cm); 230 newAXIComponent = cm; 231 } 232 233 236 public void visit(AttributeGroupReference component) { 237 SchemaComponent sc = component.getGroup().get(); 238 if(sc == null) 239 return; 240 AXIComponent referent = new AXIComponentCreator(model). 241 createNew(sc); 242 newAXIComponent = referent; 243 } 244 245 248 public void visit(GlobalComplexType schemaComponent) { 249 if(!model.fromSameSchemaModel(schemaComponent)) { 250 newAXIComponent = model.lookupFromOtherModel(schemaComponent); 251 return; 252 } 253 ContentModel cm = factory.createContentModel(schemaComponent); 254 Util.updateContentModel(cm); 255 newAXIComponent = cm; 256 } 257 258 public void visit(LocalComplexType component) { 259 } 260 public void visit(ComplexContent component) { 261 } 262 public void visit(SimpleContent component) { 263 } 264 public void visit(SimpleExtension component) { 265 } 266 public void visit(ComplexExtension component) { 267 } 268 269 275 private AXIComponent newAXIComponent; 276 private AXIComponentFactory factory; 277 } 278 279 | Popular Tags |