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