2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.sal.java.api.generator;
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.GeneratedType;
13 import org.opendaylight.yangtools.sal.binding.model.api.Type;
14 import org.opendaylight.yangtools.yang.binding.Augmentable;
15 import org.opendaylight.yangtools.yang.binding.Augmentation;
19 * Transformator of the data from the virtual form to JAVA programming language.
20 * The result source code represent java class. For generation of the source
21 * code is used the template written in XTEND language.
24 public final class BuilderGenerator implements CodeGenerator {
27 * Constant used as sufix for builder name.
29 public static final String BUILDER = "Builder";
32 * Passes via list of implemented types in <code>type</code>.
35 * JAVA <code>Type</code>
36 * @return boolean value which is true if any of implemented types is of the
37 * type <code>Augmentable</code>.
40 public boolean isAcceptable(Type type) {
41 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
42 for (Type t : ((GeneratedType) type).getImplements()) {
43 // "rpc" and "grouping" elements do not implement Augmentable
44 if (t.getFullyQualifiedName().equals(Augmentable.class.getName())) {
46 } else if (t.getFullyQualifiedName().equals(Augmentation.class.getName())) {
56 * Generates JAVA source code for generated type <code>Type</code>. The code
57 * is generated according to the template source code template which is
58 * written in XTEND language.
61 public String generate(Type type) {
62 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
63 final GeneratedType genType = (GeneratedType) type;
64 final BuilderTemplate template = new BuilderTemplate(genType);
65 return template.generate();
71 public String getUnitName(Type type) {
72 return type.getName() + BUILDER;