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