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
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
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
26 public static final Type DATA_OBJECT = typeForClass(DataObject.class);
\r
31 public static ConcreteType voidType() {
\r
32 return new ConcreteTypeImpl(Void.class.getPackage().getName(),
\r
33 Void.class.getSimpleName());
\r
37 * Returns an instance of {@link ConcreteType} describing the class
\r
41 * @return Description of class
\r
43 public static ConcreteType typeForClass(Class<?> cls) {
\r
44 return new ConcreteTypeImpl(cls.getPackage().getName(),
\r
45 cls.getSimpleName());
\r
49 * Returns an instance of {@link ParameterizedType} describing the typed
\r
56 * @return Description of generic type instance
\r
58 public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {
\r
59 return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
\r
63 * Returns an instance of {@link ParameterizedType} describing the typed
\r
64 * {@link Set}<V> with concrete type of value.
\r
68 * @return Description of generic type instance of Set
\r
70 public static ParameterizedType setTypeFor(Type valueType) {
\r
71 return parameterizedTypeFor(SET_TYPE, valueType);
\r
75 * Returns an instance of {@link ParameterizedType} describing the typed
\r
76 * {@link List}<V> with concrete type of value.
\r
80 * @return Description of type instance of List
\r
82 public static ParameterizedType listTypeFor(Type valueType) {
\r
83 return parameterizedTypeFor(LIST_TYPE, valueType);
\r
92 public static ParameterizedType parameterizedTypeFor(Type type,
\r
93 Type... parameters) {
\r
94 return new ParametrizedTypeImpl(type, parameters);
\r
97 public static ParameterizedType augmentableTypeFor(Type valueType) {
\r
98 final Type augmentable = typeForClass(Augmentable.class);
\r
99 return parameterizedTypeFor(augmentable, valueType);
\r
102 public static ParameterizedType augmentationTypeFor(Type valueType) {
\r
103 final Type augmentation = typeForClass(Augmentation.class);
\r
104 return parameterizedTypeFor(augmentation, valueType);
\r
107 private static class ConcreteTypeImpl extends AbstractBaseType implements
\r
109 private ConcreteTypeImpl(String pkName, String name) {
\r
110 super(pkName, name);
\r
114 private static class ParametrizedTypeImpl extends AbstractBaseType
\r
115 implements ParameterizedType {
\r
116 private Type[] actualTypes;
\r
117 private Type rawType;
\r
120 public Type[] getActualTypeArguments() {
\r
122 return actualTypes;
\r
126 public Type getRawType() {
\r
130 public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
\r
131 super(rawType.getPackageName(), rawType.getName());
\r
132 this.rawType = rawType;
\r
133 this.actualTypes = actTypes;
\r