2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.sal.binding.generator.impl
10 import org.opendaylight.yangtools.yang.data.api.Node
12 import org.opendaylight.yangtools.yang.common.QName
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
19 class IntermediateMapping {
23 static def Node<?> toNode(Map<?,?> map) {
24 if(map instanceof Node<?>) {
25 return map as Node<?>;
27 val nodeMap = map as Map<QName,Object>;
28 Preconditions.checkArgument(map.size == 1);
29 val elem = nodeMap.entrySet.iterator.next;
31 val value = elem.value;
32 toNodeImpl(qname, value);
36 static def dispatch Node<?> toNodeImpl(QName name, List<?> objects) {
37 val values = new ArrayList<Node<?>>(objects.size);
39 if(obj instanceof Node<?>) {
40 values.add(obj as Node<?>);
41 } else if(obj instanceof Map<?,?>) {
42 values.add(toNode(obj as Map<?,?>));
45 return new CompositeNodeTOImpl(name, null, values);
48 static def dispatch Node<?> toNodeImpl(QName name, Map<QName, Object> object) {
49 throw new UnsupportedOperationException("Unsupported node hierarchy.");
52 static def dispatch Node<?> toNodeImpl(QName name, Object object) {
53 return new SimpleNodeTOImpl(name, null, object);