Merge "HostTracker Bundle Separation"
[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.*;
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
29                                         .getPackageName()));
30                         writer.write(NL + NL);
31                         writer.write(GeneratorUtil.createEnum(enums, ""));
32                 }
33
34                 return writer;
35         }
36
37         public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
38                 final Writer writer = new StringWriter();
39
40                 if (type instanceof Enumeration) {
41                         Enumeration enums = (Enumeration) type;
42                         writer.write(GeneratorUtil.createEnum(enums, indent));
43                 }
44
45                 return writer;
46         }
47
48 }