Add IfNewHostNotify to DeviceManager
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-util / src / main / java / org / opendaylight / controller / binding / generator / util / Types.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.binding.generator.util;\r
9 \r
10 import java.util.List;\r
11 import java.util.Map;\r
12 import java.util.Set;\r
13 \r
14 import org.opendaylight.controller.sal.binding.model.api.ConcreteType;\r
15 import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;\r
16 import org.opendaylight.controller.sal.binding.model.api.Type;\r
17 import org.opendaylight.controller.yang.binding.Augmentable;\r
18 import org.opendaylight.controller.yang.binding.Augmentation;\r
19 import org.opendaylight.controller.yang.binding.DataObject;\r
20 \r
21 public final class Types {\r
22     private static final Type SET_TYPE = typeForClass(Set.class);\r
23     private static final Type LIST_TYPE = typeForClass(List.class);\r
24     private static final Type MAP_TYPE = typeForClass(Map.class);\r
25     public static final Type DATA_OBJECT = typeForClass(DataObject.class);\r
26 \r
27     public static ConcreteType voidType() {\r
28         return new ConcreteTypeImpl(Void.class.getPackage().getName(),\r
29                 Void.class.getSimpleName());\r
30     }\r
31 \r
32     public static final Type primitiveType(final String primitiveType) {\r
33         return new ConcreteTypeImpl("", primitiveType);\r
34     }\r
35 \r
36 \r
37     /**\r
38      * Returns an instance of {@link ConcreteType} describing the class\r
39      * \r
40      * @param cls\r
41      *            Class to describe\r
42      * @return Description of class\r
43      */\r
44     public static ConcreteType typeForClass(Class<?> cls) {\r
45         return new ConcreteTypeImpl(cls.getPackage().getName(),\r
46                 cls.getSimpleName());\r
47     }\r
48 \r
49     /**\r
50      * Returns an instance of {@link ParameterizedType} describing the typed\r
51      * {@link Map}<K,V>\r
52      * \r
53      * @param keyType\r
54      *            Key Type\r
55      * @param valueType\r
56      *            Value Type\r
57      * @return Description of generic type instance\r
58      */\r
59     public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {\r
60         return parameterizedTypeFor(MAP_TYPE, keyType, valueType);\r
61     }\r
62 \r
63     /**\r
64      * Returns an instance of {@link ParameterizedType} describing the typed\r
65      * {@link Set}<V> with concrete type of value.\r
66      * \r
67      * @param valueType\r
68      *            Value Type\r
69      * @return Description of generic type instance of Set\r
70      */\r
71     public static ParameterizedType setTypeFor(Type valueType) {\r
72         return parameterizedTypeFor(SET_TYPE, valueType);\r
73     }\r
74 \r
75     /**\r
76      * Returns an instance of {@link ParameterizedType} describing the typed\r
77      * {@link List}<V> with concrete type of value.\r
78      * \r
79      * @param valueType\r
80      *            Value Type\r
81      * @return Description of type instance of List\r
82      */\r
83     public static ParameterizedType listTypeFor(Type valueType) {\r
84         return parameterizedTypeFor(LIST_TYPE, valueType);\r
85     }\r
86 \r
87     /**\r
88      * \r
89      * @param type\r
90      * @param parameters\r
91      * @return\r
92      */\r
93     public static ParameterizedType parameterizedTypeFor(Type type,\r
94             Type... parameters) {\r
95         return new ParametrizedTypeImpl(type, parameters);\r
96     }\r
97     \r
98     public static ParameterizedType augmentableTypeFor(Type valueType) {\r
99         final Type augmentable = typeForClass(Augmentable.class);\r
100         return parameterizedTypeFor(augmentable, valueType);\r
101     }\r
102     \r
103     public static ParameterizedType augmentationTypeFor(Type valueType) {\r
104         final Type augmentation = typeForClass(Augmentation.class);\r
105         return parameterizedTypeFor(augmentation, valueType);\r
106     }\r
107     \r
108     private static class ConcreteTypeImpl extends AbstractBaseType implements\r
109             ConcreteType {\r
110         private ConcreteTypeImpl(String pkName, String name) {\r
111             super(pkName, name);\r
112         }\r
113     }\r
114 \r
115     private static class ParametrizedTypeImpl extends AbstractBaseType\r
116             implements ParameterizedType {\r
117         private Type[] actualTypes;\r
118         private Type rawType;\r
119 \r
120         @Override\r
121         public Type[] getActualTypeArguments() {\r
122 \r
123             return actualTypes;\r
124         }\r
125 \r
126         @Override\r
127         public Type getRawType() {\r
128             return rawType;\r
129         }\r
130 \r
131         public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {\r
132             super(rawType.getPackageName(), rawType.getName());\r
133             this.rawType = rawType;\r
134             this.actualTypes = actTypes;\r
135         }\r
136 \r
137     }\r
138 }\r