Search in sources :

Example 6 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class AbstractJsonLexicalProcessor method parseFromStart.

@NotNull
private RootXNode parseFromStart(JsonParser unconfiguredParser, ParsingContext parsingContext) throws SchemaException {
    JsonParsingContext ctx = null;
    try {
        JsonParser parser = configureParser(unconfiguredParser);
        parser.nextToken();
        if (parser.currentToken() == null) {
            throw new SchemaException("Nothing to parse: the input is empty.");
        }
        ctx = new JsonParsingContext(parser, parsingContext);
        XNode xnode = parseValue(ctx);
        if (!(xnode instanceof MapXNode) || ((MapXNode) xnode).size() != 1) {
            throw new SchemaException("Expected MapXNode with a single key; got " + xnode + " instead. At " + getPositionSuffix(ctx));
        }
        processDefaultNamespaces(xnode, null, ctx);
        processSchemaNodes(xnode);
        Entry<QName, XNode> entry = ((MapXNode) xnode).entrySet().iterator().next();
        RootXNode root = new RootXNode(entry.getKey(), entry.getValue());
        if (entry.getValue() != null) {
            // TODO - ok ????
            root.setTypeQName(entry.getValue().getTypeQName());
        }
        return root;
    } catch (IOException e) {
        throw new SchemaException("Cannot parse JSON/YAML object: " + e.getMessage() + (ctx != null ? " At: " + getPositionSuffix(ctx) : ""), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) JsonParser(com.fasterxml.jackson.core.JsonParser) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class AbstractJsonLexicalProcessor method serializeFromMap.

private void serializeFromMap(MapXNode map, JsonSerializationContext ctx) throws IOException {
    writeInlineTypeIfNeeded(map, ctx);
    ctx.generator.writeStartObject();
    resetInlineTypeIfPossible(ctx);
    String oldDefaultNamespace = ctx.currentNamespace;
    generateNsDeclarationIfNeeded(map, ctx);
    writeAuxiliaryInformation(map, ctx);
    for (Entry<QName, XNode> entry : map.entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }
        ctx.generator.writeFieldName(createKeyUri(entry, ctx));
        serialize(entry.getValue(), ctx, false);
    }
    ctx.generator.writeEndObject();
    ctx.currentNamespace = oldDefaultNamespace;
}
Also used : QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 8 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode 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);
    }
}
Also used : SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) Element(org.w3c.dom.Element) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 9 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class DomLexicalWriter method serializeInternal.

@NotNull
private Element serializeInternal(@NotNull RootXNode rootxnode, Element parentElement) throws SchemaException {
    QName rootElementName = rootxnode.getRootElementName();
    Element topElement = createElement(rootElementName, parentElement);
    if (parentElement != null) {
        parentElement.appendChild(topElement);
    }
    QName typeQName = rootxnode.getTypeQName();
    if (typeQName != null && rootxnode.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(topElement, setQNamePrefixExplicitIfNeeded(typeQName));
    }
    XNode subnode = rootxnode.getSubnode();
    if (subnode instanceof PrimitiveXNode) {
        serializePrimitiveElementOrAttribute((PrimitiveXNode) subnode, topElement, rootElementName, false);
        return DOMUtil.getFirstChildElement(topElement);
    }
    if (subnode instanceof MapXNode) {
        // at this point we can put frequently used namespaces (e.g. c, t, q, ri) into the document to eliminate their use
        // on many places inside the doc (MID-2198)
        DOMUtil.setNamespaceDeclarations(topElement, getNamespacePrefixMapper().getNamespacesDeclaredByDefault());
        serializeMap((MapXNode) subnode, topElement);
    } else if (subnode.isHeterogeneousList()) {
        DOMUtil.setNamespaceDeclarations(topElement, getNamespacePrefixMapper().getNamespacesDeclaredByDefault());
        serializeExplicitList((ListXNode) subnode, topElement);
    } else {
        throw new SchemaException("Sub-root xnode is not a map nor an explicit list, cannot serialize to XML (it is " + subnode + ")");
    }
    addDefaultNamespaceDeclaration(topElement);
    return topElement;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class DomLexicalWriter method serializeMap.

private void serializeMap(MapXNode xmap, Element topElement) throws SchemaException {
    for (Entry<QName, XNode> entry : xmap.entrySet()) {
        QName elementQName = entry.getKey();
        XNode xsubnode = entry.getValue();
        serializeSubnode(xsubnode, topElement, elementQName);
    }
}
Also used : QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Aggregations

MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)42 QName (javax.xml.namespace.QName)24 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)21 XNode (com.evolveum.midpoint.prism.xnode.XNode)18 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)15 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)13 Test (org.testng.annotations.Test)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 Element (org.w3c.dom.Element)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)4 Protector (com.evolveum.midpoint.prism.crypto.Protector)3 EncryptedDataType (com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType)3 NotNull (org.jetbrains.annotations.NotNull)3 TestProtector (com.evolveum.midpoint.prism.crypto.TestProtector)2