+ normalizeNode(child,
+ findFirstSchemaByLocalName(child.localName, (schema as DataNodeContainer).childNodes),
+ currentAugment, mountPoint)
+ }
+ if(schema instanceof ListSchemaNode) {
+ val listKeys = (schema as ListSchemaNode).keyDefinition
+ for (listKey : listKeys) {
+ var foundKey = false
+ for (child : children) {
+ if (child.unwrap.nodeType.localName == listKey.localName) {
+ foundKey = true;
+ }
+ }
+ if (!foundKey) {
+ throw new ResponseException(BAD_REQUEST,
+ "Missing key in URI \"" + listKey.localName + "\" of list \"" + schema.QName.localName + "\"")
+ }
+ }
+ }
+ } else if (nodeBuilder instanceof SimpleNodeWrapper) {
+ val simpleNode = (nodeBuilder as SimpleNodeWrapper)
+ val value = simpleNode.value
+ var inputValue = value;
+
+ if (schema.typeDefinition instanceof IdentityrefTypeDefinition) {
+ if (value instanceof String) {
+ inputValue = new IdentityValuesDTO(validQName.namespace.toString, value as String, null)
+ } // else value is instance of ValuesDTO
+ }
+
+ val outputValue = RestCodec.from(schema.typeDefinition)?.deserialize(inputValue);
+ simpleNode.setValue(outputValue)
+ } else if (nodeBuilder instanceof EmptyNodeWrapper) {
+ val emptyNodeBuilder = nodeBuilder as EmptyNodeWrapper
+ if (schema instanceof LeafSchemaNode) {
+ emptyNodeBuilder.setComposite(false);
+ } else if (schema instanceof ContainerSchemaNode) {
+
+ // FIXME: Add presence check
+ emptyNodeBuilder.setComposite(true);
+ }
+ }
+ }
+
+ private def dispatch TypeDefinition<?> typeDefinition(LeafSchemaNode node) {
+ var baseType = node.type
+ while (baseType.baseType !== null) {
+ baseType = baseType.baseType;
+ }
+ baseType
+ }
+
+ private def dispatch TypeDefinition<?> typeDefinition(LeafListSchemaNode node) {
+ var TypeDefinition<?> baseType = node.type
+ while (baseType.baseType !== null) {
+ baseType = baseType.baseType;
+ }
+ baseType
+ }
+
+ private def DataSchemaNode findFirstSchemaByLocalName(String localName, Set<DataSchemaNode> schemas) {
+ for (schema : schemas) {
+ if (schema instanceof ChoiceNode) {
+ for (caze : (schema as ChoiceNode).cases) {
+ val result = findFirstSchemaByLocalName(localName, caze.childNodes)
+ if (result !== null) {
+ return result
+ }
+ }
+ } else {
+ val result = schemas.findFirst[n|n.QName.localName.equals(localName)]
+ if (result !== null) {
+ return result;
+
+ }