6211efe417973ee0f8faf637669e4f824a1df7f3
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / ModuleFieldSerializer.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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model;
10
11 import org.opendaylight.controller.config.api.JmxAttribute;
12
13 public class ModuleFieldSerializer {
14
15
16     public static String toString(ModuleField moduleField) {
17         StringBuilder builder = new StringBuilder();
18         builder.append("    ");
19         builder.append("public static final "
20                 + JmxAttribute.class.getCanonicalName() + " "
21                 + moduleField.getName() + "JmxAttribute = new "
22                 + JmxAttribute.class.getCanonicalName() + "(\""
23                 + moduleField.getAttributeName() + "\");");
24         builder.append("\n");
25
26         builder.append("     private ");
27         for (String mod : moduleField.getModifiers()) {
28             builder.append(mod + " ");
29         }
30         builder.append(moduleField.getType() + " ");
31         builder.append(moduleField.getName());
32         if (moduleField.getNullableDefault() != null) {
33             builder.append(" = " + moduleField.getNullableDefault());
34         }
35         builder.append(";");
36
37         if (moduleField.isDependent()) {
38             String comment = moduleField.getDependency().isMandatory() ? "mandatory"
39                     : "optional";
40             builder.append(" // " + comment);
41         }
42         builder.append("\n");
43
44         builder.append("\n");
45
46         return builder.toString();
47     }
48 }