use of org.apache.xerces.xs.XSTypeDefinition in project iaf by ibissource.
the class XmlTypeToJsonSchemaConverter method buildSkippableArrayContainer.
private void buildSkippableArrayContainer(XSParticle childParticle, JsonObjectBuilder builder) {
JsonObjectBuilder refBuilder = Json.createObjectBuilder();
handleParticle(refBuilder, childParticle, null, false);
XSTerm childTerm = childParticle.getTerm();
if (childTerm instanceof XSElementDeclaration) {
XSElementDeclaration elementDeclaration = (XSElementDeclaration) childTerm;
XSTypeDefinition elementTypeDefinition = elementDeclaration.getTypeDefinition();
JsonStructure definition = getDefinition(elementTypeDefinition, true);
builder.add("type", "array");
if (elementDeclaration.getNillable()) {
definition = nillable(definition);
}
builder.add("items", definition);
}
}
use of org.apache.xerces.xs.XSTypeDefinition in project iaf by ibissource.
the class XmlTo method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
boolean xmlArrayContainer = aligner.isParentOfSingleMultipleOccurringChildElement();
boolean repeatedElement = aligner.isMultipleOccurringChildInParentElement(localName);
XSTypeDefinition typeDefinition = aligner.getTypeDefinition();
if (!localName.equals(topElement)) {
if (topElement != null) {
if (log.isTraceEnabled())
log.trace("endElementGroup [" + topElement + "]");
documentContainer.endElementGroup(topElement);
}
if (log.isTraceEnabled())
log.trace("startElementGroup [" + localName + "]");
documentContainer.startElementGroup(localName, xmlArrayContainer, repeatedElement, typeDefinition);
topElement = localName;
}
element.push(topElement);
topElement = null;
if (log.isTraceEnabled())
log.trace("startElement [" + localName + "] xml array container [" + aligner.isParentOfSingleMultipleOccurringChildElement() + "] repeated element [" + aligner.isMultipleOccurringChildInParentElement(localName) + "]");
documentContainer.startElement(localName, xmlArrayContainer, repeatedElement, typeDefinition);
super.startElement(uri, localName, qName, atts);
if (aligner.isNil(atts)) {
documentContainer.setNull();
} else {
if (writeAttributes) {
XSObjectList attributeUses = aligner.getAttributeUses();
XSWildcard wildcard = typeDefinition instanceof XSComplexTypeDefinition ? ((XSComplexTypeDefinition) typeDefinition).getAttributeWildcard() : null;
if (attributeUses == null && wildcard == null) {
if (atts.getLength() > 0) {
log.warn("found [" + atts.getLength() + "] attributes, but no declared AttributeUses");
}
} else {
if (wildcard != null) {
// if wildcard (xs:anyAttribute namespace="##any" processContents="lax") is present, then any attribute will be parsed
for (int i = 0; i < atts.getLength(); i++) {
String name = atts.getLocalName(i);
String namespace = atts.getURI(i);
String value = atts.getValue(i);
XSSimpleTypeDefinition attTypeDefinition = findAttributeTypeDefinition(attributeUses, namespace, name);
if (log.isTraceEnabled())
log.trace("startElement [" + localName + "] attribute [" + namespace + ":" + name + "] value [" + value + "]");
if (StringUtils.isNotEmpty(value)) {
documentContainer.setAttribute(name, value, attTypeDefinition);
}
}
} else {
// if no wildcard is found, then only declared attributes will be parsed
for (int i = 0; i < attributeUses.getLength(); i++) {
XSAttributeUse attributeUse = (XSAttributeUse) attributeUses.item(i);
XSAttributeDeclaration attributeDeclaration = attributeUse.getAttrDeclaration();
XSSimpleTypeDefinition attTypeDefinition = attributeDeclaration.getTypeDefinition();
String attName = attributeDeclaration.getName();
String attNS = attributeDeclaration.getNamespace();
if (log.isTraceEnabled())
log.trace("startElement [" + localName + "] searching attribute [" + attNS + ":" + attName + "]");
int attIndex = attNS != null ? atts.getIndex(attNS, attName) : atts.getIndex(attName);
if (attIndex >= 0) {
String value = atts.getValue(attIndex);
if (log.isTraceEnabled())
log.trace("startElement [" + localName + "] attribute [" + attNS + ":" + attName + "] value [" + value + "]");
if (StringUtils.isNotEmpty(value)) {
documentContainer.setAttribute(attName, value, attTypeDefinition);
}
}
}
}
}
}
}
}
Aggregations