Search in sources :

Example 1 with XmlSchemaChoiceMember

use of org.apache.ws.commons.schema.XmlSchemaChoiceMember in project cxf by apache.

the class ParticleInfo method forLocalItem.

/**
 * Fill in an ElementInfo for an element or xs:any from a sequence.
 *
 * @param sequenceElement
 * @param currentSchema
 * @param schemaCollection
 * @param prefixAccumulator
 * @return
 */
public static ParticleInfo forLocalItem(XmlSchemaObject sequenceObject, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, QName contextName) {
    XmlSchemaParticle sequenceParticle = JavascriptUtils.getObjectParticle(sequenceObject, contextName, currentSchema);
    ParticleInfo elementInfo = new ParticleInfo();
    XmlSchemaParticle realParticle = sequenceParticle;
    elementInfo.setMinOccurs(sequenceParticle.getMinOccurs());
    elementInfo.setMaxOccurs(sequenceParticle.getMaxOccurs());
    if (sequenceParticle instanceof XmlSchemaElement) {
        XmlSchemaElement sequenceElement = (XmlSchemaElement) sequenceParticle;
        if (sequenceElement.getRef().getTargetQName() != null) {
            XmlSchemaElement refElement = sequenceElement.getRef().getTarget();
            if (refElement == null) {
                Message message = new Message("ELEMENT_DANGLING_REFERENCE", LOG, sequenceElement.getQName(), sequenceElement.getRef().getTargetQName());
                throw new UnsupportedConstruct(message.toString());
            }
            realParticle = refElement;
            elementInfo.global = true;
        }
        elementInfo.nillable = ((XmlSchemaElement) realParticle).isNillable();
    } else if (sequenceParticle instanceof XmlSchemaChoice) {
        XmlSchemaChoice choice = (XmlSchemaChoice) sequenceParticle;
        if (sequenceParticle.getMaxOccurs() > 1) {
            Message message = new Message("GROUP_ELEMENT_MULTI_OCCURS", LOG, sequenceParticle.getClass().getSimpleName());
            throw new UnsupportedConstruct(message.toString());
        }
        elementInfo.children = new LinkedList<>();
        List<XmlSchemaChoiceMember> items = choice.getItems();
        for (XmlSchemaChoiceMember item : items) {
            XmlSchemaObject schemaObject = JavascriptUtils.getObjectParticle((XmlSchemaObject) item, contextName, currentSchema);
            ParticleInfo childParticle = ParticleInfo.forLocalItem(schemaObject, currentSchema, schemaCollection, prefixAccumulator, contextName);
            if (childParticle.isAny()) {
                Message message = new Message("GROUP_ELEMENT_ANY", LOG, sequenceParticle.getClass().getSimpleName());
                throw new UnsupportedConstruct(message.toString());
            }
            childParticle.setMinOccurs(0);
            elementInfo.children.add(childParticle);
        }
    } else if (sequenceParticle instanceof XmlSchemaSequence) {
        XmlSchemaSequence nestedSequence = (XmlSchemaSequence) sequenceParticle;
        if (sequenceParticle.getMaxOccurs() > 1) {
            Message message = new Message("SEQUENCE_ELEMENT_MULTI_OCCURS", LOG, sequenceParticle.getClass().getSimpleName());
            throw new UnsupportedConstruct(message.toString());
        }
        elementInfo.children = new LinkedList<>();
        List<XmlSchemaSequenceMember> items = nestedSequence.getItems();
        for (XmlSchemaSequenceMember item : items) {
            XmlSchemaObject schemaObject = JavascriptUtils.getObjectParticle((XmlSchemaObject) item, contextName, currentSchema);
            ParticleInfo childParticle = ParticleInfo.forLocalItem(schemaObject, currentSchema, schemaCollection, prefixAccumulator, contextName);
            if (childParticle.isAny()) {
                Message message = new Message("SEQUENCE_ELEMENT_ANY", LOG, sequenceParticle.getClass().getSimpleName());
                throw new UnsupportedConstruct(message.toString());
            }
            if (sequenceParticle.getMinOccurs() == 0) {
                childParticle.setMinOccurs(0);
            }
            elementInfo.children.add(childParticle);
        }
    }
    factoryCommon(realParticle, currentSchema, schemaCollection, prefixAccumulator, elementInfo);
    elementInfo.particle = realParticle;
    return elementInfo;
}
Also used : Message(org.apache.cxf.common.i18n.Message) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) LinkedList(java.util.LinkedList) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaChoiceMember(org.apache.ws.commons.schema.XmlSchemaChoiceMember) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 Message (org.apache.cxf.common.i18n.Message)1 XmlSchemaChoice (org.apache.ws.commons.schema.XmlSchemaChoice)1 XmlSchemaChoiceMember (org.apache.ws.commons.schema.XmlSchemaChoiceMember)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)1 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)1 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)1 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)1