Added support to generate interfaces from Choices and Cases.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / controller / sal / java / api / generator / EnumGenerator.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 package org.opendaylight.controller.sal.java.api.generator;
9
10 import static org.opendaylight.controller.sal.java.api.generator.Constants.NL;
11
12 import java.io.IOException;
13 import java.io.StringWriter;
14 import java.io.Writer;
15
16 import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
17 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
18 import org.opendaylight.controller.sal.binding.model.api.Type;
19
20 public class EnumGenerator implements CodeGenerator {
21
22     @Override
23     public Writer generate(Type type) throws IOException {
24         final Writer writer = new StringWriter();
25
26         if (type instanceof Enumeration) {
27             Enumeration enums = (Enumeration) type;
28             writer.write(GeneratorUtil.createPackageDeclaration(enums.getPackageName()));
29             writer.write(NL + NL);
30             writer.write(GeneratorUtil.createEnum(enums, ""));
31         }
32
33         return writer;
34     }
35
36     public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
37         final Writer writer = new StringWriter();
38
39         if (type instanceof Enumeration) {
40             Enumeration enums = (Enumeration) type;
41             writer.write(GeneratorUtil.createEnum(enums, indent));
42         }
43
44         return writer;
45     }
46
47 }