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);
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations