Package org.jibx.schema.elements

Examples of org.jibx.schema.elements.CommonCompositorDefinition


                    case SchemaBase.ALL_TYPE:
                    case SchemaBase.CHOICE_TYPE:
                    case SchemaBase.SEQUENCE_TYPE:
                    {
                        // child component is a compositor, so see if it can be deleted or replaced
                        CommonCompositorDefinition compositor = (CommonCompositorDefinition)childcomp;
                        int size = compositor.getParticleList().size();
                        if (size == 0) {
                           
                            // empty compositor, just remove (always safe to do this)
                            childext.setRemoved(true);
                            modified = true;
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug(lead + "eliminated empty compositor " + path);
                            }
                           
                        } else if (size == 1) {
                           
                            // single component in compositor, first try to convert compositor to singleton
                            OpenAttrBase grandchild = (OpenAttrBase)compositor.getParticleList().get(0);
                            IArity particle = (IArity)grandchild;
                            if (SchemaUtils.isRepeated(compositor)) {
                                if (!SchemaUtils.isRepeated(particle)) {
                                   
                                    // repeated compositor with non-repeated particle, so pass repeat to particle
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "passing repeat from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " to only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    particle.setMaxOccurs(compositor.getMaxOccurs());
                                    ((ComponentExtension)grandchild.getExtension()).setRepeated(true);
                                    compositor.setMaxOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setRepeated(false);
                                   
                                } else if ((compositor.getMaxOccurs().isUnbounded() &&
                                    particle.getMaxOccurs().isUnbounded())) {
                                   
                                    // unbounded compositor with unbounded particle, just wipe repeat from compositor
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "clearing unbounded from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " with unbounded only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    compositor.setMaxOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setRepeated(false);
                                   
                                }
                            }
                            if (SchemaUtils.isOptional(compositor)) {
                                if (SchemaUtils.isOptional(particle)) {
                                   
                                    // optional compositor with optional particle, just wipe optional from compositor
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "clearing optional from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " with optional only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    compositor.setMinOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setOptional(false);
                                   
                                } else if (Count.isCountEqual(1, particle.getMinOccurs())) {
                                   
                                    // optional compositor with required particle, so pass optional to particle
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "passing optional from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " to required only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    particle.setMinOccurs(Count.COUNT_ZERO);
                                    ((ComponentExtension)grandchild.getExtension()).setOptional(true);
                                    compositor.setMinOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setOptional(false);
                                   
                                }
                            }
                           
                            // check if top component is also a compositor
                            if (topcomp instanceof CommonCompositorDefinition) {
                               
                                // nested compositor, check if can be simplified
                                if (SchemaUtils.isSingleton(compositor)) {
                                   
                                    // nested singleton compositor with only child, just replace with the child
                                    topcomp.replaceChild(i, grandchild);
                                    modified = true;
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "replacing singleton compositor " +
                                            SchemaUtils.componentPath(childcomp) + " with only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                   
                                } else if (compositor instanceof ChoiceElement) {
                                   
                                    // replace choice with sequence to simplify handling, since just one particle
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "substituting sequence for choice " +
                                            SchemaUtils.componentPath(childcomp) + " with only one child");
                                    }
                                    SequenceElement sequence = new SequenceElement();
                                    sequence.setAnnotation(compositor.getAnnotation());
                                    sequence.setExtension(compositor.getExtension());
                                    sequence.setMaxOccurs(compositor.getMaxOccurs());
                                    sequence.setMinOccurs(compositor.getMinOccurs());
                                    sequence.getParticleList().add(grandchild);
                                    topcomp.replaceChild(i, sequence);
                                    modified = true;
                                   
                                }
View Full Code Here


     */
    private CommonCompositorDefinition buildCompositor(ContainerElementBase cont, int offset, boolean repeat,
        SchemaHolder hold) {
       
        // start with the appropriate type of compositor
        CommonCompositorDefinition cdef;
        if (cont.isChoice()) {
           
            // choice container goes directly to choice compositor
            cdef = new ChoiceElement();
           
        } else if (cont.isOrdered()) {
           
            // ordered container goes directly to sequence compositor
            cdef = new SequenceElement();
           
        } else if (repeat) {
           
            // unordered repeat treated as repeated choice compositor
            cdef = new ChoiceElement();
            cdef.setMaxOccurs(Count.COUNT_UNBOUNDED);
           
        } else {
           
            // unordered non-repeat treated as all compositor
            // TODO: verify conditions for all
            cdef = new AllElement();
        }
       
        // generate schema equivalents for content components of container
        ArrayList comps = cont.getContentComponents();
        for (int i = offset; i < comps.size(); i++) {
            IComponent comp = (IComponent)comps.get(i);
            if (comp.hasName()) {
               
                // create element for named content component
                ElementElement element = buildElement(comp, repeat, hold);
                if (comp instanceof StructureElementBase) {
                    addItemDocumentation((StructureElementBase)comp, element);
                }
                cdef.getParticleList().add(element);
               
            } else if (comp instanceof ContainerElementBase) {
                ContainerElementBase contain = (ContainerElementBase)comp;
                boolean iscoll = comp instanceof CollectionElement;
                if (contain.children().size() > 0) {
                   
                    // no element name, but children; handle with recursive call
                    CommonCompositorDefinition part = buildCompositor(contain, 0, iscoll, hold);
                    addCompositorPart(part, cdef);
                   
                } else if (iscoll) {
                   
                    // collection without a wrapper element
View Full Code Here

            if (isComplexContent(base) || isComplexContent(mapping)) {
               
                // complex extension with complex content
                ComplexExtensionElement ext = new ComplexExtensionElement();
                setComplexExtensionBase(basedet.getTypeName(), ext, hold);
                CommonCompositorDefinition comp = buildCompositor(mapping, 1, false, hold);
                if (comp.getParticleList().size() > 0) {
                    ext.setContentDefinition(comp);
                }
                fillAttributes(mapping, 0, ext.getAttributeList(), hold);
                ComplexContentElement cont = new ComplexContentElement();
                cont.setDerivation(ext);
View Full Code Here

TOP

Related Classes of org.jibx.schema.elements.CommonCompositorDefinition

Copyright © 2018 www.massapicom. 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.