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;
60 public class ModuleMXBeanEntry extends AbstractEntry {
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";
67 private final ModuleMXBeanEntryInitial initial;
69 private Map<String, AttributeIfc> yangToAttributes;
71 private final Map<String, QName> providedServices;
73 private Collection<RuntimeBeanEntry> runtimeBeans;
74 private String nullableDummyContainerName;
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;
84 public String getMXBeanInterfaceName() {
85 return initial.javaNamePrefix + CLASS_NAME_SUFFIX;
88 public String getStubFactoryName() {
89 return initial.javaNamePrefix + FACTORY_SUFFIX;
92 public String getAbstractFactoryName() {
93 return ABSTRACT_PREFIX + getStubFactoryName();
96 public String getStubModuleName() {
97 return initial.javaNamePrefix + MODULE_SUFFIX;
100 public String getAbstractModuleName() {
101 return ABSTRACT_PREFIX + getStubModuleName();
104 public String getFullyQualifiedName(final String typeName) {
105 return FullyQualifiedNameHelper.getFullyQualifiedName(initial.packageName,
109 public String getGloballyUniqueName() {
110 return initial.localName;
113 public String getPackageName() {
114 return initial.packageName;
118 * @return services implemented by this module. Keys are fully qualified
119 * java names of generated ServiceInterface classes, values are
120 * identity local names.
122 public Map<String, QName> getProvidedServices() {
123 return providedServices;
126 public void setRuntimeBeans(final Collection<RuntimeBeanEntry> newRuntimeBeans) {
127 runtimeBeans = newRuntimeBeans;
130 public Collection<RuntimeBeanEntry> getRuntimeBeans() {
134 public String getJavaNamePrefix() {
135 return initial.javaNamePrefix;
138 public String getNamespace() {
139 return initial.namespace;
143 * Transform module to zero or more ModuleMXBeanEntry instances. Each
144 * instance must have a globally unique local name.
146 * @return Map of identity local names as keys, and ModuleMXBeanEntry
147 * instances as values
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) {
155 ModuleMXBeanEntryBuilder builder = new ModuleMXBeanEntryBuilder().setModule(currentModule).setqNamesToSIEs(qNamesToSIEs)
156 .setSchemaContext(schemaContext).setTypeProviderWrapper(typeProviderWrapper)
157 .setPackageName(packageName);
159 return builder.build();
162 public Map<String, AttributeIfc> getAttributes() {
163 return yangToAttributes;
166 void setYangToAttributes(final Map<String, AttributeIfc> newAttributes) {
167 this.yangToAttributes = newAttributes;
170 public String getNullableDescription() {
171 return initial.description;
174 public QName getYangModuleQName() {
175 return initial.qName;
179 public String toString() {
180 return "ModuleMXBeanEntry{" + "globallyUniqueName='"
181 + initial.localName + '\'' + ", packageName='" + initial.packageName
185 public String getNullableDummyContainerName() {
186 return nullableDummyContainerName;
189 public void setNullableDummyContainerName(final String nullableDummyContainerName) {
190 this.nullableDummyContainerName = nullableDummyContainerName;
194 static final class ModuleMXBeanEntryInitial {
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;
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;
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;
221 public ModuleMXBeanEntryInitialBuilder setPackageName(final String packageName) {
222 this.packageName = packageName;
226 public ModuleMXBeanEntryInitialBuilder setJavaNamePrefix(final String javaNamePrefix) {
227 this.javaNamePrefix = javaNamePrefix;
231 public ModuleMXBeanEntryInitialBuilder setNamespace(final String namespace) {
232 this.namespace = namespace;
236 public ModuleMXBeanEntryInitialBuilder setqName(final QName qName) {
241 public ModuleMXBeanEntry.ModuleMXBeanEntryInitial build() {
242 return new ModuleMXBeanEntry.ModuleMXBeanEntryInitial(localName, description, packageName, javaNamePrefix, namespace, qName);
245 public ModuleMXBeanEntryInitialBuilder setIdSchemaNode(final IdentitySchemaNode idSchemaNode) {
246 this.localName = idSchemaNode.getQName().getLocalName();
247 this.description = idSchemaNode.getDescription().orElse(null);