Search in sources :

Example 31 with RootXNode

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

the class PrismSerializerImpl method serializeAnyData.

@Override
public T serializeAnyData(Object value) throws SchemaException {
    RootXNode xnode = getMarshaller().marshalAnyData(value, itemName, itemDefinition, context);
    // TODO find better way
    checkPostconditions(xnode);
    return target.write(xnode, context);
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Example 32 with RootXNode

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

the class AbstractLexicalProcessorTest method testParseUserToPrism.

@Test
public void testParseUserToPrism() throws Exception {
    final String TEST_NAME = "testParseUserToPrism";
    displayTestTitle(TEST_NAME);
    // GIVEN
    LexicalProcessor lexicalProcessor = createParser();
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN (parse to xnode)
    RootXNode xnode = lexicalProcessor.read(getFileSource(USER_JACK_FILE_BASENAME), ParsingContext.createDefault());
    System.out.println("XNode after parsing:");
    System.out.println(xnode.debugDump());
    // WHEN (parse to prism)
    PrismObject<UserType> user = prismContext.parserFor(xnode).parse();
    // THEN
    System.out.println("Parsed user:");
    System.out.println(user.debugDump());
    assertUserJackXNodeOrdering("serialized xnode", xnode);
    assertUserJack(user, true);
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 33 with RootXNode

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

the class LexicalUtils method createRootXNode.

@NotNull
public static RootXNode createRootXNode(XNode xnode, QName rootElementName) {
    if (xnode instanceof RootXNode) {
        return (RootXNode) xnode;
    } else {
        RootXNode xroot = new RootXNode(rootElementName);
        xroot.setSubnode(xnode);
        return xroot;
    }
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with RootXNode

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

the class StaticExpressionUtil method serializeValueElements.

public static <IV extends PrismValue, ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV, ID> item, String contextDescription) throws SchemaException {
    if (item == null) {
        return null;
    }
    List<JAXBElement<RawType>> elements = new ArrayList<>(item.size());
    for (PrismValue value : item.getValues()) {
        RootXNode xnode = item.getPrismContext().xnodeSerializer().serialize(value);
        RawType rawType = new RawType(xnode.getSubnode(), item.getPrismContext());
        JAXBElement<RawType> jaxbElement = new JAXBElement<>(SchemaConstants.C_VALUE, RawType.class, rawType);
        elements.add(jaxbElement);
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 35 with RootXNode

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

the class ExpressionUtil method parseSearchFilter.

// TODO move somewhere else? generalize a bit?
public static RootXNode parseSearchFilter(String data, PrismContext context) throws SchemaException {
    String xml = WebXmlUtil.wrapInElement("root", data, false);
    RootXNode rootXNode = context.parserFor(xml).xml().parseToXNode();
    if (rootXNode.getSubnode() instanceof MapXNode) {
        MapXNode mapXNode = (MapXNode) rootXNode.getSubnode();
        if (mapXNode.size() != 1) {
            throw new SchemaException("Content cannot be parsed as a search filter: " + mapXNode.debugDump());
        }
        return mapXNode.getEntryAsRoot(mapXNode.keySet().iterator().next());
    } else {
        throw new SchemaException("Content cannot be parsed as a search filter: " + DebugUtil.debugDump(rootXNode.getSubnode()));
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

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