Merge "BUG-624 make netconf tcp address optional in config.ini with default value...
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / ModuleMXBeanEntry.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.controller.config.yangjmxgenerator;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.Map;
13 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
14 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19
20 /**
21  * Represents part of yang model that describes a module.
22  *
23  * Example:
24  * <p>
25  * <blockquote>
26  *
27  * <pre>
28  *  identity threadpool-dynamic {
29  *      base config:module-type;
30  *      description "threadpool-dynamic description";
31  *      config:provided-service "th2:threadpool";
32  *      config:provided-service "th2:scheduled-threadpool";
33  *      config:java-name-prefix DynamicThreadPool
34  *  }
35  *  augment "/config:modules/config:module/config:module-type" {
36  *     case threadpool-dynamic {
37  *         when "/config:modules/config:module/config:module-type = 'threadpool-dynamic'";
38  *
39  *         container "configuration" {
40  *             // regular java attribute
41  *             leaf core-size {
42  *                 type uint32;
43  *          }
44  *
45  *             ...
46  *          // dependency
47  *             container threadfactory {
48  *                 uses config:service-ref {
49  *                     refine type {
50  *                         config:required-identity th:threadfactory;
51  *                  }
52  *              }
53  *          }
54  *      }
55  * }
56  * </pre>
57  *
58  * </blockquote>
59  * </p>
60  */
61 public class ModuleMXBeanEntry extends AbstractEntry {
62
63     private static final String MODULE_SUFFIX = "Module";
64     private static final String FACTORY_SUFFIX = MODULE_SUFFIX + "Factory";
65     private static final String CLASS_NAME_SUFFIX = MODULE_SUFFIX + "MXBean";
66     private static final String ABSTRACT_PREFIX = "Abstract";
67
68     private final ModuleMXBeanEntryInitial initial;
69
70     private Map<String, AttributeIfc> yangToAttributes;
71
72     private final Map<String, QName> providedServices;
73
74     private Collection<RuntimeBeanEntry> runtimeBeans;
75     private String nullableDummyContainerName;
76
77     ModuleMXBeanEntry(ModuleMXBeanEntryInitial initials, Map<String, AttributeIfc> yangToAttributes,
78             Map<String, QName> providedServices2, Collection<RuntimeBeanEntry> runtimeBeans) {
79         this.yangToAttributes = yangToAttributes;
80         this.providedServices = Collections.unmodifiableMap(providedServices2);
81         this.runtimeBeans = runtimeBeans;
82         this.initial = initials;
83     }
84
85     public String getMXBeanInterfaceName() {
86         return initial.javaNamePrefix + CLASS_NAME_SUFFIX;
87     }
88
89     public String getStubFactoryName() {
90         return initial.javaNamePrefix + FACTORY_SUFFIX;
91     }
92
93     public String getAbstractFactoryName() {
94         return ABSTRACT_PREFIX + getStubFactoryName();
95     }
96
97     public String getStubModuleName() {
98         return initial.javaNamePrefix + MODULE_SUFFIX;
99     }
100
101     public String getAbstractModuleName() {
102         return ABSTRACT_PREFIX + getStubModuleName();
103     }
104
105     public String getFullyQualifiedName(String typeName) {
106         return FullyQualifiedNameHelper.getFullyQualifiedName(initial.packageName,
107                 typeName);
108     }
109
110     public String getGloballyUniqueName() {
111         return initial.localName;
112     }
113
114     public String getPackageName() {
115         return initial.packageName;
116     }
117
118     /**
119      * @return services implemented by this module. Keys are fully qualified
120      *         java names of generated ServiceInterface classes, values are
121      *         identity local names.
122      */
123     public Map<String, QName> getProvidedServices() {
124         return providedServices;
125     }
126
127     public void setRuntimeBeans(Collection<RuntimeBeanEntry> newRuntimeBeans) {
128         runtimeBeans = newRuntimeBeans;
129     }
130
131     public Collection<RuntimeBeanEntry> getRuntimeBeans() {
132         return runtimeBeans;
133     }
134
135     public String getJavaNamePrefix() {
136         return initial.javaNamePrefix;
137     }
138
139     public String getNamespace() {
140         return initial.namespace;
141     }
142
143     /**
144      * Transform module to zero or more ModuleMXBeanEntry instances. Each
145      * instance must have a globally unique local name.
146      *
147      * @return Map of identity local names as keys, and ModuleMXBeanEntry
148      *         instances as values
149      */
150     public static Map<String/* identity local name */, ModuleMXBeanEntry> create(
151             Module currentModule,
152             Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
153             SchemaContext schemaContext,
154             TypeProviderWrapper typeProviderWrapper, String packageName) {
155
156         ModuleMXBeanEntryBuilder builder = new ModuleMXBeanEntryBuilder().setModule(currentModule).setqNamesToSIEs(qNamesToSIEs)
157                 .setSchemaContext(schemaContext).setTypeProviderWrapper(typeProviderWrapper)
158                 .setPackageName(packageName);
159
160         return builder.build();
161     }
162
163     public Map<String, AttributeIfc> getAttributes() {
164         return yangToAttributes;
165     }
166
167     void setYangToAttributes(Map<String, AttributeIfc> newAttributes) {
168         this.yangToAttributes = newAttributes;
169     }
170
171     public String getNullableDescription() {
172         return initial.description;
173     }
174
175     public QName getYangModuleQName() {
176         return initial.qName;
177     }
178
179     @Override
180     public String toString() {
181         return "ModuleMXBeanEntry{" + "globallyUniqueName='"
182                 + initial.localName + '\'' + ", packageName='" + initial.packageName
183                 + '\'' + '}';
184     }
185
186     public String getNullableDummyContainerName() {
187         return nullableDummyContainerName;
188     }
189
190     public void setNullableDummyContainerName(String nullableDummyContainerName) {
191         this.nullableDummyContainerName = nullableDummyContainerName;
192     }
193
194
195     static final class ModuleMXBeanEntryInitial {
196
197         private String localName;
198         private String description;
199         private String packageName;
200         private String javaNamePrefix;
201         private String namespace;
202         private QName qName;
203
204         ModuleMXBeanEntryInitial(String localName, String description, String packageName, String javaNamePrefix, String namespace, QName qName) {
205             this.localName = localName;
206             this.description = description;
207             this.packageName = packageName;
208             this.javaNamePrefix = javaNamePrefix;
209             this.namespace = namespace;
210             this.qName = qName;
211         }
212     }
213
214     static final class ModuleMXBeanEntryInitialBuilder {
215         private String localName;
216         private String description;
217         private String packageName;
218         private String javaNamePrefix;
219         private String namespace;
220         private QName qName;
221
222         public ModuleMXBeanEntryInitialBuilder setPackageName(String packageName) {
223             this.packageName = packageName;
224             return this;
225         }
226
227         public ModuleMXBeanEntryInitialBuilder setJavaNamePrefix(String javaNamePrefix) {
228             this.javaNamePrefix = javaNamePrefix;
229             return this;
230         }
231
232         public ModuleMXBeanEntryInitialBuilder setNamespace(String namespace) {
233             this.namespace = namespace;
234             return this;
235         }
236
237         public ModuleMXBeanEntryInitialBuilder setqName(QName qName) {
238             this.qName = qName;
239             return this;
240         }
241
242         public ModuleMXBeanEntry.ModuleMXBeanEntryInitial build() {
243             return new ModuleMXBeanEntry.ModuleMXBeanEntryInitial(localName, description, packageName, javaNamePrefix, namespace, qName);
244         }
245
246         public ModuleMXBeanEntryInitialBuilder setIdSchemaNode(IdentitySchemaNode idSchemaNode) {
247             this.localName = idSchemaNode.getQName().getLocalName();
248             this.description = idSchemaNode.getDescription();
249             return this;
250         }
251
252     }
253 }