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;
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;
22 * Represents part of yang model that describes a module.
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
36 * augment "/config:modules/config:module/config:module-type" {
37 * case threadpool-dynamic {
38 * when "/config:modules/config:module/config:module-type = 'threadpool-dynamic'";
40 * container "configuration" {
41 * // regular java attribute
48 * container threadfactory {
49 * uses config:service-ref {
51 * config:required-identity th:threadfactory;
62 public class ModuleMXBeanEntry extends AbstractEntry {
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";
69 private final ModuleMXBeanEntryInitial initial;
71 private Map<String, AttributeIfc> yangToAttributes;
73 private final Map<String, QName> providedServices;
75 private Collection<RuntimeBeanEntry> runtimeBeans;
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 static final class ModuleMXBeanEntryInitial {
188 private String localName;
189 private String description;
190 private String packageName;
191 private String javaNamePrefix;
192 private String namespace;
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;
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;
213 public ModuleMXBeanEntryInitialBuilder setPackageName(String packageName) {
214 this.packageName = packageName;
218 public ModuleMXBeanEntryInitialBuilder setJavaNamePrefix(String javaNamePrefix) {
219 this.javaNamePrefix = javaNamePrefix;
223 public ModuleMXBeanEntryInitialBuilder setNamespace(String namespace) {
224 this.namespace = namespace;
228 public ModuleMXBeanEntryInitialBuilder setqName(QName qName) {
233 public ModuleMXBeanEntry.ModuleMXBeanEntryInitial build() {
234 return new ModuleMXBeanEntry.ModuleMXBeanEntryInitial(localName, description, packageName, javaNamePrefix, namespace, qName);
237 public ModuleMXBeanEntryInitialBuilder setIdSchemaNode(IdentitySchemaNode idSchemaNode) {
238 this.localName = idSchemaNode.getQName().getLocalName();
239 this.description = idSchemaNode.getDescription();