Add BindingTypes.augmentation()
[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.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.TypeObject;
42 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
43 import org.opendaylight.yangtools.yang.common.QName;
44 import org.opendaylight.yangtools.yang.common.RpcResult;
45
46 public final class BindingTypes {
47
48     public static final ConcreteType BASE_IDENTITY = typeForClass(BaseIdentity.class);
49     public static final ConcreteType DATA_CONTAINER = typeForClass(DataContainer.class);
50     public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class);
51     public static final ConcreteType TYPE_OBJECT = typeForClass(TypeObject.class);
52     public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class);
53     public static final ConcreteType NOTIFICATION = typeForClass(Notification.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
60     // This is an annotation, we are current just referencing the type
61     public static final JavaTypeName ROUTING_CONTEXT = JavaTypeName.create(RoutingContext.class);
62
63     @VisibleForTesting
64     static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
65     @VisibleForTesting
66     static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
67     @VisibleForTesting
68     static final ConcreteType IDENTIFIABLE = typeForClass(Identifiable.class);
69     @VisibleForTesting
70     static final ConcreteType IDENTIFIER = typeForClass(Identifier.class);
71     @VisibleForTesting
72     static final ConcreteType INSTANCE_IDENTIFIER = typeForClass(InstanceIdentifier.class);
73
74     private static final ConcreteType ACTION = typeForClass(Action.class);
75     private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class);
76     private static final ConcreteType CHOICE_IN = typeForClass(ChoiceIn.class);
77     private static final ConcreteType INSTANCE_NOTIFICATION = typeForClass(InstanceNotification.class);
78     private static final ConcreteType KEYED_INSTANCE_IDENTIFIER = typeForClass(KeyedInstanceIdentifier.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 OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
82     private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
83
84     private BindingTypes() {
85
86     }
87
88     /**
89      * Type specializing {@link Action} for a particular type.
90      *
91      * @param parent Type of parent defining the action
92      * @param input Type input type
93      * @param output Type output type
94      * @return A parameterized type corresponding to {@code Action<Parent, Input, Output>}
95      * @throws NullPointerException if any argument is is null
96      */
97     public static ParameterizedType action(final Type parent, final Type input, final Type output) {
98         return parameterizedTypeFor(ACTION, instanceIdentifier(parent), input, output);
99     }
100
101     /**
102      * Type specializing {@link KeyedListAction} for a particular type.
103      *
104      * @param parent Type of parent defining the action
105      * @param keyType Type of parent's key
106      * @param input Type input type
107      * @param output Type output type
108      * @return A parameterized type corresponding to {@code KeyedListAction<ParentKey, Parent, Input, Output>}
109      * @throws NullPointerException if any argument is is null
110      */
111     public static ParameterizedType keyedListAction(final Type parent, final Type keyType, final Type input,
112             final Type output) {
113         return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
114     }
115
116     /**
117      * Type specializing {@link InstanceNotification} for a particular type.
118      *
119      * @param parent Type of parent defining the notification
120      * @return A parameterized type corresponding to {@code InstanceNotification<Parent>}
121      * @throws NullPointerException if {@code parent} is is null
122      */
123     public static ParameterizedType instanceNotification(final Type concreteType, final Type parent) {
124         return parameterizedTypeFor(INSTANCE_NOTIFICATION, concreteType, parent);
125     }
126
127     /**
128      * Type specializing {@link InstanceNotification} for a particular type.
129      *
130      * @param parent Type of parent defining the notification
131      * @param keyType Type of parent's key
132      * @return A parameterized type corresponding to {@code KeyedInstanceNotification<ParentKey, Parent>}
133      * @throws NullPointerException if any argument is is null
134      */
135     public static ParameterizedType keyedListNotification(final Type concreteType, final Type parent,
136             final Type keyType) {
137         return parameterizedTypeFor(KEYED_LIST_NOTIFICATION, concreteType, parent, keyType);
138     }
139
140     /**
141      * Specialize {@link Augmentable} for a particular type.
142      *
143      * @param type Type for which to specialize
144      * @return A parameterized type corresponding to {@code Augmentable<Type>}
145      * @throws NullPointerException if {@code type} is null
146      */
147     public static @NonNull ParameterizedType augmentable(final Type type) {
148         return parameterizedTypeFor(AUGMENTABLE, type);
149     }
150
151     /**
152      * Specialize {@link Augmentation} for a particular type.
153      *
154      * @param type Type for which to specialize
155      * @return A parameterized type corresponding to {@code Augmentation<Type>}
156      * @throws NullPointerException if {@code type} is null
157      */
158     public static @NonNull ParameterizedType augmentation(final Type type) {
159         return parameterizedTypeFor(AUGMENTATION, type);
160     }
161
162     /**
163      * Specialize {@link ChildOf} for a particular type.
164      *
165      * @param type Type for which to specialize
166      * @return A parameterized type corresponding to {@code ChildOf<Type>}
167      * @throws NullPointerException if {@code type} is null
168      */
169     public static ParameterizedType childOf(final Type type) {
170         return parameterizedTypeFor(CHILD_OF, type);
171     }
172
173     /**
174      * Type specializing {@link ChoiceIn} for a particular type.
175      *
176      * @param type Type for which to specialize
177      * @return A parameterized type corresponding to {@code ChoiceIn<Type>}
178      * @throws NullPointerException if {@code type} is null
179      */
180     public static ParameterizedType choiceIn(final Type type) {
181         return parameterizedTypeFor(CHOICE_IN, type);
182     }
183
184     /**
185      * Type specializing {@link Identifier} for a particular type.
186      *
187      * @param type Type for which to specialize
188      * @return A parameterized type corresponding to {@code Identifier<Type>}
189      * @throws NullPointerException if {@code type} is null
190      */
191     public static ParameterizedType identifier(final Type type) {
192         return parameterizedTypeFor(IDENTIFIER, type);
193     }
194
195     /**
196      * Type specializing {@link Identifiable} for a particular type.
197      *
198      * @param type Type for which to specialize
199      * @return A parameterized type corresponding to {@code Identifiable<Type>}
200      * @throws NullPointerException if {@code type} is null
201      */
202     public static ParameterizedType identifiable(final Type type) {
203         return parameterizedTypeFor(IDENTIFIABLE, type);
204     }
205
206     /**
207      * Type specializing {@link InstanceIdentifier} for a particular type.
208      *
209      * @param type Type for which to specialize
210      * @return A parameterized type corresponding to {@code InstanceIdentifier<Type>}
211      * @throws NullPointerException if {@code type} is null
212      */
213     public static ParameterizedType instanceIdentifier(final Type type) {
214         return parameterizedTypeFor(INSTANCE_IDENTIFIER, type);
215     }
216
217     /**
218      * Type specializing {@link KeyedInstanceIdentifier} for a particular type.
219      *
220      * @param type Type for which to specialize
221      * @param keyType Type of key
222      * @return A parameterized type corresponding to {@code KeyedInstanceIdentifier<Type, KeyType>}
223      * @throws NullPointerException if any argument is is null
224      */
225     public static ParameterizedType keyedInstanceIdentifier(final Type type, final Type keyType) {
226         return parameterizedTypeFor(KEYED_INSTANCE_IDENTIFIER, type, keyType);
227     }
228
229     /**
230      * Type specializing {@link OpaqueObject} for a particular type.
231      *
232      * @param type Type for which to specialize
233      * @return A parameterized type corresponding to {@code OpaqueObject<Type>}
234      * @throws NullPointerException if {@code type} is null
235      */
236     public static ParameterizedType opaqueObject(final Type type) {
237         return parameterizedTypeFor(OPAQUE_OBJECT, type);
238     }
239
240     /**
241      * Type specializing {@link RpcResult} for a particular type.
242      *
243      * @param type Type for which to specialize
244      * @return A parameterized type corresponding to {@code RpcResult<Type>}
245      * @throws NullPointerException if {@code type} is null
246      */
247     public static ParameterizedType rpcResult(final Type type) {
248         return parameterizedTypeFor(RPC_RESULT, type);
249     }
250 }