Search in sources :

Example 11 with RootXNode

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

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

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

the class SearchFilterType method getFilterClauseAsRootXNode.

public RootXNode getFilterClauseAsRootXNode() throws SchemaException {
    MapXNode clause = getFilterClauseXNode();
    if (clause == null) {
        return null;
    }
    Entry<QName, XNode> singleEntry = clause.getSingleSubEntry("getFilterClauseAsRootXNode");
    if (singleEntry == null) {
        return null;
    }
    return new RootXNode(singleEntry.getKey(), singleEntry.getValue());
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 14 with RootXNode

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

the class PrismUtil method serializeExpression.

// TODO: Unify the two serializeExpression() methods
public static MapXNode serializeExpression(ExpressionWrapper expressionWrapper, PrismSerializer<RootXNode> xnodeSerializer) throws SchemaException {
    MapXNode xmap = new MapXNode();
    Object expressionObject = expressionWrapper.getExpression();
    if (expressionObject == null) {
        return xmap;
    }
    RootXNode xroot = xnodeSerializer.serializeAnyData(expressionObject, expressionWrapper.getElementName());
    if (xroot == null) {
        return xmap;
    }
    xmap.merge(expressionWrapper.getElementName(), xroot.getSubnode());
    return xmap;
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 15 with RootXNode

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

the class PrismUtil method parseExpression.

public static ExpressionWrapper parseExpression(Entry<QName, XNode> expressionEntry, PrismContext prismContext) throws SchemaException {
    if (expressionEntry == null) {
        return null;
    }
    RootXNode expressionRoot = new RootXNode(expressionEntry);
    PrismPropertyValue expressionPropertyValue = prismContext.parserFor(expressionRoot).parseItemValue();
    ExpressionWrapper expressionWrapper = new ExpressionWrapper(expressionEntry.getKey(), expressionPropertyValue.getValue());
    return expressionWrapper;
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Aggregations

RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)51 Test (org.testng.annotations.Test)22 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)14 QName (javax.xml.namespace.QName)13 XNode (com.evolveum.midpoint.prism.xnode.XNode)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)7 NotNull (org.jetbrains.annotations.NotNull)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)3 ArrayList (java.util.ArrayList)3 ResourceType (com.evolveum.midpoint.prism.foo.ResourceType)2 UserType (com.evolveum.midpoint.prism.foo.UserType)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 Element (org.w3c.dom.Element)2