abb3e4ccafb4d8ad684c4eef542aca6485d7e03f
[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         builder.append(JmxAttribute.class.getCanonicalName());
21         builder.append(" ");
22         builder.append(moduleField.getName());
23         builder.append("JmxAttribute = new ");
24         builder.append(JmxAttribute.class.getCanonicalName());
25         builder.append("(\"");
26         builder.append(moduleField.getAttributeName());
27         builder.append("\");");
28         builder.append("\n");
29
30         builder.append("     private ");
31         for (String mod : moduleField.getModifiers()) {
32             builder.append(mod).append(" ");
33         }
34         builder.append(moduleField.getType()).append(" ");
35         builder.append(moduleField.getName());
36         if (moduleField.getNullableDefault() != null) {
37             builder.append(" = ").append(moduleField.getNullableDefault());
38         }
39         builder.append(";");
40
41         if (moduleField.isDependent()) {
42             String comment = moduleField.getDependency().isMandatory() ? "mandatory"
43                     : "optional";
44             builder.append(" // ").append(comment);
45         }
46         builder.append("\n");
47
48         builder.append("\n");
49
50         return builder.toString();
51     }
52 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.