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