use of org.apache.ws.commons.schema.XmlSchemaParticle in project cxf by apache.
the class JavascriptUtils method getAll.
public static XmlSchemaAll getAll(XmlSchemaComplexType type) {
XmlSchemaParticle particle = type.getParticle();
XmlSchemaAll all = null;
if (particle == null) {
// a null pointer, and certainly an exception.
return EMPTY_ALL;
}
try {
all = (XmlSchemaAll) particle;
} catch (ClassCastException cce) {
unsupportedConstruct("NON_CHOICE_PARTICLE", type);
}
return all;
}
use of org.apache.ws.commons.schema.XmlSchemaParticle in project cxf by apache.
the class JavascriptUtils method getContentSequence.
public static XmlSchemaSequence getContentSequence(XmlSchemaComplexType type) {
XmlSchemaContentModel model = type.getContentModel();
if (model == null) {
return null;
}
XmlSchemaContent content = model.getContent();
if (content == null) {
return null;
}
if (!(content instanceof XmlSchemaComplexContentExtension)) {
return null;
}
XmlSchemaComplexContentExtension ext = (XmlSchemaComplexContentExtension) content;
XmlSchemaParticle particle = ext.getParticle();
if (particle == null) {
return null;
}
XmlSchemaSequence sequence = null;
try {
sequence = (XmlSchemaSequence) particle;
} catch (ClassCastException cce) {
unsupportedConstruct("NON_SEQUENCE_PARTICLE", type);
}
return sequence;
}
use of org.apache.ws.commons.schema.XmlSchemaParticle 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;
}
use of org.apache.ws.commons.schema.XmlSchemaParticle in project tomee by apache.
the class SchemaCollection method addCrossImports.
private void addCrossImports(XmlSchema schema, XmlSchemaContentModel contentModel) {
if (contentModel == null) {
return;
}
XmlSchemaContent content = contentModel.getContent();
if (content == null) {
return;
}
if (content instanceof XmlSchemaComplexContentExtension) {
XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
addCrossImportsAttributeList(schema, extension.getAttributes());
XmlSchemaParticle particle = extension.getParticle();
if (particle instanceof XmlSchemaSequence) {
addCrossImports(schema, (XmlSchemaSequence) particle);
} else if (particle instanceof XmlSchemaChoice) {
addCrossImports(schema, (XmlSchemaChoice) particle);
} else if (particle instanceof XmlSchemaAll) {
addCrossImports(schema, (XmlSchemaAll) particle);
}
} else if (content instanceof XmlSchemaComplexContentRestriction) {
XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
addCrossImportsAttributeList(schema, restriction.getAttributes());
} else if (content instanceof XmlSchemaSimpleContentExtension) {
XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
addCrossImportsAttributeList(schema, extension.getAttributes());
} else if (content instanceof XmlSchemaSimpleContentRestriction) {
XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
addCrossImportsAttributeList(schema, restriction.getAttributes());
}
}
use of org.apache.ws.commons.schema.XmlSchemaParticle in project tomee by apache.
the class CommonsSchemaInfoBuilder method extractSoapArrayComponentType.
/**
* Extract the nested component type of an Array from the XML Schema Type.
*
* @return the QName of the nested component type or null if the schema type can not be determined
* @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType
*/
private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) {
// Soap arrays are based on complex content restriction
if (!isSoapArray(complexType)) {
return null;
}
XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType.getContentModel().getContent();
// First, handle case that looks like this:
// <complexType name="ArrayOfstring">
// <complexContent>
// <restriction base="soapenc:Array">
// <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
// </restriction>
// </complexContent>
// </complexType>
XmlSchemaObjectCollection attributes = restriction.getAttributes();
for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
Object item = iterator.next();
if (item instanceof XmlSchemaAttribute) {
XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) {
for (Attr attr : attribute.getUnhandledAttributes()) {
QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName());
if (WSDL_ARRAY_TYPE.equals(attQName)) {
// value is a namespace prefixed xsd type
String value = attr.getValue();
// extract local part
int pos = value.lastIndexOf(":");
QName componentType;
if (pos < 0) {
componentType = new QName("", value);
} else {
String localPart = value.substring(pos + 1);
// resolve the namespace prefix
String prefix = value.substring(0, pos);
String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement());
componentType = new QName(namespace, localPart);
}
LOG.debug("determined component type from element type");
return componentType;
}
}
}
}
}
// If that didn't work, try to handle case like this:
// <complexType name="ArrayOfstring1">
// <complexContent>
// <restriction base="soapenc:Array">
// <sequence>
// <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
// </sequence>
// </restriction>
// </complexContent>
// </complexType>
XmlSchemaParticle particle = restriction.getParticle();
if (particle instanceof XmlSchemaSequence) {
XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
if (sequence.getItems().getCount() != 1) {
throw new IllegalArgumentException("more than one element inside array definition: " + complexType);
}
XmlSchemaObject item = sequence.getItems().getItem(0);
if (item instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) item;
QName componentType = element.getSchemaTypeName();
LOG.debug("determined component type from element type");
return componentType;
}
}
return null;
}
Aggregations