Revert "Fixed resolving of NotificationDefinition."
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / impl / IntermediateMapping.xtend
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.sal.binding.generator.impl
9
10 import org.opendaylight.yangtools.yang.data.api.Node
11 import java.util.Map
12 import org.opendaylight.yangtools.yang.common.QName
13 import java.util.List
14 import java.util.ArrayList
15 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl
16 import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl
17 import com.google.common.base.Preconditions
18
19 class IntermediateMapping {
20
21
22
23     static def Node<?> toNode(Map<?,?> map) {
24         if(map instanceof Node<?>) {
25             return map as Node<?>;
26         }
27         val nodeMap = map as Map<QName,Object>;
28         Preconditions.checkArgument(map.size == 1);
29         val elem = nodeMap.entrySet.iterator.next;
30         val qname = elem.key;
31         val value = elem.value;
32         toNodeImpl(qname, value);
33     }
34
35
36     static def dispatch Node<?> toNodeImpl(QName name, List<?> objects) {
37         val values = new ArrayList<Node<?>>(objects.size);
38         for (obj : objects) {
39             if(obj instanceof Node<?>) {
40                 values.add(obj as Node<?>);
41             } else if(obj instanceof Map<?,?>) {
42                 values.add(toNode(obj as Map<?,?>));
43             }
44         }
45         return new CompositeNodeTOImpl(name, null, values);
46     }
47
48     static def dispatch Node<?> toNodeImpl(QName name, Map<QName, Object> object) {
49         throw new UnsupportedOperationException("Unsupported node hierarchy.");
50     }
51
52     static def dispatch Node<?> toNodeImpl(QName name, Object object) {
53         return new SimpleNodeTOImpl(name, null, object);
54     }
55 }