Search in sources :

Example 6 with RootXNode

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

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

the class PrismParserImpl method doParseObjects.

@NotNull
List<PrismObject<? extends Objectable>> doParseObjects() throws IOException, SchemaException {
    List<RootXNode> roots = getLexicalProcessor().readObjects(source, context);
    List<PrismObject<? extends Objectable>> objects = new ArrayList<>();
    for (RootXNode root : roots) {
        PrismObject<? extends Objectable> object = prismContext.getPrismUnmarshaller().parseObject(root, null, null, null, null, context);
        objects.add(object);
    }
    return objects;
}
Also used : ArrayList(java.util.ArrayList) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with RootXNode

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

the class PrismSerializerImpl method serialize.

//endregion
//region Serialization =============================================================================================
@NotNull
@Override
public T serialize(@NotNull Item<?, ?> item) throws SchemaException {
    RootXNode xroot = getMarshaller().marshalItemAsRoot(item, itemName, itemDefinition, context);
    // TODO find better way
    checkPostconditions(xroot);
    return target.write(xroot, context);
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with RootXNode

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

the class PrismSerializerImpl method serialize.

@NotNull
@Override
public T serialize(@NotNull PrismValue value) throws SchemaException {
    QName nameToUse;
    if (itemName != null) {
        nameToUse = itemName;
    } else if (itemDefinition != null) {
        nameToUse = itemDefinition.getName();
    } else if (value.getParent() != null) {
        nameToUse = value.getParent().getElementName();
    } else {
        nameToUse = null;
    }
    //		else {
    //			// TODO derive from the value type itself? Not worth the effort.
    //			throw new IllegalArgumentException("Item name nor definition is not known for " + value);
    //		}
    RootXNode xroot = getMarshaller().marshalPrismValueAsRoot(value, nameToUse, itemDefinition, context);
    // TODO find better way
    checkPostconditions(xroot);
    return target.write(xroot, context);
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with RootXNode

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

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