1 19 package org.netbeans.modules.xml.axi; 20 21 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType; 22 import org.netbeans.modules.xml.axi.Compositor.CompositorType; 23 import org.netbeans.modules.xml.axi.ContentModel.ContentModelType; 24 import org.netbeans.modules.xml.axi.impl.AnyAttributeProxy; 25 import org.netbeans.modules.xml.axi.impl.AnyElementProxy; 26 import org.netbeans.modules.xml.axi.impl.AttributeImpl; 27 import org.netbeans.modules.xml.axi.impl.AttributeProxy; 28 import org.netbeans.modules.xml.axi.impl.AttributeRef; 29 import org.netbeans.modules.xml.axi.impl.CompositorProxy; 30 import org.netbeans.modules.xml.axi.impl.ElementImpl; 31 import org.netbeans.modules.xml.axi.impl.ElementProxy; 32 import org.netbeans.modules.xml.axi.impl.ElementRef; 33 import org.netbeans.modules.xml.axi.visitor.DefaultVisitor; 34 import org.netbeans.modules.xml.schema.model.SchemaComponent; 35 36 41 public class AXIComponentFactory { 42 43 46 AXIComponentFactory(AXIModel model) { 47 this.model = model; 48 } 49 50 public long getComponentCount() { 51 return elementCount + attributeCount + 52 compositorCount + contentModelCount + 53 proxyComponentCount + 1; 54 } 55 56 59 public AXIComponent copy(AXIComponent original) { 60 AXICopier copier = new AXICopier(model); 61 return copier.copy(original); 62 } 63 64 67 public Element createElement() { 68 elementCount++; 69 return new ElementImpl(model); 70 } 71 72 75 public Element createElement(SchemaComponent component) { 76 elementCount++; 77 return new ElementImpl(model, component); 78 } 79 80 83 public Element createElementReference(Element referent) { 84 elementCount++; 85 return new ElementRef(model, referent); 86 } 87 88 91 public Element createElementReference(SchemaComponent component, Element referent) { 92 elementCount++; 93 return new ElementRef(model, component, referent); 94 } 95 96 99 public Attribute createAttribute() { 100 attributeCount++; 101 return new AttributeImpl(model); 102 } 103 104 107 public Attribute createAttribute(SchemaComponent component) { 108 attributeCount++; 109 return new AttributeImpl(model, component); 110 } 111 112 115 public Attribute createAttributeReference(Attribute referent) { 116 attributeCount++; 117 return new AttributeRef(model, referent); 118 } 119 120 123 public Attribute createAttributeReference(SchemaComponent component, Attribute referent) { 124 attributeCount++; 125 return new AttributeRef(model, component, referent); 126 } 127 128 131 public Compositor createCompositor(CompositorType type) { 132 compositorCount++; 133 Compositor compositor = new Compositor(model, type); 134 return compositor; 135 } 136 137 140 public Compositor createSequence() { 141 compositorCount++; 142 return new Compositor(model, CompositorType.SEQUENCE); 143 } 144 145 148 public Compositor createSequence(SchemaComponent component) { 149 compositorCount++; 150 Compositor compositor = new Compositor(model, component); 151 return compositor; 152 } 153 154 157 public Compositor createChoice() { 158 compositorCount++; 159 return new Compositor(model, CompositorType.CHOICE); 160 } 161 162 165 public Compositor createChoice(SchemaComponent component) { 166 compositorCount++; 167 Compositor compositor = new Compositor(model, component); 168 return compositor; 169 } 170 171 174 public Compositor createAll() { 175 compositorCount++; 176 return new Compositor(model, CompositorType.ALL); 177 } 178 179 182 public Compositor createAll(SchemaComponent component) { 183 compositorCount++; 184 Compositor compositor = new Compositor(model, component); 185 return compositor; 186 } 187 188 191 public AnyElement createAnyElement() { 192 compositorCount++; 193 return new AnyElement(model); 194 } 195 196 199 public AnyElement createAnyElement(SchemaComponent component) { 200 compositorCount++; 201 return new AnyElement(model, component); 202 } 203 204 207 public AnyAttribute createAnyAttribute() { 208 compositorCount++; 209 return new AnyAttribute(model); 210 } 211 214 public AnyAttribute createAnyAttribute(SchemaComponent component) { 215 compositorCount++; 216 return new AnyAttribute(model, component); 217 } 218 219 222 public ContentModel createComplexType() { 223 contentModelCount++; 224 return new ContentModel(model, ContentModelType.COMPLEX_TYPE); 225 } 226 227 230 public ContentModel createGroup() { 231 contentModelCount++; 232 return new ContentModel(model, ContentModelType.GROUP); 233 } 234 235 238 public ContentModel createAttributeGroup() { 239 contentModelCount++; 240 return new ContentModel(model, ContentModelType.ATTRIBUTE_GROUP); 241 } 242 243 246 public ContentModel createContentModel(ContentModelType type) { 247 contentModelCount++; 248 return new ContentModel(model, type); 249 } 250 251 254 public ContentModel createContentModel(SchemaComponent component) { 255 contentModelCount++; 256 return new ContentModel(model, component); 257 } 258 259 public AXIComponent createProxy(AXIComponent original) { 260 proxyComponentCount++; 261 return new ProxyComponentFactory().createProxy(original); 262 } 263 264 public String toString() { 265 StringBuffer buffer = new StringBuffer (); 266 buffer.append("elementCount: " + elementCount + "\n"); 267 buffer.append("attributeCount: " + attributeCount + "\n"); 268 buffer.append("compositorCount: " + compositorCount + "\n"); 269 buffer.append("contentModelCount: " + contentModelCount + "\n"); 270 buffer.append("proxyComponentCount: " + proxyComponentCount + "\n"); 271 return buffer.toString(); 272 } 273 274 277 private class ProxyComponentFactory extends DefaultVisitor { 278 279 private AXIComponent proxyComponent; 280 281 ProxyComponentFactory() { 282 } 283 284 AXIComponent createProxy(AXIComponent original) { 285 original.accept(this); 286 return proxyComponent; 287 } 288 289 public void visit(Element element) { 290 proxyComponent = new ElementProxy(model, element); 291 } 292 293 public void visit(AnyElement element) { 294 proxyComponent = new AnyElementProxy(model, element); 295 } 296 297 public void visit(Attribute attribute) { 298 proxyComponent = new AttributeProxy(model, attribute); 299 } 300 301 public void visit(AnyAttribute attribute) { 302 proxyComponent = new AnyAttributeProxy(model, attribute); 303 } 304 305 public void visit(Compositor compositor) { 306 proxyComponent = new CompositorProxy(model, compositor); 307 } 308 } 309 310 313 private class AXICopier extends DefaultVisitor { 314 315 private AXIComponent copiedComponent; 316 private AXIModel model; 317 318 321 public AXICopier(AXIModel model) { 322 this.model = model; 323 } 324 325 public AXIComponent copy(AXIComponent original) { 326 if(original.getComponentType() == ComponentType.PROXY) { 328 AXIComponentFactory f = model.getComponentFactory(); 329 copiedComponent = f.createProxy(original.getSharedComponent()); 330 assert(copiedComponent != null); 331 return copiedComponent; 332 } 333 334 original.accept(this); 336 assert(copiedComponent != null); 337 return copiedComponent; 338 } 339 340 public void visit(Element element) { 341 if(element instanceof ElementRef) { 342 ElementRef ref = (ElementRef)element; 343 copiedComponent = model.getComponentFactory(). 344 createElementReference(ref.getReferent()); 345 ((Element)copiedComponent).setMaxOccurs(element.getMaxOccurs()); 346 ((Element)copiedComponent).setMinOccurs(element.getMinOccurs()); 347 return; 348 } 349 copiedComponent = model.getComponentFactory(). 350 createElement(); 351 ((Element)copiedComponent).setAbstract(element.getAbstract()); 352 ((Element)copiedComponent).setBlock(element.getBlock()); 353 ((Element)copiedComponent).setDefault(element.getDefault()); 354 ((Element)copiedComponent).setFinal(element.getFinal()); 355 ((Element)copiedComponent).setForm(element.getForm()); 356 ((Element)copiedComponent).setFixed(element.getFixed()); 357 ((Element)copiedComponent).setMaxOccurs(element.getMaxOccurs()); 358 ((Element)copiedComponent).setMinOccurs(element.getMinOccurs()); 359 ((Element)copiedComponent).setName(element.getName()); 360 ((Element)copiedComponent).setNillable(element.getNillable()); 361 } 362 363 public void visit(AnyElement element) { 364 copiedComponent = model.getComponentFactory(). 365 createAnyElement(); 366 ((AnyElement)copiedComponent).setProcessContents(element.getProcessContents()); 367 ((AnyElement)copiedComponent).setTargetNamespace(element.getTargetNamespace()); 368 } 369 370 public void visit(Attribute attribute) { 371 if(attribute instanceof AttributeRef) { 372 AttributeRef ref = (AttributeRef)attribute; 373 copiedComponent = model.getComponentFactory(). 374 createAttributeReference(ref.getReferent()); 375 ((Attribute)copiedComponent).setFixed(attribute.getFixed()); 376 ((Attribute)copiedComponent).setDefault(attribute.getDefault()); 377 ((Attribute)copiedComponent).setUse(attribute.getUse()); 378 return; 379 } 380 copiedComponent = model.getComponentFactory(). 381 createAttribute(); 382 ((Attribute)copiedComponent).setDefault(attribute.getDefault()); 383 ((Attribute)copiedComponent).setFixed(attribute.getFixed()); 384 ((Attribute)copiedComponent).setForm(attribute.getForm()); 385 ((Attribute)copiedComponent).setUse(attribute.getUse()); 386 ((Attribute)copiedComponent).setName(attribute.getName()); 387 } 388 389 public void visit(AnyAttribute attribute) { 390 copiedComponent = model.getComponentFactory(). 391 createAnyAttribute(); 392 ((AnyAttribute)copiedComponent).setProcessContents(attribute.getProcessContents()); 393 ((AnyAttribute)copiedComponent).setTargetNamespace(attribute.getTargetNamespace()); 394 } 395 396 public void visit(Compositor compositor) { 397 copiedComponent = model.getComponentFactory(). 398 createCompositor(compositor.getType()); 399 ((Compositor)copiedComponent).setMaxOccurs(compositor.getMaxOccurs()); 400 ((Compositor)copiedComponent).setMinOccurs(compositor.getMinOccurs()); 401 } 402 403 public void visit(ContentModel contentModel) { 404 copiedComponent = model.getComponentFactory(). 405 createContentModel(contentModel.getType()); 406 } 407 } 408 409 private AXIModel model; 413 private long elementCount; 414 private long attributeCount; 415 private long compositorCount; 416 private long contentModelCount; 417 private long proxyComponentCount; 418 } 419 | Popular Tags |