1 /*2 * The contents of this file are subject to the terms of the Common Development3 * and Distribution License (the License). You may not use this file except in4 * compliance with the License.5 * 6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html7 * or http://www.netbeans.org/cddl.txt.8 * 9 * When distributing Covered Code, include this CDDL Header Notice in each file10 * and include the License file at http://www.netbeans.org/cddl.txt.11 * If applicable, add the following below the CDDL Header, with the fields12 * 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 Original16 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun17 * Microsystems, Inc. All Rights Reserved.18 */19 20 /*21 * AbstractXSDVisitor.java22 *23 * Created on March 28, 2006, 6:09 PM24 *25 * To change this template, choose Tools | Template Manager26 * and open the template in the editor.27 */28 29 package org.netbeans.modules.xml.wsdl.ui.schema.visitor;30 31 import java.util.Collection ;32 import java.util.Iterator ;33 import org.netbeans.modules.xml.schema.model.All;34 import org.netbeans.modules.xml.schema.model.Annotation;35 import org.netbeans.modules.xml.schema.model.AnyAttribute;36 import org.netbeans.modules.xml.schema.model.AnyElement;37 import org.netbeans.modules.xml.schema.model.AppInfo;38 import org.netbeans.modules.xml.schema.model.AttributeGroupReference;39 import org.netbeans.modules.xml.schema.model.AttributeReference;40 import org.netbeans.modules.xml.schema.model.Choice;41 import org.netbeans.modules.xml.schema.model.ComplexContent;42 import org.netbeans.modules.xml.schema.model.ComplexContentDefinition;43 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;44 import org.netbeans.modules.xml.schema.model.ComplexExtension;45 import org.netbeans.modules.xml.schema.model.ComplexExtensionDefinition;46 import org.netbeans.modules.xml.schema.model.ComplexType;47 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;48 import org.netbeans.modules.xml.schema.model.Documentation;49 import org.netbeans.modules.xml.schema.model.ElementReference;50 import org.netbeans.modules.xml.schema.model.Enumeration;51 import org.netbeans.modules.xml.schema.model.Field;52 import org.netbeans.modules.xml.schema.model.FractionDigits;53 import org.netbeans.modules.xml.schema.model.GlobalAttribute;54 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup;55 import org.netbeans.modules.xml.schema.model.GlobalComplexType;56 import org.netbeans.modules.xml.schema.model.GlobalElement;57 import org.netbeans.modules.xml.schema.model.GlobalGroup;58 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;59 import org.netbeans.modules.xml.schema.model.GlobalType;60 import org.netbeans.modules.xml.schema.model.GroupReference;61 import org.netbeans.modules.xml.schema.model.Import;62 import org.netbeans.modules.xml.schema.model.Include;63 import org.netbeans.modules.xml.schema.model.Key;64 import org.netbeans.modules.xml.schema.model.KeyRef;65 import org.netbeans.modules.xml.schema.model.Length;66 import org.netbeans.modules.xml.schema.model.List;67 import org.netbeans.modules.xml.schema.model.LocalAttribute;68 import org.netbeans.modules.xml.schema.model.LocalComplexType;69 import org.netbeans.modules.xml.schema.model.LocalElement;70 import org.netbeans.modules.xml.schema.model.LocalGroupDefinition;71 import org.netbeans.modules.xml.schema.model.LocalSimpleType;72 import org.netbeans.modules.xml.schema.model.LocalType;73 import org.netbeans.modules.xml.schema.model.MaxExclusive;74 import org.netbeans.modules.xml.schema.model.MaxInclusive;75 import org.netbeans.modules.xml.schema.model.MaxLength;76 import org.netbeans.modules.xml.schema.model.MinExclusive;77 import org.netbeans.modules.xml.schema.model.MinInclusive;78 import org.netbeans.modules.xml.schema.model.MinLength;79 import org.netbeans.modules.xml.schema.model.Notation;80 import org.netbeans.modules.xml.schema.model.Pattern;81 import org.netbeans.modules.xml.schema.model.Redefine;82 import org.netbeans.modules.xml.schema.model.Schema;83 import org.netbeans.modules.xml.schema.model.SchemaComponent;84 import org.netbeans.modules.xml.schema.model.Selector;85 import org.netbeans.modules.xml.schema.model.Sequence;86 import org.netbeans.modules.xml.schema.model.SequenceDefinition;87 import org.netbeans.modules.xml.schema.model.SimpleContent;88 import org.netbeans.modules.xml.schema.model.SimpleContentDefinition;89 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;90 import org.netbeans.modules.xml.schema.model.SimpleExtension;91 import org.netbeans.modules.xml.schema.model.SimpleType;92 import org.netbeans.modules.xml.schema.model.SimpleTypeDefinition;93 import org.netbeans.modules.xml.schema.model.SimpleTypeRestriction;94 import org.netbeans.modules.xml.schema.model.TotalDigits;95 import org.netbeans.modules.xml.schema.model.TypeContainer;96 import org.netbeans.modules.xml.schema.model.Union;97 import org.netbeans.modules.xml.schema.model.Unique;98 import org.netbeans.modules.xml.schema.model.Whitespace;99 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;100 101 /**102 *103 * @author radval104 */105 public abstract class AbstractXSDVisitor implements XSDVisitor {106 107 /** Creates a new instance of AbstractXSDVisitor */108 public AbstractXSDVisitor() {109 }110 111 public void visit(All all) {112 Collection <LocalElement> allElements = all.getElements();113 Iterator <LocalElement> it = allElements.iterator();114 while(it.hasNext()) {115 LocalElement element = it.next();116 visit(element);117 }118 }119 120 121 public void visit(Annotation ann) {122 // TODO Auto-generated method stub123 124 }125 126 public void visit(AnyAttribute anyAttr) {127 // TODO Auto-generated method stub128 129 }130 131 public void visit(AnyElement any) {132 // TODO Auto-generated method stub133 134 }135 136 public void visit(AppInfo appinfo) {137 // TODO Auto-generated method stub138 139 }140 141 public void visit(AttributeGroupReference agr) {142 NamedComponentReference<GlobalAttributeGroup> gagRef = agr.getGroup();143 if(gagRef != null && gagRef.get() != null) {144 visit(gagRef.get());145 }146 }147 148 public void visit(AttributeReference reference) {149 NamedComponentReference<GlobalAttribute> gaRef = reference.getRef();150 if(gaRef != null && gaRef.get() != null) {151 visit(gaRef.get());152 }153 154 }155 156 public void visit(Choice choice) {157 java.util.List <SchemaComponent> children = choice.getChildren();158 Iterator <SchemaComponent> it = children.iterator();159 160 while(it.hasNext()) {161 SchemaComponent comp = it.next();162 if(comp instanceof AnyElement) {163 visit((AnyElement) comp);164 } else if(comp instanceof Choice) {165 visit((Choice) comp);166 } else if(comp instanceof ElementReference) {167 visit((ElementReference) comp);168 } else if(comp instanceof GroupReference) {169 visit((GroupReference) comp);170 } else if(comp instanceof LocalElement) {171 visit((LocalElement) comp);172 } else if(comp instanceof Sequence) {173 visit((Sequence) comp);174 } 175 }176 }177 178 179 180 public void visit(Documentation d) {181 // TODO Auto-generated method stub182 183 }184 185 public void visit(ElementReference er) {186 NamedComponentReference<GlobalElement> ref = er.getRef();187 if(ref != null && ref.get() != null) {188 visit(ref.get());189 }190 191 }192 193 public void visit(Enumeration e) {194 // TODO Auto-generated method stub195 196 }197 198 public void visit(Field f) {199 // TODO Auto-generated method stub200 201 }202 203 public void visit(FractionDigits fd) {204 // TODO Auto-generated method stub205 206 }207 208 public void visit(GlobalAttribute ga) {209 // TODO Auto-generated method stub210 211 }212 213 public void visit(GlobalAttributeGroup gag) {214 java.util.List <SchemaComponent> children = gag.getChildren();215 Iterator <SchemaComponent> it = children.iterator();216 217 while(it.hasNext()) {218 SchemaComponent sc = it.next();219 if(sc instanceof LocalAttribute) {220 visit((LocalAttribute) sc);221 } else if(sc instanceof AttributeReference) {222 visit((AttributeReference) sc );223 } else if(sc instanceof AttributeGroupReference) {224 visit((AttributeGroupReference) sc);225 }226 }227 228 }229 230 231 public void visit(GlobalElement ge) {232 visitTypeContainer(ge);233 }234 235 236 public void visit(GroupReference gr) {237 NamedComponentReference<GlobalGroup> ggRef = gr.getRef();238 if(ggRef != null && ggRef.get() != null) {239 visit(ggRef.get());240 }241 242 }243 244 245 public void visit(Import im) {246 // TODO Auto-generated method stub247 248 }249 250 public void visit(Include include) {251 // TODO Auto-generated method stub252 253 }254 255 public void visit(Key key) {256 // TODO Auto-generated method stub257 258 }259 260 public void visit(KeyRef kr) {261 // TODO Auto-generated method stub262 263 }264 265 public void visit(Length length) {266 // TODO Auto-generated method stub267 268 }269 270 public void visit(List l) {271 // TODO Auto-generated method stub272 273 }274 275 public void visit(LocalAttribute la) {276 // TODO Auto-generated method stub277 278 }279 280 281 public void visit(LocalElement le) {282 visitTypeContainer(le);283 }284 285 286 public void visit(MaxExclusive me) {287 // TODO Auto-generated method stub288 289 }290 291 public void visit(MaxInclusive mi) {292 // TODO Auto-generated method stub293 294 }295 296 public void visit(MaxLength ml) {297 // TODO Auto-generated method stub298 299 }300 301 public void visit(MinExclusive me) {302 // TODO Auto-generated method stub303 304 }305 306 public void visit(MinInclusive mi) {307 // TODO Auto-generated method stub308 309 }310 311 public void visit(MinLength ml) {312 // TODO Auto-generated method stub313 314 }315 316 public void visit(Notation notation) {317 // TODO Auto-generated method stub318 319 }320 321 public void visit(Pattern p) {322 // TODO Auto-generated method stub323 324 }325 326 public void visit(Redefine rd) {327 // TODO Auto-generated method stub328 329 }330 331 public void visit(Schema s) {332 java.util.List <SchemaComponent> children = s.getChildren();333 Iterator <SchemaComponent> it = children.iterator();334 335 while(it.hasNext()) {336 SchemaComponent sc = it.next();337 if(sc instanceof GlobalAttributeGroup) {338 visit((GlobalAttributeGroup) sc);339 }else if(sc instanceof GlobalAttribute) {340 visit((GlobalAttribute) sc);341 }else if(sc instanceof GlobalComplexType) {342 visit((GlobalComplexType) sc);343 }else if(sc instanceof GlobalElement) {344 visit((GlobalElement) sc);345 }else if(sc instanceof GlobalGroup) {346 visit((GlobalGroup) sc);347 }else if(sc instanceof Import) {348 visit((Import) sc);349 }else if(sc instanceof Include) {350 visit((Include) sc);351 }else if(sc instanceof Redefine) {352 visit((Redefine) sc);353 }354 }355 }356 357 public void visit(Selector s) {358 // TODO Auto-generated method stub359 360 }361 362 public void visit(SimpleContent sc) {363 SimpleContentDefinition scd = sc.getLocalDefinition();364 if(scd instanceof SimpleContentRestriction) {365 visit((SimpleContentRestriction) scd);366 } else if(scd instanceof SimpleExtension) {367 visit((SimpleExtension) scd);368 }369 370 }371 372 public void visit(SimpleContentRestriction scr) {373 NamedComponentReference<GlobalType> baseRef = scr.getBase();374 if(baseRef != null && baseRef.get() != null) {375 visit(baseRef.get());376 } 377 378 java.util.List <SchemaComponent> children = scr.getChildren();379 Iterator <SchemaComponent> it = children.iterator();380 381 while(it.hasNext()) {382 SchemaComponent sc = it.next();383 if(sc instanceof AttributeGroupReference) {384 visit((AttributeGroupReference) sc);385 } else if(sc instanceof AttributeReference) {386 visit((AttributeReference) sc);387 } else if(sc instanceof Enumeration) {388 visit((Enumeration) sc);389 } else if(sc instanceof FractionDigits) {390 visit((FractionDigits) sc);391 } else if(sc instanceof LocalAttribute) {392 visit((LocalAttribute) sc);393 }else if(sc instanceof LocalSimpleType) {394 visit((LocalSimpleType) sc);395 }else if(sc instanceof Length) {396 visit((Length) sc);397 }else if(sc instanceof MaxExclusive) {398 visit((MaxExclusive) sc);399 }else if(sc instanceof MinExclusive) {400 visit((MinExclusive) sc);401 }else if(sc instanceof MaxLength) {402 visit((MaxLength) sc);403 }else if(sc instanceof MinLength) {404 visit((MinLength) sc);405 }406 }407 408 }409 410 public void visit(SimpleExtension se) {411 // TODO Auto-generated method stub412 413 }414 415 public void visit(SimpleTypeRestriction str) {416 NamedComponentReference<GlobalSimpleType> baseRef = str.getBase();417 if(baseRef != null && baseRef.get() != null) {418 visit(baseRef.get());419 }420 421 422 }423 424 public void visit(TotalDigits td) {425 // TODO Auto-generated method stub426 427 }428 429 public void visit(Union u) {430 // TODO Auto-generated method stub431 432 }433 434 public void visit(Unique u) {435 // TODO Auto-generated method stub436 437 }438 439 public void visit(Whitespace ws) {440 // TODO Auto-generated method stub441 442 }443 444 public void visit(LocalComplexType type) {445 visit((ComplexType) type);446 }447 448 public void visit(LocalSimpleType type) {449 visit((SimpleType) type);450 }451 452 public void visit(Sequence s) {453 visit(s.getContent());454 }455 456 457 public void visit(ComplexContentRestriction ccr) {458 NamedComponentReference<GlobalComplexType> baseRef = ccr.getBase();459 if(baseRef != null) {460 GlobalComplexType gType = baseRef.get();461 if(gType != null) {462 visit(gType);463 }464 }465 466 java.util.List children = ccr.getChildren();467 Iterator it = children.iterator();468 while(it.hasNext()) {469 Object child = it.next();470 471 if(child instanceof AnyAttribute) {472 visit((AnyAttribute) child);473 } else if(child instanceof AttributeGroupReference) {474 visit((AttributeGroupReference) child);475 } else if(child instanceof AttributeReference) {476 visit((AttributeReference) child);477 } else if (child instanceof LocalAttribute) {478 visit((LocalAttribute) child);479 } else if (child instanceof ComplexTypeDefinition) {480 visit((ComplexTypeDefinition) child);481 }482 }483 }484 485 public void visit(ComplexExtension ce) {486 NamedComponentReference<GlobalType> baseRef = ce.getBase();487 if(baseRef != null) {488 GlobalType gType = baseRef.get();489 if(gType != null) {490 visit(gType);491 }492 }493 494 java.util.List children = ce.getChildren();495 Iterator it = children.iterator();496 while(it.hasNext()) {497 Object child = it.next();498 499 if(child instanceof LocalAttribute) {500 visit((LocalAttribute) child);501 }else if(child instanceof AnyAttribute) {502 visit((AnyAttribute) child);503 } else if(child instanceof AttributeGroupReference) {504 visit((AttributeGroupReference) child);505 } else if(child instanceof AttributeReference) {506 visit((AttributeReference) child);507 } else if (child instanceof ComplexExtensionDefinition) {508 visit((ComplexExtensionDefinition) child);509 }510 }511 }512 513 public void visit(ComplexContent cc) {514 ComplexContentDefinition ccd = cc.getLocalDefinition();515 if(ccd != null) {516 visit(ccd);517 }518 }519 520 521 522 523 524 public void visit(GlobalComplexType gct) {525 visit((ComplexType) gct);526 }527 528 529 public void visit(GlobalGroup gd) {530 LocalGroupDefinition lgd = gd.getDefinition();531 if(lgd != null) {532 if(lgd instanceof Choice) {533 visit((Choice) lgd);534 } else if(lgd instanceof All) {535 visit((All) lgd );536 } else if(lgd instanceof Sequence) {537 visit((Sequence)lgd);538 }539 }540 }541 542 public void visit(GlobalSimpleType gst) {543 visit((SimpleType) gst);544 }545 546 protected void visitTypeContainer(TypeContainer tc) {547 if(tc.getType() != null) {548 GlobalType gt = tc.getType().get();549 visit(gt);550 } else {551 LocalType lt = tc.getInlineType();552 visit(lt);553 }554 }555 556 protected void visit(GlobalType gt) {557 if(gt instanceof ComplexType) {558 visit((GlobalComplexType) gt);559 } else if(gt instanceof SimpleType) {560 visit((GlobalSimpleType) gt);561 }562 }563 564 protected void visit(LocalType lt) {565 if(lt instanceof ComplexType) {566 visit((LocalComplexType) lt);567 } else if(lt instanceof SimpleType) {568 visit((LocalSimpleType) lt);569 }570 }571 572 private void visit(ComplexTypeDefinition ctd) {573 if (ctd instanceof All) {574 visit((All) ctd);575 } else if (ctd instanceof Choice) {576 visit((Choice) ctd);577 } else if (ctd instanceof Sequence) {578 visit((Sequence) ctd);579 } else if(ctd instanceof ComplexContent) {580 visit((ComplexContent) ctd);581 } else if(ctd instanceof GroupReference) {582 visit((GroupReference) ctd);583 } else if (ctd instanceof SimpleContent) {584 visit((SimpleContent) ctd);585 }586 }587 588 private void visit(ComplexContentDefinition ccd) {589 590 if(ccd instanceof ComplexContentRestriction) {591 visit((ComplexContentRestriction) ccd);592 } else if(ccd instanceof ComplexExtension) {593 visit((ComplexExtension) ccd);594 }595 596 }597 598 private void visit(ComplexExtensionDefinition ced) {599 if (ced instanceof All) {600 visit((All) ced);601 } else if (ced instanceof Choice) {602 visit((Choice) ced);603 } else if (ced instanceof Sequence) {604 visit((Sequence) ced);605 } else if(ced instanceof GroupReference) {606 visit((GroupReference) ced);607 }608 }609 610 private void visit(java.util.List <SequenceDefinition> sdList) {611 Iterator <SequenceDefinition> it = sdList.iterator();612 while(it.hasNext()) {613 SequenceDefinition sd = it.next();614 if(sd instanceof Sequence) {615 visit((Sequence) sd);616 } else if(sd instanceof AnyElement) {617 visit((AnyElement) sd);618 } else if(sd instanceof Choice) {619 visit((Choice) sd);620 } else if(sd instanceof ElementReference) {621 visit((ElementReference) sd);622 } else if(sd instanceof GroupReference) {623 visit((GroupReference) sd);624 } else if(sd instanceof LocalElement) {625 visit((LocalElement) sd);626 }627 628 }629 }630 631 private void visit(SimpleType st) {632 SimpleTypeDefinition std = st.getDefinition();633 if(std != null) {634 visit(std);635 }636 }637 638 private void visit(SimpleTypeDefinition std) {639 if(std instanceof List) {640 visit((List) std);641 } else if(std instanceof Union) {642 visit((Union) std);643 } else if(std instanceof SimpleTypeRestriction) {644 visit((SimpleTypeRestriction) std);645 }646 }647 648 private void visit(ComplexType ct) {649 java.util.List <SchemaComponent> children = ct.getChildren();650 Iterator <SchemaComponent> it = children.iterator();651 while(it.hasNext()) {652 SchemaComponent sc = it.next();653 if(sc instanceof AnyAttribute) {654 visit((AnyAttribute) sc );655 } else if(sc instanceof AttributeGroupReference) {656 visit((AttributeGroupReference) sc);657 }else if(sc instanceof AttributeReference) {658 visit((AttributeReference) sc);659 }else if(sc instanceof LocalAttribute) {660 visit((LocalAttribute) sc);661 }else if(sc instanceof ComplexTypeDefinition) {662 visit((ComplexTypeDefinition) sc);663 }664 }665 666 //search TypeContainer667 //getAttributeGroupReferences668 669 }670 }671