Initial code drop of yang model driven configuration system
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / TypeProviderWrapper.java
1 /*
2  * Copyright (c) 2013 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.controller.config.yangjmxgenerator;
9
10 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;
11 import org.opendaylight.yangtools.sal.binding.model.api.Type;
12 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
14
15 public class TypeProviderWrapper {
16     private final TypeProvider typeProvider;
17
18     public TypeProviderWrapper(TypeProvider typeProvider) {
19         this.typeProvider = typeProvider;
20     }
21
22     public Type getType(LeafSchemaNode leaf) {
23         Type javaType;
24         try {
25             javaType = typeProvider.javaTypeForSchemaDefinitionType(
26                     leaf.getType(), leaf);
27             if (javaType == null)
28                 throw new IllegalArgumentException("Unknown type received for "
29                         + leaf.toString());
30         } catch (IllegalArgumentException e) {
31             throw new IllegalArgumentException("Error while resolving type of "
32                     + leaf, e);
33         }
34         return javaType;
35     }
36
37     // there is no getType in common interface
38     public Type getType(LeafListSchemaNode leaf) {
39         Type javaType;
40         try {
41             javaType = typeProvider.javaTypeForSchemaDefinitionType(
42                     leaf.getType(), leaf);
43             if (javaType == null)
44                 throw new IllegalArgumentException(
45                         "Unknown type received for  " + leaf.toString());
46         } catch (IllegalArgumentException e) {
47             throw new IllegalArgumentException("Error while resolving type of "
48                     + leaf, e);
49         }
50         return javaType;
51     }
52
53 }