--- /dev/null
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.binding.generator.util;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.opendaylight.controller.sal.binding.model.api.ConcreteType;\r
+import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;\r
+import org.opendaylight.controller.sal.binding.model.api.Type;\r
+\r
+public class Types {\r
+ private static final Type SET_TYPE = typeForClass(Set.class);\r
+ private static final Type LIST_TYPE = typeForClass(List.class);\r
+ private static final Type MAP_TYPE = typeForClass(Map.class);\r
+\r
+ private Types() {\r
+ }\r
+\r
+ public static ConcreteType voidType() {\r
+ return new ConcreteTypeImpl(Void.class.getPackage().getName(),\r
+ Void.class.getSimpleName());\r
+ }\r
+\r
+ /**\r
+ * Returns an instance of {@link ConcreteType} describing the class\r
+ * \r
+ * @param cls\r
+ * Class to describe\r
+ * @return Description of class\r
+ */\r
+ public static ConcreteType typeForClass(Class<?> cls) {\r
+ return new ConcreteTypeImpl(cls.getPackage().getName(),\r
+ cls.getSimpleName());\r
+ }\r
+\r
+ /**\r
+ * Returns an instance of {@link ParameterizedType} describing the typed\r
+ * {@link Map}<K,V>\r
+ * \r
+ * @param keyType\r
+ * Key Type\r
+ * @param valueType\r
+ * Value Type\r
+ * @return Description of generic type instance\r
+ */\r
+ public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {\r
+ return parameterizedTypeFor(MAP_TYPE, keyType, valueType);\r
+ }\r
+\r
+ /**\r
+ * Returns an instance of {@link ParameterizedType} describing the typed\r
+ * {@link Set}<V> with concrete type of value.\r
+ * \r
+ * @param valueType\r
+ * Value Type\r
+ * @return Description of generic type instance of Set\r
+ */\r
+ public static ParameterizedType setTypeFor(Type valueType) {\r
+ return parameterizedTypeFor(SET_TYPE, valueType);\r
+ }\r
+\r
+ /**\r
+ * Returns an instance of {@link ParameterizedType} describing the typed\r
+ * {@link List}<V> with concrete type of value.\r
+ * \r
+ * @param valueType\r
+ * Value Type\r
+ * @return Description of type instance of List\r
+ */\r
+ public static ParameterizedType listTypeFor(Type valueType) {\r
+ return parameterizedTypeFor(LIST_TYPE, valueType);\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @param type\r
+ * @param parameters\r
+ * @return\r
+ */\r
+ public static ParameterizedType parameterizedTypeFor(Type type,\r
+ Type... parameters) {\r
+ return new ParametrizedTypeImpl(type, parameters);\r
+ }\r
+\r
+ private static class ConcreteTypeImpl extends AbstractBaseType implements\r
+ ConcreteType {\r
+ private ConcreteTypeImpl(String pkName, String name) {\r
+ super(pkName, name);\r
+ }\r
+ }\r
+\r
+ private static class ParametrizedTypeImpl extends AbstractBaseType\r
+ implements ParameterizedType {\r
+ private Type[] actualTypes;\r
+ private Type rawType;\r
+\r
+ @Override\r
+ public Type[] getActualTypeArguments() {\r
+\r
+ return actualTypes;\r
+ }\r
+\r
+ @Override\r
+ public Type getRawType() {\r
+ return rawType;\r
+ }\r
+\r
+ public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {\r
+ super(rawType.getPackageName(), rawType.getName());\r
+ this.rawType = rawType;\r
+ this.actualTypes = actTypes;\r
+ }\r
+\r
+ }\r
+}\r