4cfc2e9e4bbca4f33c83eed2012b81d5f78e11b0
[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.KeyedListAction;
31 import org.opendaylight.yangtools.yang.binding.Notification;
32 import org.opendaylight.yangtools.yang.binding.NotificationListener;
33 import org.opendaylight.yangtools.yang.binding.OpaqueObject;
34 import org.opendaylight.yangtools.yang.binding.RpcInput;
35 import org.opendaylight.yangtools.yang.binding.RpcOutput;
36 import org.opendaylight.yangtools.yang.binding.RpcService;
37 import org.opendaylight.yangtools.yang.binding.TypeObject;
38 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40
41 public final class BindingTypes {
42
43     public static final ConcreteType BASE_IDENTITY = typeForClass(BaseIdentity.class);
44     public static final ConcreteType DATA_CONTAINER = typeForClass(DataContainer.class);
45     public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class);
46     public static final ConcreteType TYPE_OBJECT = typeForClass(TypeObject.class);
47     public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class);
48     public static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
49     public static final ConcreteType NOTIFICATION_LISTENER = typeForClass(NotificationListener.class);
50     public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
51     public static final ConcreteType RPC_OUTPUT = typeForClass(RpcOutput.class);
52     public static final ConcreteType RPC_SERVICE = typeForClass(RpcService.class);
53
54     // This is an annotation, we are current just referencing the type
55     public static final JavaTypeName ROUTING_CONTEXT = JavaTypeName.create(RoutingContext.class);
56
57     @VisibleForTesting
58     static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
59     @VisibleForTesting
60     static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
61     @VisibleForTesting
62     static final ConcreteType IDENTIFIABLE = typeForClass(Identifiable.class);
63     @VisibleForTesting
64     static final ConcreteType IDENTIFIER = typeForClass(Identifier.class);
65     @VisibleForTesting
66     static final ConcreteType INSTANCE_IDENTIFIER = typeForClass(InstanceIdentifier.class);
67
68     private static final ConcreteType ACTION = typeForClass(Action.class);
69     private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class);
70     private static final ConcreteType CHOICE_IN = typeForClass(ChoiceIn.class);
71     private static final ConcreteType KEYED_LIST_ACTION = typeForClass(KeyedListAction.class);
72     private static final ConcreteType OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
73     private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
74
75     private BindingTypes() {
76
77     }
78
79     /**
80      * Type specializing {@link Action} for a particular type.
81      *
82      * @param parent Type of parent defining the action
83      * @param input Type input type
84      * @param output Type output type
85      * @return A parameterized type corresponding to {@code Action<Parent, Input, Output>}
86      * @throws NullPointerException if any argument is is null
87      */
88     public static ParameterizedType action(final Type parent, final Type input, final Type output) {
89         return parameterizedTypeFor(ACTION, instanceIdentifier(parent), input, output);
90     }
91
92     /**
93      * Type specializing {@link KeyedListAction} for a particular type.
94      *
95      * @param parent Type of parent defining the action
96      * @param keyType Type of parent's key
97      * @param input Type input type
98      * @param output Type output type
99      * @return A parameterized type corresponding to {@code KeyedListAction<ParentKey, Parent, Input, Output>}
100      * @throws NullPointerException if any argument is is null
101      */
102     public static ParameterizedType keyedListAction(final Type parent, final Type keyType, final Type input,
103             final Type output) {
104         return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
105     }
106
107     /**
108      * Specialize {@link Augmentable} for a particular type.
109      *
110      * @param type Type for which to specialize
111      * @return A parameterized type corresponding to {@code Augmentable<Type>}
112      * @throws NullPointerException if {@code type} is null
113      */
114     public static ParameterizedType augmentable(final Type type) {
115         return parameterizedTypeFor(AUGMENTABLE, type);
116     }
117
118     /**
119      * Specialize {@link ChildOf} for a particular type.
120      *
121      * @param type Type for which to specialize
122      * @return A parameterized type corresponding to {@code ChildOf<Type>}
123      * @throws NullPointerException if {@code type} is null
124      */
125     public static ParameterizedType childOf(final Type type) {
126         return parameterizedTypeFor(CHILD_OF, type);
127     }
128
129     /**
130      * Type specializing {@link ChoiceIn} for a particular type.
131      *
132      * @param type Type for which to specialize
133      * @return A parameterized type corresponding to {@code ChoiceIn<Type>}
134      * @throws NullPointerException if {@code type} is null
135      */
136     public static ParameterizedType choiceIn(final Type type) {
137         return parameterizedTypeFor(CHOICE_IN, type);
138     }
139
140     /**
141      * Type specializing {@link Identifier} for a particular type.
142      *
143      * @param type Type for which to specialize
144      * @return A parameterized type corresponding to {@code Identifier<Type>}
145      * @throws NullPointerException if {@code type} is null
146      */
147     public static ParameterizedType identifier(final Type type) {
148         return parameterizedTypeFor(IDENTIFIER, type);
149     }
150
151     /**
152      * Type specializing {@link Identifiable} for a particular type.
153      *
154      * @param type Type for which to specialize
155      * @return A parameterized type corresponding to {@code Identifiable<Type>}
156      * @throws NullPointerException if {@code type} is null
157      */
158     public static ParameterizedType identifiable(final Type type) {
159         return parameterizedTypeFor(IDENTIFIABLE, type);
160     }
161
162     /**
163      * Type specializing {@link InstanceIdentifier} for a particular type.
164      *
165      * @param type Type for which to specialize
166      * @return A parameterized type corresponding to {@code InstanceIdentifier<Type>}
167      * @throws NullPointerException if {@code type} is null
168      */
169     public static ParameterizedType instanceIdentifier(final Type type) {
170         return parameterizedTypeFor(INSTANCE_IDENTIFIER, type);
171     }
172
173     /**
174      * Type specializing {@link OpaqueObject} for a particular type.
175      *
176      * @param type Type for which to specialize
177      * @return A parameterized type corresponding to {@code OpaqueObject<Type>}
178      * @throws NullPointerException if {@code type} is null
179      */
180     public static ParameterizedType opaqueObject(final Type type) {
181         return parameterizedTypeFor(OPAQUE_OBJECT, type);
182     }
183
184     /**
185      * Type specializing {@link RpcResult} for a particular type.
186      *
187      * @param type Type for which to specialize
188      * @return A parameterized type corresponding to {@code RpcResult<Type>}
189      * @throws NullPointerException if {@code type} is null
190      */
191     public static ParameterizedType rpcResult(final Type type) {
192         return parameterizedTypeFor(RPC_RESULT, type);
193     }
194 }