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