+ private def void createMapping(Class<?> inputType, SchemaNode node, InstanceIdentifier<?> parentId) {
+ var ClassLoader cl = inputType.classLoader
+ if (cl === null) {
+ cl = Thread.currentThread.contextClassLoader
+ }
+ ClassLoaderUtils.withClassLoader(cl,
+ [ |
+ if (!(node instanceof DataNodeContainer)) {
+ return null
+ }
+ var InstanceIdentifier<?> bindingId = getBindingIdentifierByPath(node.path)
+ if (bindingId != null) {
+ return null
+ }
+ val ref = Types.typeForClass(inputType)
+ var typeSpecBuilder = getDefinition(ref)
+ if (typeSpecBuilder == null) {
+ typeSpecBuilder = getTypeBuilder(node.path);
+ }
+ checkState(typeSpecBuilder !== null, "Could not find type definition for %s, $s", inputType.name, node);
+ val typeSpec = typeSpecBuilder.toInstance();
+ var InstanceIdentifier<?> parent
+ if (parentId == null) {
+ bindingId = InstanceIdentifier.create(inputType as Class)
+ parent = bindingId
+ putPathToBindingIdentifier(node.path, bindingId)
+ } else {
+ parent = putPathToBindingIdentifier(node.path, parentId, inputType)
+ }
+ val Map<String, Type> properties = typeSpec.allProperties
+ if (node instanceof DataNodeContainer) {
+ mappingForNodes((node as DataNodeContainer).childNodes, properties, parent)
+ } else if (node instanceof ChoiceNode) {
+ mappingForNodes((node as ChoiceNode).cases, properties, parent)
+ }
+ return null;
+ ])
+ }
+
+ private def void mappingForNodes(Collection<? extends DataSchemaNode> childNodes, Map<String, Type> properties,
+ InstanceIdentifier<?> parent) {
+ for (DataSchemaNode child : childNodes) {
+ val signature = properties.getFor(child)
+ if (signature != null) {
+ val Type childType = signature.value
+ var Class<?> childTypeClass = null;
+ if (child instanceof ListSchemaNode && childType instanceof ParameterizedType) {
+ childTypeClass = loadClass((childType as ParameterizedType).actualTypeArguments.get(0))
+ } else {
+ childTypeClass = loadClass(childType)
+ }
+ createMapping(childTypeClass, child, parent)
+ }
+ }
+ }
+