Introduce top-level pom file.
[mdsal.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / TOGenerator.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.GeneratedTransferObject;
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 class. For generating of the source code
18  * is used the template written in XTEND language.
19  *
20  */
21 public final class TOGenerator implements CodeGenerator {
22
23     /**
24      * Generates JAVA source code for generated type <code>Type</code>. The code
25      * is generated according to the template source code template which is
26      * written in XTEND language.
27      */
28     @Override
29     public String generate(Type type) {
30         if (type instanceof GeneratedTransferObject) {
31             final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
32             if(genTO.isUnionType()) {
33                 final UnionTemplate template = new UnionTemplate(genTO);
34                 return template.generate();
35             } else if (genTO.isUnionTypeBuilder()) {
36                 final UnionBuilderTemplate template = new UnionBuilderTemplate(genTO);
37                 return template.generate();
38             } else {
39                 final ClassTemplate template = new ClassTemplate(genTO);
40                 return template.generate();
41             }
42         }
43         return "";
44     }
45
46     @Override
47     public boolean isAcceptable(Type type) {
48         return type instanceof GeneratedTransferObject;
49     }
50
51     @Override
52     public String getUnitName(Type type) {
53         return type.getName();
54     }
55
56 }