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