2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\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
8 package org.opendaylight.controller.binding.generator.util;
\r
10 import java.util.List;
\r
11 import java.util.Map;
\r
12 import java.util.Set;
\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
18 public class Types {
\r
19 private static final Type SET_TYPE = typeForClass(Set.class);
\r
20 private static final Type LIST_TYPE = typeForClass(List.class);
\r
21 private static final Type MAP_TYPE = typeForClass(Map.class);
\r
26 public static ConcreteType voidType() {
\r
27 return new ConcreteTypeImpl(Void.class.getPackage().getName(),
\r
28 Void.class.getSimpleName());
\r
32 * Returns an instance of {@link ConcreteType} describing the class
\r
36 * @return Description of class
\r
38 public static ConcreteType typeForClass(Class<?> cls) {
\r
39 return new ConcreteTypeImpl(cls.getPackage().getName(),
\r
40 cls.getSimpleName());
\r
44 * Returns an instance of {@link ParameterizedType} describing the typed
\r
51 * @return Description of generic type instance
\r
53 public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {
\r
54 return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
\r
58 * Returns an instance of {@link ParameterizedType} describing the typed
\r
59 * {@link Set}<V> with concrete type of value.
\r
63 * @return Description of generic type instance of Set
\r
65 public static ParameterizedType setTypeFor(Type valueType) {
\r
66 return parameterizedTypeFor(SET_TYPE, valueType);
\r
70 * Returns an instance of {@link ParameterizedType} describing the typed
\r
71 * {@link List}<V> with concrete type of value.
\r
75 * @return Description of type instance of List
\r
77 public static ParameterizedType listTypeFor(Type valueType) {
\r
78 return parameterizedTypeFor(LIST_TYPE, valueType);
\r
87 public static ParameterizedType parameterizedTypeFor(Type type,
\r
88 Type... parameters) {
\r
89 return new ParametrizedTypeImpl(type, parameters);
\r
92 private static class ConcreteTypeImpl extends AbstractBaseType implements
\r
94 private ConcreteTypeImpl(String pkName, String name) {
\r
95 super(pkName, name);
\r
99 private static class ParametrizedTypeImpl extends AbstractBaseType
\r
100 implements ParameterizedType {
\r
101 private Type[] actualTypes;
\r
102 private Type rawType;
\r
105 public Type[] getActualTypeArguments() {
\r
107 return actualTypes;
\r
111 public Type getRawType() {
\r
115 public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
\r
116 super(rawType.getPackageName(), rawType.getName());
\r
117 this.rawType = rawType;
\r
118 this.actualTypes = actTypes;
\r