2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.binding.generator.util;
10 import java.util.List;
14 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
15 import org.opendaylight.controller.sal.binding.model.api.ConcreteType;
16 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
17 import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
18 import org.opendaylight.controller.sal.binding.model.api.Type;
19 import org.opendaylight.controller.sal.binding.model.api.WildcardType;
20 import org.opendaylight.yangtools.yang.binding.Augmentable;
21 import org.opendaylight.yangtools.yang.binding.Augmentation;
22 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
25 public final class Types {
26 private static final Type SET_TYPE = typeForClass(Set.class);
27 private static final Type LIST_TYPE = typeForClass(List.class);
28 private static final Type MAP_TYPE = typeForClass(Map.class);
29 public static final Type DATA_OBJECT = typeForClass(DataObject.class);
31 public static ConcreteType voidType() {
32 return new ConcreteTypeImpl(Void.class.getPackage().getName(), Void.class.getSimpleName());
35 public static final Type primitiveType(final String primitiveType) {
36 return new ConcreteTypeImpl("", primitiveType);
40 * Returns an instance of {@link ConcreteType} describing the class
44 * @return Description of class
46 public static ConcreteType typeForClass(Class<?> cls) {
47 return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName());
51 * Returns an instance of {@link ParameterizedType} describing the typed
58 * @return Description of generic type instance
60 public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {
61 return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
65 * Returns an instance of {@link ParameterizedType} describing the typed
66 * {@link Set}<V> with concrete type of value.
70 * @return Description of generic type instance of Set
72 public static ParameterizedType setTypeFor(Type valueType) {
73 return parameterizedTypeFor(SET_TYPE, valueType);
77 * Returns an instance of {@link ParameterizedType} describing the typed
78 * {@link List}<V> with concrete type of value.
82 * @return Description of type instance of List
84 public static ParameterizedType listTypeFor(Type valueType) {
85 return parameterizedTypeFor(LIST_TYPE, valueType);
88 public static GeneratedTransferObject getBaseIdentityTO() {
89 Class<BaseIdentity> cls = BaseIdentity.class;
90 GeneratedTOBuilderImpl gto = new GeneratedTOBuilderImpl(cls.getPackage().getName(), cls.getSimpleName());
91 return gto.toInstance();
100 public static ParameterizedType parameterizedTypeFor(Type type, Type... parameters) {
101 return new ParametrizedTypeImpl(type, parameters);
104 public static WildcardType wildcardTypeFor(String packageName, String typeName) {
105 return new WildcardTypeImpl(packageName, typeName);
108 public static ParameterizedType augmentableTypeFor(Type valueType) {
109 final Type augmentable = typeForClass(Augmentable.class);
110 return parameterizedTypeFor(augmentable, valueType);
113 public static ParameterizedType augmentationTypeFor(Type valueType) {
114 final Type augmentation = typeForClass(Augmentation.class);
115 return parameterizedTypeFor(augmentation, valueType);
118 private static class ConcreteTypeImpl extends AbstractBaseType implements ConcreteType {
119 private ConcreteTypeImpl(String pkName, String name) {
124 private static class ParametrizedTypeImpl extends AbstractBaseType implements ParameterizedType {
125 private Type[] actualTypes;
126 private Type rawType;
129 public Type[] getActualTypeArguments() {
135 public Type getRawType() {
139 public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
140 super(rawType.getPackageName(), rawType.getName());
141 this.rawType = rawType;
142 this.actualTypes = actTypes;
147 private static class WildcardTypeImpl extends AbstractBaseType implements WildcardType {
148 public WildcardTypeImpl(String packageName, String typeName) {
149 super(packageName, typeName);