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.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
\r
15 import org.opendaylight.controller.sal.binding.model.api.ConcreteType;
\r
16 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
\r
17 import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
\r
18 import org.opendaylight.controller.sal.binding.model.api.Type;
\r
19 import org.opendaylight.controller.sal.binding.model.api.WildcardType;
\r
20 import org.opendaylight.controller.yang.binding.Augmentable;
\r
21 import org.opendaylight.controller.yang.binding.Augmentation;
\r
22 import org.opendaylight.controller.yang.binding.BaseIdentity;
\r
23 import org.opendaylight.controller.yang.binding.DataObject;
\r
25 public final class Types {
\r
26 private static final Type SET_TYPE = typeForClass(Set.class);
\r
27 private static final Type LIST_TYPE = typeForClass(List.class);
\r
28 private static final Type MAP_TYPE = typeForClass(Map.class);
\r
29 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
36 public static final Type primitiveType(final String primitiveType) {
\r
37 return new ConcreteTypeImpl("", primitiveType);
\r
42 * Returns an instance of {@link ConcreteType} describing the class
\r
46 * @return Description of class
\r
48 public static ConcreteType typeForClass(Class<?> cls) {
\r
49 return new ConcreteTypeImpl(cls.getPackage().getName(),
\r
50 cls.getSimpleName());
\r
54 * Returns an instance of {@link ParameterizedType} describing the typed
\r
61 * @return Description of generic type instance
\r
63 public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {
\r
64 return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
\r
68 * Returns an instance of {@link ParameterizedType} describing the typed
\r
69 * {@link Set}<V> with concrete type of value.
\r
73 * @return Description of generic type instance of Set
\r
75 public static ParameterizedType setTypeFor(Type valueType) {
\r
76 return parameterizedTypeFor(SET_TYPE, valueType);
\r
80 * Returns an instance of {@link ParameterizedType} describing the typed
\r
81 * {@link List}<V> with concrete type of value.
\r
85 * @return Description of type instance of List
\r
87 public static ParameterizedType listTypeFor(Type valueType) {
\r
88 return parameterizedTypeFor(LIST_TYPE, valueType);
\r
91 public static GeneratedTransferObject getBaseIdentityTO() {
\r
92 Class<BaseIdentity> cls = BaseIdentity.class;
\r
93 GeneratedTOBuilderImpl gto = new GeneratedTOBuilderImpl(cls.getPackage().getName(),
\r
94 cls.getSimpleName());
\r
95 return gto.toInstance();
\r
101 * @param parameters
\r
104 public static ParameterizedType parameterizedTypeFor(Type type,
\r
105 Type... parameters) {
\r
106 return new ParametrizedTypeImpl(type, parameters);
\r
109 public static WildcardType wildcardTypeFor(String packageName, String typeName) {
\r
110 return new WildcardTypeImpl(packageName, typeName);
\r
113 public static ParameterizedType augmentableTypeFor(Type valueType) {
\r
114 final Type augmentable = typeForClass(Augmentable.class);
\r
115 return parameterizedTypeFor(augmentable, valueType);
\r
118 public static ParameterizedType augmentationTypeFor(Type valueType) {
\r
119 final Type augmentation = typeForClass(Augmentation.class);
\r
120 return parameterizedTypeFor(augmentation, valueType);
\r
123 private static class ConcreteTypeImpl extends AbstractBaseType implements
\r
125 private ConcreteTypeImpl(String pkName, String name) {
\r
126 super(pkName, name);
\r
130 private static class ParametrizedTypeImpl extends AbstractBaseType
\r
131 implements ParameterizedType {
\r
132 private Type[] actualTypes;
\r
133 private Type rawType;
\r
136 public Type[] getActualTypeArguments() {
\r
138 return actualTypes;
\r
142 public Type getRawType() {
\r
146 public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
\r
147 super(rawType.getPackageName(), rawType.getName());
\r
148 this.rawType = rawType;
\r
149 this.actualTypes = actTypes;
\r
154 private static class WildcardTypeImpl extends AbstractBaseType
\r
155 implements WildcardType {
\r
156 public WildcardTypeImpl(String packageName, String typeName) {
\r
157 super(packageName, typeName);
\r