1 16 package org.apache.ws.jaxme.generator.sg.impl; 17 18 import org.apache.ws.jaxme.generator.sg.Context; 19 import org.apache.ws.jaxme.generator.sg.GroupSG; 20 import org.apache.ws.jaxme.generator.sg.GroupSGChain; 21 import org.apache.ws.jaxme.generator.sg.ParticleSG; 22 import org.apache.ws.jaxme.generator.sg.ParticleSGChain; 23 import org.apache.ws.jaxme.generator.sg.SGFactory; 24 import org.apache.ws.jaxme.generator.sg.SchemaSG; 25 import org.apache.ws.jaxme.xs.XSGroup; 26 import org.apache.ws.jaxme.xs.XSParticle; 27 import org.apache.ws.jaxme.xs.xml.XsQName; 28 import org.xml.sax.Locator ; 29 import org.xml.sax.SAXException ; 30 31 32 35 public class JAXBGroupSG extends JAXBSGItem implements GroupSGChain { 36 private ParticleSG[] particles; 37 private final boolean isGlobal, isAll, isSequence, isChoice; 38 private final Context classContext; 39 private final XsQName qName; 40 41 43 protected JAXBGroupSG(SGFactory pFactory, SchemaSG pSchema, XSGroup pGroup) throws SAXException { 44 super(pFactory, pSchema, pGroup); 45 isGlobal = true; 46 qName = pGroup.getName(); 47 isAll = pGroup.isAll(); 48 isSequence = pGroup.isSequence(); 49 isChoice = pGroup.isChoice(); 50 classContext = new GlobalContext(pGroup.getName(), pGroup, null, "Group", pSchema); 51 } 52 53 55 protected JAXBGroupSG(SGFactory pFactory, SchemaSG pSchema, XSGroup pGroup, Context pContext) 56 throws SAXException { 57 super(pFactory, pSchema, pGroup); 58 isGlobal = pGroup.isGlobal(); 59 qName = isGlobal ? pGroup.getName() : null; 60 isAll = pGroup.isAll(); 61 isSequence = pGroup.isSequence(); 62 isChoice = pGroup.isChoice(); 63 classContext = pContext; 64 } 65 66 public Object newParticleSG(GroupSG pController, XSParticle pParticle) throws SAXException { 67 return new JAXBParticleSG(pController.getFactory(), pParticle, classContext); 68 } 69 70 public Context getClassContext(GroupSG pController) { return classContext; } 71 72 public SGFactory getFactory(GroupSG pController) { return getFactory(); } 73 public SchemaSG getSchema(GroupSG pController) { return getSchema(); } 74 public Locator getLocator(GroupSG pController) { return getLocator(); } 75 public ParticleSG[] getParticles(GroupSG pController) throws SAXException { 76 if (particles == null) { 77 XSParticle[] xsParticles = ((XSGroup) getXSObject()).getParticles(); 78 particles = new ParticleSG[xsParticles.length]; 79 for (int i = 0; i < xsParticles.length; i++) { 80 ParticleSGChain chain = (ParticleSGChain) pController.newParticleSG(xsParticles[i]); 81 ParticleSG particle = new ParticleSGImpl(chain); 82 particle.init(); 83 particles[i] = particle; 84 } 85 } 86 return particles; 87 } 88 89 public void init(GroupSG pController) throws SAXException { 90 } 91 92 public boolean isAll(GroupSG pController) { return isAll; } 93 public boolean isGlobal(GroupSG pController) { return isGlobal; } 94 public boolean isChoice(GroupSG pController) { return isChoice; } 95 public boolean isSequence(GroupSG pController) { return isSequence; } 96 97 public XsQName getName(GroupSG pController) { 98 if (qName == null) { 99 throw new IllegalStateException ("Attempt to obtain a local groups name."); 100 } 101 return qName; 102 } 103 } 104 | Popular Tags |