use of org.apache.xerces.xs.XSParticle in project iaf by ibissource.
the class ToXml method getBestChildElementPath.
public List<XSParticle> getBestChildElementPath(XSElementDeclaration elementDeclaration, N node, boolean silent) throws SAXException {
XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
if (typeDefinition == null) {
log.warn("getBestChildElementPath typeDefinition is null");
return null;
}
switch(typeDefinition.getTypeCategory()) {
case XSTypeDefinition.SIMPLE_TYPE:
if (log.isTraceEnabled())
log.trace("getBestChildElementPath typeDefinition.typeCategory is SimpleType, no child elements");
return null;
case XSTypeDefinition.COMPLEX_TYPE:
XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDefinition;
switch(complexTypeDefinition.getContentType()) {
case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
if (log.isTraceEnabled())
log.trace("getBestChildElementPath complexTypeDefinition.contentType is Empty, no child elements");
return null;
case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
if (log.isTraceEnabled())
log.trace("getBestChildElementPath complexTypeDefinition.contentType is Simple, no child elements (only characters)");
return null;
case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
XSParticle particle = complexTypeDefinition.getParticle();
if (particle == null) {
throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.particle is null for Element or Mixed contentType");
// log.warn("typeDefinition particle is null, is this a problem?");
// return null;
}
if (log.isTraceEnabled())
log.trace("typeDefinition particle [" + ToStringBuilder.reflectionToString(particle, ToStringStyle.MULTI_LINE_STYLE) + "]");
List<XSParticle> result = new LinkedList<XSParticle>();
List<String> failureReasons = new LinkedList<String>();
if (getBestMatchingElementPath(elementDeclaration, node, particle, result, failureReasons)) {
return result;
}
String msg = "Cannot find path:";
for (String reason : failureReasons) {
msg += '\n' + reason;
}
if (!silent) {
handleError(msg);
}
return null;
default:
throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but [" + complexTypeDefinition.getContentType() + "]");
}
default:
throw new IllegalStateException("getBestChildElementPath typeDefinition.typeCategory is not SimpleType or ComplexType, but [" + typeDefinition.getTypeCategory() + "] class [" + typeDefinition.getClass().getName() + "]");
}
}
use of org.apache.xerces.xs.XSParticle 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.XSParticle 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.XSParticle in project iaf by ibissource.
the class XmlTypeToJsonSchemaConverter method handleComplexTypeDefinitionOfElementContentType.
private void handleComplexTypeDefinitionOfElementContentType(XSComplexTypeDefinition complexTypeDefinition, boolean shouldCreateReferences, JsonObjectBuilder builder) {
if (shouldCreateReferences) {
String complexTypeDefinitionName = complexTypeDefinition.getName();
if (complexTypeDefinitionName == null && complexTypeDefinition.getContext() != null && complexTypeDefinition.getContext().getNamespaceItem() != null) {
// complex type definition name defaults to name of context
complexTypeDefinitionName = complexTypeDefinition.getContext().getName();
}
if (complexTypeDefinitionName != null) {
if (log.isTraceEnabled())
log.trace("handleComplexTypeDefinitionOfElementContentType creating ref!");
builder.add("$ref", definitionsPath + complexTypeDefinitionName);
return;
}
}
XSObjectList attributeUses = complexTypeDefinition.getAttributeUses();
XSParticle particle = complexTypeDefinition.getParticle();
handleParticle(builder, particle, attributeUses, false);
}
use of org.apache.xerces.xs.XSParticle in project iaf by ibissource.
the class XmlTypeToJsonSchemaConverter method handleCompositorChoice.
private void handleCompositorChoice(JsonObjectBuilder builder, XSObjectList particles, boolean forProperties) {
if (log.isTraceEnabled())
log.trace("modelGroup COMPOSITOR_CHOICE forProperties [" + forProperties + "]");
if (forProperties) {
for (int i = 0; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
if (log.isTraceEnabled())
log.trace("childParticle [" + i + "][" + ToStringBuilder.reflectionToString(childParticle, ToStringStyle.MULTI_LINE_STYLE) + "] for properties");
handleParticle(builder, childParticle, null, false);
}
} else {
JsonArrayBuilder oneOfBuilder = Json.createArrayBuilder();
for (int i = 0; i < particles.getLength(); i++) {
XSParticle childParticle = (XSParticle) particles.item(i);
if (log.isTraceEnabled())
log.trace("childParticle [" + i + "][" + ToStringBuilder.reflectionToString(childParticle, ToStringStyle.MULTI_LINE_STYLE) + "]");
JsonObjectBuilder typeBuilder = Json.createObjectBuilder();
handleParticle(typeBuilder, childParticle, null, false);
oneOfBuilder.add(typeBuilder.build());
}
builder.add("oneOf", oneOfBuilder.build());
}
}
Aggregations