+ private def dispatch URI namespace(CompositeNodeWrapper data) {
+ return data.namespace
+ }
+
+ private def dispatch String localName(CompositeNode data) {
+ return data.nodeType.localName
+ }
+
+ private def dispatch String localName(CompositeNodeWrapper data) {
+ return data.localName
+ }
+
+ private def dispatch Module findModule(MountInstance mountPoint, CompositeNode data) {
+ if (mountPoint !== null) {
+ return mountPoint.findModuleByNamespace(data.nodeType.namespace)
+ } else {
+ return findModuleByNamespace(data.nodeType.namespace)
+ }
+ }
+
+ private def dispatch Module findModule(MountInstance mountPoint, CompositeNodeWrapper data) {
+ Preconditions.checkNotNull(data.namespace)
+ var Module module = null;
+ if (mountPoint !== null) {
+ module = mountPoint.findModuleByNamespace(data.namespace) // namespace from XML
+ if (module === null) {
+ module = mountPoint.findModuleByName(data.namespace.toString) // namespace (module name) from JSON
+ }
+ } else {
+ module = data.namespace.findModuleByNamespace // namespace from XML
+ if (module === null) {
+ module = data.namespace.toString.findModuleByName // namespace (module name) from JSON
+ }
+ }
+ return module
+ }
+
+ private def dispatch getName(CompositeNode data) {
+ return data.nodeType.localName
+ }
+
+ private def dispatch getName(CompositeNodeWrapper data) {
+ return data.localName
+ }
+
+ private def InstanceIdWithSchemaNode addLastIdentifierFromData(InstanceIdWithSchemaNode identifierWithSchemaNode,
+ CompositeNode data, DataSchemaNode schemaOfData) {
+ val iiOriginal = identifierWithSchemaNode?.instanceIdentifier
+ var InstanceIdentifierBuilder iiBuilder = null
+ if (iiOriginal === null) {
+ iiBuilder = InstanceIdentifier.builder
+ } else {
+ iiBuilder = InstanceIdentifier.builder(iiOriginal)
+ }
+
+ if (schemaOfData instanceof ListSchemaNode) {
+ iiBuilder.nodeWithKey(schemaOfData.QName, (schemaOfData as ListSchemaNode).resolveKeysFromData(data))
+ } else {
+ iiBuilder.node(schemaOfData.QName)
+ }
+ return new InstanceIdWithSchemaNode(iiBuilder.toInstance, schemaOfData, identifierWithSchemaNode?.mountPoint)
+ }
+
+ private def resolveKeysFromData(ListSchemaNode listNode, CompositeNode dataNode) {
+ val keyValues = new HashMap<QName, Object>();
+ for (key : listNode.keyDefinition) {
+ val dataNodeKeyValueObject = dataNode.getSimpleNodesByName(key.localName)?.head?.value
+ if (dataNodeKeyValueObject === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "Data contains list \"" + dataNode.nodeType.localName + "\" which does not contain key: \"" +
+ key.localName + "\"")
+ }
+ keyValues.put(key, dataNodeKeyValueObject);
+ }
+ return keyValues