Bug 1029: Remove dead code: sal-schema-repository-api
[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
14 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
15 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 /**
22  * Represents part of yang model that describes a module.
23  *
24  * Example:
25  * <p>
26  * <blockquote>
27  *
28  * <pre>
29  *  identity threadpool-dynamic {
30  *      base config:module-type;
31  *      description "threadpool-dynamic description";
32  *      config:provided-service "th2:threadpool";
33  *      config:provided-service "th2:scheduled-threadpool";
34  *      config:java-name-prefix DynamicThreadPool
35  *  }
36  *  augment "/config:modules/config:module/config:module-type" {
37  *     case threadpool-dynamic {
38  *         when "/config:modules/config:module/config:module-type = 'threadpool-dynamic'";
39  *
40  *         container "configuration" {
41  *             // regular java attribute
42  *             leaf core-size {
43  *                 type uint32;
44  *          }
45  *
46  *             ...
47  *          // dependency
48  *             container threadfactory {
49  *                 uses config:service-ref {
50  *                     refine type {
51  *                         config:required-identity th:threadfactory;
52  *                  }
53  *              }
54  *          }
55  *      }
56  * }
57  * </pre>
58  *
59  * </blockquote>
60  * </p>
61  */
62 public class ModuleMXBeanEntry extends AbstractEntry {
63
64     private static final String MODULE_SUFFIX = "Module";
65     private static final String FACTORY_SUFFIX = MODULE_SUFFIX + "Factory";
66     private static final String CLASS_NAME_SUFFIX = MODULE_SUFFIX + "MXBean";
67     private static final String ABSTRACT_PREFIX = "Abstract";
68
69     private final ModuleMXBeanEntryInitial initial;
70
71     private Map<String, AttributeIfc> yangToAttributes;
72
73     private final Map<String, QName> providedServices;
74
75     private Collection<RuntimeBeanEntry> runtimeBeans;
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     static final class ModuleMXBeanEntryInitial {
187
188         private String localName;
189         private String description;
190         private String packageName;
191         private String javaNamePrefix;
192         private String namespace;
193         private QName qName;
194
195         ModuleMXBeanEntryInitial(String localName, String description, String packageName, String javaNamePrefix, String namespace, QName qName) {
196             this.localName = localName;
197             this.description = description;
198             this.packageName = packageName;
199             this.javaNamePrefix = javaNamePrefix;
200             this.namespace = namespace;
201             this.qName = qName;
202         }
203     }
204
205     static final class ModuleMXBeanEntryInitialBuilder {
206         private String localName;
207         private String description;
208         private String packageName;
209         private String javaNamePrefix;
210         private String namespace;
211         private QName qName;
212
213         public ModuleMXBeanEntryInitialBuilder setPackageName(String packageName) {
214             this.packageName = packageName;
215             return this;
216         }
217
218         public ModuleMXBeanEntryInitialBuilder setJavaNamePrefix(String javaNamePrefix) {
219             this.javaNamePrefix = javaNamePrefix;
220             return this;
221         }
222
223         public ModuleMXBeanEntryInitialBuilder setNamespace(String namespace) {
224             this.namespace = namespace;
225             return this;
226         }
227
228         public ModuleMXBeanEntryInitialBuilder setqName(QName qName) {
229             this.qName = qName;
230             return this;
231         }
232
233         public ModuleMXBeanEntry.ModuleMXBeanEntryInitial build() {
234             return new ModuleMXBeanEntry.ModuleMXBeanEntryInitial(localName, description, packageName, javaNamePrefix, namespace, qName);
235         }
236
237         public ModuleMXBeanEntryInitialBuilder setIdSchemaNode(IdentitySchemaNode idSchemaNode) {
238             this.localName = idSchemaNode.getQName().getLocalName();
239             this.description = idSchemaNode.getDescription();
240             return this;
241         }
242
243     }
244 }