Comments of source code.
[yangtools.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / 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.yangtools.sal.java.api.generator;
9
10 import org.opendaylight.yangtools.sal.binding.model.api.CodeGenerator;
11 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
12 import org.opendaylight.yangtools.sal.binding.model.api.Type;
13
14 /**
15  * 
16  * Transformator of the data from the virtual form to JAVA source code. The
17  * result source code represents JAVA enumeration. For generation of the source
18  * code is used the template written in XTEND language.
19  * 
20  */
21 public class EnumGenerator implements CodeGenerator {
22
23     @Override
24     public boolean isAcceptable(Type type) {
25         return type instanceof Enumeration;
26     }
27
28     /**
29      * Generates JAVA source code for generated type <code>Type</code>. The code
30      * is generated according to the template source code template which is
31      * written in XTEND language.
32      */
33     @Override
34     public String generate(Type type) {
35         if (type instanceof Enumeration) {
36             final Enumeration enums = (Enumeration) type;
37             final EnumTemplate enumTemplate = new EnumTemplate(enums);
38             return enumTemplate.generate();
39         }
40         return "";
41     }
42
43     @Override
44     public String getUnitName(Type type) {
45         return type.getName();
46     }
47
48 }