1 package org.opendaylight.yangtools.sal.java.api.generator;
3 import org.opendaylight.yangtools.sal.binding.model.api.CodeGenerator;
4 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
5 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
6 import org.opendaylight.yangtools.sal.binding.model.api.Type;
7 import org.opendaylight.yangtools.yang.binding.Augmentable;
8 import org.opendaylight.yangtools.yang.binding.Augmentation;
12 * Transformator of the data from the virtual form to JAVA programming language.
13 * The result source code represent java class. For generation of the source
14 * code is used the template written in XTEND language.
17 public final class BuilderGenerator implements CodeGenerator {
20 * Constant used as sufix for builder name.
22 public static final String BUILDER = "Builder";
25 * Passes via list of implemented types in <code>type</code>.
28 * JAVA <code>Type</code>
29 * @return boolean value which is true if any of implemented types is of the
30 * type <code>Augmentable</code>.
33 public boolean isAcceptable(Type type) {
34 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
35 for (Type t : ((GeneratedType) type).getImplements()) {
36 // "rpc" and "grouping" elements do not implement Augmentable
37 if (t.getFullyQualifiedName().equals(Augmentable.class.getName())) {
39 } else if (t.getFullyQualifiedName().equals(Augmentation.class.getName())) {
49 * Generates JAVA source code for generated type <code>Type</code>. The code
50 * is generated according to the template source code template which is
51 * written in XTEND language.
54 public String generate(Type type) {
55 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
56 final GeneratedType genType = (GeneratedType) type;
57 final BuilderTemplate template = new BuilderTemplate(genType);
58 return template.generate();
64 public String getUnitName(Type type) {
65 return type.getName() + BUILDER;