Update the API generation code and code generation sample
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / controller / sal / java / api / generator / InterfaceGenerator.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.sal.java.api.generator;\r
9 \r
10 import static org.opendaylight.controller.sal.java.api.generator.Constants.NL;\r
11 import static org.opendaylight.controller.sal.java.api.generator.Constants.RCB;\r
12 import static org.opendaylight.controller.sal.java.api.generator.Constants.TAB;\r
13 \r
14 import java.io.IOException;\r
15 import java.io.StringWriter;\r
16 import java.io.Writer;\r
17 import java.util.List;\r
18 \r
19 import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;\r
20 import org.opendaylight.controller.sal.binding.model.api.Constant;\r
21 import org.opendaylight.controller.sal.binding.model.api.Enumeration;\r
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;\r
23 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;\r
24 import org.opendaylight.controller.sal.binding.model.api.Type;\r
25 \r
26 public class InterfaceGenerator implements CodeGenerator {\r
27 \r
28     public Writer generate(Type type) throws IOException {\r
29         Writer writer = new StringWriter();\r
30         if (type instanceof GeneratedType) {\r
31             GeneratedType genType = (GeneratedType) type;\r
32             \r
33             final List<Constant> constants = genType.getConstantDefinitions();\r
34             final List<MethodSignature> methods = genType.getMethodDefinitions();\r
35             final List<Enumeration> enums = genType.getEnumDefintions();\r
36 \r
37             writer.write(GeneratorUtil.createIfcDeclarationWithPkgName(\r
38                     type.getPackageName(), type.getName(), ""));\r
39             writer.write(NL);\r
40 \r
41             if (constants != null) {\r
42                 for (Constant c : constants) {\r
43                     writer.write(GeneratorUtil.createConstant(c, TAB) + NL);\r
44                 }\r
45                 writer.write(NL);\r
46             }\r
47 \r
48             if (methods != null) {\r
49                 for (MethodSignature m : methods) {\r
50                     writer.write(GeneratorUtil.createMethodDeclaration(m, TAB) + NL);\r
51                 }\r
52                 writer.write(NL);\r
53             }\r
54 \r
55             if (enums != null) {\r
56                 for (Enumeration e : enums) {\r
57                     writer.write(GeneratorUtil.createEnum(e, TAB) + NL);\r
58                 }\r
59                 writer.write(NL);\r
60             }\r
61 \r
62             writer.write(RCB);\r
63         }\r
64         return writer;\r
65     }\r
66 \r
67 }\r

©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.