Add codegen support for nested notifications
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / util / 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.util;
9
10 import static org.opendaylight.mdsal.binding.model.util.Types.parameterizedTypeFor;
11 import static org.opendaylight.mdsal.binding.model.util.Types.typeForClass;
12
13 import com.google.common.annotations.VisibleForTesting;
14 import org.opendaylight.mdsal.binding.model.api.ConcreteType;
15 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
16 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
17 import org.opendaylight.mdsal.binding.model.api.Type;
18 import org.opendaylight.yangtools.yang.binding.Action;
19 import org.opendaylight.yangtools.yang.binding.Augmentable;
20 import org.opendaylight.yangtools.yang.binding.Augmentation;
21 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
22 import org.opendaylight.yangtools.yang.binding.ChildOf;
23 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
24 import org.opendaylight.yangtools.yang.binding.DataContainer;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.DataRoot;
27 import org.opendaylight.yangtools.yang.binding.Identifiable;
28 import org.opendaylight.yangtools.yang.binding.Identifier;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.InstanceNotification;
31 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
32 import org.opendaylight.yangtools.yang.binding.KeyedListAction;
33 import org.opendaylight.yangtools.yang.binding.KeyedListNotification;
34 import org.opendaylight.yangtools.yang.binding.Notification;
35 import org.opendaylight.yangtools.yang.binding.NotificationListener;
36 import org.opendaylight.yangtools.yang.binding.OpaqueObject;
37 import org.opendaylight.yangtools.yang.binding.RpcInput;
38 import org.opendaylight.yangtools.yang.binding.RpcOutput;
39 import org.opendaylight.yangtools.yang.binding.RpcService;
40 import org.opendaylight.yangtools.yang.binding.TypeObject;
41 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
42 import org.opendaylight.yangtools.yang.common.RpcResult;
43
44 public final class BindingTypes {
45
46     public static final ConcreteType BASE_IDENTITY = typeForClass(BaseIdentity.class);
47     public static final ConcreteType DATA_CONTAINER = typeForClass(DataContainer.class);
48     public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class);
49     public static final ConcreteType TYPE_OBJECT = typeForClass(TypeObject.class);
50     public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class);
51     public static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
52     public static final ConcreteType NOTIFICATION_LISTENER = typeForClass(NotificationListener.class);
53     public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
54     public static final ConcreteType RPC_OUTPUT = typeForClass(RpcOutput.class);
55     public static final ConcreteType RPC_SERVICE = typeForClass(RpcService.class);
56
57     // This is an annotation, we are current just referencing the type
58     public static final JavaTypeName ROUTING_CONTEXT = JavaTypeName.create(RoutingContext.class);
59
60     @VisibleForTesting
61     static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
62     @VisibleForTesting
63     static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
64     @VisibleForTesting
65     static final ConcreteType IDENTIFIABLE = typeForClass(Identifiable.class);
66     @VisibleForTesting
67     static final ConcreteType IDENTIFIER = typeForClass(Identifier.class);
68     @VisibleForTesting
69     static final ConcreteType INSTANCE_IDENTIFIER = typeForClass(InstanceIdentifier.class);
70
71     private static final ConcreteType ACTION = typeForClass(Action.class);
72     private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class);
73     private static final ConcreteType CHOICE_IN = typeForClass(ChoiceIn.class);
74     private static final ConcreteType INSTANCE_NOTIFICATION = typeForClass(InstanceNotification.class);
75     private static final ConcreteType KEYED_INSTANCE_IDENTIFIER = typeForClass(KeyedInstanceIdentifier.class);
76     private static final ConcreteType KEYED_LIST_ACTION = typeForClass(KeyedListAction.class);
77     private static final ConcreteType KEYED_LIST_NOTIFICATION = typeForClass(KeyedListNotification.class);
78     private static final ConcreteType OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
79     private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
80
81     private BindingTypes() {
82
83     }
84
85     /**
86      * Type specializing {@link Action} for a particular type.
87      *
88      * @param parent Type of parent defining the action
89      * @param input Type input type
90      * @param output Type output type
91      * @return A parameterized type corresponding to {@code Action<Parent, Input, Output>}
92      * @throws NullPointerException if any argument is is null
93      */
94     public static ParameterizedType action(final Type parent, final Type input, final Type output) {
95         return parameterizedTypeFor(ACTION, instanceIdentifier(parent), input, output);
96     }
97
98     /**
99      * Type specializing {@link KeyedListAction} for a particular type.
100      *
101      * @param parent Type of parent defining the action
102      * @param keyType Type of parent's key
103      * @param input Type input type
104      * @param output Type output type
105      * @return A parameterized type corresponding to {@code KeyedListAction<ParentKey, Parent, Input, Output>}
106      * @throws NullPointerException if any argument is is null
107      */
108     public static ParameterizedType keyedListAction(final Type parent, final Type keyType, final Type input,
109             final Type output) {
110         return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
111     }
112
113     /**
114      * Type specializing {@link InstanceNotification} for a particular type.
115      *
116      * @param parent Type of parent defining the notification
117      * @return A parameterized type corresponding to {@code InstanceNotification<Parent>}
118      * @throws NullPointerException if {@code parent} is is null
119      */
120     public static ParameterizedType instanceNotification(final Type concreteType, final Type parent) {
121         return parameterizedTypeFor(INSTANCE_NOTIFICATION, concreteType, parent);
122     }
123
124     /**
125      * Type specializing {@link InstanceNotification} for a particular type.
126      *
127      * @param parent Type of parent defining the notification
128      * @param keyType Type of parent's key
129      * @return A parameterized type corresponding to {@code KeyedInstanceNotification<ParentKey, Parent>}
130      * @throws NullPointerException if any argument is is null
131      */
132     public static ParameterizedType keyedListNotification(final Type concreteType, final Type parent,
133             final Type keyType) {
134         return parameterizedTypeFor(KEYED_LIST_NOTIFICATION, concreteType, parent, keyType);
135     }
136
137     /**
138      * Specialize {@link Augmentable} for a particular type.
139      *
140      * @param type Type for which to specialize
141      * @return A parameterized type corresponding to {@code Augmentable<Type>}
142      * @throws NullPointerException if {@code type} is null
143      */
144     public static ParameterizedType augmentable(final Type type) {
145         return parameterizedTypeFor(AUGMENTABLE, type);
146     }
147
148     /**
149      * Specialize {@link ChildOf} for a particular type.
150      *
151      * @param type Type for which to specialize
152      * @return A parameterized type corresponding to {@code ChildOf<Type>}
153      * @throws NullPointerException if {@code type} is null
154      */
155     public static ParameterizedType childOf(final Type type) {
156         return parameterizedTypeFor(CHILD_OF, type);
157     }
158
159     /**
160      * Type specializing {@link ChoiceIn} for a particular type.
161      *
162      * @param type Type for which to specialize
163      * @return A parameterized type corresponding to {@code ChoiceIn<Type>}
164      * @throws NullPointerException if {@code type} is null
165      */
166     public static ParameterizedType choiceIn(final Type type) {
167         return parameterizedTypeFor(CHOICE_IN, type);
168     }
169
170     /**
171      * Type specializing {@link Identifier} for a particular type.
172      *
173      * @param type Type for which to specialize
174      * @return A parameterized type corresponding to {@code Identifier<Type>}
175      * @throws NullPointerException if {@code type} is null
176      */
177     public static ParameterizedType identifier(final Type type) {
178         return parameterizedTypeFor(IDENTIFIER, type);
179     }
180
181     /**
182      * Type specializing {@link Identifiable} for a particular type.
183      *
184      * @param type Type for which to specialize
185      * @return A parameterized type corresponding to {@code Identifiable<Type>}
186      * @throws NullPointerException if {@code type} is null
187      */
188     public static ParameterizedType identifiable(final Type type) {
189         return parameterizedTypeFor(IDENTIFIABLE, type);
190     }
191
192     /**
193      * Type specializing {@link InstanceIdentifier} for a particular type.
194      *
195      * @param type Type for which to specialize
196      * @return A parameterized type corresponding to {@code InstanceIdentifier<Type>}
197      * @throws NullPointerException if {@code type} is null
198      */
199     public static ParameterizedType instanceIdentifier(final Type type) {
200         return parameterizedTypeFor(INSTANCE_IDENTIFIER, type);
201     }
202
203     /**
204      * Type specializing {@link KeyedInstanceIdentifier} for a particular type.
205      *
206      * @param type Type for which to specialize
207      * @param keyType Type of key
208      * @return A parameterized type corresponding to {@code KeyedInstanceIdentifier<Type, KeyType>}
209      * @throws NullPointerException if any argument is is null
210      */
211     public static ParameterizedType keyedInstanceIdentifier(final Type type, final Type keyType) {
212         return parameterizedTypeFor(KEYED_INSTANCE_IDENTIFIER, type, keyType);
213     }
214
215     /**
216      * Type specializing {@link OpaqueObject} for a particular type.
217      *
218      * @param type Type for which to specialize
219      * @return A parameterized type corresponding to {@code OpaqueObject<Type>}
220      * @throws NullPointerException if {@code type} is null
221      */
222     public static ParameterizedType opaqueObject(final Type type) {
223         return parameterizedTypeFor(OPAQUE_OBJECT, type);
224     }
225
226     /**
227      * Type specializing {@link RpcResult} for a particular type.
228      *
229      * @param type Type for which to specialize
230      * @return A parameterized type corresponding to {@code RpcResult<Type>}
231      * @throws NullPointerException if {@code type} is null
232      */
233     public static ParameterizedType rpcResult(final Type type) {
234         return parameterizedTypeFor(RPC_RESULT, type);
235     }
236 }