2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.yangjmxgenerator;
10 import java.util.Collection;
11 import java.util.Collections;
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;
21 * Represents part of yang model that describes a module.
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
35 * augment "/config:modules/config:module/config:module-type" {
36 * case threadpool-dynamic {
37 * when "/config:modules/config:module/config:module-type = 'threadpool-dynamic'";
39 * container "configuration" {
40 * // regular java attribute
47 * container threadfactory {
48 * uses config:service-ref {
50 * config:required-identity th:threadfactory;
61 public class ModuleMXBeanEntry extends AbstractEntry {
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";
68 private final ModuleMXBeanEntryInitial initial;
70 private Map<String, AttributeIfc> yangToAttributes;
72 private final Map<String, QName> providedServices;
74 private Collection<RuntimeBeanEntry> runtimeBeans;
75 private String nullableDummyContainerName;
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;
85 public String getMXBeanInterfaceName() {
86 return initial.javaNamePrefix + CLASS_NAME_SUFFIX;
89 public String getStubFactoryName() {
90 return initial.javaNamePrefix + FACTORY_SUFFIX;
93 public String getAbstractFactoryName() {
94 return ABSTRACT_PREFIX + getStubFactoryName();
97 public String getStubModuleName() {
98 return initial.javaNamePrefix + MODULE_SUFFIX;
101 public String getAbstractModuleName() {
102 return ABSTRACT_PREFIX + getStubModuleName();
105 public String getFullyQualifiedName(String typeName) {
106 return FullyQualifiedNameHelper.getFullyQualifiedName(initial.packageName,
110 public String getGloballyUniqueName() {
111 return initial.localName;
114 public String getPackageName() {
115 return initial.packageName;
119 * @return services implemented by this module. Keys are fully qualified
120 * java names of generated ServiceInterface classes, values are
121 * identity local names.
123 public Map<String, QName> getProvidedServices() {
124 return providedServices;
127 public void setRuntimeBeans(Collection<RuntimeBeanEntry> newRuntimeBeans) {
128 runtimeBeans = newRuntimeBeans;
131 public Collection<RuntimeBeanEntry> getRuntimeBeans() {
135 public String getJavaNamePrefix() {
136 return initial.javaNamePrefix;
139 public String getNamespace() {
140 return initial.namespace;
144 * Transform module to zero or more ModuleMXBeanEntry instances. Each
145 * instance must have a globally unique local name.
147 * @return Map of identity local names as keys, and ModuleMXBeanEntry
148 * instances as values
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) {
156 ModuleMXBeanEntryBuilder builder = new ModuleMXBeanEntryBuilder().setModule(currentModule).setqNamesToSIEs(qNamesToSIEs)
157 .setSchemaContext(schemaContext).setTypeProviderWrapper(typeProviderWrapper)
158 .setPackageName(packageName);
160 return builder.build();
163 public Map<String, AttributeIfc> getAttributes() {
164 return yangToAttributes;
167 void setYangToAttributes(Map<String, AttributeIfc> newAttributes) {
168 this.yangToAttributes = newAttributes;
171 public String getNullableDescription() {
172 return initial.description;
175 public QName getYangModuleQName() {
176 return initial.qName;
180 public String toString() {
181 return "ModuleMXBeanEntry{" + "globallyUniqueName='"
182 + initial.localName + '\'' + ", packageName='" + initial.packageName
186 public String getNullableDummyContainerName() {
187 return nullableDummyContainerName;
190 public void setNullableDummyContainerName(String nullableDummyContainerName) {
191 this.nullableDummyContainerName = nullableDummyContainerName;
195 static final class ModuleMXBeanEntryInitial {
197 private String localName;
198 private String description;
199 private String packageName;
200 private String javaNamePrefix;
201 private String namespace;
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;
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;
222 public ModuleMXBeanEntryInitialBuilder setPackageName(String packageName) {
223 this.packageName = packageName;
227 public ModuleMXBeanEntryInitialBuilder setJavaNamePrefix(String javaNamePrefix) {
228 this.javaNamePrefix = javaNamePrefix;
232 public ModuleMXBeanEntryInitialBuilder setNamespace(String namespace) {
233 this.namespace = namespace;
237 public ModuleMXBeanEntryInitialBuilder setqName(QName qName) {
242 public ModuleMXBeanEntry.ModuleMXBeanEntryInitial build() {
243 return new ModuleMXBeanEntry.ModuleMXBeanEntryInitial(localName, description, packageName, javaNamePrefix, namespace, qName);
246 public ModuleMXBeanEntryInitialBuilder setIdSchemaNode(IdentitySchemaNode idSchemaNode) {
247 this.localName = idSchemaNode.getQName().getLocalName();
248 this.description = idSchemaNode.getDescription();