use of com.evolveum.midpoint.prism.xnode.SchemaXNode in project midpoint by Evolveum.
the class DomLexicalWriter method serializeSubnode.
private void serializeSubnode(XNode xsubnode, Element parentElement, QName elementName) throws SchemaException {
if (xsubnode == null) {
return;
}
if (xsubnode instanceof RootXNode) {
Element element = createElement(elementName, parentElement);
appendCommentIfPresent(element, xsubnode);
parentElement.appendChild(element);
serializeSubnode(((RootXNode) xsubnode).getSubnode(), element, ((RootXNode) xsubnode).getRootElementName());
} else if (xsubnode instanceof MapXNode) {
Element element = createElement(elementName, parentElement);
appendCommentIfPresent(element, xsubnode);
if (xsubnode.isExplicitTypeDeclaration() && xsubnode.getTypeQName() != null) {
DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(xsubnode.getTypeQName()));
}
parentElement.appendChild(element);
serializeMap((MapXNode) xsubnode, element);
} else if (xsubnode instanceof PrimitiveXNode<?>) {
PrimitiveXNode<?> xprim = (PrimitiveXNode<?>) xsubnode;
if (xprim.isAttribute()) {
serializePrimitiveElementOrAttribute(xprim, parentElement, elementName, true);
} else {
serializePrimitiveElementOrAttribute(xprim, parentElement, elementName, false);
}
} else if (xsubnode instanceof ListXNode) {
ListXNode xlist = (ListXNode) xsubnode;
if (xlist.isHeterogeneousList()) {
Element element = createElement(elementName, parentElement);
serializeExplicitList(xlist, element);
parentElement.appendChild(element);
} else {
for (XNode xsubsubnode : xlist) {
serializeSubnode(xsubsubnode, parentElement, elementName);
}
}
} else if (xsubnode instanceof SchemaXNode) {
serializeSchema((SchemaXNode) xsubnode, parentElement);
} else {
throw new IllegalArgumentException("Unknown subnode " + xsubnode);
}
}
use of com.evolveum.midpoint.prism.xnode.SchemaXNode in project midpoint by Evolveum.
the class AbstractJsonLexicalProcessor method processSchemaNodes.
// Schema nodes can be detected only after namespaces are resolved.
// We simply convert primitive nodes to schema ones.
private void processSchemaNodes(XNode xnode) throws SchemaException, IOException {
if (xnode instanceof MapXNode) {
MapXNode map = (MapXNode) xnode;
XNode schemaNode = null;
for (Entry<QName, XNode> entry : map.entrySet()) {
QName fieldName = entry.getKey();
XNode subnode = entry.getValue();
if (DOMUtil.XSD_SCHEMA_ELEMENT.equals(fieldName)) {
schemaNode = subnode;
} else {
processSchemaNodes(subnode);
}
}
if (schemaNode != null) {
if (schemaNode instanceof PrimitiveXNode) {
PrimitiveXNode<?> primitiveXNode = (PrimitiveXNode<?>) schemaNode;
if (primitiveXNode.isParsed()) {
throw new SchemaException("Cannot convert from PrimitiveXNode to SchemaXNode: node is already parsed: " + primitiveXNode);
}
SchemaXNode schemaXNode = new SchemaXNode();
map.replace(DOMUtil.XSD_SCHEMA_ELEMENT, schemaXNode);
schemaXNode.setSchemaElement(((JsonValueParser) primitiveXNode.getValueParser()).asDomElement());
} else {
throw new SchemaException("Cannot convert 'schema' field to SchemaXNode: not a PrimitiveNode but " + schemaNode);
}
}
} else if (xnode instanceof ListXNode) {
for (XNode item : (ListXNode) xnode) {
processSchemaNodes(item);
}
}
}
Aggregations