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.mdsal.binding.model.util;
10 import static org.opendaylight.mdsal.binding.model.util.Types.parameterizedTypeFor;
11 import static org.opendaylight.mdsal.binding.model.util.Types.typeForClass;
13 import com.google.common.annotations.VisibleForTesting;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.mdsal.binding.model.api.ConcreteType;
16 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
17 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.yangtools.yang.binding.Action;
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.ChildOf;
24 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
25 import org.opendaylight.yangtools.yang.binding.DataContainer;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.DataRoot;
28 import org.opendaylight.yangtools.yang.binding.Identifiable;
29 import org.opendaylight.yangtools.yang.binding.Identifier;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.InstanceNotification;
32 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.binding.KeyedListAction;
34 import org.opendaylight.yangtools.yang.binding.KeyedListNotification;
35 import org.opendaylight.yangtools.yang.binding.Notification;
36 import org.opendaylight.yangtools.yang.binding.NotificationListener;
37 import org.opendaylight.yangtools.yang.binding.OpaqueObject;
38 import org.opendaylight.yangtools.yang.binding.RpcInput;
39 import org.opendaylight.yangtools.yang.binding.RpcOutput;
40 import org.opendaylight.yangtools.yang.binding.RpcService;
41 import org.opendaylight.yangtools.yang.binding.ScalarTypeObject;
42 import org.opendaylight.yangtools.yang.binding.TypeObject;
43 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
44 import org.opendaylight.yangtools.yang.common.QName;
45 import org.opendaylight.yangtools.yang.common.RpcResult;
47 public final class BindingTypes {
49 public static final ConcreteType BASE_IDENTITY = typeForClass(BaseIdentity.class);
50 public static final ConcreteType DATA_CONTAINER = typeForClass(DataContainer.class);
51 public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class);
52 public static final ConcreteType TYPE_OBJECT = typeForClass(TypeObject.class);
53 public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class);
54 public static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
55 public static final ConcreteType NOTIFICATION_LISTENER = typeForClass(NotificationListener.class);
56 public static final ConcreteType QNAME = typeForClass(QName.class);
57 public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
58 public static final ConcreteType RPC_OUTPUT = typeForClass(RpcOutput.class);
59 public static final ConcreteType RPC_SERVICE = typeForClass(RpcService.class);
60 public static final ConcreteType SCALAR_TYPE_OBJECT = typeForClass(ScalarTypeObject.class);
61 public static final ConcreteType INSTANCE_IDENTIFIER = typeForClass(InstanceIdentifier.class);
62 public static final ConcreteType KEYED_INSTANCE_IDENTIFIER = typeForClass(KeyedInstanceIdentifier.class);
64 // This is an annotation, we are current just referencing the type
65 public static final JavaTypeName ROUTING_CONTEXT = JavaTypeName.create(RoutingContext.class);
68 static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
70 static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
72 static final ConcreteType IDENTIFIABLE = typeForClass(Identifiable.class);
74 static final ConcreteType IDENTIFIER = typeForClass(Identifier.class);
76 private static final ConcreteType ACTION = typeForClass(Action.class);
77 private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class);
78 private static final ConcreteType CHOICE_IN = typeForClass(ChoiceIn.class);
79 private static final ConcreteType INSTANCE_NOTIFICATION = typeForClass(InstanceNotification.class);
80 private static final ConcreteType KEYED_LIST_ACTION = typeForClass(KeyedListAction.class);
81 private static final ConcreteType KEYED_LIST_NOTIFICATION = typeForClass(KeyedListNotification.class);
82 private static final ConcreteType OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
83 private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
85 private BindingTypes() {
90 * Type specializing {@link Action} for a particular type.
92 * @param parent Type of parent defining the action
93 * @param input Type input type
94 * @param output Type output type
95 * @return A parameterized type corresponding to {@code Action<Parent, Input, Output>}
96 * @throws NullPointerException if any argument is is null
98 public static ParameterizedType action(final Type parent, final Type input, final Type output) {
99 return parameterizedTypeFor(ACTION, instanceIdentifier(parent), input, output);
103 * Type specializing {@link KeyedListAction} for a particular type.
105 * @param parent Type of parent defining the action
106 * @param keyType Type of parent's key
107 * @param input Type input type
108 * @param output Type output type
109 * @return A parameterized type corresponding to {@code KeyedListAction<ParentKey, Parent, Input, Output>}
110 * @throws NullPointerException if any argument is is null
112 public static ParameterizedType keyedListAction(final Type parent, final Type keyType, final Type input,
114 return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
118 * Type specializing {@link InstanceNotification} for a particular type.
120 * @param parent Type of parent defining the notification
121 * @return A parameterized type corresponding to {@code InstanceNotification<Parent>}
122 * @throws NullPointerException if {@code parent} is is null
124 public static ParameterizedType instanceNotification(final Type concreteType, final Type parent) {
125 return parameterizedTypeFor(INSTANCE_NOTIFICATION, concreteType, parent);
129 * Type specializing {@link InstanceNotification} for a particular type.
131 * @param parent Type of parent defining the notification
132 * @param keyType Type of parent's key
133 * @return A parameterized type corresponding to {@code KeyedInstanceNotification<ParentKey, Parent>}
134 * @throws NullPointerException if any argument is is null
136 public static ParameterizedType keyedListNotification(final Type concreteType, final Type parent,
137 final Type keyType) {
138 return parameterizedTypeFor(KEYED_LIST_NOTIFICATION, concreteType, parent, keyType);
142 * Specialize {@link Augmentable} for a particular type.
144 * @param type Type for which to specialize
145 * @return A parameterized type corresponding to {@code Augmentable<Type>}
146 * @throws NullPointerException if {@code type} is null
148 public static @NonNull ParameterizedType augmentable(final Type type) {
149 return parameterizedTypeFor(AUGMENTABLE, type);
153 * Specialize {@link Augmentation} for a particular type.
155 * @param type Type for which to specialize
156 * @return A parameterized type corresponding to {@code Augmentation<Type>}
157 * @throws NullPointerException if {@code type} is null
159 public static @NonNull ParameterizedType augmentation(final Type type) {
160 return parameterizedTypeFor(AUGMENTATION, type);
164 * Specialize {@link ChildOf} for a particular type.
166 * @param type Type for which to specialize
167 * @return A parameterized type corresponding to {@code ChildOf<Type>}
168 * @throws NullPointerException if {@code type} is null
170 public static ParameterizedType childOf(final Type type) {
171 return parameterizedTypeFor(CHILD_OF, type);
175 * Type specializing {@link ChoiceIn} for a particular type.
177 * @param type Type for which to specialize
178 * @return A parameterized type corresponding to {@code ChoiceIn<Type>}
179 * @throws NullPointerException if {@code type} is null
181 public static ParameterizedType choiceIn(final Type type) {
182 return parameterizedTypeFor(CHOICE_IN, type);
186 * Type specializing {@link Identifier} for a particular type.
188 * @param type Type for which to specialize
189 * @return A parameterized type corresponding to {@code Identifier<Type>}
190 * @throws NullPointerException if {@code type} is null
192 public static ParameterizedType identifier(final Type type) {
193 return parameterizedTypeFor(IDENTIFIER, type);
197 * Type specializing {@link Identifiable} for a particular type.
199 * @param type Type for which to specialize
200 * @return A parameterized type corresponding to {@code Identifiable<Type>}
201 * @throws NullPointerException if {@code type} is null
203 public static ParameterizedType identifiable(final Type type) {
204 return parameterizedTypeFor(IDENTIFIABLE, type);
208 * Type specializing {@link InstanceIdentifier} for a particular type.
210 * @param type Type for which to specialize
211 * @return A parameterized type corresponding to {@code InstanceIdentifier<Type>}
212 * @throws NullPointerException if {@code type} is null
214 public static ParameterizedType instanceIdentifier(final Type type) {
215 return parameterizedTypeFor(INSTANCE_IDENTIFIER, type);
219 * Type specializing {@link KeyedInstanceIdentifier} for a particular type.
221 * @param type Type for which to specialize
222 * @param keyType Type of key
223 * @return A parameterized type corresponding to {@code KeyedInstanceIdentifier<Type, KeyType>}
224 * @throws NullPointerException if any argument is is null
226 public static ParameterizedType keyedInstanceIdentifier(final Type type, final Type keyType) {
227 return parameterizedTypeFor(KEYED_INSTANCE_IDENTIFIER, type, keyType);
231 * Type specializing {@link OpaqueObject} for a particular type.
233 * @param type Type for which to specialize
234 * @return A parameterized type corresponding to {@code OpaqueObject<Type>}
235 * @throws NullPointerException if {@code type} is null
237 public static ParameterizedType opaqueObject(final Type type) {
238 return parameterizedTypeFor(OPAQUE_OBJECT, type);
242 * Type specializing {@link RpcResult} for a particular type.
244 * @param type Type for which to specialize
245 * @return A parameterized type corresponding to {@code RpcResult<Type>}
246 * @throws NullPointerException if {@code type} is null
248 public static ParameterizedType rpcResult(final Type type) {
249 return parameterizedTypeFor(RPC_RESULT, type);
253 * Type specializing {@link ScalarTypeObject} for a particular type.
255 * @param type Type for which to specialize
256 * @return A parameterized type corresponding to {@code ScalarTypeObject<Type>}
257 * @throws NullPointerException if {@code type} is null
259 public static ParameterizedType scalarTypeObject(final Type type) {
260 return parameterizedTypeFor(SCALAR_TYPE_OBJECT, type);