use of org.apache.xerces.xs.XSTerm in project iaf by ibissource.
the class XmlAligner method determineIsParentOfSingleMultipleOccurringChildElement.
protected ChildOccurrence determineIsParentOfSingleMultipleOccurringChildElement(XSParticle particle) {
if (particle == null) {
log.warn("Particle is null, is this a problem? Appearantly not");
return ChildOccurrence.EMPTY;
}
XSTerm term = particle.getTerm();
if (term == null) {
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement particle.term is null");
}
if (log.isTraceEnabled())
log.trace("term name [" + term.getName() + "] occurring unbounded [" + particle.getMaxOccursUnbounded() + "] max occur [" + particle.getMaxOccurs() + "] term [" + ToStringBuilder.reflectionToString(term) + "]");
if (term instanceof XSModelGroup) {
XSModelGroup modelGroup = (XSModelGroup) term;
short compositor = modelGroup.getCompositor();
XSObjectList particles = modelGroup.getParticles();
switch(compositor) {
case XSModelGroup.COMPOSITOR_SEQUENCE:
case XSModelGroup.COMPOSITOR_ALL:
{
if (log.isTraceEnabled())
log.trace("sequence or all particles [" + ToStringBuilder.reflectionToString(particles) + "]");
ChildOccurrence result = ChildOccurrence.EMPTY;
for (int i = 0; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
ChildOccurrence current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
if (log.isTraceEnabled())
log.trace("sequence or all, particle [" + i + "] current result [" + current + "]");
switch(current) {
case EMPTY:
break;
case ONE_SINGLE_OCCURRING_ELEMENT:
case ONE_MULTIPLE_OCCURRING_ELEMENT:
if (result.ordinal() > ChildOccurrence.EMPTY.ordinal()) {
if (log.isTraceEnabled())
log.trace("sequence or all, result [" + result + "] current [" + current + "]");
return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
result = current;
break;
case MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING:
return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
default:
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement child occurrence [" + current + "]");
}
}
if (log.isTraceEnabled())
log.trace("end of sequence or all, returning [" + result + "]");
return result;
}
case XSModelGroup.COMPOSITOR_CHOICE:
{
if (log.isTraceEnabled())
log.trace("choice particles [" + ToStringBuilder.reflectionToString(particles) + "]");
if (particles.getLength() == 0) {
if (log.isTraceEnabled())
log.trace("choice length 0, returning [" + ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING + "]");
return ChildOccurrence.EMPTY;
}
ChildOccurrence result = determineIsParentOfSingleMultipleOccurringChildElement((XSParticle) particles.item(0));
if (result == ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING) {
if (log.isTraceEnabled())
log.trace("choice single mixed, returning [" + ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING + "]");
return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
for (int i = 1; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
ChildOccurrence current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
if (current != result) {
if (log.isTraceEnabled())
log.trace("break out of choice, returning [" + ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING + "]");
return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
}
if (log.isTraceEnabled())
log.trace("end of choice, returning [" + result + "]");
return result;
}
default:
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement() modelGroup.compositor is not COMPOSITOR_SEQUENCE, COMPOSITOR_ALL or COMPOSITOR_CHOICE, but [" + compositor + "]");
}
}
if (term instanceof XSElementDeclaration) {
XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
String elementName = elementDeclaration.getName();
if (log.isTraceEnabled())
log.trace("ElementDeclaration name [" + elementName + "] unbounded [" + particle.getMaxOccursUnbounded() + "] maxOccurs [" + particle.getMaxOccurs() + "]");
if (particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1) {
return ChildOccurrence.ONE_MULTIPLE_OCCURRING_ELEMENT;
}
if (particle.getMaxOccurs() == 1) {
return ChildOccurrence.ONE_SINGLE_OCCURRING_ELEMENT;
}
return ChildOccurrence.EMPTY;
}
if (term instanceof XSWildcard) {
return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement unknown Term type [" + term.getClass().getName() + "]");
}
use of org.apache.xerces.xs.XSTerm in project iaf by ibissource.
the class XmlAligner method collectChildElements.
protected void collectChildElements(XSParticle particle, Set<String> elementNames) {
if (particle == null) {
log.warn("collectChildElements() particle is null, is this a problem?");
return;
}
XSTerm term = particle.getTerm();
if (term == null) {
throw new IllegalStateException("collectChildElements() particle.term is null");
}
if (term instanceof XSModelGroup) {
XSModelGroup modelGroup = (XSModelGroup) term;
XSObjectList particles = modelGroup.getParticles();
for (int i = 0; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
collectChildElements(childParticle, elementNames);
}
return;
}
if (term instanceof XSElementDeclaration) {
XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
String elementName = elementDeclaration.getName();
if (log.isTraceEnabled())
log.trace("ElementDeclaration name [" + elementName + "]");
elementNames.add(elementName);
}
return;
}
use of org.apache.xerces.xs.XSTerm 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.XSTerm in project iaf by ibissource.
the class XmlAligner method findMultipleOccurringChildElements.
protected Set<String> findMultipleOccurringChildElements(XSParticle particle) {
Set<String> result = new HashSet<String>();
if (particle == null) {
log.warn("typeDefinition particle is null, is this a problem?");
return result;
}
XSTerm term = particle.getTerm();
if (term == null) {
throw new IllegalStateException("findMultipleOccurringChildElements particle.term is null");
}
if (log.isTraceEnabled())
log.trace("term name [" + term.getName() + "] occurring unbounded [" + particle.getMaxOccursUnbounded() + "] max occur [" + particle.getMaxOccurs() + "] term [" + ToStringBuilder.reflectionToString(term) + "]");
if (particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1) {
collectChildElements(particle, result);
return result;
}
if (term instanceof XSModelGroup) {
XSModelGroup modelGroup = (XSModelGroup) term;
XSObjectList particles = modelGroup.getParticles();
if (log.isTraceEnabled())
log.trace("modelGroup particles [" + ToStringBuilder.reflectionToString(particles) + "]");
for (int i = 0; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
result.addAll(findMultipleOccurringChildElements(childParticle));
}
}
return result;
}
Aggregations