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;
}
Aggregations