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
25 public static final Type DATA_OBJECT = typeForClass(DataObject.class);
\r
27 public static ConcreteType voidType() {
\r
28 return new ConcreteTypeImpl(Void.class.getPackage().getName(),
\r
29 Void.class.getSimpleName());
\r
32 public static final Type primitiveType(final String primitiveType) {
\r
33 return new ConcreteTypeImpl("", primitiveType);
\r
38 * Returns an instance of {@link ConcreteType} describing the class
\r
42 * @return Description of class
\r
44 public static ConcreteType typeForClass(Class<?> cls) {
\r
45 return new ConcreteTypeImpl(cls.getPackage().getName(),
\r
46 cls.getSimpleName());
\r
50 * Returns an instance of {@link ParameterizedType} describing the typed
\r
57 * @return Description of generic type instance
\r
59 public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {
\r
60 return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
\r
64 * Returns an instance of {@link ParameterizedType} describing the typed
\r
65 * {@link Set}<V> with concrete type of value.
\r
69 * @return Description of generic type instance of Set
\r
71 public static ParameterizedType setTypeFor(Type valueType) {
\r
72 return parameterizedTypeFor(SET_TYPE, valueType);
\r
76 * Returns an instance of {@link ParameterizedType} describing the typed
\r
77 * {@link List}<V> with concrete type of value.
\r
81 * @return Description of type instance of List
\r
83 public static ParameterizedType listTypeFor(Type valueType) {
\r
84 return parameterizedTypeFor(LIST_TYPE, valueType);
\r
93 public static ParameterizedType parameterizedTypeFor(Type type,
\r
94 Type... parameters) {
\r
95 return new ParametrizedTypeImpl(type, parameters);
\r
98 public static ParameterizedType augmentableTypeFor(Type valueType) {
\r
99 final Type augmentable = typeForClass(Augmentable.class);
\r
100 return parameterizedTypeFor(augmentable, valueType);
\r
103 public static ParameterizedType augmentationTypeFor(Type valueType) {
\r
104 final Type augmentation = typeForClass(Augmentation.class);
\r
105 return parameterizedTypeFor(augmentation, valueType);
\r
108 private static class ConcreteTypeImpl extends AbstractBaseType implements
\r
110 private ConcreteTypeImpl(String pkName, String name) {
\r
111 super(pkName, name);
\r
115 private static class ParametrizedTypeImpl extends AbstractBaseType
\r
116 implements ParameterizedType {
\r
117 private Type[] actualTypes;
\r
118 private Type rawType;
\r
121 public Type[] getActualTypeArguments() {
\r
123 return actualTypes;
\r
127 public Type getRawType() {
\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