1 package org.apache.ws.jaxme.generator.sg.impl.ccsg; 2 3 import org.apache.ws.jaxme.generator.sg.ComplexContentSG; 4 import org.apache.ws.jaxme.generator.sg.ComplexTypeSG; 5 import org.apache.ws.jaxme.generator.sg.GroupSG; 6 import org.apache.ws.jaxme.generator.sg.ParticleSG; 7 import org.apache.ws.jaxme.generator.sg.TypeSG; 8 import org.xml.sax.SAXException ; 9 10 11 16 public class ParticleWalker { 17 private final ParticleVisitor visitor; 18 19 21 public ParticleWalker(ParticleVisitor pVisitor) { 22 visitor = pVisitor; 23 } 24 25 28 public void walk(ComplexTypeSG pType) throws SAXException { 29 if (pType.hasSimpleContent()) { 30 visitor.simpleContent(pType); 31 } else { 32 ComplexContentSG ccSG = pType.getComplexContentSG(); 33 if (ccSG.isEmpty()) { 34 visitor.emptyType(pType); 35 } else { 36 visitor.startComplexContent(pType); 37 walkGroup(ccSG.getRootParticle().getGroupSG()); 38 visitor.endComplexContent(pType); 39 } 40 } 41 } 42 43 46 private void walkGroup(GroupSG pGroup) throws SAXException { 47 if (pGroup.isSequence()) { 48 visitor.startSequence(pGroup); 49 walkParticles(pGroup); 50 visitor.endSequence(pGroup); 51 } else if (pGroup.isChoice()) { 52 visitor.startChoice(pGroup); 53 walkParticles(pGroup); 54 visitor.endChoice(pGroup); 55 } else if (pGroup.isAll()) { 56 visitor.startAll(pGroup); 57 walkParticles(pGroup); 58 visitor.endAll(pGroup); 59 } else { 60 throw new IllegalStateException ("Invalid group type"); 61 } 62 } 63 64 67 private void walkParticles(GroupSG pGroup) throws SAXException { 68 ParticleSG[] particles = pGroup.getParticles(); 69 for (int i = 0; i < particles.length; i++) { 70 ParticleSG particle = particles[i]; 71 if (particle.isElement()) { 72 TypeSG type = particle.getObjectSG().getTypeSG(); 73 if (type.isComplex()) { 74 visitor.complexElementParticle(pGroup, particle); 75 } else { 76 visitor.simpleElementParticle(pGroup, particle); 77 } 78 } else if (particle.isGroup()) { 79 walkGroup(particle.getGroupSG()); 80 } else if (particle.isWildcard()) { 81 visitor.wildcardParticle(particle); 82 } else { 83 throw new IllegalStateException ("Invalid particle type"); 84 } 85 } 86 } 87 } 88 | Popular Tags |