Adjust to yangtools-2.0.0 changes
[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  */
60 public class ModuleMXBeanEntry extends AbstractEntry {
61
62     private static final String MODULE_SUFFIX = "Module";
63     private static final String FACTORY_SUFFIX = MODULE_SUFFIX + "Factory";
64     private static final String CLASS_NAME_SUFFIX = MODULE_SUFFIX + "MXBean";
65     private static final String ABSTRACT_PREFIX = "Abstract";
66
67     private final ModuleMXBeanEntryInitial initial;
68
69     private Map<String, AttributeIfc> yangToAttributes;
70
71     private final Map<String, QName> providedServices;
72
73     private Collection<RuntimeBeanEntry> runtimeBeans;
74     private String nullableDummyContainerName;
75
76     ModuleMXBeanEntry(final ModuleMXBeanEntryInitial initials, final Map<String, AttributeIfc> yangToAttributes,
77             final Map<String, QName> providedServices2, final Collection<RuntimeBeanEntry> runtimeBeans) {
78         this.yangToAttributes = yangToAttributes;
79         this.providedServices = Collections.unmodifiableMap(providedServices2);
80         this.runtimeBeans = runtimeBeans;
81         this.initial = initials;
82     }
83
84     public String getMXBeanInterfaceName() {
85         return initial.javaNamePrefix + CLASS_NAME_SUFFIX;
86     }
87
88     public String getStubFactoryName() {
89         return initial.javaNamePrefix + FACTORY_SUFFIX;
90     }
91
92     public String getAbstractFactoryName() {
93         return ABSTRACT_PREFIX + getStubFactoryName();
94     }
95
96     public String getStubModuleName() {
97         return initial.javaNamePrefix + MODULE_SUFFIX;
98     }
99
100     public String getAbstractModuleName() {
101         return ABSTRACT_PREFIX + getStubModuleName();
102     }
103
104     public String getFullyQualifiedName(final String typeName) {
105         return FullyQualifiedNameHelper.getFullyQualifiedName(initial.packageName,
106                 typeName);
107     }
108
109     public String getGloballyUniqueName() {
110         return initial.localName;
111     }
112
113     public String getPackageName() {
114         return initial.packageName;
115     }
116
117     /**
118      * @return services implemented by this module. Keys are fully qualified
119      *         java names of generated ServiceInterface classes, values are
120      *         identity local names.
121      */
122     public Map<String, QName> getProvidedServices() {
123         return providedServices;
124     }
125
126     public void setRuntimeBeans(final Collection<RuntimeBeanEntry> newRuntimeBeans) {
127         runtimeBeans = newRuntimeBeans;
128     }
129
130     public Collection<RuntimeBeanEntry> getRuntimeBeans() {
131         return runtimeBeans;
132     }
133
134     public String getJavaNamePrefix() {
135         return initial.javaNamePrefix;
136     }
137
138     public String getNamespace() {
139         return initial.namespace;
140     }
141
142     /**
143      * Transform module to zero or more ModuleMXBeanEntry instances. Each
144      * instance must have a globally unique local name.
145      *
146      * @return Map of identity local names as keys, and ModuleMXBeanEntry
147      *         instances as values
148      */
149     public static Map<String/* identity local name */, ModuleMXBeanEntry> create(
150             final Module currentModule,
151             final Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
152             final SchemaContext schemaContext,
153             final TypeProviderWrapper typeProviderWrapper, final String packageName) {
154
155         ModuleMXBeanEntryBuilder builder = new ModuleMXBeanEntryBuilder().setModule(currentModule).setqNamesToSIEs(qNamesToSIEs)
156                 .setSchemaContext(schemaContext).setTypeProviderWrapper(typeProviderWrapper)
157                 .setPackageName(packageName);
158
159         return builder.build();
160     }
161
162     public Map<String, AttributeIfc> getAttributes() {
163         return yangToAttributes;
164     }
165
166     void setYangToAttributes(final Map<String, AttributeIfc> newAttributes) {
167         this.yangToAttributes = newAttributes;
168     }
169
170     public String getNullableDescription() {
171         return initial.description;
172     }
173
174     public QName getYangModuleQName() {
175         return initial.qName;
176     }
177
178     @Override
179     public String toString() {
180         return "ModuleMXBeanEntry{" + "globallyUniqueName='"
181                 + initial.localName + '\'' + ", packageName='" + initial.packageName
182                 + '\'' + '}';
183     }
184
185     public String getNullableDummyContainerName() {
186         return nullableDummyContainerName;
187     }
188
189     public void setNullableDummyContainerName(final String nullableDummyContainerName) {
190         this.nullableDummyContainerName = nullableDummyContainerName;
191     }
192
193
194     static final class ModuleMXBeanEntryInitial {
195
196         private final String localName;
197         private final String description;
198         private final String packageName;
199         private final String javaNamePrefix;
200         private final String namespace;
201         private final QName qName;
202
203         ModuleMXBeanEntryInitial(final String localName, final String description, final String packageName, final String javaNamePrefix, final String namespace, final QName qName) {
204             this.localName = localName;
205             this.description = description;
206             this.packageName = packageName;
207             this.javaNamePrefix = javaNamePrefix;
208             this.namespace = namespace;
209             this.qName = qName;
210         }
211     }
212
213     static final class ModuleMXBeanEntryInitialBuilder {
214         private String localName;
215         private String description;
216         private String packageName;
217         private String javaNamePrefix;
218         private String namespace;
219         private QName qName;
220
221         public ModuleMXBeanEntryInitialBuilder setPackageName(final String packageName) {
222             this.packageName = packageName;
223             return this;
224         }
225
226         public ModuleMXBeanEntryInitialBuilder setJavaNamePrefix(final String javaNamePrefix) {
227             this.javaNamePrefix = javaNamePrefix;
228             return this;
229         }
230
231         public ModuleMXBeanEntryInitialBuilder setNamespace(final String namespace) {
232             this.namespace = namespace;
233             return this;
234         }
235
236         public ModuleMXBeanEntryInitialBuilder setqName(final QName qName) {
237             this.qName = qName;
238             return this;
239         }
240
241         public ModuleMXBeanEntry.ModuleMXBeanEntryInitial build() {
242             return new ModuleMXBeanEntry.ModuleMXBeanEntryInitial(localName, description, packageName, javaNamePrefix, namespace, qName);
243         }
244
245         public ModuleMXBeanEntryInitialBuilder setIdSchemaNode(final IdentitySchemaNode idSchemaNode) {
246             this.localName = idSchemaNode.getQName().getLocalName();
247             this.description = idSchemaNode.getDescription().orElse(null);
248             return this;
249         }
250
251     }
252 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.