use of org.apache.xerces.xs.XSElementDeclaration in project iaf by ibissource.
the class XmlAligner method determineIsParentOfSingleMultipleOccurringChildElement.
protected int determineIsParentOfSingleMultipleOccurringChildElement(XSParticle particle) {
if (particle == null) {
log.warn("Particle is null, is this a problem? Appearantly not");
return CHILD_OCCURRENCE_EMPTY;
}
XSTerm term = particle.getTerm();
if (term == null) {
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement particle.term is null");
}
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() 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 (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() sequence or all particles [" + ToStringBuilder.reflectionToString(particles) + "]");
int result = CHILD_OCCURRENCE_EMPTY;
for (int i = 0; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
int current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() sequence or all, particle [" + i + "] current result [" + CHILD_OCCURRENCE_DESCRIPTION[current] + "]");
switch(current) {
case CHILD_OCCURRENCE_EMPTY:
break;
case CHILD_OCCURRENCE_ONE_SINGLE_OCCURRING_ELEMENT:
case CHILD_OCCURRENCE_ONE_MULTIPLE_OCCURRING_ELEMENT:
if (result > CHILD_OCCURRENCE_EMPTY) {
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() sequence or all, result [" + CHILD_OCCURRENCE_DESCRIPTION[result] + "] current [" + CHILD_OCCURRENCE_DESCRIPTION[current] + "]");
return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
result = current;
break;
case CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING:
return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
default:
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement child occurrence [" + CHILD_OCCURRENCE_DESCRIPTION[current] + "]");
}
}
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() end of sequence or all, returning [" + CHILD_OCCURRENCE_DESCRIPTION[result] + "]");
return result;
}
case XSModelGroup.COMPOSITOR_CHOICE:
{
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() choice particles [" + ToStringBuilder.reflectionToString(particles) + "]");
if (particles.getLength() == 0) {
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() choice length 0, returning [" + CHILD_OCCURRENCE_DESCRIPTION[CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING] + "]");
return CHILD_OCCURRENCE_EMPTY;
}
int result = determineIsParentOfSingleMultipleOccurringChildElement((XSParticle) particles.item(0));
if (result == CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING) {
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() choice single mixed, returning [" + CHILD_OCCURRENCE_DESCRIPTION[CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING] + "]");
return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
for (int i = 1; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
int current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
if (current != result) {
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() break out of choice, returning [" + CHILD_OCCURRENCE_DESCRIPTION[CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING] + "]");
return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
}
if (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() end of choice, returning [" + CHILD_OCCURRENCE_DESCRIPTION[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 (DEBUG)
log.debug("determineIsParentOfSingleMultipleOccurringChildElement() ElementDeclaration name [" + elementName + "] unbounded [" + particle.getMaxOccursUnbounded() + "] maxOccurs [" + particle.getMaxOccurs() + "]");
if (particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1) {
return CHILD_OCCURRENCE_ONE_MULTIPLE_OCCURRING_ELEMENT;
}
if (particle.getMaxOccurs() == 1) {
return CHILD_OCCURRENCE_ONE_SINGLE_OCCURRING_ELEMENT;
}
return CHILD_OCCURRENCE_EMPTY;
}
if (term instanceof XSWildcard) {
return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
}
throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement unknown Term type [" + term.getClass().getName() + "]");
}
use of org.apache.xerces.xs.XSElementDeclaration 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 (DEBUG)
log.debug("collectChildElements() ElementDeclaration name [" + elementName + "]");
elementNames.add(elementName);
}
return;
}
Aggregations