Package org.apache.ws.jaxme.generator.sg.impl.ccsg

Source Code of org.apache.ws.jaxme.generator.sg.impl.ccsg.GroupBeanSG

package org.apache.ws.jaxme.generator.sg.impl.ccsg;

import org.apache.ws.jaxme.generator.sg.ComplexContentSG;
import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
import org.apache.ws.jaxme.generator.sg.GroupSG;
import org.apache.ws.jaxme.generator.sg.ObjectSG;
import org.apache.ws.jaxme.generator.sg.ParticleSG;
import org.apache.ws.jaxme.generator.sg.TypeSG;
import org.apache.ws.jaxme.generator.sg.impl.AllBeanSG;
import org.apache.ws.jaxme.generator.sg.impl.ChoiceBeanSG;
import org.apache.ws.jaxme.generator.sg.impl.SequenceBeanSG;
import org.apache.ws.jaxme.js.JavaSource;
import org.xml.sax.SAXException;


/** Base implementation of {@link BeanSG} for elements
* with complex content.
*/
public abstract class GroupBeanSG extends BeanSGImpl {
  protected final ComplexContentSG ccSG;
  protected final GroupSG group;
  protected final ParticleSG[] particles;

  protected GroupBeanSG(ComplexTypeSG pType, JavaSource pJs) throws SAXException {
    super(pType, pJs);
    ccSG = pType.getComplexContentSG();
    group = ccSG.getGroupSG();
    particles = group.getParticles();
  }

  protected GroupBeanSG(ComplexTypeSG pType, GroupSG pGroup, JavaSource pJs)
      throws SAXException {
    super(pType, pJs);
    ccSG = null;
    group = pGroup;
    particles = group.getParticles();
  }

  private GroupBeanSG newBeanSG(GroupSG pGroup) throws SAXException {
    if (pGroup.isSequence()) {
      return new SequenceBeanSG(ctSG, pGroup, null);
    } else if (pGroup.isChoice()) {
      return new ChoiceBeanSG(ctSG, pGroup, null);
    } else if (pGroup.isAll()) {
      return new AllBeanSG(ctSG, pGroup, null);
    } else {
      throw new IllegalStateException("Invalid group type");
    }
  }

  private void generateSubclasses(JavaSource pJs) throws SAXException {
    for (int i = 0;  i < particles.length;  i++) {
      ParticleSG particle = particles[i];
      if (particle.isElement()) {
        ObjectSG elementSG = particle.getObjectSG();
        TypeSG typeSG = elementSG.getTypeSG();
        if (!typeSG.isGlobalType()  &&  !typeSG.isGlobalClass()  &&  typeSG.isComplex()) {
          ComplexTypeSG complexTypeSG = typeSG.getComplexTypeSG();
          if (pJs.isInterface()) {
            complexTypeSG.getXMLInterface(pJs);
          } else {
            complexTypeSG.getXMLImplementation(pJs);
          }
            }
      } else if (particle.isGroup()) {
        GroupBeanSG beanSG = newBeanSG(particle.getGroupSG());
        beanSG.generateSubclasses(pJs);
      } else if (particle.isWildcard()) {
        throw new IllegalStateException("TODO: Add support for wildcards");
      } else {
        throw new IllegalStateException("Unknown particle type: Neither of element, group, or wildcard");
      }
    }
  }

  public void generate() throws SAXException {
    super.generate();
    JavaSource js = getJavaSource();
    generateSubclasses(js);
    ctSG.getComplexContentSG().generateProperties(js);
  }
}
TOP

Related Classes of org.apache.ws.jaxme.generator.sg.impl.ccsg.GroupBeanSG

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.