c4beb7b174144d2a046e2a00e67efafee327a20b
[mdsal.git] / binding / mdsal-binding-model-ri / src / main / java / org / opendaylight / mdsal / binding / model / ri / BindingTypes.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.model.ri;
9
10 import static org.opendaylight.mdsal.binding.model.ri.Types.parameterizedTypeFor;
11 import static org.opendaylight.mdsal.binding.model.ri.Types.typeForClass;
12
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;
46
47 public final class BindingTypes {
48
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_LISTENER = typeForClass(NotificationListener.class);
55     public static final ConcreteType QNAME = typeForClass(QName.class);
56     public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
57     public static final ConcreteType RPC_OUTPUT = typeForClass(RpcOutput.class);
58     public static final ConcreteType RPC_SERVICE = typeForClass(RpcService.class);
59     public static final ConcreteType SCALAR_TYPE_OBJECT = typeForClass(ScalarTypeObject.class);
60     public static final ConcreteType INSTANCE_IDENTIFIER = typeForClass(InstanceIdentifier.class);
61     public static final ConcreteType KEYED_INSTANCE_IDENTIFIER = typeForClass(KeyedInstanceIdentifier.class);
62
63     // This is an annotation, we are current just referencing the type
64     public static final JavaTypeName ROUTING_CONTEXT = JavaTypeName.create(RoutingContext.class);
65
66     @VisibleForTesting
67     static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
68     @VisibleForTesting
69     static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
70     @VisibleForTesting
71     static final ConcreteType IDENTIFIABLE = typeForClass(Identifiable.class);
72     @VisibleForTesting
73     static final ConcreteType IDENTIFIER = typeForClass(Identifier.class);
74
75     private static final ConcreteType ACTION = typeForClass(Action.class);
76     private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class);
77     private static final ConcreteType CHOICE_IN = typeForClass(ChoiceIn.class);
78     private static final ConcreteType INSTANCE_NOTIFICATION = typeForClass(InstanceNotification.class);
79     private static final ConcreteType KEYED_LIST_ACTION = typeForClass(KeyedListAction.class);
80     private static final ConcreteType KEYED_LIST_NOTIFICATION = typeForClass(KeyedListNotification.class);
81     private static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
82     private static final ConcreteType OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
83     private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
84
85     private BindingTypes() {
86
87     }
88
89     /**
90      * Type specializing {@link Action} for a particular type.
91      *
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
97      */
98     public static ParameterizedType action(final Type parent, final Type input, final Type output) {
99         return parameterizedTypeFor(ACTION, instanceIdentifier(parent), input, output);
100     }
101
102     /**
103      * Type specializing {@link KeyedListAction} for a particular type.
104      *
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
111      */
112     public static ParameterizedType keyedListAction(final Type parent, final Type keyType, final Type input,
113             final Type output) {
114         return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
115     }
116
117     /**
118      * Type specializing {@link Notification} for a particular type.
119      *
120      * @param concreteType The concrete type of this notification
121      * @return A parameterized type corresponding to {@code Notification<ConcreteType>}
122      * @throws NullPointerException if any argument is is null
123      */
124     public static ParameterizedType notification(final Type concreteType) {
125         return parameterizedTypeFor(NOTIFICATION, concreteType);
126     }
127
128     /**
129      * Type specializing {@link InstanceNotification} for a particular type.
130      *
131      * @param concreteType The concrete type of this notification
132      * @param parent Type of parent defining the notification
133      * @return A parameterized type corresponding to {@code InstanceNotification<ConcreteType, Parent>}
134      * @throws NullPointerException if {@code parent} is is null
135      */
136     public static ParameterizedType instanceNotification(final Type concreteType, final Type parent) {
137         return parameterizedTypeFor(INSTANCE_NOTIFICATION, concreteType, parent);
138     }
139
140     /**
141      * Type specializing {@link InstanceNotification} for a particular type.
142      *
143      * @param concreteType The concrete type of this notification
144      * @param parent Type of parent defining the notification
145      * @param keyType Type of parent's key
146      * @return A parameterized type corresponding to {@code KeyedInstanceNotification<ConcreteType, ParentKey, Parent>}
147      * @throws NullPointerException if any argument is is null
148      */
149     public static ParameterizedType keyedListNotification(final Type concreteType, final Type parent,
150             final Type keyType) {
151         return parameterizedTypeFor(KEYED_LIST_NOTIFICATION, concreteType, parent, keyType);
152     }
153
154     /**
155      * Specialize {@link Augmentable} for a particular type.
156      *
157      * @param type Type for which to specialize
158      * @return A parameterized type corresponding to {@code Augmentable<Type>}
159      * @throws NullPointerException if {@code type} is null
160      */
161     public static @NonNull ParameterizedType augmentable(final Type type) {
162         return parameterizedTypeFor(AUGMENTABLE, type);
163     }
164
165     /**
166      * Specialize {@link Augmentation} for a particular type.
167      *
168      * @param type Type for which to specialize
169      * @return A parameterized type corresponding to {@code Augmentation<Type>}
170      * @throws NullPointerException if {@code type} is null
171      */
172     public static @NonNull ParameterizedType augmentation(final Type type) {
173         return parameterizedTypeFor(AUGMENTATION, type);
174     }
175
176     /**
177      * Specialize {@link ChildOf} for a particular type.
178      *
179      * @param type Type for which to specialize
180      * @return A parameterized type corresponding to {@code ChildOf<Type>}
181      * @throws NullPointerException if {@code type} is null
182      */
183     public static ParameterizedType childOf(final Type type) {
184         return parameterizedTypeFor(CHILD_OF, type);
185     }
186
187     /**
188      * Type specializing {@link ChoiceIn} for a particular type.
189      *
190      * @param type Type for which to specialize
191      * @return A parameterized type corresponding to {@code ChoiceIn<Type>}
192      * @throws NullPointerException if {@code type} is null
193      */
194     public static ParameterizedType choiceIn(final Type type) {
195         return parameterizedTypeFor(CHOICE_IN, type);
196     }
197
198     /**
199      * Type specializing {@link Identifier} for a particular type.
200      *
201      * @param type Type for which to specialize
202      * @return A parameterized type corresponding to {@code Identifier<Type>}
203      * @throws NullPointerException if {@code type} is null
204      */
205     public static ParameterizedType identifier(final Type type) {
206         return parameterizedTypeFor(IDENTIFIER, type);
207     }
208
209     /**
210      * Type specializing {@link Identifiable} for a particular type.
211      *
212      * @param type Type for which to specialize
213      * @return A parameterized type corresponding to {@code Identifiable<Type>}
214      * @throws NullPointerException if {@code type} is null
215      */
216     public static ParameterizedType identifiable(final Type type) {
217         return parameterizedTypeFor(IDENTIFIABLE, type);
218     }
219
220     /**
221      * Type specializing {@link InstanceIdentifier} for a particular type.
222      *
223      * @param type Type for which to specialize
224      * @return A parameterized type corresponding to {@code InstanceIdentifier<Type>}
225      * @throws NullPointerException if {@code type} is null
226      */
227     public static ParameterizedType instanceIdentifier(final Type type) {
228         return parameterizedTypeFor(INSTANCE_IDENTIFIER, type);
229     }
230
231     /**
232      * Type specializing {@link KeyedInstanceIdentifier} for a particular type.
233      *
234      * @param type Type for which to specialize
235      * @param keyType Type of key
236      * @return A parameterized type corresponding to {@code KeyedInstanceIdentifier<Type, KeyType>}
237      * @throws NullPointerException if any argument is is null
238      */
239     public static ParameterizedType keyedInstanceIdentifier(final Type type, final Type keyType) {
240         return parameterizedTypeFor(KEYED_INSTANCE_IDENTIFIER, type, keyType);
241     }
242
243     /**
244      * Type specializing {@link OpaqueObject} for a particular type.
245      *
246      * @param type Type for which to specialize
247      * @return A parameterized type corresponding to {@code OpaqueObject<Type>}
248      * @throws NullPointerException if {@code type} is null
249      */
250     public static ParameterizedType opaqueObject(final Type type) {
251         return parameterizedTypeFor(OPAQUE_OBJECT, type);
252     }
253
254     /**
255      * Type specializing {@link RpcResult} for a particular type.
256      *
257      * @param type Type for which to specialize
258      * @return A parameterized type corresponding to {@code RpcResult<Type>}
259      * @throws NullPointerException if {@code type} is null
260      */
261     public static ParameterizedType rpcResult(final Type type) {
262         return parameterizedTypeFor(RPC_RESULT, type);
263     }
264
265     /**
266      * Type specializing {@link ScalarTypeObject} for a particular type.
267      *
268      * @param type Type for which to specialize
269      * @return A parameterized type corresponding to {@code ScalarTypeObject<Type>}
270      * @throws NullPointerException if {@code type} is null
271      */
272     public static ParameterizedType scalarTypeObject(final Type type) {
273         return parameterizedTypeFor(SCALAR_TYPE_OBJECT, type);
274     }
275 }