Search in sources :

Example 1 with ListXNode

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

the class TestDomParser method testParseUserToXNode.

@Test
public void testParseUserToXNode() throws Exception {
    final String TEST_NAME = "testParseUserToXNode";
    displayTestTitle(TEST_NAME);
    // GIVEN
    DomLexicalProcessor parser = createParser();
    // WHEN
    XNode xnode = parser.read(getFile(USER_JACK_FILE_BASENAME), ParsingContext.createDefault());
    // THEN
    System.out.println("Parsed XNode:");
    System.out.println(xnode.debugDump());
    RootXNode root = getAssertXNode("root node", xnode, RootXNode.class);
    MapXNode rootMap = getAssertXNode("root subnode", root.getSubnode(), MapXNode.class);
    PrimitiveXNode<String> xname = getAssertXMapSubnode("root map", rootMap, UserType.F_NAME, PrimitiveXNode.class);
    // TODO: assert value
    ListXNode xass = getAssertXMapSubnode("root map", rootMap, UserType.F_ASSIGNMENT, ListXNode.class);
    assertEquals("assignment size", 2, xass.size());
    // TODO: asserts
    MapXNode xextension = getAssertXMapSubnode("root map", rootMap, UserType.F_EXTENSION, MapXNode.class);
}
Also used : DomLexicalProcessor(com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) 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) Test(org.testng.annotations.Test)

Example 2 with ListXNode

use of com.evolveum.midpoint.prism.xnode.ListXNode 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 3 with ListXNode

use of com.evolveum.midpoint.prism.xnode.ListXNode 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 4 with ListXNode

use of com.evolveum.midpoint.prism.xnode.ListXNode 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);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) 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) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 5 with ListXNode

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

the class PrismProperty method createRaw.

public static <T> PrismProperty<T> createRaw(@NotNull XNode node, @NotNull QName itemName, PrismContext prismContext) throws SchemaException {
    Validate.isTrue(!(node instanceof RootXNode));
    PrismProperty<T> property = new PrismProperty<>(itemName, prismContext);
    if (node instanceof ListXNode) {
        for (XNode subnode : (ListXNode) node) {
            property.add(PrismPropertyValue.createRaw(subnode));
        }
    } else {
        property.add(PrismPropertyValue.createRaw(node));
    }
    return property;
}
Also used : ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) 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) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Aggregations

ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)12 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)10 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)8 XNode (com.evolveum.midpoint.prism.xnode.XNode)8 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)7 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)5 QName (javax.xml.namespace.QName)5 Test (org.testng.annotations.Test)5 Element (org.w3c.dom.Element)4 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)3 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrimitiveXNodeImpl (com.evolveum.midpoint.prism.impl.xnode.PrimitiveXNodeImpl)1 DomLexicalProcessor (com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 AbstractUnitTest (com.evolveum.midpoint.tools.testng.AbstractUnitTest)1 PipelineDataType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)1 NotNull (org.jetbrains.annotations.NotNull)1